|
@@ -26,11 +26,19 @@ namespace LOTRO_DAT {
|
|
|
|
|
|
DatOperationResult<int> DatExporter::ExtractAllFilesByType(const FILE_TYPE &type, std::string output_directory_path) {
|
|
|
int success_exported = 0;
|
|
|
+ int iterated_files = 0;
|
|
|
|
|
|
- auto operation = dat->GetFileSystem().PerformOperationOnAllFiles([&success_exported, this, type, &output_directory_path](std::shared_ptr<SubFile>& file) -> void {
|
|
|
+ dat->GetStatusModule().SetStatus(DatStatus::E_EXTRACTING);
|
|
|
+ dat->GetStatusModule().SetPercentage(0);
|
|
|
+ dat->GetStatusModule().SetDebugMessage("Starting extracting files of type " + std::to_string(type));
|
|
|
+
|
|
|
+ auto operation = dat->GetFileSystem().PerformOperationOnAllFiles([&iterated_files, &success_exported, this, type, &output_directory_path](std::shared_ptr<SubFile>& file) -> void {
|
|
|
+ iterated_files++;
|
|
|
+ dat->GetStatusModule().SetPercentage(iterated_files * 100u / dat->GetFileSystem().GetInitialisedFilesNumber());
|
|
|
if (file->FileType() != type)
|
|
|
return;
|
|
|
SubfileData export_file = file->PrepareForExport(dat->GetFileSystem().GetFileData(file->file_id(), 8).value);
|
|
|
+ dat->GetStatusModule().SetDebugMessage("Extracting file " + std::to_string(file->file_id()) + " (Files by type -> directory)");
|
|
|
|
|
|
if (export_file.Empty())
|
|
|
return;
|
|
@@ -45,6 +53,8 @@ namespace LOTRO_DAT {
|
|
|
if (result)
|
|
|
success_exported++;
|
|
|
});
|
|
|
+
|
|
|
+ dat->GetStatusModule().ClearAll();
|
|
|
return DatOperationResult<int>(success_exported, SUCCESS);
|
|
|
}
|
|
|
|
|
@@ -58,14 +68,22 @@ namespace LOTRO_DAT {
|
|
|
*/
|
|
|
|
|
|
DatOperationResult<> DatExporter::ExtractFileById(long long file_id, std::string output_filename) {
|
|
|
+ dat->GetStatusModule().SetStatus(DatStatus::E_EXTRACTING);
|
|
|
+ dat->GetStatusModule().SetPercentage(0);
|
|
|
+ dat->GetStatusModule().SetDebugMessage("Extracting file " + std::to_string(file_id) + " to file " + output_filename);
|
|
|
+
|
|
|
auto operation_GetFileData = dat->GetFileSystem().GetFileData(file_id, 8);
|
|
|
- if (operation_GetFileData.result == ERROR)
|
|
|
+ if (operation_GetFileData.result == ERROR) {
|
|
|
+ dat->GetStatusModule().ClearAll();
|
|
|
return DatOperationResult<>(ERROR, "EXTRACTFILEBYID: Can't get data for id = " + std::to_string(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));
|
|
|
+ if (operation_GetFileData.result == ERROR) {
|
|
|
+ dat->GetStatusModule().ClearAll();
|
|
|
+ return DatOperationResult<>(ERROR,
|
|
|
+ "EXTRACTFILEBYID: Can't get pointer for id = " + std::to_string(file_id));
|
|
|
+ }
|
|
|
|
|
|
std::shared_ptr<SubFile> file = operation_GetFilePointer.value;
|
|
|
|
|
@@ -78,6 +96,7 @@ namespace LOTRO_DAT {
|
|
|
else
|
|
|
result = export_data.binary_data.WriteToFile(output_filename + file->Extension());
|
|
|
|
|
|
+ dat->GetStatusModule().ClearAll();
|
|
|
if (!result)
|
|
|
return DatOperationResult<>(ERROR, "EXTRACTFILEBYID: Cannot write to file" + output_filename + file->Extension());
|
|
|
|
|
@@ -100,11 +119,22 @@ namespace LOTRO_DAT {
|
|
|
if (!db)
|
|
|
return DatOperationResult<int>(0, ERROR, "EXTRACTALLBYTYPETODB: database is nullptr");
|
|
|
|
|
|
+ dat->GetStatusModule().SetStatus(DatStatus::E_EXTRACTING);
|
|
|
+ dat->GetStatusModule().SetPercentage(0);
|
|
|
+ dat->GetStatusModule().SetDebugMessage("Initialising extraction of files by type " + std::to_string(type) + "to database...");
|
|
|
+
|
|
|
int success_exported = 0;
|
|
|
- auto operation = dat->GetFileSystem().PerformOperationOnAllFiles([&success_exported, this, type, db](std::shared_ptr<SubFile>& file) {
|
|
|
+ int iterated_files = 0;
|
|
|
+
|
|
|
+ auto operation = dat->GetFileSystem().PerformOperationOnAllFiles([&success_exported, &iterated_files, this, type, db](std::shared_ptr<SubFile>& file) {
|
|
|
+ iterated_files++;
|
|
|
+ dat->GetStatusModule().SetPercentage(iterated_files * 100u / dat->GetFileSystem().GetInitialisedFilesNumber());
|
|
|
+
|
|
|
if (file->FileType() != type)
|
|
|
return;
|
|
|
|
|
|
+ dat->GetStatusModule().SetDebugMessage("Extracting file " + std::to_string(file->file_id()) + " (Files by type -> directory)");
|
|
|
+
|
|
|
SubfileData export_file = file->PrepareForExport(dat->GetFileSystem().GetFileData(file->file_id(), 8).value);
|
|
|
|
|
|
bool result = db->PushFile(export_file);
|
|
@@ -112,6 +142,8 @@ namespace LOTRO_DAT {
|
|
|
if (result)
|
|
|
success_exported++;
|
|
|
});
|
|
|
+
|
|
|
+ dat->GetStatusModule().ClearAll();
|
|
|
return DatOperationResult<int>(success_exported, SUCCESS);
|
|
|
}
|
|
|
|