savedata_factory.h 2.8 KB

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