123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- //
- // Created by Иван_Архипов on 23.11.2017.
- //
- #include <iostream>
- #include <ctime>
- #include <algorithm>
- #ifdef WIN32
- #include <direct.h>
- #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;
- }
|