DatFile.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. bool Initialized() const;
  25. const std::string& GetFilename() const;
  26. SubfileInfo getSubfileInfo(int file_id) const;
  27. size_t GetFilesNumInDatFile();
  28. size_t PatchAllFilesFromDatabase(Database& db);
  29. void PatchFile(SubfileData file_data, int version = -1, int iteration = -1, bool create = false);
  30. void PatchFile(int file_id, FILE_TYPE type, std::string path_to_file, int version = -1, int iteration = -1);
  31. FILE_TYPE GetExistingFileType(int file_id);
  32. void PerformOperationOnAllSubfiles(const SubfileOperation& operation);
  33. int ExportFilesByType(FILE_TYPE type, Database& db);
  34. int ExportFilesByType(FILE_TYPE type, std::string path_to_directory);
  35. void ExportFileById(int file_id, Database& db);
  36. void ExportFileById(int file_id, std::string target_file_path);
  37. int GetFileVersion(int file_id);
  38. SubfileData GetFile(int file_id);
  39. private:
  40. static DatExportApi api_;
  41. int file_handle_;
  42. bool initialized_;
  43. std::map<int, SubfileInfo> files_info_;
  44. std::string filename_;
  45. BinaryData export_data_buf_;
  46. };
  47. } // namespace LOTRO_DAT