yuzu-emu
/
yuzu
Archived
1
0
Fork 0

Merge pull request #5023 from lioncash/save-global

savedata_factory: Eliminate usage of the global system instance
This commit is contained in:
Chloe 2020-11-28 02:33:42 +11:00 committed by GitHub
commit f397edff0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 14 deletions

View File

@ -70,7 +70,8 @@ std::string SaveDataAttribute::DebugInfo() const {
static_cast<u8>(rank), index); static_cast<u8>(rank), index);
} }
SaveDataFactory::SaveDataFactory(VirtualDir save_directory) : dir(std::move(save_directory)) { SaveDataFactory::SaveDataFactory(Core::System& system_, VirtualDir save_directory_)
: dir{std::move(save_directory_)}, system{system_} {
// Delete all temporary storages // Delete all temporary storages
// On hardware, it is expected that temporary storage be empty at first use. // On hardware, it is expected that temporary storage be empty at first use.
dir->DeleteSubdirectoryRecursive("temp"); dir->DeleteSubdirectoryRecursive("temp");
@ -83,7 +84,7 @@ ResultVal<VirtualDir> SaveDataFactory::Create(SaveDataSpaceId space,
PrintSaveDataAttributeWarnings(meta); PrintSaveDataAttributeWarnings(meta);
const auto save_directory = const auto save_directory =
GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id); GetFullPath(system, space, meta.type, meta.title_id, meta.user_id, meta.save_id);
auto out = dir->CreateDirectoryRelative(save_directory); auto out = dir->CreateDirectoryRelative(save_directory);
@ -100,7 +101,7 @@ ResultVal<VirtualDir> SaveDataFactory::Open(SaveDataSpaceId space,
const SaveDataAttribute& meta) const { const SaveDataAttribute& meta) const {
const auto save_directory = const auto save_directory =
GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id); GetFullPath(system, space, meta.type, meta.title_id, meta.user_id, meta.save_id);
auto out = dir->GetDirectoryRelative(save_directory); auto out = dir->GetDirectoryRelative(save_directory);
@ -135,13 +136,14 @@ std::string SaveDataFactory::GetSaveDataSpaceIdPath(SaveDataSpaceId space) {
} }
} }
std::string SaveDataFactory::GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id, std::string SaveDataFactory::GetFullPath(Core::System& system, SaveDataSpaceId space,
u128 user_id, u64 save_id) { 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 // 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. // be interpreted as the title id of the current process.
if (type == SaveDataType::SaveData || type == SaveDataType::DeviceSaveData) { if (type == SaveDataType::SaveData || type == SaveDataType::DeviceSaveData) {
if (title_id == 0) { if (title_id == 0) {
title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID(); title_id = system.CurrentProcess()->GetTitleID();
} }
} }
@ -167,7 +169,7 @@ std::string SaveDataFactory::GetFullPath(SaveDataSpaceId space, SaveDataType typ
SaveDataSize SaveDataFactory::ReadSaveDataSize(SaveDataType type, u64 title_id, SaveDataSize SaveDataFactory::ReadSaveDataSize(SaveDataType type, u64 title_id,
u128 user_id) const { u128 user_id) const {
const auto path = GetFullPath(SaveDataSpaceId::NandUser, type, title_id, user_id, 0); const auto path = GetFullPath(system, SaveDataSpaceId::NandUser, type, title_id, user_id, 0);
const auto dir = GetOrCreateDirectoryRelative(this->dir, path); const auto dir = GetOrCreateDirectoryRelative(this->dir, path);
const auto size_file = dir->GetFile(SAVE_DATA_SIZE_FILENAME); const auto size_file = dir->GetFile(SAVE_DATA_SIZE_FILENAME);
@ -182,7 +184,7 @@ SaveDataSize SaveDataFactory::ReadSaveDataSize(SaveDataType type, u64 title_id,
void SaveDataFactory::WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id, void SaveDataFactory::WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id,
SaveDataSize new_value) const { SaveDataSize new_value) const {
const auto path = GetFullPath(SaveDataSpaceId::NandUser, type, title_id, user_id, 0); const auto path = GetFullPath(system, SaveDataSpaceId::NandUser, type, title_id, user_id, 0);
const auto dir = GetOrCreateDirectoryRelative(this->dir, path); const auto dir = GetOrCreateDirectoryRelative(this->dir, path);
const auto size_file = dir->CreateFile(SAVE_DATA_SIZE_FILENAME); const auto size_file = dir->CreateFile(SAVE_DATA_SIZE_FILENAME);

View File

@ -12,6 +12,10 @@
#include "core/file_sys/vfs.h" #include "core/file_sys/vfs.h"
#include "core/hle/result.h" #include "core/hle/result.h"
namespace Core {
class System;
}
namespace FileSys { namespace FileSys {
enum class SaveDataSpaceId : u8 { enum class SaveDataSpaceId : u8 {
@ -84,7 +88,7 @@ struct SaveDataSize {
/// File system interface to the SaveData archive /// File system interface to the SaveData archive
class SaveDataFactory { class SaveDataFactory {
public: public:
explicit SaveDataFactory(VirtualDir dir); explicit SaveDataFactory(Core::System& system_, VirtualDir save_directory_);
~SaveDataFactory(); ~SaveDataFactory();
ResultVal<VirtualDir> Create(SaveDataSpaceId space, const SaveDataAttribute& meta) const; ResultVal<VirtualDir> Create(SaveDataSpaceId space, const SaveDataAttribute& meta) const;
@ -93,8 +97,8 @@ public:
VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const; VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const;
static std::string GetSaveDataSpaceIdPath(SaveDataSpaceId space); static std::string GetSaveDataSpaceIdPath(SaveDataSpaceId space);
static std::string GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id, static std::string GetFullPath(Core::System& system, SaveDataSpaceId space, SaveDataType type,
u128 user_id, u64 save_id); u64 title_id, u128 user_id, u64 save_id);
SaveDataSize ReadSaveDataSize(SaveDataType type, u64 title_id, u128 user_id) const; SaveDataSize ReadSaveDataSize(SaveDataType type, u64 title_id, u128 user_id) const;
void WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id, void WriteSaveDataSize(SaveDataType type, u64 title_id, u128 user_id,
@ -102,6 +106,7 @@ public:
private: private:
VirtualDir dir; VirtualDir dir;
Core::System& system;
}; };
} // namespace FileSys } // namespace FileSys

View File

@ -717,7 +717,8 @@ void FileSystemController::CreateFactories(FileSys::VfsFilesystem& vfs, bool ove
} }
if (save_data_factory == nullptr) { if (save_data_factory == nullptr) {
save_data_factory = std::make_unique<FileSys::SaveDataFactory>(std::move(nand_directory)); save_data_factory =
std::make_unique<FileSys::SaveDataFactory>(system, std::move(nand_directory));
} }
if (sdmc_factory == nullptr) { if (sdmc_factory == nullptr) {

View File

@ -1342,12 +1342,12 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
const auto user_id = manager.GetUser(static_cast<std::size_t>(index)); const auto user_id = manager.GetUser(static_cast<std::size_t>(index));
ASSERT(user_id); ASSERT(user_id);
path = nand_dir + FileSys::SaveDataFactory::GetFullPath( path = nand_dir + FileSys::SaveDataFactory::GetFullPath(
FileSys::SaveDataSpaceId::NandUser, system, FileSys::SaveDataSpaceId::NandUser,
FileSys::SaveDataType::SaveData, program_id, user_id->uuid, 0); FileSys::SaveDataType::SaveData, program_id, user_id->uuid, 0);
} else { } else {
// Device save data // Device save data
path = nand_dir + FileSys::SaveDataFactory::GetFullPath( path = nand_dir + FileSys::SaveDataFactory::GetFullPath(
FileSys::SaveDataSpaceId::NandUser, system, FileSys::SaveDataSpaceId::NandUser,
FileSys::SaveDataType::SaveData, program_id, {}, 0); FileSys::SaveDataType::SaveData, program_id, {}, 0);
} }