// // Created by Иван_Архипов on 23.11.2017. // #include #include #include #ifdef WIN32 #include #define mkdir(dir, mode) _mkdir(dir) #endif #include "LotroDat.h" using namespace LOTRO_DAT; void DatStatusChangedHandler(DatStatus::ProgressInfo info) { if (info.status == DatStatus::DAT_STATUS::E_FREE) { std::cout << "DatStatus: operation finished" << std::endl; return; } if (info.status == DatStatus::DAT_STATUS::E_BACKUP_CREATING) { std::cout << "DatStatus: creating backup " << info.percentage << "% " << "(" << info.finished_parts << "/" << info.total_parts << ")" << std::endl; return; } if (info.status == DatStatus::DAT_STATUS::E_BACKUP_REMOVING) { std::cout << "DatStatus: removing backup " << info.percentage << "% " << "(" << info.finished_parts << "/" << info.total_parts << ")" << std::endl; return; } if (info.status == DatStatus::DAT_STATUS::E_BACKUP_RESTORING) { std::cout << "DatStatus: restoring backup " << info.percentage << "% " << "(" << info.finished_parts << "/" << info.total_parts << ")" << std::endl; return; } if (info.status == DatStatus::DAT_STATUS::E_COMMITING) { std::cout << "DatStatus: applying locales " << info.percentage << "% " << "(" << info.finished_parts << "/" << info.total_parts << ")" << std::endl; return; } if (info.status == DatStatus::DAT_STATUS::E_EXTRACTING) { std::cout << "DatStatus: extracting data " << info.percentage << "% " << "(" << info.finished_parts << "/" << info.total_parts << ")" << std::endl; return; } if (info.status == DatStatus::DAT_STATUS::E_GATHERING_INFO) { std::cout << "DatStatus: gathering info " << info.percentage << "% " << "(" << info.finished_parts << "/" << info.total_parts << ")" << std::endl; return; } if (info.status == DatStatus::DAT_STATUS::E_INITIALISING) { std::cout << "DatStatus: initialising " << info.percentage << "% " << "(" << info.finished_parts << "/" << info.total_parts << ")" << std::endl; return; } if (info.status == DatStatus::DAT_STATUS::E_PATCHING) { std::cout << "DatStatus: applying patch " << info.percentage << "% " << "(" << info.finished_parts << "/" << info.total_parts << ")" << std::endl; return; } } int main() { std::cout.precision(1); std::cout << std::fixed; std::cout << "Gi1dor's LotRO .dat patcher ver. " << LOTRO_DAT_VERSION << std::endl; freopen("patcher_errors.log", "w", stderr); setbuf(stdout, nullptr); setbuf(stderr, nullptr); setvbuf (stdout, nullptr, _IONBF, BUFSIZ); setvbuf (stderr, nullptr, _IONBF, BUFSIZ); std::cout << "Hello! I'm a basic shell version of .dat file patcher. I can open .dat file directly, " "if you write path to it (with name of file) in file \"dat_file_path.txt\"\n"; DatFile file; std::ifstream in("dat_file_path.txt"); if (!in.fail()) { std::string filename; std::getline(in, filename); std::string file_id_str; std::getline(in, file_id_str); int file_id = 0; try { file_id = stoi(file_id_str); } catch (std::invalid_argument) { file_id = -1; std::cout << "Invalid file_id on second line of file dat_file_path.txt!\n\n"; } if (file_id != -1) { std::cout << "Using .dat file from dat_file_path.txt...\n"; std::cout << "Opening file " << filename << " with id = " << file_id << std::endl; auto operation = file.Initialise(filename, file_id); if (operation.result == false) { std::cout << "Dat initialisation failed. Error message: " << operation.msg << "\n"; } } } while (!file.Initialized()) { std::cout << "Please, tell, where the .dat file is\n"; std::cout << "Enter path to file (including filename): "; std::string filename; std::getline(std::cin, filename); std::cout << "Enter file id: "; std::string file_id_str; std::getline(std::cin, file_id_str); int file_id = 0; try { file_id = stoi(file_id_str); } catch (std::invalid_argument) { std::cout << "Invalid command entered!\n\n"; continue; } std::cout << "Opening file " << filename << std::endl; auto operation = file.Initialise(filename, file_id); if (operation.result == false) { std::cout << "Dat initialisation failed. Error message: " << operation.msg << "\nTo try again enter path to .dat file\n"; } } std::cout << "Great! File initialised successfully!\n"; file.GetStatusModule().AddStatusChangedCallbackFunction(&DatStatusChangedHandler); while (true) { std::cout << "Please, choose, what should I do. I can patch datfile from database to .dat file (enter 1), " "change locale (enter 2), print current locale (enter 3), enable category (enter 4), disable category (enter 5), " "print disabled categories (enter 6), create backup (enter 7), remove backup (enter 8), " "restore .dat file from backup (enter 9), check if backup exists (enter 10) or exit (enter -1)\n"; std::cout << "Enter number of command (1-10): "; std::string command; std::getline(std::cin, command); int cmd = -10; try { cmd = stoi(command); } catch (std::invalid_argument) { std::cout << "Invalid command entered!\n\n"; continue; } if (cmd == -1) { std::cout << "Exiting. Thanks for using me!\n"; file.Deinitialize(); break; } if (cmd == 1) { std::cout << "You've chosen to patch database! Write name of database file (it should be in the same " "directory), of enter 0 to return to main dialogue.\n"; while (true) { std::cout << "Enter name of file or 0: "; std::string dbname; std::getline(std::cin, dbname); if (dbname == std::to_string(0)) { std::cout << "Okay, returning back...\n\n"; break; } Database db; std::cout << "Opening database... " << dbname << std::endl; if (!db.InitDatabase(dbname)) { std::cout << "Unfortunately, I cannot open this database. Could you try again please?\n"; continue; }; if (db.CountRows() == 0) { std::cout << "There are no files in database or database doesn't exist. " "Please, try again!\n"; continue; } std::cout << "There are " << db.CountRows() << " files in database." << std::endl; std::cout << "Successfully opened database! Beginning patching...\n"; const clock_t begin_time = clock(); file.GetPatcher().PatchAllDatabase(&db); db.CloseDatabase(); fprintf(stdout, "Spent %f seconds on patching! Thank you for your patience!\n", float(clock() - begin_time) / CLOCKS_PER_SEC); std::cout << "Great! File was patched successfully!\n\n"; break; } } if (cmd == 2) { std::cout << "Old locale is " << (file.GetLocaleManager().GetCurrentLocale() == DatLocaleManager::PATCHED ? "RU" : "Original") << std::endl; std::cout << "Changing locale..." << std::endl; file.GetLocaleManager().SetLocale(file.GetLocaleManager().GetCurrentLocale() == DatLocaleManager::PATCHED ? DatLocaleManager::ORIGINAL : DatLocaleManager::PATCHED); std::cout << "New locale is " << (file.GetLocaleManager().GetCurrentLocale() == DatLocaleManager::PATCHED ? "RU" : "Original") << std::endl; } if (cmd == 3) { std::cout << "Current locale is " << (file.GetLocaleManager().GetCurrentLocale() == DatLocaleManager::PATCHED ? "RU" : "Original") << std::endl; } if (cmd == 4) { int category_id = 0; std::cout << "Enter category id: "; std::cin >> category_id; file.GetLocaleManager().EnableCategory(category_id); std::cout << "Category successfully enabled!" << std::endl; } if (cmd == 5) { int category_id = 0; std::cout << "Enter category id: "; std::cin >> category_id; file.GetLocaleManager().DisableCategory(category_id); std::cout << "Category successfully disabled!" << std::endl; } if (cmd == 6) { std::cout << "Disabled categories: "; for (auto i : file.GetLocaleManager().GetInactiveCategories()) std::cout << i << " "; std::cout << std::endl; } if (cmd == 7) { std::cout << "Creating backup..." << std::endl; std::cout << "Create backup function returned " << file.GetBackupManager().CreateBackup("cli_local_En.backup").result << std::endl; } if (cmd == 8) { std::cout << "Removing backup..." << std::endl; std::cout << "Remove backup function returned " << file.GetBackupManager().RemoveBackup("cli_local_En.backup").result << std::endl; } if (cmd == 9) { std::cout << "Restoring file from backup..." << std::endl; std::cout << "Restore file function returned " << file.GetBackupManager().RestoreFromBackup("cli_local_En.backup").result << std::endl; } if (cmd == 10) { std::cout << "Backup file " << (file.GetBackupManager().CheckIfBackupAvailable("cli_local_En.backup") ? "exists!" : "doesn't exist.") << std::endl; } } //system("pause"); return 0; }