// // Created by Иван_Архипов on 31.10.2017. // #define NOMINMAX #include #include #include #ifdef WIN32 #define fseek _fseeki64 #define ftell _ftelli64 #endif #define VERSION "7.0.0" INITIALIZE_EASYLOGGINGPP extern "C++" { namespace LOTRO_DAT { //------------------------------------------------// // INIT SECTION //------------------------------------------------// DatFile::DatFile() { el::Configurations defaultConf; el::Loggers::removeFlag(el::LoggingFlag::CreateLoggerAutomatically); el::Loggers::addFlag(el::LoggingFlag::NewLineForContainer); el::Loggers::addFlag(el::LoggingFlag::LogDetailedCrashReason); el::Loggers::addFlag(el::LoggingFlag::ImmediateFlush); el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck); el::Loggers::addFlag(el::LoggingFlag::HierarchicalLogging); defaultConf.setToDefault(); defaultConf.setGlobally(el::ConfigurationType::Format, "%datetime %level : %msg (function: %func)"); defaultConf.setGlobally(el::ConfigurationType::ToFile, "true"); defaultConf.setGlobally(el::ConfigurationType::Filename, "dat_library.log"); defaultConf.setGlobally(el::ConfigurationType::ToStandardOutput, "false"); defaultConf.setGlobally(el::ConfigurationType::PerformanceTracking, "true"); defaultConf.setGlobally(el::ConfigurationType::MaxLogFileSize, "5242880"); // 5MB defaultConf.set(el::Level::Debug, el::ConfigurationType::Enabled, "false"); defaultConf.set(el::Level::Debug, el::ConfigurationType::Filename, "logs/dat_library_debug.log"); el::Loggers::reconfigureAllLoggers(defaultConf); LOG(INFO) << "=================================================================="; LOG(INFO) << "Starting new DatFile class instance"; io_ = std::make_unique(this); fileSystem_ = std::make_unique(this); localeManager_ = std::make_unique(this); // exporter_ = std::make_unique(this); // patcher_ = std::make_unique(this); // backupManager_ = std::make_unique(this); } LOTRO_DAT::DatLocaleManager &DatFile::getLocaleManager() { return *localeManager_; } // DatExporter &DatFile::getExporter() { // return *exporter_; // } // // LOTRO_DAT::DatPatcher &DatFile::getPatcher() { // return *patcher_; // } // // DatBackupManager &DatFile::getBackupManager() { // return *backupManager_; // } DatIO &DatFile::getIO() { return *io_; } DatFileSystem &DatFile::getFileSystem() { return *fileSystem_; } DatOperationResult<> DatFile::Initialise(const std::string &filename) { if (initialized_ && io_->GetFilename().result == SUCCESS && io_->GetFilename().value == filename) return DatOperationResult<>(); auto operation = io_->Init(filename); if (operation.result != SUCCESS) return DatOperationResult<>(ERROR, "DATINIT: Error, cannot initialize. msg: " + operation.msg); operation = fileSystem_->Init(); if (operation.result != SUCCESS) return DatOperationResult<>(ERROR, "DATINIT: Error, cannot initialize. msg: " + operation.msg); operation = localeManager_->Init(); if (operation.result != SUCCESS) return DatOperationResult<>(ERROR, "DATINIT: Error, cannot initialize. msg: " + operation.msg); initialized_ = true; return DatOperationResult<>(); } DatOperationResult<> DatFile::GatherInformation(const std::string &output_filename) { FILE *out = fopen(output_filename.c_str(), "w"); if (!out) return DatOperationResult<>(ERROR, "GATHERDATINFO: Cannot open file " + output_filename); fprintf(out, "########################################################################################\n" "# LOTRO Dat library version: %8s #\n" "# Author: Gi1dor (e1.gildor@gmail.com) #\n" "# Is part of LOTRO Legacy project (http://translate.lotros.ru/) #\n" "# Last version is available on http://git.gi1dor.ru/LotRO_Legacy/Universal_dat_library #\n" "########################################################################################\n\n\n", VERSION); io_->PrintInformaion(out); fileSystem_->PrintInformaion(out); localeManager_->PrintInformaion(out); return DatOperationResult<>(SUCCESS); } DatOperationResult<> DatFile::Deinitialize() { if (!initialized_) return DatOperationResult<>(); auto operation = localeManager_->DeInit(); if (operation.result != SUCCESS) return DatOperationResult<>(ERROR, "DATDEINIT: Error, cannot deinitialize. msg: " + operation.msg); operation = fileSystem_->DeInit(); if (operation.result != SUCCESS) return DatOperationResult<>(ERROR, "DATDEINIT: Error, cannot deinitialize. msg: " + operation.msg); operation = io_->DeInit(); if (operation.result != SUCCESS) return DatOperationResult<>(ERROR, "DATDEINIT: Error, cannot deinitialize. msg: " + operation.msg); return DatOperationResult<>(); } bool DatFile::Initialized() { return initialized_; } } }