From bb207fe27adcaa0d4c00b1962a519195ff4fc200 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Tue, 22 Oct 2019 15:47:31 -0400 Subject: [PATCH] savedata_factory: Automatically create certain savedata After further hardware investigation, it appears that some games, perhaps those more lazily coded, will not call EnsureSaveData, meaning that they expect the normal (current) save to be automatically made. Additionally, some games do not create a cache or temporary save before use. In these 3 specific instances, the save is created automatically for the game if it doesn't exist. --- src/core/file_sys/savedata_factory.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index fc8755c78e..e2a7eaf7b0 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp @@ -16,6 +16,7 @@ namespace FileSys { constexpr char SAVE_DATA_SIZE_FILENAME[] = ".yuzu_save_size"; namespace { + void PrintSaveDataDescriptorWarnings(SaveDataDescriptor meta) { if (meta.type == SaveDataType::SystemSaveData || meta.type == SaveDataType::SaveData) { if (meta.zero_1 != 0) { @@ -52,6 +53,13 @@ void PrintSaveDataDescriptorWarnings(SaveDataDescriptor meta) { meta.user_id[1], meta.user_id[0]); } } + +bool ShouldSaveDataBeAutomaticallyCreated(SaveDataSpaceId space, const SaveDataDescriptor& desc) { + return desc.type == SaveDataType::CacheStorage || desc.type == SaveDataType::TemporaryStorage || + (space == SaveDataSpaceId::NandUser && ///< Normal Save Data -- Current Title & User + desc.type == SaveDataType::SaveData && desc.title_id == 0 && desc.save_id == 0); +} + } // Anonymous namespace std::string SaveDataDescriptor::DebugInfo() const { @@ -96,6 +104,10 @@ ResultVal SaveDataFactory::Open(SaveDataSpaceId space, auto out = dir->GetDirectoryRelative(save_directory); + if (out == nullptr && ShouldSaveDataBeAutomaticallyCreated(space, meta)) { + return Create(space, meta); + } + // Return an error if the save data doesn't actually exist. if (out == nullptr) { // TODO(Subv): Find out correct error code.