Jelajahi Sumber

Fixed bug with always adding space in dat file

Function UpdateBufferIfNeeded was writing empty buffer data to dat file
in case when data to be written shouldn't be written after end of file.
This caused permanent dat file growth in every iteration of writing data
Ivan Arkhipov 7 tahun lalu
induk
melakukan
3def9a2944
6 mengubah file dengan 11 tambahan dan 8 penghapusan
  1. TEMPAT SAMPAH
      bin/LotRO_dat_extractor.exe
  2. TEMPAT SAMPAH
      bin/LotRO_dat_patcher.exe
  3. TEMPAT SAMPAH
      lib/libLotroDat.dll.a
  4. TEMPAT SAMPAH
      lib/libLotroDat_static.a
  5. 7 4
      src/DatSubsystems/DatIO.cpp
  6. 4 4
      src/Subfiles/TextSubFile.cpp

TEMPAT SAMPAH
bin/LotRO_dat_extractor.exe


TEMPAT SAMPAH
bin/LotRO_dat_patcher.exe


TEMPAT SAMPAH
lib/libLotroDat.dll.a


TEMPAT SAMPAH
lib/libLotroDat_static.a


+ 7 - 4
src/DatSubsystems/DatIO.cpp

@@ -3,10 +3,10 @@
 #include "EasyLogging++/easylogging++.h"
 #include <DatOperationResult.h>
 
-#include "DatSubsystems/DatIO.h"
 #include <algorithm>
 #include <locale>
 #include <DatSubsystems/DatIO.h>
+#include <zconf.h>
 
 
 #ifdef WIN32
@@ -238,7 +238,8 @@ namespace LOTRO_DAT {
         if (data_offset + size > data.size())
             return DatOperationResult<>(ERROR, "IOWRITEDATA: writing more than BinaryData size.");
 
-        UpdateBufferIfNeeded(size);
+        if (offset + size > actual_dat_size_)
+            UpdateBufferIfNeeded(offset + size - actual_dat_size_);
 
         if (offset != ftell(file_handler_))
             fseek(file_handler_, offset, SEEK_SET);
@@ -260,9 +261,10 @@ namespace LOTRO_DAT {
      */
 
     DatOperationResult<> DatIO::DeInit() {
-        if (file_handler_ != nullptr) {
+        if (file_handler_ != nullptr)
             fclose(file_handler_);
-        }
+
+        truncate64(filename_.c_str(), actual_dat_size_);
 
         filename_ = "none";
         file_handler_ = nullptr;
@@ -276,6 +278,7 @@ namespace LOTRO_DAT {
         fragmentation_journal_end = 0;
         root_directory_offset = 0;
         fragmentation_journal_offset = 0;
+        elapsed_eof_buffer_ = 0;
 
         return DatOperationResult<>(SUCCESS, "File deinitialisation successfull");
     }

+ 4 - 4
src/Subfiles/TextSubFile.cpp

@@ -373,10 +373,10 @@ namespace LOTRO_DAT {
         // Moving &offset pointer in &data
         GetArgumentReferenceData(data, offset);
 
-        if (file_id_ == 620757423 && new_data.fragment_id == 96627013) {
-            std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> codecvt;
-            std::cout << "ARG_REFS: " << new_data.args << std::endl;
-        }
+//        if (file_id_ == 620757423 && new_data.fragment_id == 96627013) {
+//            std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> codecvt;
+//            std::cout << "ARG_REFS: " << new_data.args << std::endl;
+//        }
 
         // If there are no args - making 4 null-bytes and return;
         if (new_data.args.empty()) {