Browse Source

Added DatStatus module, changed DatFile getters declaration to uppercase

Ivan Arkhipov 5 years ago
parent
commit
24371695f2

+ 3 - 3
CMakeLists.txt

@@ -5,7 +5,7 @@ set(CMAKE_CXX_STANDARD 14)
 set(PROJECT_BINARY_DIR bin)
 set(PROJECT_VERSION 5.2.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} -O3 -Wall -Wextra")
 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
 
 if (MSVS)
@@ -47,7 +47,7 @@ set(HEADER_FILES
         ${CMAKE_SOURCE_DIR}/include/DatSubsystems/DatIO.h
         ${CMAKE_SOURCE_DIR}/include/DatSubsystems/DatLocaleManager.h
         ${CMAKE_SOURCE_DIR}/include/DatSubsystems/DatPatcher.h
-        )
+        ${CMAKE_SOURCE_DIR}/include/DatSubsystems/DatStatus.h)
 
 set(SOURCE_FILES
         ${CMAKE_SOURCE_DIR}/src/DatFile.cpp
@@ -73,7 +73,7 @@ set(SOURCE_FILES
         ${CMAKE_SOURCE_DIR}/src/DatSubsystems/DatIO.cpp
         ${CMAKE_SOURCE_DIR}/src/DatSubsystems/DatLocaleManager.cpp
         ${CMAKE_SOURCE_DIR}/src/DatSubsystems/DatPatcher.cpp
-        )
+        ${CMAKE_SOURCE_DIR}/src/DatSubsystems/DatStatus.cpp)
 
 set(CompilerFlags
         CMAKE_CXX_FLAGS

BIN
bin/LotRO_dat_extractor.exe


BIN
bin/LotRO_dat_patcher.exe


+ 11 - 12
include/DatFile.h

@@ -18,6 +18,7 @@
 #include "DatSubsystems/DatIO.h"
 #include "DatSubsystems/DatLocaleManager.h"
 #include "DatSubsystems/DatPatcher.h"
+#include "DatSubsystems/DatStatus.h"
 
 // Dat file names definitions
 
@@ -35,12 +36,6 @@ namespace LOTRO_DAT {
     };
 
     class DatFile {
-        friend class DatIO;
-        friend class DatFileSystem;
-        friend class DatLocaleManager;
-        friend class DatPatcher;
-        friend class DatExporter;
-        friend class DatBackupManager;
 
     public:
         DatFile();
@@ -50,17 +45,19 @@ namespace LOTRO_DAT {
         DatFile &operator=(DatFile &&other) = default;
         ~DatFile();
 
-        DatLocaleManager &getLocaleManager();
-        DatExporter &getExporter();
-        DatPatcher &getPatcher();
-        DatBackupManager &getBackupManager();
-        DatIO &getIO();
-        DatFileSystem &getFileSystem();
+        DatLocaleManager &GetLocaleManager();
+        DatExporter &GetExporter();
+        DatPatcher &GetPatcher();
+        DatBackupManager &GetBackupManager();
+        DatIO &GetIO();
+        DatFileSystem &GetFileSystem();
+        DatStatus &GetStatusModule();
 
         DatOperationResult<> Initialise(const std::string &filename, long long dat_id);
         DatOperationResult<> GatherInformation(const std::string &output_filename);
         DatOperationResult<> Deinitialize();
         bool Initialized();
+        long long GetDatID();
 
     private:
         std::unique_ptr<DatIO> io_;
@@ -69,6 +66,8 @@ namespace LOTRO_DAT {
         std::unique_ptr<DatPatcher> patcher_;
         std::unique_ptr<DatExporter> exporter_;
         std::unique_ptr<DatBackupManager> backupManager_;
+        std::unique_ptr<DatStatus> status_;
+
         bool initialized_;
         long long dat_id_;
     };

+ 1 - 0
include/DatSubsystems/DatLocaleManager.h

@@ -27,6 +27,7 @@ namespace LOTRO_DAT {
      */
 
     class DatLocaleManager {
+        friend class DatStatus;
     public:
         enum LOCALE : int {
             ORIGINAL = 0,

+ 54 - 0
include/DatSubsystems/DatStatus.h

@@ -0,0 +1,54 @@
+#ifndef LOTRO_DAT_LIBRARY_DATSTATUS_H
+#define LOTRO_DAT_LIBRARY_DATSTATUS_H
+
+#include <string>
+
+namespace LOTRO_DAT {
+    class DatFile;
+
+    /*!
+     * \brief Модуль работы с локалями
+     * \author Gi1dor
+     * \date 06.07.2018
+     *
+     * Класс для работы с искуственно внедряемымыми в dat контейнер копиями файлов. Позволяет независимо хранить
+     * информацию о двух версиях каждого файла, которую можно подставлять в файловую систему.
+     * В рамках русификации хранит информацию об оригинальной и русифицированной версии тех файлов, для которых
+     * существует русификация.
+     *
+     * \warning Данные локалей чувствительны к обновлениям игры и могут быть стёрты после них!
+     * \warning Объекты этого класса не должны создаваться отдельно! Созданием и управлением ими занимается класс DatFile
+     */
+
+    class DatStatus {
+    public:
+        DatStatus() = delete;
+
+        DatStatus(const DatStatus &other) = delete;
+
+        DatStatus &operator=(const DatStatus &other) = delete;
+
+        ~DatStatus() = default;
+
+        explicit DatStatus(DatFile *datFilePtr);
+
+        void UpdatePercentage(unsigned percent);
+
+        unsigned GetPercentage();
+
+        void UpdateStatusText(const std::string &message);
+
+        void RemoveStatusText();
+
+        std::string GetStatusText();
+
+        bool CheckIfNotPatched();
+
+    private:
+        DatFile *dat;
+        unsigned percentage;
+        std::string status_text;
+    };
+}
+
+#endif //LOTRO_DAT_LIBRARY_DATSTATUS_H

BIN
lib/libLotroDat.dll.a


BIN
lib/libLotroDat_static.a


+ 15 - 7
src/DatFile.cpp

@@ -53,7 +53,8 @@ namespace LOTRO_DAT {
         localeManager_ = std::make_unique<DatLocaleManager>(this);
         exporter_ = std::make_unique<DatExporter>(this);
         patcher_ = std::make_unique<DatPatcher>(this);
-//        backupManager_ = std::make_unique<DatBackupManager>(this);
+        backupManager_ = std::make_unique<DatBackupManager>(this);
+        status_ = std::make_unique<DatStatus>(this);
     }
 
 
@@ -62,30 +63,34 @@ namespace LOTRO_DAT {
             Deinitialize();
     }
 
-    LOTRO_DAT::DatLocaleManager &DatFile::getLocaleManager() {
+    LOTRO_DAT::DatLocaleManager &DatFile::GetLocaleManager() {
         return *localeManager_;
     }
 
-    DatExporter &DatFile::getExporter() {
+    DatExporter &DatFile::GetExporter() {
         return *exporter_;
     }
 
-    LOTRO_DAT::DatPatcher &DatFile::getPatcher() {
+    LOTRO_DAT::DatPatcher &DatFile::GetPatcher() {
         return *patcher_;
     }
 
-    DatBackupManager &DatFile::getBackupManager() {
+    DatBackupManager &DatFile::GetBackupManager() {
         return *backupManager_;
     }
 
-    DatIO &DatFile::getIO() {
+    DatIO &DatFile::GetIO() {
         return *io_;
     }
 
-    DatFileSystem &DatFile::getFileSystem() {
+    DatFileSystem &DatFile::GetFileSystem() {
         return *fileSystem_;
     }
 
+    DatStatus &DatFile::GetStatusModule() {
+        return *status_;
+    }
+
     DatOperationResult<> DatFile::Initialise(const std::string &filename, long long dat_id) {
         dat_id_ = dat_id;
 
@@ -156,5 +161,8 @@ namespace LOTRO_DAT {
         return initialized_;
     }
 
+    long long DatFile::GetDatID() {
+        return dat_id_;
+    }
 }
 }

+ 6 - 5
src/DatSubsystems/DatBackupManager.cpp

@@ -63,7 +63,7 @@ namespace LOTRO_DAT {
         DatFile backup_file;
         backup_file.Initialise(backup_datname, 0);
 
-        std::string dat_filename = dat->getIO().GetFilename().value;
+        std::string dat_filename = dat->GetIO().GetFilename().value;
         dat->Deinitialize();
 
         FILE* file = fopen(backup_datname.c_str(), "w+b");
@@ -76,7 +76,7 @@ namespace LOTRO_DAT {
         if (operation.result == ERROR)
             return DatOperationResult<>(ERROR, "RESTOREFROMBACKUP: error in copy dat file");
 
-        dat->Initialise(dat_filename, dat->dat_id_);
+        dat->Initialise(dat_filename, dat->GetDatID());
         return DatOperationResult<>(SUCCESS);
     }
 
@@ -104,13 +104,14 @@ namespace LOTRO_DAT {
      */
 
     DatOperationResult<> DatBackupManager::CopyDatFile(DatFile &source, FILE *target) {
-        long long parts_count = source.getIO().file_size / COPY_BLOCK_SIZE + (source.getIO().file_size % COPY_BLOCK_SIZE != 0);
+        long long parts_count =
+                source.GetIO().file_size / COPY_BLOCK_SIZE + (source.GetIO().file_size % COPY_BLOCK_SIZE != 0);
         long long newfile_size = 0;
-        long long elapsed_size = source.getIO().file_size - newfile_size;
+        long long elapsed_size = source.GetIO().file_size - newfile_size;
 
         BinaryData data(COPY_BLOCK_SIZE);
         for (unsigned i = 0; i < parts_count; i++) {
-            auto operation = source.getIO().ReadData(data, std::min((long long)(COPY_BLOCK_SIZE), elapsed_size), newfile_size);
+            auto operation = source.GetIO().ReadData(data, std::min((long long)(COPY_BLOCK_SIZE), elapsed_size), newfile_size);
             if (operation.result == ERROR)
                 return DatOperationResult<>(ERROR, "Copy failed. Read data error");
             fwrite(data.data(), data.size(), 1, target);

+ 6 - 6
src/DatSubsystems/DatExporter.cpp

@@ -27,10 +27,10 @@ namespace LOTRO_DAT {
     DatOperationResult<int> DatExporter::ExtractAllFilesByType(const FILE_TYPE &type, std::string output_directory_path) {
         int success_exported = 0;
 
-        auto operation = dat->getFileSystem().PerformOperationOnAllFiles([&success_exported, this, type, &output_directory_path](std::shared_ptr<SubFile>& file) -> void {
+        auto operation = dat->GetFileSystem().PerformOperationOnAllFiles([&success_exported, this, type, &output_directory_path](std::shared_ptr<SubFile>& file) -> void {
             if (file->FileType() != type)
                 return;
-            SubfileData export_file = file->PrepareForExport(dat->getFileSystem().GetFileData(file->file_id(), 8).value);
+            SubfileData export_file = file->PrepareForExport(dat->GetFileSystem().GetFileData(file->file_id(), 8).value);
 
             if (export_file.Empty())
                 return;
@@ -58,12 +58,12 @@ namespace LOTRO_DAT {
      */
 
     DatOperationResult<> DatExporter::ExtractFileById(long long file_id, std::string output_filename) {
-        auto operation_GetFileData = dat->getFileSystem().GetFileData(file_id, 8);
+        auto operation_GetFileData = dat->GetFileSystem().GetFileData(file_id, 8);
         if (operation_GetFileData.result == ERROR)
             return DatOperationResult<>(ERROR, "EXTRACTFILEBYID: Can't get data for id = " + std::to_string(file_id));
 
 
-        auto operation_GetFilePointer = dat->getFileSystem().GetFile(file_id);
+        auto operation_GetFilePointer = dat->GetFileSystem().GetFile(file_id);
         if (operation_GetFileData.result == ERROR)
             return DatOperationResult<>(ERROR, "EXTRACTFILEBYID: Can't get pointer for id = " + std::to_string(file_id));
 
@@ -101,11 +101,11 @@ namespace LOTRO_DAT {
             return DatOperationResult<int>(0, ERROR, "EXTRACTALLBYTYPETODB: database is nullptr");
 
         int success_exported = 0;
-        auto operation = dat->getFileSystem().PerformOperationOnAllFiles([&success_exported, this, type, db](std::shared_ptr<SubFile>& file) {
+        auto operation = dat->GetFileSystem().PerformOperationOnAllFiles([&success_exported, this, type, db](std::shared_ptr<SubFile>& file) {
             if (file->FileType() != type)
                 return;
 
-            SubfileData export_file = file->PrepareForExport(dat->getFileSystem().GetFileData(file->file_id(), 8).value);
+            SubfileData export_file = file->PrepareForExport(dat->GetFileSystem().GetFileData(file->file_id(), 8).value);
 
             bool result = db->PushFile(export_file);
 

+ 9 - 9
src/DatSubsystems/DatFileSystem.cpp

@@ -55,28 +55,28 @@ namespace LOTRO_DAT {
 
         BinaryData data((unsigned) (file->file_size() + (8 - offset)));
         if (file->block_size() >= file->file_size() + 8) {
-            dat->getIO().ReadData(data, file->file_size() + (8 - offset), file->file_offset() + offset);
+            dat->GetIO().ReadData(data, file->file_size() + (8 - offset), file->file_offset() + offset);
             return DatOperationResult<BinaryData>(data, SUCCESS);
         }
 
         BinaryData fragments_count(4);
-        dat->getIO().ReadData(fragments_count, 4, file->file_offset());
+        dat->GetIO().ReadData(fragments_count, 4, file->file_offset());
 
         long long fragments_number = fragments_count.ToNumber<4>(0);
 
         long long current_block_size = file->block_size() - offset - 8 * fragments_number;
 
-        dat->getIO().ReadData(data, current_block_size, file->file_offset() + offset);
+        dat->GetIO().ReadData(data, current_block_size, file->file_offset() + offset);
 
         BinaryData FragmentsDictionary(8 * unsigned(fragments_number));
-        dat->getIO().ReadData(FragmentsDictionary, 8 * unsigned(fragments_number),
+        dat->GetIO().ReadData(FragmentsDictionary, 8 * unsigned(fragments_number),
                               file->file_offset() + file->block_size() - 8 * fragments_number);
 
 
         for (long long i = 0; i < fragments_number; i++) {
             long long fragment_size = FragmentsDictionary.ToNumber<4>(8 * i);
             long long fragment_offset = FragmentsDictionary.ToNumber<4>(8 * i + 4);
-            dat->getIO().ReadData(data, std::min(fragment_size, file->file_size() - current_block_size),
+            dat->GetIO().ReadData(data, std::min(fragment_size, file->file_size() - current_block_size),
                                   fragment_offset,
                                   current_block_size);
             current_block_size += fragment_size;
@@ -154,7 +154,7 @@ namespace LOTRO_DAT {
             return DatOperationResult<bool>(false, SUCCESS);
 
         BinaryData mfile_id(20);
-        auto operation = dat->getIO().ReadData(mfile_id, 20, file->file_offset() + 8);
+        auto operation = dat->GetIO().ReadData(mfile_id, 20, file->file_offset() + 8);
         if (operation.result == ERROR)
             return DatOperationResult<bool>(false, ERROR, "DATFSCORRECTSUBFILE: cannot read file header data");
 
@@ -188,7 +188,7 @@ namespace LOTRO_DAT {
 //                continue;
 //            }
 
-            auto operation1 = dat->getIO().WriteData(dictionary_[file_id]->MakeHeaderData(), 32,
+            auto operation1 = dat->GetIO().WriteData(dictionary_[file_id]->MakeHeaderData(), 32,
                                                      dictionary_[file_id]->dictionary_offset());
             if (operation1.result == ERROR)
                 LOG(ERROR) << "Unable to write data to dictionary for file " << file_id;
@@ -209,7 +209,7 @@ namespace LOTRO_DAT {
             return DatOperationResult<>(ERROR, "DATFSINIT: no connection with Dat (dat is nullptr)");
 
         DeInit();
-        SubDirectory root_directory(0, (unsigned) dat->getIO().root_directory_offset);
+        SubDirectory root_directory(0, (unsigned) dat->GetIO().root_directory_offset);
         subdir_init_queue_.insert(root_directory);
         return DatOperationResult<>(SUCCESS);
     }
@@ -417,7 +417,7 @@ namespace LOTRO_DAT {
             return DatOperationResult<>(ERROR, "DATFSINITSUBDIR: no connection with Dat (dat is nullptr)");
 
         BinaryData subdir_data(63 * 8 + 4 + 32 * 64);
-        auto operation = dat->getIO().ReadData(subdir_data, 63 * 8 + 4 + 32 * 64, dir.offset());
+        auto operation = dat->GetIO().ReadData(subdir_data, 63 * 8 + 4 + 32 * 64, dir.offset());
         if (operation.result == ERROR)
             return DatOperationResult<>(ERROR, "DATFSINITSUBDIR: cannot init dir (read error) with offset = " +
                                                std::to_string((dir.offset())));

+ 32 - 32
src/DatSubsystems/DatLocaleManager.cpp

@@ -49,22 +49,22 @@ namespace LOTRO_DAT {
 
         LOG(INFO) << "Initialising locales...";
         BinaryData locale_offset_data(4);
-        dat->getIO().ReadData(locale_offset_data, 4, 300);
+        dat->GetIO().ReadData(locale_offset_data, 4, 300);
         long long locale_offset = locale_offset_data.ToNumber<4>(0);
 
-        if (locale_offset == 0 || locale_offset + 8 >= dat->getIO().GetActualDatSize().value) {
+        if (locale_offset == 0 || locale_offset + 8 >= dat->GetIO().GetActualDatSize().value) {
             LOG(INFO) << "Dictionary offset is empty or incorrect. Passing.";
             return DatOperationResult<>();
         }
 
         BinaryData locale_info(12);
-        dat->getIO().ReadData(locale_info, 12, locale_offset);
+        dat->GetIO().ReadData(locale_info, 12, locale_offset);
 
         long long dict_size = locale_info.ToNumber<4>(0);
         long long dict_version = locale_info.ToNumber<4>(4);
 
         if (dict_version != 101) {
-            dat->getIO().WriteData(BinaryData::FromNumber<4>(0), 4, 300);
+            dat->GetIO().WriteData(BinaryData::FromNumber<4>(0), 4, 300);
             if (CheckLocaleCorrect())
                 return DatOperationResult<>(SUCCESS);
             else
@@ -72,10 +72,10 @@ namespace LOTRO_DAT {
         }
 
         BinaryData dicts_data = BinaryData((unsigned)dict_size);
-        dat->getIO().ReadData(dicts_data, dict_size - 12, locale_offset + 12);
+        dat->GetIO().ReadData(dicts_data, dict_size - 12, locale_offset + 12);
 
         if (dicts_data.size() < 15) {
-            dat->getIO().WriteData(BinaryData::FromNumber<4>(0), 4, 300);
+            dat->GetIO().WriteData(BinaryData::FromNumber<4>(0), 4, 300);
             return DatOperationResult<>(ERROR, "INITLOCALE: Data in locales' dictionary is incorrect.");
         }
 
@@ -118,8 +118,8 @@ namespace LOTRO_DAT {
         LOG(INFO) << "Finished initialising locales";
 
         if (CheckLocaleCorrect()) {
-            dat->getIO().file_size = locale_info.ToNumber<4>(8);
-            LOG(INFO) << "Locales initialisation success. Dictionary size is " << dict_size << ". Version is " << dict_version << ". Localed .dat size = " << dat->getIO().file_size;
+            dat->GetIO().file_size = locale_info.ToNumber<4>(8);
+            LOG(INFO) << "Locales initialisation success. Dictionary size is " << dict_size << ". Version is " << dict_version << ". Localed .dat size = " << dat->GetIO().file_size;
             return DatOperationResult<>(SUCCESS);
         } else
             return DatOperationResult<>(ERROR, "Locale dict is incorrect, through patched mark is standing. Dat file may be corrupted");
@@ -148,7 +148,7 @@ namespace LOTRO_DAT {
         for (const auto &file : dict) {
             long long file_id = file.first;
 
-            auto dict_file_result = dat->getFileSystem().GetFile(file_id);
+            auto dict_file_result = dat->GetFileSystem().GetFile(file_id);
             if (dict_file_result.result != SUCCESS) {
                 LOG(WARNING) << "Unable to get file with id = " << file_id << "from datFileSystem!";
                 dict.erase(file_id);
@@ -160,7 +160,7 @@ namespace LOTRO_DAT {
             if (dict_file->MakeHeaderData().CutData(8, 16) == file.second.MakeHeaderData().CutData(8, 16))
                 continue;
 
-            dat->getFileSystem().UpdateFileInfo(file.second);
+            dat->GetFileSystem().UpdateFileInfo(file.second);
         }
         current_locale_ = locale;
         return DatOperationResult<>(SUCCESS);
@@ -212,7 +212,7 @@ namespace LOTRO_DAT {
             return DatOperationResult<>(ERROR, "LOCALEDEINIT: no connection with Dat (dat is nullptr)");
 
         if (patch_dict_.empty()) {
-            dat->getIO().WriteData(BinaryData::FromNumber<4>(0), 4, 300);
+            dat->GetIO().WriteData(BinaryData::FromNumber<4>(0), 4, 300);
             return DatOperationResult<>(SUCCESS);
         }
 
@@ -259,40 +259,40 @@ namespace LOTRO_DAT {
 
 
         BinaryData dicts_data(4);
-        dat->getIO().ReadData(dicts_data, 4, 300);
+        dat->GetIO().ReadData(dicts_data, 4, 300);
         long long dict_offset = dicts_data.ToNumber<4>(0);
-        dat->getIO().ReadData(dicts_data, 4, dict_offset);
+        dat->GetIO().ReadData(dicts_data, 4, dict_offset);
         long long dict_size = dicts_data.ToNumber<4>(0);
 
         if (binary_data.size() > dict_size || dict_offset == 0) {
-            long long new_dict_offset = dat->getIO().file_size + 12;
+            long long new_dict_offset = dat->GetIO().file_size + 12;
 
             // Updating first 12 bytes
             binary_data.Append(BinaryData::FromNumber<4>(std::max(binary_data.size() + 4, 20u * 1024u * 1024u)), 0);
             binary_data.Append(BinaryData::FromNumber<4>(101), 4);
-            binary_data.Append(BinaryData::FromNumber<4>(dat->getIO().file_size + binary_data.size() + 20 * 1024 * 1024), 8);
+            binary_data.Append(BinaryData::FromNumber<4>(dat->GetIO().file_size + binary_data.size() + 20 * 1024 * 1024), 8);
 
-            auto operation = dat->getIO().WriteData(binary_data, binary_data.size(), new_dict_offset);
+            auto operation = dat->GetIO().WriteData(binary_data, binary_data.size(), new_dict_offset);
             if (operation.result != SUCCESS)
                 return DatOperationResult<>(ERROR, "LOCALEDEINIT: Cannot write locales");
 
 
-            dat->getIO().WriteData(BinaryData::FromNumber<4>(new_dict_offset), 4, 300);
-            dat->getIO().WriteData(BinaryData::FromNumber<4>(current_locale_), 4, 296);
+            dat->GetIO().WriteData(BinaryData::FromNumber<4>(new_dict_offset), 4, 300);
+            dat->GetIO().WriteData(BinaryData::FromNumber<4>(current_locale_), 4, 296);
 
-            dat->getIO().file_size += binary_data.size();
+            dat->GetIO().file_size += binary_data.size();
 
             // Adding space for 20 megabytes locales file in total.
             BinaryData nulls(unsigned(20 * 1024 * 1024));
-            dat->getIO().WriteData(nulls, nulls.size(), dat->getIO().file_size);
-            dat->getIO().file_size += nulls.size();
+            dat->GetIO().WriteData(nulls, nulls.size(), dat->GetIO().file_size);
+            dat->GetIO().file_size += nulls.size();
         } else {
             binary_data.Append(BinaryData::FromNumber<4>(std::max(binary_data.size() + 4, 20u * 1024u * 1024u)), 0);
             binary_data.Append(BinaryData::FromNumber<4>(101), 4);
-            binary_data.Append(BinaryData::FromNumber<4>(dat->getIO().file_size), 8);
+            binary_data.Append(BinaryData::FromNumber<4>(dat->GetIO().file_size), 8);
 
-            dat->getIO().WriteData(BinaryData::FromNumber<4>(current_locale_), 4, 296, 0);
-            auto operation = dat->getIO().WriteData(binary_data, binary_data.size(), dict_offset);
+            dat->GetIO().WriteData(BinaryData::FromNumber<4>(current_locale_), 4, 296, 0);
+            auto operation = dat->GetIO().WriteData(binary_data, binary_data.size(), dict_offset);
             if (operation.result != SUCCESS)
                 return DatOperationResult<>(ERROR, "LOCALEDEINIT: Cannot write locales. ERRMSG: " + operation.msg);
         }
@@ -354,27 +354,27 @@ namespace LOTRO_DAT {
     void DatLocaleManager::PrintInformaion(FILE *file) {
         fprintf(file, "========= Locales info ========\n");
         BinaryData locale_offset_data(4);
-        dat->getIO().ReadData(locale_offset_data, 4, 300);
+        dat->GetIO().ReadData(locale_offset_data, 4, 300);
         long long locale_offset = locale_offset_data.ToNumber<4>(0);
 
         fprintf(file, "Locales' dictionary offset = %lld\n", locale_offset);
 
         BinaryData locale_status_data(4);
-        dat->getIO().ReadData(locale_status_data, 4, 296);
+        dat->GetIO().ReadData(locale_status_data, 4, 296);
         long long locale_status = locale_offset_data.ToNumber<4>(0);
 
         fprintf(file, "Locale status = %lld\n", locale_status);
 
         if (locale_offset != 0) {
             BinaryData locale_info(12);
-            dat->getIO().ReadData(locale_info, 12, locale_offset);
+            dat->GetIO().ReadData(locale_info, 12, locale_offset);
 
             long long dict_size = locale_info.ToNumber<4>(0);
             long long dict_version = locale_info.ToNumber<4>(4);
 
             fprintf(file, "Locales' dictionary size = %lld, version = %lld\n", dict_size, dict_version);
 
-            dat->getIO().file_size = locale_info.ToNumber<4>(8);
+            dat->GetIO().file_size = locale_info.ToNumber<4>(8);
         }
 
         fprintf(file, "Current locale id = %d\n", current_locale_);
@@ -393,21 +393,21 @@ namespace LOTRO_DAT {
 
     bool DatLocaleManager::CheckLocaleCorrect() {
         BinaryData locale_info(4);
-        dat->getIO().ReadData(locale_info, 4, 296);
+        dat->GetIO().ReadData(locale_info, 4, 296);
         long long locale_status = locale_info.ToNumber<4>(0);
 
         if (locale_status == ORIGINAL)
             return true;
 
         BinaryData locale_offset_data(4);
-        dat->getIO().ReadData(locale_offset_data, 4, 300);
+        dat->GetIO().ReadData(locale_offset_data, 4, 300);
         long long locale_offset = locale_offset_data.ToNumber<4>(0);
 
-        if (locale_offset == 0 || locale_offset + 8 >= dat->getIO().GetActualDatSize().value)
+        if (locale_offset == 0 || locale_offset + 8 >= dat->GetIO().GetActualDatSize().value)
             return locale_status == ORIGINAL;
 
         BinaryData dicts_data = BinaryData(4);
-        auto operation = dat->getIO().ReadData(dicts_data, 4, locale_offset + 12 + 15);
+        auto operation = dat->GetIO().ReadData(dicts_data, 4, locale_offset + 12 + 15);
         if (operation.result == ERROR)
             return locale_status == ORIGINAL;
 

+ 18 - 18
src/DatSubsystems/DatPatcher.cpp

@@ -19,7 +19,7 @@ namespace LOTRO_DAT {
     DatOperationResult<> DatPatcher::PatchFile(const SubfileData &data) {
         auto file_id = data.options["fid"].as<long long>();
 
-        auto getfile_operation = dat->getFileSystem().GetFile(file_id);
+        auto getfile_operation = dat->GetFileSystem().GetFile(file_id);
         if (getfile_operation.result == ERROR)
             return DatOperationResult<>(ERROR,
                                         "PATCHSUBFILEDATA: Unable to find file with id " + std::to_string(file_id));
@@ -29,10 +29,10 @@ namespace LOTRO_DAT {
         // If file has inactive category, then we should set it to patched state in order to commit patch and
         // then in ApplyFilePatch() function, if new category is still inactive, return dictionary to its original state;
 
-        if (dat->getLocaleManager().CategoryIsInactive(file->category) != 0) {
-            auto operation = dat->getLocaleManager().GetLocaleFile(file->file_id(), DatLocaleManager::PATCHED);
+        if (dat->GetLocaleManager().CategoryIsInactive(file->category) != 0) {
+            auto operation = dat->GetLocaleManager().GetLocaleFile(file->file_id(), DatLocaleManager::PATCHED);
             if (operation.result == SUCCESS)
-                dat->getFileSystem().UpdateFileInfo(operation.value);
+                dat->GetFileSystem().UpdateFileInfo(operation.value);
         }
 
         if (data.options["cat"].IsDefined())
@@ -40,7 +40,7 @@ namespace LOTRO_DAT {
         else
             file->category = 1;
 
-        auto getdata_operation = dat->getFileSystem().GetFileData(file_id, 0);
+        auto getdata_operation = dat->GetFileSystem().GetFileData(file_id, 0);
         if (getdata_operation.result == ERROR)
             return DatOperationResult<>(ERROR,
                                         "PATCHSUBFILEDATA: can't get file data for id = " + std::to_string(file_id));
@@ -99,25 +99,25 @@ namespace LOTRO_DAT {
     DatOperationResult<> DatPatcher::ApplyFilePatch(std::shared_ptr<SubFile> file, BinaryData &data) {
         long long file_id = file->file_id();
 
-        if (dat->getLocaleManager().GetCurrentLocale() != DatLocaleManager::PATCHED) {
+        if (dat->GetLocaleManager().GetCurrentLocale() != DatLocaleManager::PATCHED) {
             LOG(INFO) << "Changing locale to PATCHED(RU) in order to patch file";
-            dat->getLocaleManager().SetLocale(DatLocaleManager::PATCHED);
+            dat->GetLocaleManager().SetLocale(DatLocaleManager::PATCHED);
         }
 
         LOG(INFO) << "Patching file with id = " << file_id;
 
-        if (dat->getLocaleManager().GetLocaleFile(file_id, DatLocaleManager::ORIGINAL).result == ERROR)
-            dat->getLocaleManager().UpdateLocaleFile(DatLocaleManager::ORIGINAL, SubFile(*file));
+        if (dat->GetLocaleManager().GetLocaleFile(file_id, DatLocaleManager::ORIGINAL).result == ERROR)
+            dat->GetLocaleManager().UpdateLocaleFile(DatLocaleManager::ORIGINAL, SubFile(*file));
 
 
         SubFile new_file = SubFile(*file);
 
-        if (dat->getLocaleManager().GetLocaleFile(file_id, DatLocaleManager::PATCHED).result == ERROR
+        if (dat->GetLocaleManager().GetLocaleFile(file_id, DatLocaleManager::PATCHED).result == ERROR
             || data.size() > file->block_size()) {
 
-            new_file.file_offset_ = dat->getIO().file_size;
+            new_file.file_offset_ = dat->GetIO().file_size;
             new_file.block_size_ = std::max(data.size(), 256u);
-            dat->getIO().file_size += new_file.block_size_ + 8;
+            dat->GetIO().file_size += new_file.block_size_ + 8;
         }
         new_file.file_size_ = data.size() - 8;
 
@@ -127,20 +127,20 @@ namespace LOTRO_DAT {
         if (file_id != data.ToNumber<4>(8))
             LOG(WARNING) << "Created data's file_id " << file_id << "doesn't match to original: " << data.ToNumber<4>(8);
 
-        auto operation = dat->getIO().WriteData(data, data.size(), new_file.file_offset());
+        auto operation = dat->GetIO().WriteData(data, data.size(), new_file.file_offset());
         if (operation.result == ERROR)
             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);
+        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
-        if (dat->getLocaleManager().CategoryIsInactive(new_file.category))
-            dat->getFileSystem().UpdateFileInfo(dat->getLocaleManager().GetLocaleFile(file_id, DatLocaleManager::ORIGINAL).value);
+        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);
+        dat->GetLocaleManager().UpdateCategory(file_id, new_file.category);
         LOG(INFO) << "Successfully patched file with id = " << file_id;
 
         return DatOperationResult<>(SUCCESS);

+ 31 - 0
src/DatSubsystems/DatStatus.cpp

@@ -0,0 +1,31 @@
+#include <DatSubsystems/DatStatus.h>
+#include <DatFile.h>
+
+namespace LOTRO_DAT {
+    void DatStatus::UpdatePercentage(unsigned percent) {
+        percentage = std::min(100u, std::max(0u, percent));
+    }
+
+    unsigned DatStatus::GetPercentage() {
+        return percentage;
+    }
+
+    void DatStatus::UpdateStatusText(const std::string &message) {
+        status_text = message;
+    }
+
+    void DatStatus::RemoveStatusText() {
+        status_text = "none";
+    }
+
+    std::string DatStatus::GetStatusText() {
+        return status_text == "none" ? "Свободен" : status_text;
+    }
+
+    bool DatStatus::CheckIfNotPatched() {
+        return dat->GetLocaleManager().patch_dict_.empty();
+    }
+
+    DatStatus::DatStatus(DatFile *datFilePtr) : dat(datFilePtr), percentage(0), status_text("none") {
+    }
+}

+ 14 - 14
src/Examples/extractor_example.cpp

@@ -97,7 +97,7 @@ int main() {
             memcpy(out_time, ttime, 24);
             out_time[24] = '\0';
 
-            std::string filename = file.getIO().GetFilename().value;
+            std::string filename = file.GetIO().GetFilename().value;
             std::cout << "FILENAME = " << filename << std::endl;
             std::string output_dir = std::string("Extracted data\\") + filename.substr(std::max(filename.length() - 16, 0u), 16) + " " + std::string(out_time) + "\\";
             std::replace(output_dir.begin(), output_dir.end(), ':', '-');
@@ -111,65 +111,65 @@ int main() {
 
             if (exportImagesToDb) {
                 output_db.InitDatabase(output_dir + std::string("Images.db"));
-                std::cout << "Extracted " << file.getExporter().ExtractAllFilesByType(JPG, &output_db).value << " .jpg files to Images.db" << std::endl << std::flush;
+                std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(JPG, &output_db).value << " .jpg files to Images.db" << std::endl << std::flush;
                 output_db.CloseDatabase();
             }
 
             if (exportSoundsToDb) {
                 output_db.InitDatabase(output_dir + std::string("Sounds.db"));
-                std::cout << "Extracted " << file.getExporter().ExtractAllFilesByType(WAV, &output_db).value << " .wav files to Sounds.db" << std::endl << std::flush;
-                std::cout << "Extracted " << file.getExporter().ExtractAllFilesByType(OGG, &output_db).value << " .ogg files to Sounds.db" << std::endl << std::flush;
+                std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(WAV, &output_db).value << " .wav files to Sounds.db" << std::endl << std::flush;
+                std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(OGG, &output_db).value << " .ogg files to Sounds.db" << std::endl << std::flush;
                 output_db.CloseDatabase();
             }
 
             if (exportTextsToDb) {
                 output_db.InitDatabase(output_dir + std::string("Texts.db"));
-                std::cout << "Extracted " << file.getExporter().ExtractAllFilesByType(TEXT, &output_db).value << " text files to Texts.db" << std::endl << std::flush;
+                std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(TEXT, &output_db).value << " text files to Texts.db" << std::endl << std::flush;
                 output_db.CloseDatabase();
             }
 
             if (exportFontsToDb) {
                 output_db.InitDatabase(output_dir + std::string("Fonts.db"));
-                std::cout << "Extracted " << file.getExporter().ExtractAllFilesByType(FONT, &output_db).value << " font files to Fonts.db" << std::endl << std::flush;
+                std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(FONT, &output_db).value << " font files to Fonts.db" << std::endl << std::flush;
                 output_db.CloseDatabase();
             }
 
             if (exportTexturesToDb) {
                 output_db.InitDatabase(output_dir + std::string("Textures.db"));
-                std::cout << "Extracted " << file.getExporter().ExtractAllFilesByType(DDS, &output_db).value << " .dds files to Textures.db" << std::endl << std::flush;
+                std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(DDS, &output_db).value << " .dds files to Textures.db" << std::endl << std::flush;
                 output_db.CloseDatabase();
             }
 
             if (exportImagesToFiles) {
                 mkdir((output_dir + "jpg").c_str(), 744);
-                std::cout << "Extracted " << file.getExporter().ExtractAllFilesByType(JPG, output_dir + "jpg\\").value << " .jpg files to directory" << std::endl << std::flush;
+                std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(JPG, output_dir + "jpg\\").value << " .jpg files to directory" << std::endl << std::flush;
             }
 
             if (exportTexturesToFiles) {
                 mkdir((output_dir + "dds").c_str(), 744);
-                std::cout << "Extracted " << file.getExporter().ExtractAllFilesByType(DDS, output_dir + "dds\\").value << " .dds files to directory" << std::endl << std::flush;
+                std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(DDS, output_dir + "dds\\").value << " .dds files to directory" << std::endl << std::flush;
             }
 
             if (exportSoundsToFiles) {
                 mkdir((output_dir + "wav").c_str(), 744);
-                std::cout << "Extracted " << file.getExporter().ExtractAllFilesByType(WAV, output_dir + "wav\\").value << " .wav files to directory" << std::endl << std::flush;
+                std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(WAV, output_dir + "wav\\").value << " .wav files to directory" << std::endl << std::flush;
                 mkdir((output_dir + "ogg").c_str(), 744);
-                std::cout << "Extracted " << file.getExporter().ExtractAllFilesByType(OGG, output_dir + "ogg\\").value << " .ogg files to directory" << std::endl << std::flush;
+                std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(OGG, output_dir + "ogg\\").value << " .ogg files to directory" << std::endl << std::flush;
             }
 
             if (exportFontsToFiles) {
                 mkdir((output_dir + "fonts").c_str(), 744);
-                std::cout << "Extracted " << file.getExporter().ExtractAllFilesByType(FONT, output_dir + "fonts\\").value << " font files to directory" << std::endl << std::flush;
+                std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(FONT, output_dir + "fonts\\").value << " font files to directory" << std::endl << std::flush;
             }
 
             if (exportUnknownToFiles) {
                 mkdir((output_dir + "unknown").c_str(), 744);
-                std::cout << "Extracted " << file.getExporter().ExtractAllFilesByType(UNKNOWN, output_dir + "unknown\\").value << " unknown files to directory" << std::endl << std::flush;
+                std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(UNKNOWN, output_dir + "unknown\\").value << " unknown files to directory" << std::endl << std::flush;
             }
 
             if (exportTextsToFiles) {
                 mkdir((output_dir + "texts").c_str(), 744);
-                std::cout << "Extracted " << file.getExporter().ExtractAllFilesByType(TEXT, output_dir + "texts\\").value << " text files to directory" << std::endl << std::flush;
+                std::cout << "Extracted " << file.GetExporter().ExtractAllFilesByType(TEXT, output_dir + "texts\\").value << " text files to directory" << std::endl << std::flush;
             }
 
             fprintf(stdout, "Spent %f seconds on running unpacker! Thank you for your patience!\n",

+ 5 - 5
src/Examples/patcher_example.cpp

@@ -112,7 +112,7 @@ int main() {
 
                 SubfileData subfile = db.GetNextFile();
                 while (!subfile.Empty()) {
-                    if (file.getPatcher().PatchFile(subfile).result == ERROR) {
+                    if (file.GetPatcher().PatchFile(subfile).result == ERROR) {
                         fprintf(stderr, "Error! Caught exception while patching file! Passing it\n");
                     }
 
@@ -132,14 +132,14 @@ int main() {
             }
         }
         if (cmd == 2) {
-            std::cout << "Old locale is " << (file.getLocaleManager().GetCurrentLocale() == DatLocaleManager::PATCHED ? "RU" : "Original") << endl;
+            std::cout << "Old locale is " << (file.GetLocaleManager().GetCurrentLocale() == DatLocaleManager::PATCHED ? "RU" : "Original") << endl;
             std::cout << "Changing locale..." << std::endl;
-            file.getLocaleManager().SetLocale(file.getLocaleManager().GetCurrentLocale() == DatLocaleManager::PATCHED  ? DatLocaleManager::ORIGINAL : DatLocaleManager::PATCHED);
-            std::cout << "New locale is " << (file.getLocaleManager().GetCurrentLocale() == DatLocaleManager::PATCHED ? "RU" : "Original") << endl;
+            file.GetLocaleManager().SetLocale(file.GetLocaleManager().GetCurrentLocale() == DatLocaleManager::PATCHED  ? DatLocaleManager::ORIGINAL : DatLocaleManager::PATCHED);
+            std::cout << "New locale is " << (file.GetLocaleManager().GetCurrentLocale() == DatLocaleManager::PATCHED ? "RU" : "Original") << endl;
         }
 
         if (cmd == 3) {
-            std::cout << "Current locale is " << (file.getLocaleManager().GetCurrentLocale() == DatLocaleManager::PATCHED ? "RU" : "Original") << endl;
+            std::cout << "Current locale is " << (file.GetLocaleManager().GetCurrentLocale() == DatLocaleManager::PATCHED ? "RU" : "Original") << endl;
         }
 //
 //        if (cmd == 4) {

+ 1 - 1
src/SubFile.cpp

@@ -216,7 +216,7 @@ namespace LOTRO_DAT {
             return FONT;
 
         BinaryData header(64);
-        dat.getIO().ReadData(header, 64, (unsigned) preinit_file.file_offset_ + 8);
+        dat.GetIO().ReadData(header, 64, (unsigned) preinit_file.file_offset_ + 8);
 
         if (header.Empty()) {
             LOG(ERROR) << "Unable to read file header. file_id = " << preinit_file.file_id_ << ", offset = "