diff options
Diffstat (limited to 'src/core/file_sys')
-rw-r--r-- | src/core/file_sys/savedata_factory.cpp | 17 | ||||
-rw-r--r-- | src/core/file_sys/savedata_factory.h | 10 |
2 files changed, 16 insertions, 11 deletions
diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index 12b3bd797..23196cd5f 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp @@ -97,8 +97,9 @@ std::string SaveDataAttribute::DebugInfo() const { static_cast<u8>(rank), index); } -SaveDataFactory::SaveDataFactory(Core::System& system_, VirtualDir save_directory_) - : dir{std::move(save_directory_)}, system{system_} { +SaveDataFactory::SaveDataFactory(Core::System& system_, ProgramId program_id_, + VirtualDir save_directory_) + : system{system_}, program_id{program_id_}, dir{std::move(save_directory_)} { // Delete all temporary storages // On hardware, it is expected that temporary storage be empty at first use. dir->DeleteSubdirectoryRecursive("temp"); @@ -110,7 +111,7 @@ VirtualDir SaveDataFactory::Create(SaveDataSpaceId space, const SaveDataAttribut PrintSaveDataAttributeWarnings(meta); const auto save_directory = - GetFullPath(system, dir, space, meta.type, meta.title_id, meta.user_id, meta.save_id); + GetFullPath(program_id, dir, space, meta.type, meta.title_id, meta.user_id, meta.save_id); return dir->CreateDirectoryRelative(save_directory); } @@ -118,7 +119,7 @@ VirtualDir SaveDataFactory::Create(SaveDataSpaceId space, const SaveDataAttribut VirtualDir SaveDataFactory::Open(SaveDataSpaceId space, const SaveDataAttribute& meta) const { const auto save_directory = - GetFullPath(system, dir, space, meta.type, meta.title_id, meta.user_id, meta.save_id); + GetFullPath(program_id, dir, space, meta.type, meta.title_id, meta.user_id, meta.save_id); auto out = dir->GetDirectoryRelative(save_directory); @@ -147,14 +148,14 @@ std::string SaveDataFactory::GetSaveDataSpaceIdPath(SaveDataSpaceId space) { } } -std::string SaveDataFactory::GetFullPath(Core::System& system, VirtualDir dir, +std::string SaveDataFactory::GetFullPath(ProgramId program_id, VirtualDir dir, SaveDataSpaceId space, SaveDataType type, u64 title_id, u128 user_id, u64 save_id) { // According to switchbrew, if a save is of type SaveData and the title id field is 0, it should // be interpreted as the title id of the current process. if (type == SaveDataType::SaveData || type == SaveDataType::DeviceSaveData) { if (title_id == 0) { - title_id = system.GetApplicationProcessProgramID(); + title_id = program_id; } } @@ -201,7 +202,7 @@ std::string SaveDataFactory::GetUserGameSaveDataRoot(u128 user_id, bool future) SaveDataSize SaveDataFactory::ReadSaveDataSize(SaveDataType type, u64 title_id, u128 user_id) const { const auto path = - GetFullPath(system, dir, SaveDataSpaceId::NandUser, type, title_id, user_id, 0); + GetFullPath(program_id, dir, SaveDataSpaceId::NandUser, type, title_id, user_id, 0); const auto relative_dir = GetOrCreateDirectoryRelative(dir, path); const auto size_file = relative_dir->GetFile(GetSaveDataSizeFileName()); @@ -220,7 +221,7 @@ SaveDataSize SaveDataFactory::ReadSaveDataSize(SaveDataType type, u64 title_id, void SaveDataFactory::WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id, SaveDataSize new_value) const { const auto path = - GetFullPath(system, dir, SaveDataSpaceId::NandUser, type, title_id, user_id, 0); + GetFullPath(program_id, dir, SaveDataSpaceId::NandUser, type, title_id, user_id, 0); const auto relative_dir = GetOrCreateDirectoryRelative(dir, path); const auto size_file = relative_dir->CreateFile(GetSaveDataSizeFileName()); diff --git a/src/core/file_sys/savedata_factory.h b/src/core/file_sys/savedata_factory.h index fd4887e99..30d96928e 100644 --- a/src/core/file_sys/savedata_factory.h +++ b/src/core/file_sys/savedata_factory.h @@ -87,10 +87,13 @@ constexpr const char* GetSaveDataSizeFileName() { return ".yuzu_save_size"; } +using ProgramId = u64; + /// File system interface to the SaveData archive class SaveDataFactory { public: - explicit SaveDataFactory(Core::System& system_, VirtualDir save_directory_); + explicit SaveDataFactory(Core::System& system_, ProgramId program_id_, + VirtualDir save_directory_); ~SaveDataFactory(); VirtualDir Create(SaveDataSpaceId space, const SaveDataAttribute& meta) const; @@ -99,7 +102,7 @@ public: VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const; static std::string GetSaveDataSpaceIdPath(SaveDataSpaceId space); - static std::string GetFullPath(Core::System& system, VirtualDir dir, SaveDataSpaceId space, + static std::string GetFullPath(ProgramId program_id, VirtualDir dir, SaveDataSpaceId space, SaveDataType type, u64 title_id, u128 user_id, u64 save_id); static std::string GetUserGameSaveDataRoot(u128 user_id, bool future); @@ -110,8 +113,9 @@ public: void SetAutoCreate(bool state); private: - VirtualDir dir; Core::System& system; + ProgramId program_id; + VirtualDir dir; bool auto_create{true}; }; |