Boot: Initialize Wii root before saving SYSCONF file

Fixes netplay and movie overrides of SYSCONF settings not applying.
This commit is contained in:
JosJuice 2021-03-06 19:14:18 +01:00
parent 359ed5348a
commit 46dbb455e1
7 changed files with 44 additions and 16 deletions

View File

@ -433,11 +433,23 @@ bool BootCore(std::unique_ptr<BootParameters> boot, const WindowSystemInfo& wsi)
if (StartUp.bWii && DiscIO::IsNTSC(StartUp.m_region) && Config::Get(Config::SYSCONF_PAL60))
Config::SetCurrent(Config::SYSCONF_PAL60, false);
// Ensure any new settings are written to the SYSCONF
if (StartUp.bWii)
{
Core::BackupWiiSettings();
ConfigLoaders::SaveToSYSCONF(Config::LayerType::Meta);
const bool want_determinism = Movie::IsMovieActive() || NetPlay::IsNetPlayRunning();
Core::InitializeWiiRoot(want_determinism);
// Ensure any new settings are written to the SYSCONF
if (!want_determinism)
{
Core::BackupWiiSettings();
ConfigLoaders::SaveToSYSCONF(Config::LayerType::Meta);
}
else
{
ConfigLoaders::SaveToSYSCONF(Config::LayerType::Meta, [](const Config::Location& location) {
return Config::GetActiveLayerForConfig(location) >= Config::LayerType::Movie;
});
}
}
const bool load_ipl = !StartUp.bWii && !StartUp.bHLE_BS2 &&
@ -486,8 +498,14 @@ static void RestoreSYSCONF()
void RestoreConfig()
{
Core::RestoreWiiSettings(Core::RestoreReason::EmulationEnd);
RestoreSYSCONF();
Core::ShutdownWiiRoot();
if (!Core::WiiRootIsTemporary())
{
Core::RestoreWiiSettings(Core::RestoreReason::EmulationEnd);
RestoreSYSCONF();
}
Config::ClearCurrentRunLayer();
Config::RemoveLayer(Config::LayerType::Movie);
Config::RemoveLayer(Config::LayerType::Netplay);

View File

@ -6,6 +6,7 @@
#include <algorithm>
#include <cstring>
#include <functional>
#include <list>
#include <map>
#include <memory>
@ -29,7 +30,7 @@
namespace ConfigLoaders
{
void SaveToSYSCONF(Config::LayerType layer)
void SaveToSYSCONF(Config::LayerType layer, std::function<bool(const Config::Location&)> predicate)
{
if (Core::IsRunning())
return;
@ -40,7 +41,10 @@ void SaveToSYSCONF(Config::LayerType layer)
for (const Config::SYSCONFSetting& setting : Config::SYSCONF_SETTINGS)
{
std::visit(
[layer, &setting, &sysconf](auto* info) {
[&](auto* info) {
if (predicate && !predicate(info->GetLocation()))
return;
const std::string key = info->GetLocation().section + "." + info->GetLocation().key;
if (setting.type == SysConf::Entry::Type::Long)

View File

@ -4,16 +4,19 @@
#pragma once
#include <functional>
#include <memory>
namespace Config
{
class ConfigLayerLoader;
enum class LayerType;
struct Location;
} // namespace Config
namespace ConfigLoaders
{
void SaveToSYSCONF(Config::LayerType layer);
void SaveToSYSCONF(Config::LayerType layer,
std::function<bool(const Config::Location&)> predicate = {});
std::unique_ptr<Config::ConfigLayerLoader> GenerateBaseConfigLoader();
} // namespace ConfigLoaders

View File

@ -590,7 +590,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
return;
// Initialise Wii filesystem contents.
// This is done here after Boot and not in HW to ensure that we operate
// This is done here after Boot and not in BootManager to ensure that we operate
// with the correct title context since save copying requires title directories to exist.
Common::ScopeGuard wiifs_guard{&Core::CleanUpWiiFileSystemContents};
if (SConfig::GetInstance().bWii)

View File

@ -25,7 +25,6 @@
#include "Core/HW/WII_IPC.h"
#include "Core/IOS/IOS.h"
#include "Core/State.h"
#include "Core/WiiRoot.h"
namespace HW
{
@ -52,8 +51,6 @@ void Init()
if (SConfig::GetInstance().bWii)
{
// The NAND should only be initialised once per emulation session.
Core::InitializeWiiRoot(Core::WantsDeterminism());
IOS::Init();
IOS::HLE::Init(); // Depends on Memory
}
@ -64,7 +61,6 @@ void Shutdown()
// IOS should always be shut down regardless of bWii because it can be running in GC mode (MIOS).
IOS::HLE::Shutdown(); // Depends on Memory
IOS::Shutdown();
Core::ShutdownWiiRoot();
SystemTimers::Shutdown();
CPU::Shutdown();

View File

@ -202,13 +202,18 @@ void InitializeWiiRoot(bool use_temporary)
void ShutdownWiiRoot()
{
if (!s_temp_wii_root.empty())
if (WiiRootIsTemporary())
{
File::DeleteDirRecursively(s_temp_wii_root);
s_temp_wii_root.clear();
}
}
bool WiiRootIsTemporary()
{
return !s_temp_wii_root.empty();
}
void BackupWiiSettings()
{
// Back up files which Dolphin can modify at boot, so that we can preserve the original contents.
@ -282,7 +287,7 @@ void InitializeWiiFileSystemContents()
if (!CopySysmenuFilesToFS(fs.get(), File::GetSysDirectory() + WII_USER_DIR, ""))
WARN_LOG_FMT(CORE, "Failed to copy initial System Menu files to the NAND");
if (s_temp_wii_root.empty())
if (!WiiRootIsTemporary())
return;
// Generate a SYSCONF with default settings for the temporary Wii NAND.
@ -294,7 +299,7 @@ void InitializeWiiFileSystemContents()
void CleanUpWiiFileSystemContents()
{
if (s_temp_wii_root.empty() || !SConfig::GetInstance().bEnableMemcardSdWriting ||
if (!WiiRootIsTemporary() || !SConfig::GetInstance().bEnableMemcardSdWriting ||
NetPlay::GetWiiSyncFS())
{
return;

View File

@ -15,6 +15,8 @@ enum class RestoreReason
void InitializeWiiRoot(bool use_temporary);
void ShutdownWiiRoot();
bool WiiRootIsTemporary();
void BackupWiiSettings();
void RestoreWiiSettings(RestoreReason reason);