Quellcode durchsuchen

Upgrade to v 7.2.0. Reimplemented categories support

Ivan Arkhipov vor 6 Jahren
Ursprung
Commit
20b25d0e75

+ 11 - 0
CHANGELOG

@@ -59,3 +59,14 @@ Version 5.2.0
     * Improved speed of opening .dat file by visiting each directory only once.
     * Removed DatException class and all it's calls. Throwing exceptions changed to returning special null data.
 ----------------------------------------------------------------------
+Version 7.0.0
+    * Everything except some simpliest modules or structures was rewritten
+    * Logic part divided into submodules (DatIO, DatFileSystem, DatBackupManager, DatExporter, DatLocaleManager, DatPatcher, DatStatus)
+    * Slightly improved stability, added extra features (normal backup, operation status & percentage and so on)
+----------------------------------------------------------------------
+Version 7.1.0
+    * Improved security, added special fields, which help to recognize whether .dat file was broken
+----------------------------------------------------------------------
+Version 7.2.0
+    * Minor security fixes
+    * Reimplemented categories support

+ 1 - 1
CMakeLists.txt

@@ -5,7 +5,7 @@ set(CMAKE_CXX_STANDARD 14)
 set(PROJECT_BINARY_DIR bin)
 set(PROJECT_VERSION 7.1.0)
 
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS} -Wall -Wextra")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS} -Wall -Wextra -O2")
 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
 
 if (MSVS)

+ 4 - 0
include/DatSubsystems/DatLocaleManager.h

