feat(fs): Implement Global Custom Save Path

Added a "Global Custom Save Path" configuration option in the Filesystem settings.

Implemented a prioritized save-loading hierarchy: Global Path (if enabled) > Per-Game Custom Path > Default NAND.

Introduced a non-destructive migration tool that allows users to consolidate their existing saves into the new global location.

The migration tool specifically prioritizes per-game custom saves over NAND saves to ensure the most up-to-date data is preserved during consolidation.

The migration process is copy-only; no data is deleted from the source directories, ensuring absolute user data safety.

Maintained compatibility with the existing "Backup Saves to NAND" feature, ensuring saves continue to be mirrored internally if configured.

Signed-off-by: Collecting <collecting@noreply.localhost>
This commit is contained in:
Collecting
2025-12-29 01:12:50 +00:00
parent e7d0bf1af5
commit 2e8d5992a2

View File

@@ -422,17 +422,22 @@ std::shared_ptr<FileSys::SaveDataFactory> FileSystemController::CreateSaveDataFa
const auto rw_mode = FileSys::OpenMode::ReadWrite;
auto vfs = system.GetFilesystem();
// Check for a custom save path for the current game.
if (Settings::values.custom_save_paths.count(program_id)) {
const std::string& custom_path_str = Settings::values.custom_save_paths.at(program_id);
std::string custom_path_str;
// 1. Priority 1: Global Override
if (Settings::values.global_custom_save_path_enabled.GetValue()) {
custom_path_str = Settings::values.global_custom_save_path.GetValue();
}
// 2. Priority 2: Individual Game Override
else if (Settings::values.custom_save_paths.count(program_id)) {
custom_path_str = Settings::values.custom_save_paths.at(program_id);
}
// If any custom logic is hit, use that path but KEEP NAND as backup target
if (!custom_path_str.empty()) {
const std::filesystem::path custom_path = custom_path_str;
// If the custom path is valid and points to a directory, use it.
if (!custom_path_str.empty() && Common::FS::IsDir(custom_path)) {
LOG_INFO(Service_FS, "Using custom save path for program_id={:016X}: {}", program_id, custom_path_str);
if (Common::FS::IsDir(custom_path)) {
auto custom_save_directory = vfs->OpenDirectory(custom_path_str, rw_mode);
// Fetch the default NAND directory to act as the backup location
auto nand_directory = vfs->OpenDirectory(Common::FS::GetCitronPathString(CitronPath::NANDDir), rw_mode);
return std::make_shared<FileSys::SaveDataFactory>(
@@ -440,12 +445,10 @@ std::shared_ptr<FileSys::SaveDataFactory> FileSystemController::CreateSaveDataFa
}
}
// If no valid custom path was found, use the default NAND directory.
const auto nand_directory =
vfs->OpenDirectory(Common::FS::GetCitronPathString(CitronPath::NANDDir), rw_mode);
return std::make_shared<FileSys::SaveDataFactory>(system, program_id,
std::move(nand_directory));
}
// 3. Fallback: Standard NAND
const auto nand_directory = vfs->OpenDirectory(Common::FS::GetCitronPathString(CitronPath::NANDDir), rw_mode);
return std::make_shared<FileSys::SaveDataFactory>(system, program_id, std::move(nand_directory));
}
Result FileSystemController::OpenSDMC(FileSys::VirtualDir* out_sdmc) const {
LOG_TRACE(Service_FS, "Opening SDMC");