savedata_factory.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <memory>
  6. #include <string>
  7. #include "common/common_funcs.h"
  8. #include "common/common_types.h"
  9. #include "common/swap.h"
  10. #include "core/file_sys/vfs.h"
  11. #include "core/hle/result.h"
  12. namespace FileSys {
  13. enum class SaveDataSpaceId : u8 {
  14. NandSystem = 0,
  15. NandUser = 1,
  16. SdCardSystem = 2,
  17. TemporaryStorage = 3,
  18. SdCardUser = 4,
  19. ProperSystem = 100,
  20. };
  21. enum class SaveDataType : u8 {
  22. SystemSaveData = 0,
  23. SaveData = 1,
  24. BcatDeliveryCacheStorage = 2,
  25. DeviceSaveData = 3,
  26. TemporaryStorage = 4,
  27. CacheStorage = 5,
  28. };
  29. enum class SaveDataRank : u8 {
  30. Primary,
  31. Secondary,
  32. };
  33. struct SaveDataDescriptor {
  34. u64_le title_id;
  35. u128 user_id;
  36. u64_le save_id;
  37. SaveDataType type;
  38. SaveDataRank rank;
  39. u16_le index;
  40. INSERT_PADDING_BYTES(4);
  41. u64_le zero_1;
  42. u64_le zero_2;
  43. u64_le zero_3;
  44. std::string DebugInfo() const;
  45. };
  46. static_assert(sizeof(SaveDataDescriptor) == 0x40, "SaveDataDescriptor has incorrect size.");
  47. struct SaveDataSize {
  48. u64 normal;
  49. u64 journal;
  50. };
  51. /// File system interface to the SaveData archive
  52. class SaveDataFactory {
  53. public:
  54. explicit SaveDataFactory(VirtualDir dir);
  55. ~SaveDataFactory();
  56. ResultVal<VirtualDir> Create(SaveDataSpaceId space, const SaveDataDescriptor& meta);
  57. ResultVal<VirtualDir> Open(SaveDataSpaceId space, const SaveDataDescriptor& meta);
  58. VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const;
  59. static std::string GetSaveDataSpaceIdPath(SaveDataSpaceId space);
  60. static std::string GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id,
  61. u128 user_id, u64 save_id);
  62. SaveDataSize ReadSaveDataSize(SaveDataType type, u64 title_id, u128 user_id) const;
  63. void WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id, SaveDataSize new_value);
  64. private:
  65. VirtualDir dir;
  66. };
  67. } // namespace FileSys