|
@@ -11,19 +11,17 @@
|
|
#include "SubfileData.h"
|
|
#include "SubfileData.h"
|
|
|
|
|
|
#include <locale>
|
|
#include <locale>
|
|
|
|
+#include <algorithm>
|
|
|
|
|
|
extern "C++"
|
|
extern "C++"
|
|
{
|
|
{
|
|
namespace LOTRO_DAT {
|
|
namespace LOTRO_DAT {
|
|
- DatFile::DatFile() {
|
|
|
|
- dat_state_ = CLOSED;
|
|
|
|
- patched_ = false;
|
|
|
|
- }
|
|
|
|
|
|
+ DatFile::DatFile() : dat_state_(CLOSED), patched_(false) {}
|
|
|
|
|
|
- DatFile::DatFile(const char *filename, int dat_id) {
|
|
|
|
- dat_id_ = dat_id;
|
|
|
|
- dat_state_ = CLOSED;
|
|
|
|
- patched_ = false;
|
|
|
|
|
|
+ DatFile::DatFile(const char *filename, int dat_id)
|
|
|
|
+ : dat_id_(dat_id)
|
|
|
|
+ , dat_state_(CLOSED)
|
|
|
|
+ , patched_(false) {
|
|
OpenDatFile(filename);
|
|
OpenDatFile(filename);
|
|
ReadSuperBlock();
|
|
ReadSuperBlock();
|
|
MakeDirectories();
|
|
MakeDirectories();
|
|
@@ -135,7 +133,7 @@ namespace LOTRO_DAT {
|
|
}
|
|
}
|
|
|
|
|
|
if (export_data == SubfileData()) {
|
|
if (export_data == SubfileData()) {
|
|
- fprintf(stderr, "WARNING: file with id %lld is too small. Passing it\n", dictionary_[file_id]->file_id());
|
|
|
|
|
|
+ fprintf(stderr, "WARNING: file with id %lld is empty. Passing it\n", dictionary_[file_id]->file_id());
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -225,6 +223,12 @@ namespace LOTRO_DAT {
|
|
bool DatFile::PatchFile(const SubfileData &data) {
|
|
bool DatFile::PatchFile(const SubfileData &data) {
|
|
auto file_id = data.options["fid"].as<long long>();
|
|
auto file_id = data.options["fid"].as<long long>();
|
|
Subfile *file = dictionary_[file_id];
|
|
Subfile *file = dictionary_[file_id];
|
|
|
|
+
|
|
|
|
+ if (file == nullptr) {
|
|
|
|
+ fprintf(stderr, "ERROR DatFile::PatchFile() - Cannot patch file - there is no file in dictionary with file_id = %lld.\n", file_id);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
BinaryData old_data = GetFileData(file);
|
|
BinaryData old_data = GetFileData(file);
|
|
BinaryData patch_data = file->MakeForImport(old_data, data);
|
|
BinaryData patch_data = file->MakeForImport(old_data, data);
|
|
ApplyFilePatch(file, patch_data);
|
|
ApplyFilePatch(file, patch_data);
|
|
@@ -461,18 +465,16 @@ namespace LOTRO_DAT {
|
|
fprintf(stderr, "Warning: DatFile::ApplyFilePatch - found 2 files in patch with the same file_id. Passing last...\n");
|
|
fprintf(stderr, "Warning: DatFile::ApplyFilePatch - found 2 files in patch with the same file_id. Passing last...\n");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
patched_list[file->file_id()] = new BinaryData(file->MakeHeaderData());
|
|
patched_list[file->file_id()] = new BinaryData(file->MakeHeaderData());
|
|
patched_ = true;
|
|
patched_ = true;
|
|
|
|
|
|
auto journal = GetFragmentationJournal();
|
|
auto journal = GetFragmentationJournal();
|
|
|
|
|
|
file->file_size_ = data.size() - 8;
|
|
file->file_size_ = data.size() - 8;
|
|
- //file->fragments_count_ = 0;
|
|
|
|
|
|
|
|
- if (data.size() > file->block_size()) {
|
|
|
|
|
|
+ //if (data.size() > file->block_size()) {
|
|
file->file_offset_ = journal[0].second;
|
|
file->file_offset_ = journal[0].second;
|
|
- file->block_size_ = data.size();
|
|
|
|
|
|
+ file->block_size_ = std::max(data.size(), 256u);
|
|
|
|
|
|
journal[0].second += data.size();
|
|
journal[0].second += data.size();
|
|
|
|
|
|
@@ -480,7 +482,7 @@ namespace LOTRO_DAT {
|
|
WriteData(nulls, nulls.size(), file_size_);
|
|
WriteData(nulls, nulls.size(), file_size_);
|
|
|
|
|
|
this->file_size_ += data.size();
|
|
this->file_size_ += data.size();
|
|
- }
|
|
|
|
|
|
+ //}
|
|
|
|
|
|
BinaryData fragments_count(4);
|
|
BinaryData fragments_count(4);
|
|
fragments_count.FromNumber<4>(0);
|
|
fragments_count.FromNumber<4>(0);
|
|
@@ -492,6 +494,9 @@ namespace LOTRO_DAT {
|
|
"Patch wasn't written to .dat file");
|
|
"Patch wasn't written to .dat file");
|
|
|
|
|
|
WriteData(file_data, file_data.size(), file->file_offset());
|
|
WriteData(file_data, file_data.size(), file->file_offset());
|
|
|
|
+
|
|
|
|
+ nulls = BinaryData(unsigned(file->block_size_ - file_data.size()));
|
|
|
|
+ WriteData(nulls, nulls.size(), file->file_offset() + file_data.size());
|
|
UpdateFragmentationJournal(journal);
|
|
UpdateFragmentationJournal(journal);
|
|
}
|
|
}
|
|
|
|
|