|
@@ -76,6 +76,29 @@ void DatFile::Deinit() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+bool DatFile::checkIfPatchedByLegacyV1(const std::string& filename) {
|
|
|
+ FILE* file_handler = fopen(filename.c_str(), "r+b");
|
|
|
+ if (file_handler == nullptr) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ BinaryData data(1024);
|
|
|
+ fread(data.data(), 1024, 1, file_handler);
|
|
|
+ fclose(file_handler);
|
|
|
+ return (data.ToNumber<4>(0x128) != 0 || data.ToNumber<4>(0x12C) != 0);
|
|
|
+}
|
|
|
+
|
|
|
+int DatFile::GetDatFileMaxIteration() const {
|
|
|
+ int subfiles_num = api_.GetNumSubfiles(file_handle_);
|
|
|
+ int max_iteration = -1;
|
|
|
+ for (int i = 0; i < subfiles_num; ++i) {
|
|
|
+ SubfileInfo file_info;
|
|
|
+ api_.GetSubfileSizes(file_handle_, &file_info.file_id, &file_info.size, &file_info.iteration, i, 1);
|
|
|
+ max_iteration = std::max(max_iteration, file_info.iteration);
|
|
|
+ }
|
|
|
+
|
|
|
+ return max_iteration;
|
|
|
+}
|
|
|
+
|
|
|
bool DatFile::Initialized() const{
|
|
|
return initialized_;
|
|
|
}
|
|
@@ -120,17 +143,24 @@ size_t DatFile::PatchAllFilesFromDatabase(Database& db) {
|
|
|
return patched_files_num;
|
|
|
}
|
|
|
|
|
|
-void DatFile::PatchFile(SubfileData file_data, int version, int iteration) {
|
|
|
+void DatFile::PatchFile(SubfileData file_data, int version, int iteration, bool create) {
|
|
|
if (!file_data.options["fid"]) {
|
|
|
LOG(ERROR) << "Trying to patch file, but file id is not specified, skipping!";
|
|
|
return;
|
|
|
}
|
|
|
int file_id = file_data.options["fid"].as<int>();
|
|
|
|
|
|
- if (files_info_.count(file_id) == 0) {
|
|
|
+ if (files_info_.count(file_id) == 0 && !create) {
|
|
|
LOG(ERROR) << "Trying to patch file, not existing in files_info. File id = " << file_id;
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ if (create) {
|
|
|
+ BinaryData file = file_data.binary_data;
|
|
|
+ api_.PutSubfileData(file_handle_, file_id, file.data(), 0, file.size(), version, iteration);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
const SubfileInfo& file_info = files_info_[file_id];
|
|
|
|
|
|
int existing_file_version = 0; // will be evaluated with api_.GetSubfileData
|