@@ -67,6 +67,10 @@ namespace LOTRO_DAT {
 
         void UpdateCategory(long long file_id, long long category);
 
+        DatOperationResult<> EnableCategory(long long category);
+
+        DatOperationResult<> DisableCategory(long long category);
+
         const std::set<long long>& GetInactiveCategories();
 
     private:

+ 65 - 2
src/DatSubsystems/DatLocaleManager.cpp

@@ -107,7 +107,7 @@ namespace LOTRO_DAT {
         offset += 4;
         for (size_t i = 0; i < orig_dict_size; i++) {
             auto file = SubFile(*dat, dicts_data.CutData(offset, offset + 32));
-            file.category = dicts_data.ToNumber<4>(offset);
+            file.category = dicts_data.ToNumber<4>(offset + 32);
             orig_dict_[file.file_id()] = file;
             offset += 36;
         }
@@ -116,13 +116,22 @@ namespace LOTRO_DAT {
         offset += 4;
         for (size_t i = 0; i < patch_dict_size; i++) {
             auto file = SubFile(*dat, dicts_data.CutData(offset, offset + 32));
-            file.category = dicts_data.ToNumber<4>(offset);
+            file.category = dicts_data.ToNumber<4>(offset + 32);
             patch_dict_[file.file_id()] = file;
             offset += 36;
         }
 
+        size_t inactive_categories_set_size = size_t(dicts_data.ToNumber<4>(offset));
+        offset += 4;
+        for (size_t i = 0; i < inactive_categories_set_size; i++) {
+            size_t category_id = size_t(dicts_data.ToNumber<4>(offset));
+            inactive_categories.insert(category_id);
+            offset += 4;
+        }
+
         LOG(INFO) << "There are " << patch_dict_.size() << " files in patch locale dictionary";
         LOG(INFO) << "There are " << orig_dict_.size() << " files in original locale dictionary";
+        LOG(INFO) << "There are " << inactive_categories.size() << " categories inactive: ";
         LOG(INFO) << "Finished initialising locales";
 
         if (CheckLocaleCorrect()) {
@@ -170,7 +179,17 @@ namespace LOTRO_DAT {
         }
 
         std::map<long long, SubFile> &dict = GetLocaleDictReference(locale);
+
+        size_t files_total = dict.size();
+        size_t files_proceeded = 0;
+
         for (const auto &file : dict) {
+            ++files_proceeded;
+            dat->GetStatusModule().SetPercentage(files_proceeded * 100 / files_total);
+
+            if (CategoryIsInactive(file.second.category) && locale == PATCHED)
+                continue;
+
             long long file_id = file.first;
 
             auto dict_file_result = dat->GetFileSystem().GetFile(file_id);
@@ -534,4 +553,48 @@ namespace LOTRO_DAT {
         inactive_categories.clear();
         current_locale_ = LOCALE(-1);
     }
+
+    DatOperationResult<> DatLocaleManager::EnableCategory(long long category) {
+        inactive_categories.erase(category);
+        dat->GetStatusModule().SetStatus(DatStatus::E_COMMITING);
+        dat->GetStatusModule().SetPercentage(0);
+
+        size_t files_count = patch_dict_.size();
+        size_t files_processed = 0;
+
+        for (const auto& entry : patch_dict_) {
+            SubFile file = entry.second;
+            ++files_processed;
+            dat->GetStatusModule().SetPercentage(files_processed * 100 / files_count);
+
+            if (file.category == category) {
+                dat->GetFileSystem().UpdateFileInfo(file);
+            }
+        }
+
+        dat->GetStatusModule().ClearAll();
+        return DatOperationResult<>(SUCCESS);
+    }
+
+    DatOperationResult<> DatLocaleManager::DisableCategory(long long category) {
+        inactive_categories.insert(category);
+        dat->GetStatusModule().SetStatus(DatStatus::E_COMMITING);
+        dat->GetStatusModule().SetPercentage(0);
+
+        size_t files_count = orig_dict_.size();
+        size_t files_processed = 0;
+
+        for (const auto& entry : orig_dict_) {
+            SubFile file = entry.second;
+            ++files_processed;
+            dat->GetStatusModule().SetPercentage(files_processed * 100 / files_count);
+
+            if (file.category == category) {
+                dat->GetFileSystem().UpdateFileInfo(file);
+            }
+        }
+
+        dat->GetStatusModule().ClearAll();
+        return DatOperationResult<>(SUCCESS);
+    }
 }

+ 9 - 2
src/DatSubsystems/DatPatcher.cpp

@@ -138,6 +138,13 @@ namespace LOTRO_DAT {
             dat->GetLocaleManager().SetLocale(DatLocaleManager::PATCHED);
         }
 
+        if (dat->GetLocaleManager().CategoryIsInactive(file->category) &&
+            dat->GetLocaleManager().GetLocaleFile(file_id, DatLocaleManager::PATCHED).result == SUCCESS)
+        {
+            dat->GetFileSystem().UpdateFileInfo(
+                    dat->GetLocaleManager().GetLocaleFile(file_id, DatLocaleManager::PATCHED).value);
+        }
+
         //LOG(INFO) << "Patching file with id = " << file_id;
 
         if (dat->GetLocaleManager().GetLocaleFile(file_id, DatLocaleManager::ORIGINAL).result == ERROR)
@@ -167,17 +174,17 @@ namespace LOTRO_DAT {
             return DatOperationResult<>(ERROR, "APPLYPATCHFILE: Unable to write data for file with id " +
                                                std::to_string(file_id));
 
-
         dat->GetFileSystem().UpdateFileInfo(new_file);
         dat->GetLocaleManager().UpdateLocaleFile(DatLocaleManager::PATCHED, new_file);
 
 
         // If file category is inactive, then return file header data in dictionary to original state
+        dat->GetLocaleManager().UpdateCategory(file_id, new_file.category);
+
         if (dat->GetLocaleManager().CategoryIsInactive(new_file.category))
             dat->GetFileSystem().UpdateFileInfo(
                     dat->GetLocaleManager().GetLocaleFile(file_id, DatLocaleManager::ORIGINAL).value);
 
-        dat->GetLocaleManager().UpdateCategory(file_id, new_file.category);
         //LOG(INFO) << "Successfully patched file with id = " << file_id;
 
         return DatOperationResult<>(SUCCESS);

+ 1 - 1
src/Examples/extractor_example.cpp

@@ -32,7 +32,7 @@ bool exportUnknownToDb = false;
 // There is no need to change anything else
 
 int main() {
-    std::cout << "Gi1dor's LotRO .dat extractor ver. 7.1.0" << std::endl;
+    std::cout << "Gi1dor's LotRO .dat extractor ver. 7.2.0" << std::endl;
 
     std::cout << "Hello! I'm a basic shell version of .dat file extractor. I can open .dat file directly, "
             "if you write path to it (with name of file) in file \"dat_file_path.txt\"\n";

+ 1 - 1
src/Examples/info_gatherer.cpp

@@ -11,7 +11,7 @@ using namespace LOTRO_DAT;
 #include <ctime>
 
 int main() {
-    std::cout << "Gi1dor's LotRO .dat patcher ver. 7.1.0" << std::endl;
+    std::cout << "Gi1dor's LotRO .dat patcher ver. 7.2.0" << std::endl;
     freopen("patcher_errors.log", "w", stderr);
 
     setbuf(stdout, nullptr);

+ 16 - 17
src/Examples/patcher_example.cpp

@@ -15,7 +15,7 @@ using namespace LOTRO_DAT;
 using namespace std;
 
 int main() {
-    std::cout << "Gi1dor's LotRO .dat patcher ver. 7.1.0" << std::endl;
+    std::cout << "Gi1dor's LotRO .dat patcher ver. 7.2.0" << std::endl;
     freopen("patcher_errors.log", "w", stderr);
 
     setbuf(stdout, nullptr);
@@ -61,7 +61,6 @@ int main() {
                 "print disabled categories (enter 6), create backup (enter 7), remove backup (enter 8), "
                 "restore .dat file from backup (enter 9), check if backup exists (enter 10) or exit (enter -1)\n";
 
-        std::cout << "\n=================\nOptions 4,5 are currently unavailable\n";
         int cmd = 0;
         std::cout << "Enter number of command (1-10): ";
         std::cin >> cmd;
@@ -142,21 +141,21 @@ int main() {
             std::cout << "Current locale is " << (file.GetLocaleManager().GetCurrentLocale() == DatLocaleManager::PATCHED ? "RU" : "Original") << endl;
         }
 
-//        if (cmd == 4) {
-//            int category_id = 0;
-//            std::cout << "Enter category id: ";
-//            std::cin >> category_id;
-//            file.EnableCategory(category_id);
-//            std::cout << "Category successfully enabled!" << std::endl;
-//        }
-
-//        if (cmd == 5) {
-//            int category_id = 0;
-//            std::cout << "Enter category id: ";
-//            std::cin >> category_id;
-//            file.GetLocaleManager().Ca DisableCategory(category_id);
-//            std::cout << "Category successfully disabled!" << std::endl;
-//        }
+        if (cmd == 4) {
+            int category_id = 0;
+            std::cout << "Enter category id: ";
+            std::cin >> category_id;
+            file.GetLocaleManager().EnableCategory(category_id);
+            std::cout << "Category successfully enabled!" << std::endl;
+        }
+
+        if (cmd == 5) {
+            int category_id = 0;
+            std::cout << "Enter category id: ";
+            std::cin >> category_id;
+            file.GetLocaleManager().DisableCategory(category_id);
+            std::cout << "Category successfully disabled!" << std::endl;
+        }
 
         if (cmd == 6) {
             std::cout << "Disabled categories: ";