mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 05:40:01 -06:00
Back up Wii setting.txt and SYSCONF while emulating
When booting a Wii game, Dolphin can overwrite certain settings in the SYSCONF file, such as turning off PAL60 for NTSC games. Normally, these settings get reverted at the end of emulation, but this does not happen if Dolphin crashes or force quits in some other way. (Personally, I have a tendency to use Visual Studio's Stop Debugging button, which kills the process...) Dolphin also overwrites certain values in setting.txt when booting a Wii game. Unlike with SYSCONF, we currently make no effort to preserve the original values in this file. This change fixes both of these problems by copying SYSCONF and setting.txt to the Backup folder when booting a Wii game, and then copying them back either when launching Dolphin (in case the previous run of Dolphin crashed) or when ending emulation.
This commit is contained in:
@ -16,6 +16,8 @@
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/NandPaths.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Core/CommonTitles.h"
|
||||
#include "Core/ConfigManager.h"
|
||||
#include "Core/HW/WiiSave.h"
|
||||
#include "Core/IOS/ES/ES.h"
|
||||
@ -32,6 +34,38 @@ namespace FS = IOS::HLE::FS;
|
||||
|
||||
static std::string s_temp_wii_root;
|
||||
|
||||
static bool CopyBackupFile(const std::string& path_from, const std::string& path_to)
|
||||
{
|
||||
if (!File::Exists(path_from))
|
||||
return false;
|
||||
|
||||
return File::Copy(path_from, path_to);
|
||||
}
|
||||
|
||||
static void DeleteBackupFile(const std::string& file_name)
|
||||
{
|
||||
File::Delete(File::GetUserPath(D_BACKUP_IDX) + DIR_SEP + file_name);
|
||||
}
|
||||
|
||||
static void BackupFile(const std::string& path_in_nand)
|
||||
{
|
||||
const std::string file_name = PathToFileName(path_in_nand);
|
||||
const std::string original_path = File::GetUserPath(D_WIIROOT_IDX) + DIR_SEP + path_in_nand;
|
||||
const std::string backup_path = File::GetUserPath(D_BACKUP_IDX) + DIR_SEP + file_name;
|
||||
|
||||
CopyBackupFile(original_path, backup_path);
|
||||
}
|
||||
|
||||
static void RestoreFile(const std::string& path_in_nand)
|
||||
{
|
||||
const std::string file_name = PathToFileName(path_in_nand);
|
||||
const std::string original_path = File::GetUserPath(D_WIIROOT_IDX) + DIR_SEP + path_in_nand;
|
||||
const std::string backup_path = File::GetUserPath(D_BACKUP_IDX) + DIR_SEP + file_name;
|
||||
|
||||
if (CopyBackupFile(backup_path, original_path))
|
||||
DeleteBackupFile(file_name);
|
||||
}
|
||||
|
||||
static void CopySave(FS::FileSystem* source, FS::FileSystem* dest, const u64 title_id)
|
||||
{
|
||||
dest->CreateFullPath(IOS::PID_KERNEL, IOS::PID_KERNEL, Common::GetTitleDataPath(title_id) + '/',
|
||||
@ -173,6 +207,29 @@ void ShutdownWiiRoot()
|
||||
}
|
||||
}
|
||||
|
||||
void BackupWiiSettings()
|
||||
{
|
||||
// Back up files which Dolphin can modify at boot, so that we can preserve the original contents.
|
||||
// For SYSCONF, the backup is only needed in case Dolphin crashes or otherwise exists unexpectedly
|
||||
// during emulation, since the config system will restore the SYSCONF settings at emulation end.
|
||||
// For setting.txt, there is no other code that restores the original values for us.
|
||||
|
||||
BackupFile(Common::GetTitleDataPath(Titles::SYSTEM_MENU) + "/" WII_SETTING);
|
||||
BackupFile("/shared2/sys/SYSCONF");
|
||||
}
|
||||
|
||||
void RestoreWiiSettings(RestoreReason reason)
|
||||
{
|
||||
RestoreFile(Common::GetTitleDataPath(Titles::SYSTEM_MENU) + "/" WII_SETTING);
|
||||
|
||||
// We must not restore the SYSCONF backup when ending emulation cleanly, since the user may have
|
||||
// edited the SYSCONF file in the NAND using the emulated software (e.g. the Wii Menu settings).
|
||||
if (reason == RestoreReason::CrashRecovery)
|
||||
RestoreFile("/shared2/sys/SYSCONF");
|
||||
else
|
||||
DeleteBackupFile("SYSCONF");
|
||||
}
|
||||
|
||||
/// Copy a directory from host_source_path (on the host FS) to nand_target_path on the NAND.
|
||||
///
|
||||
/// Both paths should not have trailing slashes. To specify the NAND root, use "".
|
||||
|
Reference in New Issue
Block a user