DatFile.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // Created by Иван_Архипов on 31.10.2017.
  3. //
  4. #define NOMINMAX
  5. #include <DatFile.h>
  6. #include <DatOperationResult.h>
  7. #include <EasyLogging++/easylogging++.h>
  8. #ifdef WIN32
  9. #define fseek _fseeki64
  10. #define ftell _ftelli64
  11. #endif
  12. #define VERSION "7.0.0"
  13. INITIALIZE_EASYLOGGINGPP
  14. extern "C++"
  15. {
  16. namespace LOTRO_DAT {
  17. //------------------------------------------------//
  18. // INIT SECTION
  19. //------------------------------------------------//
  20. DatFile::DatFile() {
  21. el::Configurations defaultConf;
  22. el::Loggers::removeFlag(el::LoggingFlag::CreateLoggerAutomatically);
  23. el::Loggers::addFlag(el::LoggingFlag::NewLineForContainer);
  24. el::Loggers::addFlag(el::LoggingFlag::LogDetailedCrashReason);
  25. el::Loggers::addFlag(el::LoggingFlag::ImmediateFlush);
  26. el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
  27. el::Loggers::addFlag(el::LoggingFlag::HierarchicalLogging);
  28. defaultConf.setToDefault();
  29. defaultConf.setGlobally(el::ConfigurationType::Format, "%datetime %level : %msg (function: %func)");
  30. defaultConf.setGlobally(el::ConfigurationType::ToFile, "true");
  31. defaultConf.setGlobally(el::ConfigurationType::Filename, "dat_library.log");
  32. defaultConf.setGlobally(el::ConfigurationType::ToStandardOutput, "false");
  33. defaultConf.setGlobally(el::ConfigurationType::PerformanceTracking, "true");
  34. defaultConf.setGlobally(el::ConfigurationType::MaxLogFileSize, "5242880"); // 5MB
  35. defaultConf.set(el::Level::Debug, el::ConfigurationType::Enabled, "false");
  36. defaultConf.set(el::Level::Debug, el::ConfigurationType::Filename, "logs/dat_library_debug.log");
  37. el::Loggers::reconfigureAllLoggers(defaultConf);
  38. LOG(INFO) << "==================================================================";
  39. LOG(INFO) << "Starting new DatFile class instance";
  40. io_ = std::make_unique<DatIO>(this);
  41. fileSystem_ = std::make_unique<DatFileSystem>(this);
  42. localeManager_ = std::make_unique<DatLocaleManager>(this);
  43. // exporter_ = std::make_unique<DatExporter>(this);
  44. // patcher_ = std::make_unique<DatPatcher>(this);
  45. // backupManager_ = std::make_unique<DatBackupManager>(this);
  46. }
  47. LOTRO_DAT::DatLocaleManager &DatFile::getLocaleManager() {
  48. return *localeManager_;
  49. }
  50. // DatExporter &DatFile::getExporter() {
  51. // return *exporter_;
  52. // }
  53. //
  54. // LOTRO_DAT::DatPatcher &DatFile::getPatcher() {
  55. // return *patcher_;
  56. // }
  57. //
  58. // DatBackupManager &DatFile::getBackupManager() {
  59. // return *backupManager_;
  60. // }
  61. DatIO &DatFile::getIO() {
  62. return *io_;
  63. }
  64. DatFileSystem &DatFile::getFileSystem() {
  65. return *fileSystem_;
  66. }
  67. DatOperationResult<> DatFile::Initialise(const std::string &filename) {
  68. if (initialized_ && io_->GetFilename().result == SUCCESS && io_->GetFilename().value == filename)
  69. return DatOperationResult<>();
  70. auto operation = io_->Init(filename);
  71. if (operation.result != SUCCESS)
  72. return DatOperationResult<>(ERROR, "DATINIT: Error, cannot initialize. msg: " + operation.msg);
  73. operation = fileSystem_->Init();
  74. if (operation.result != SUCCESS)
  75. return DatOperationResult<>(ERROR, "DATINIT: Error, cannot initialize. msg: " + operation.msg);
  76. operation = localeManager_->Init();
  77. if (operation.result != SUCCESS)
  78. return DatOperationResult<>(ERROR, "DATINIT: Error, cannot initialize. msg: " + operation.msg);
  79. initialized_ = true;
  80. return DatOperationResult<>();
  81. }
  82. DatOperationResult<> DatFile::GatherInformation(const std::string &output_filename) {
  83. FILE *out = fopen(output_filename.c_str(), "w");
  84. if (!out)
  85. return DatOperationResult<>(ERROR, "GATHERDATINFO: Cannot open file " + output_filename);
  86. fprintf(out, "########################################################################################\n"
  87. "# LOTRO Dat library version: %8s #\n"
  88. "# Author: Gi1dor (e1.gildor@gmail.com) #\n"
  89. "# Is part of LOTRO Legacy project (http://translate.lotros.ru/) #\n"
  90. "# Last version is available on http://git.gi1dor.ru/LotRO_Legacy/Universal_dat_library #\n"
  91. "########################################################################################\n\n\n",
  92. VERSION);
  93. io_->PrintInformaion(out);
  94. fileSystem_->PrintInformaion(out);
  95. localeManager_->PrintInformaion(out);
  96. return DatOperationResult<>(SUCCESS);
  97. }
  98. DatOperationResult<> DatFile::Deinitialize() {
  99. if (!initialized_)
  100. return DatOperationResult<>();
  101. auto operation = localeManager_->DeInit();
  102. if (operation.result != SUCCESS)
  103. return DatOperationResult<>(ERROR, "DATDEINIT: Error, cannot deinitialize. msg: " + operation.msg);
  104. operation = fileSystem_->DeInit();
  105. if (operation.result != SUCCESS)
  106. return DatOperationResult<>(ERROR, "DATDEINIT: Error, cannot deinitialize. msg: " + operation.msg);
  107. operation = io_->DeInit();
  108. if (operation.result != SUCCESS)
  109. return DatOperationResult<>(ERROR, "DATDEINIT: Error, cannot deinitialize. msg: " + operation.msg);
  110. return DatOperationResult<>();
  111. }
  112. bool DatFile::Initialized() {
  113. return initialized_;
  114. }
  115. }
  116. }