datfile.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "datexportapi.h"
  2. #include "database.h"
  3. #include "subfile.h"
  4. #include <string>
  5. #include <functional>
  6. namespace LOTRO_DAT {
  7. struct SubfileInfo {
  8. int file_id = -1;
  9. int size = -1;
  10. int iteration = -1;
  11. friend bool operator<(const SubfileInfo& info1, const SubfileInfo& info2) {
  12. return info1.file_id < info2.file_id;
  13. }
  14. };
  15. class DatFile;
  16. typedef std::function<void (const SubfileInfo&)> SubfileOperation;
  17. class DatFile {
  18. public:
  19. DatFile(int file_handle);
  20. ~DatFile();
  21. bool Init(const std::string& filename);
  22. void LoadAllFilesInfo();
  23. void Deinit();
  24. static bool checkIfPatchedByLegacyV1(const std::string& filename);
  25. bool Initialized() const;
  26. const std::string& GetFilename() const;
  27. int GetDatFileMaxIteration() const;
  28. SubfileInfo getSubfileInfo(int file_id) const;
  29. size_t GetFilesNumInDatFile();
  30. size_t PatchAllFilesFromDatabase(Database& db);
  31. void PatchFile(SubfileData file_data, int version = -1, int iteration = -1, bool create = false);
  32. void PatchFile(int file_id, FILE_TYPE type, std::string path_to_file, int version = -1, int iteration = -1);
  33. FILE_TYPE GetExistingFileType(int file_id);
  34. void PerformOperationOnAllSubfiles(const SubfileOperation& operation);
  35. int ExportFilesByType(FILE_TYPE type, Database& db);
  36. int ExportFilesByType(FILE_TYPE type, std::string path_to_directory);
  37. void ExportFileById(int file_id, Database& db);
  38. void ExportFileById(int file_id, std::string target_file_path);
  39. int GetFileVersion(int file_id);
  40. SubfileData GetFile(int file_id);
  41. private:
  42. static DatExportApi api_;
  43. int file_handle_;
  44. bool initialized_;
  45. std::map<int, SubfileInfo> files_info_;
  46. std::string filename_;
  47. BinaryData export_data_buf_;
  48. };
  49. } // namespace LOTRO_DAT