Pārlūkot izejas kodu

Fixing bug, connected with duplicated files in dictionary

Gi1dor (Ivan Arkhipov) 7 gadi atpakaļ
vecāks
revīzija
8375e8db80
3 mainītis faili ar 20 papildinājumiem un 6 dzēšanām
  1. 13 3
      DatFile.cpp
  2. 6 2
      SubDirectory.cpp
  3. 1 1
      test.cpp

+ 13 - 3
DatFile.cpp

@@ -23,7 +23,12 @@ namespace LOTRO_DAT {
         OpenDatFile(filename);
         ReadSuperBlock();
         MakeDirectories();
-        MakeDictionary();
+        try {
+            MakeDictionary();
+        } catch (...) {
+            fprintf(stderr, "Unable to make dictionary!! Unable to init DatFile!!!");
+            return;
+        }
         if (dat_state_ == SUCCESS_DICTIONARY)
             dat_state_ = READY;
         else
@@ -114,8 +119,13 @@ namespace LOTRO_DAT {
     void DatFile::MakeDictionary() {
         if (dat_state_ != SUCCESS_DIRECTORIES)
             throw DatException("Bad DatFile::MakeDictionary() - DatFile isn't in valid state!", INIT_EXCEPTION);
-        root_directory_->MakeDictionary(dictionary_);
-        dat_state_ = SUCCESS_DICTIONARY;
+		try {
+			root_directory_->MakeDictionary(dictionary_);
+		} catch (...) {
+			fprintf(stderr, "Bad DatFile::MakeDictionary() - File is corrupted?\n");
+			return;
+		}
+		dat_state_ = SUCCESS_DICTIONARY;
     }
 
     void DatFile::ReadData(BinaryData &data, long long size, long long offset, long long data_offset) {

+ 6 - 2
SubDirectory.cpp

@@ -86,8 +86,12 @@ void LOTRO_DAT::SubDirectory::MakeSubFiles() {
 }
 
 void LOTRO_DAT::SubDirectory::MakeDictionary(std::unordered_map<long long, Subfile *> &dict) {
-    for (Subfile &i : subfiles_)
-        dict[i.file_id()] = &i;
+    for (Subfile &i : subfiles_) {
+        //if (dict.count(i.file_id()) != 0 && dict[i.file_id()]->file_offset() != i.file_offset())
+        //    throw DatException("Bad SubDirectory::MakeDictionary() - found 2 files with different offset!!!", SUBFILE_EXCEPTION);
+        if (dict.count(i.file_id()) == 0 || dict[i.file_id()]->timestamp() < i.timestamp())
+			dict[i.file_id()] = &i;
+    }
     for (SubDirectory &i : subdirs_)
         i.MakeDictionary(dict);
 }

+ 1 - 1
test.cpp

@@ -34,7 +34,7 @@ int main() {
 	// There is no need to touch something else
 
 	std::string output_dir = std::string("Data (") + filename + std::string(")\\");
-    freopen((output_dir + std::string("errors.log")).c_str(), "w", stderr);
+    //freopen((output_dir + std::string("errors.log")).c_str(), "w", stderr);
 
 	std::string txt_dir = "txt\\";
 	std::string jpg_dir = "jpg\\";