123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- #include "lotro.h"
- #include "filesystem.h"
- #include <QtConcurrent/QtConcurrent>
- #include <QFontDatabase>
- #include <QMessageBox>
- Lotro::Lotro(QSettings& app_settings_, QObject *parent) : app_settings(app_settings_),
- QObject(parent) {
- }
- void Lotro::initialiseDatFile(QString file_name) {
- if (!tryToBlockFile())
- return;
- qDebug() << "Initialising file " << file_name;
- emit processStarted("initialiseDatFile", {file_name});
- if (!FileSystem::fileExists(file_path)) {
- emit caughtError("initialiseDatFile", {QString("Ошибка инициализации"), QString("Файл " + file_path + " несуществует! Невозможно инициализировать файл ресурсов.")});
- return;
- }
- file.Initialise((file_path).toStdString(), 0);
- busy = false;
- emit processFinished("initialiseDatFile", {QString("Success")});
- }
- void Lotro::changeLocale() {
- if (!tryToBlockFile())
- return;
- qDebug() << "Changing locale of dat file...";
- // Setting locale, opposite to current
- auto current_locale = file.GetLocaleManager().GetCurrentLocale();
- auto new_locale = current_locale == LOTRO_DAT::DatLocaleManager::PATCHED ?
- LOTRO_DAT::DatLocaleManager::ORIGINAL :
- LOTRO_DAT::DatLocaleManager::PATCHED;
- QString old_locale_name = (current_locale == LOTRO_DAT::DatLocaleManager::PATCHED ? "Русифицированная" : "Оригинальная");
- QString new_locale_name = (new_locale == LOTRO_DAT::DatLocaleManager::PATCHED ? "Русифицированная" : "Оригинальная");
- emit processStarted("changeLocale", {current_locale, new_locale});
- auto operation = file.GetLocaleManager().SetLocale(new_locale);
- auto new_current_locale = file.GetLocaleManager().GetCurrentLocale();
- QString new_current_locale_name = (new_current_locale == LOTRO_DAT::DatLocaleManager::PATCHED ? "Русифицированная" : "Оригинальная");
- if (operation.result == LOTRO_DAT::SUCCESS) {
- emit processFinished("changeLocale", {"Success", new_current_locale_name});
- } else {
- emit caughtError("changeLocale", {"Ошибка смены локали!", QString("Не удалось сменить локаль игры! Текущая локаль: ") + new_current_locale_name});
- emit processFinished("changeLocale", {"Error", new_current_locale_name});
- }
- busy = false;
- }
- void Lotro::getLocaleFileContents(long long file_id, int locale) {
- if (!tryToBlockFile())
- return;
- emit processStarted("getFileContents", {file_id, locale});
- auto getfile_op = file.GetLocaleManager().GetLocaleFile(file_id, locale);
- if (!getfile_op.result) {
- emit caughtError("getOriginalFileContents", {"Файл не найден!", QString("Не удаётся найти файл с id ") + QString::number(file_id)});
- emit processFinished("getOriginalFileContents", {"Error"});
- return false;
- }
- LOTRO_DAT::SubFile subfile = getfile_op.value;
- auto getfiledata_op = file.GetFileSystem().GetFileData(subfile, 8);
- if (!getfile_op.result) {
- emit caughtError("getOriginalFileContents", {"Ошибка извлечения!", QString("Обнаружены некорректные данные файла в словаре! Файл ресурсов мог быть повреждён!\nid = ") + QString::number(file_id) + ", locale_id = " + QString::number(locale)});
- emit processFinished("getOriginalFileContents", {"Error"});
- return false;
- }
- LOTRO_DAT::SubfileData result = subfile.PrepareForExport(getfiledata_op.value);
- emit LocaleFileContentsReceived(locale, result);
- emit processFinished("getFileContents", {"Success", file_id, locale});
- busy = false;
- }
- void Lotro::importFilesFromDatabase(QString database_path) {
- if (!tryToBlockFile())
- return;
- if (!FileSystem::fileExists(database_path)) {
- emit caughtError("importFilesFromDatabase", {QString("Ошибка импорта!"), QString("Файл " + file_path + " несуществует! Невозможно инициализировать базу данных!")});
- return;
- }
- emit processStarted("importFilesFromDatabase", {database_path});
- LOTRO_DAT::Database db;
- if (!db.InitDatabase(database_path.toStdString())) {
- emit caughtError("importFilesFromDatabase", {QString("Ошибка импорта!"), QString("Внутренняя ошибка инициализации базы данных!")});
- emit processFinished("importFilesFromDatabase", {QString("Error")});
- return;
- }
- auto patch_operation = file.GetPatcher().PatchAllDatabase(&db);
- if (patch_operation.result) {
- emit processFinished("importFilesFromDatabase", {QString("Success"), patch_operation.value});
- } else {
- emit processFinished("importFilesFromDatabase", {QString("Error"), 0});
- }
- busy = false;
- }
- void Lotro::importFile(long long file_id, QString file_path) {
- }
- void Lotro::importTextFragment(long long file_id, long long fragment_id,
- QString fragment_contents, QString arguments) {
- }
- void Lotro::getTextFragment(long long file_id, long long fragment_id) {
- }
- void Lotro::createCoreStatusFile(QString output_filename) {
- }
- void Lotro::extractSingleFile(QString output_filename, long long file_id) {
- }
- void Lotro::extractSingleFileToDatabase(QString database_path, long long file_id) {
- }
- void Lotro::extractGrouppedFiles(QString output_foldername, LOTRO_DAT::FILE_TYPE type) {
- }
- void Lotro::extractGrouppedFilesToDatabase(QString database_path, LOTRO_DAT::FILE_TYPE type) {
- }
- void Lotro::getUnactiveCategories() {
- }
- void Lotro::startGame() {
- }
- bool Lotro::initialised() {
- }
- int Lotro::currentLocale() {
- }
- bool Lotro::patched() {
- }
- bool Lotro::tryToBlockFile()
- {
- if (busy) {
- emit caughtError("common", {QString("Ошибка инициализации!"), QString("Уже выполняется другой процесс с ресурсами игры! Невозможно инициализировать во время выполнения другого процесса!")});
- return false;
- }
- busy = true;
- }
- void LegacyApp::ExtractFiles(QString folder_name, bool to_database, bool is_single_file, int file_id, LOTRO_DAT::FILE_TYPE type)
- {
- qDebug() << "Extracting files with parameters " << folder_name << to_database << is_single_file << file_id << type;
- QtConcurrent::run([this, folder_name, to_database, is_single_file, file_id, type](){
- if (client_local_dat_busy == false) {
- client_local_dat_busy = true;
- if (is_single_file) {
- auto operation = client_local_dat.GetExporter().ExtractFileById(file_id, std::string((folder_name + "/output").toLocal8Bit().constData()));
- if (operation.result == LOTRO_DAT::SUCCESS)
- QMessageBox::information(nullptr, "Извлечение успешно!", "Файл " + QString::number(file_id) + " был успешно извлечён!\nПуть к файлу: " + folder_name + "/output.{расширение файла}");
- else
- QMessageBox::critical(nullptr, "Ошибка извлечения!", "Файл " + QString::number(file_id) + " не был извлечён ввиду внутренней ошибки\nТекст ошибки: " + QString::fromStdString(operation.msg));
- }
- if (!is_single_file) {
- if (to_database) {
- LOTRO_DAT::Database db;
- qint64 msecs = QDateTime::currentDateTime().toMSecsSinceEpoch();
- QString output_database_filename = folder_name + "/database_" + QString::number(msecs) + ".db";
- db.InitDatabase(std::string(output_database_filename.toStdString()));
- auto operation = client_local_dat.GetExporter().ExtractAllFilesByType(type, &db);
- db.CloseDatabase();
- if (operation.result == LOTRO_DAT::SUCCESS)
- QMessageBox::information(nullptr, "Извлечение успешно!", "Выбранные типы файлов были успешно извлечены в базу данных\nКол-во извлечённых файлов: " + QString::number(operation.value) + "\nПуть к извлечённой базе данных: " + output_database_filename);
- else
- QMessageBox::critical(nullptr, "Ошибка извлечения!", "Файлы не были извлечены ввиду внутренней ошибки\nТекст ошибки: " + QString::fromStdString(operation.msg));
- } else {
- QString output_directory_path = folder_name + "/";
- auto operation = client_local_dat.GetExporter().ExtractAllFilesByType(type, std::string(output_directory_path.toLocal8Bit().constData()));
- if (operation.result == LOTRO_DAT::SUCCESS)
- QMessageBox::information(nullptr, "Извлечение успешно!", "Выбранные типы файлов были успешно извлечены в папку\nКол-во извлечённых файлов: " + QString::number(operation.value) + "\nПуть к папке: " + output_directory_path);
- else
- QMessageBox::critical(nullptr, "Ошибка извлечения!", "Файлы не были извлечены ввиду внутренней ошибки\nТекст ошибки: " + QString::fromStdString(operation.msg));
- }
- }
- client_local_dat_busy = false;
- }
- });
- }
- void LegacyApp::ChangeLocale()
- {
- }
- void LegacyApp::CreateCoreStatusFile(QString output_folder)
- {
- qDebug() << "Creating core status file to output folder " << output_folder;
- QtConcurrent::run([this, output_folder](){
- if (client_local_dat_busy == false) {
- client_local_dat_busy = true;
- qint64 msecs = QDateTime::currentDateTime().toMSecsSinceEpoch();
- QString output_filename = output_folder + "/core_" + QString::number(msecs) + ".txt";
- auto operation = client_local_dat.GatherInformation(std::string(output_filename.toLocal8Bit().constData()));
- client_local_dat_busy = false;
- if (operation.result == LOTRO_DAT::SUCCESS)
- QMessageBox::information(nullptr, "Успех!", "Файл ядра успешно создан!\nПуть к файлу: " + output_filename);
- else
- QMessageBox::critical(nullptr, "Неудача!", "Ошибка создания файла ядра!\nТекст ошибки: " + QString::fromStdString(operation.msg));
- }
- });
- }
|