savedata_factory.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 "core/file_sys/vfs.h"
  10. #include "core/hle/result.h"
  11. namespace Core {
  12. class System;
  13. }
  14. namespace FileSys {
  15. enum class SaveDataSpaceId : u8 {
  16. NandSystem = 0,
  17. NandUser = 1,
  18. SdCardSystem = 2,
  19. TemporaryStorage = 3,
  20. SdCardUser = 4,
  21. ProperSystem = 100,
  22. SafeMode = 101,
  23. };
  24. enum class SaveDataType : u8 {
  25. SystemSaveData = 0,
  26. SaveData = 1,
  27. BcatDeliveryCacheStorage = 2,
  28. DeviceSaveData = 3,
  29. TemporaryStorage = 4,
  30. CacheStorage = 5,
  31. SystemBcat = 6,
  32. };
  33. enum class SaveDataRank : u8 {
  34. Primary = 0,
  35. Secondary = 1,
  36. };
  37. enum class SaveDataFlags : u32 {
  38. None = (0 << 0),
  39. KeepAfterResettingSystemSaveData = (1 << 0),
  40. KeepAfterRefurbishment = (1 << 1),
  41. KeepAfterResettingSystemSaveDataWithoutUserSaveData = (1 << 2),
  42. NeedsSecureDelete = (1 << 3),
  43. };
  44. struct SaveDataAttribute {
  45. u64 title_id;
  46. u128 user_id;
  47. u64 save_id;
  48. SaveDataType type;
  49. SaveDataRank rank;
  50. u16 index;
  51. INSERT_PADDING_BYTES_NOINIT(4);
  52. u64 zero_1;
  53. u64 zero_2;
  54. u64 zero_3;
  55. std::string DebugInfo() const;
  56. };
  57. static_assert(sizeof(SaveDataAttribute) == 0x40, "SaveDataAttribute has incorrect size.");
  58. struct SaveDataExtraData {
  59. SaveDataAttribute attr;
  60. u64 owner_id;
  61. s64 timestamp;
  62. SaveDataFlags flags;
  63. INSERT_PADDING_BYTES_NOINIT(4);
  64. s64 available_size;
  65. s64 journal_size;
  66. s64 commit_id;
  67. std::array<u8, 0x190> unused;
  68. };
  69. static_assert(sizeof(SaveDataExtraData) == 0x200, "SaveDataExtraData has incorrect size.");
  70. struct SaveDataSize {
  71. u64 normal;
  72. u64 journal;
  73. };
  74. /// File system interface to the SaveData archive
  75. class SaveDataFactory {
  76. public:
  77. explicit SaveDataFactory(Core::System& system_, VirtualDir save_directory_);
  78. ~SaveDataFactory();
  79. ResultVal<VirtualDir> Create(SaveDataSpaceId space, const SaveDataAttribute& meta) const;
  80. ResultVal<VirtualDir> Open(SaveDataSpaceId space, const SaveDataAttribute& meta) const;
  81. VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const;
  82. static std::string GetSaveDataSpaceIdPath(SaveDataSpaceId space);
  83. static std::string GetFullPath(Core::System& system, SaveDataSpaceId space, SaveDataType type,
  84. u64 title_id, u128 user_id, u64 save_id);
  85. SaveDataSize ReadSaveDataSize(SaveDataType type, u64 title_id, u128 user_id) const;
  86. void WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id,
  87. SaveDataSize new_value) const;
  88. void SetAutoCreate(bool state);
  89. private:
  90. VirtualDir dir;
  91. Core::System& system;
  92. bool auto_create{true};
  93. };
  94. } // namespace FileSys