Browse Source

Basically implemented version managementt in dat file

Ivan Arkhipov 3 years ago
parent
commit
aceb6b1224

+ 1 - 1
import/LotroDat/DatFile.h

@@ -37,7 +37,7 @@ class DatFile {
 	size_t GetFilesNumInDatFile();
 
   	size_t PatchAllFilesFromDatabase(Database& db);
-	void PatchFile(SubfileData file_data, int version = -1, int iteration = -1);
+	void PatchFile(SubfileData file_data, int version = -1, int iteration = -1, bool create = false);
   	void PatchFile(int file_id, FILE_TYPE type, std::string path_to_file, int version = -1, int iteration = -1);
 
 	FILE_TYPE GetExistingFileType(int file_id);

+ 1 - 1
import/LotroDat/Database.h

@@ -18,7 +18,7 @@ class Database {
 
   ~Database();
 
-  bool InitDatabase(const std::string &filename);
+  bool InitDatabase(const std::string &filename, bool create_if_not_exists=false);
 
   bool CloseDatabase();
 

+ 27 - 7
src/Legacy/models/patchinstaller.cpp

@@ -118,7 +118,7 @@ void PatchInstaller::installPatch(QString patch_name, LOTRO_DAT::Database* datab
             qWarning() << "Unknown dat id parameter for file " << file.options["fid"].as<long long>() << " (dat id value = " << dat_id << "), SKIPPING!";
         }
 
-        if (file_version != 721359) {
+        if (file_version != _patch_files_versions) {
             const QString query = "INSERT INTO `patch_data` (`file_id`, `options`) VALUES ('"
                     + QString::number(file_id) + "', '" + QString::number(file_version)
                     + "') ON CONFLICT(`file_id`) DO UPDATE SET `options`='" + QString::number(file_version) + "';";
@@ -256,9 +256,29 @@ PatchInstaller::AppliedPatchesInfo PatchInstaller::getAppliedPatchesInfoFromDatF
     if (patch_versions_file.Empty()) {
         result.has_no_patch_mark = true;
     } else {
+        const QString text_data = QString::fromUtf8(reinterpret_cast<const char*>(patch_versions_file.binary_data.data() + 4), patch_versions_file.binary_data.size() - 4);
+        const QStringList text_data_splitted = text_data.split("\n");
+        if (text_data_splitted.length() < 0 || text_data_splitted[0] != _patch_mark_header) {
+            return result;
+        }
         result.has_no_patch_mark = false;
-//        const QString text_data = QString::fromUtf16(reinterpret_cast<const ushort*>(patch_versions_file.binary_data.data()), patch_versions_file.binary_data.size() / sizeof(ushort));
-//        qDebug() << "AAAAAAAAA PATCH INFO TEXT DATA " << text_data;
+        for (const QString& str: text_data_splitted) {
+            if (str.startsWith("TEXTS:")) {
+                result.texts_patch_hashsum = QString(str).remove(0, 6);
+            } else if (str.startsWith("IMAGES:")) {
+                result.images_patch_hashsum = QString(str).remove(0, 7);
+            } else if (str.startsWith("SOUNDS:")) {
+                result.sounds_patch_hashsum = QString(str).remove(0, 7);
+            } else if (str.startsWith("LOADSCREENS:")) {
+                result.loadscreens_patch_hashsum = QString(str).remove(0, 12);
+            } else if (str.startsWith("TEXTURES:")) {
+                result.textures_patch_hashsum = QString(str).remove(0, 9);
+            } else if (str.startsWith("FONTS:")) {
+                result.fonts_patch_hashsum = QString(str).remove(0, 6);
+            } else if (str.startsWith("VIDEOS:")) {
+                result.videos_patch_hashsum = QString(str).remove(0, 6);
+            }
+        }
     }
     // TODO: PATCHED BY OLD LEGACY CHECK
     return result;
@@ -269,7 +289,7 @@ void PatchInstaller::insertPatchesInfoInDatFile(const PatchInstaller::AppliedPat
     file_data.options["fid"] = _applied_patches_file_id;
     file_data.options["ext"] = LOTRO_DAT::StringFromFileType(LOTRO_DAT::TEXT);
 
-    QString patches_info_data = "1::::::[HI_FROM_ENDEVIR_V2.0\n";
+    QString patches_info_data = _patch_mark_header + "\n";
     patches_info_data += "TEXTS:" + info.texts_patch_hashsum + "\n";
     patches_info_data += "IMAGES:" + info.images_patch_hashsum + "\n";
     patches_info_data += "SOUNDS:" + info.sounds_patch_hashsum + "\n";
@@ -277,10 +297,10 @@ void PatchInstaller::insertPatchesInfoInDatFile(const PatchInstaller::AppliedPat
     patches_info_data += "TEXTURES:" + info.textures_patch_hashsum + "\n";
     patches_info_data += "FONTS:" + info.fonts_patch_hashsum + "\n";
     patches_info_data += "VIDEOS:" + info.videos_patch_hashsum + "\n";
-    patches_info_data += "]";
 
-    file_data.text_data = patches_info_data.toStdU16String();
-    client_local_file_->PatchFile(file_data);
+    QByteArray data = QByteArray((char*)&_applied_patches_file_id, 4) + patches_info_data.toUtf8();
+    file_data.binary_data = LOTRO_DAT::BinaryData(data.data(), data.size());
+    client_local_file_->PatchFile(file_data, _patch_files_versions, 1, true);
 }
 
 

+ 4 - 1
src/Legacy/models/patchinstaller.h

@@ -93,9 +93,12 @@ private:
 //    const QString upset_table_value_query = "INSERT INTO `patch_data` (`file_id`, ``) VALUES (?);";
     AppliedPatchesInfo _current_applied_patches_info;
     Status current_status;
-    const int _applied_patches_file_id = 0x2500F0F0;
+    const QString _patch_mark_header = "HI_FROM_ENDEVIR_V2.0";
+    const int _applied_patches_file_id = 0x23F4F0F0;
+    const int _patch_files_versions = 721359;
     int download_video_finished_videos = 0;
     int download_video_total_videos = 0;
+
 };
 
 Q_DECLARE_METATYPE(PatchInstaller::Status)