diff --git a/Source/Core/Common/CommonPaths.h b/Source/Core/Common/CommonPaths.h index 046e3bfd90..6e248a3c2d 100644 --- a/Source/Core/Common/CommonPaths.h +++ b/Source/Core/Common/CommonPaths.h @@ -76,6 +76,7 @@ #define PIPES_DIR "Pipes" #define MEMORYWATCHER_DIR "MemoryWatcher" #define WFSROOT_DIR "WFS" +#define BACKUP_DIR "Backup" // This one is only used to remove it if it was present #define SHADERCACHE_LEGACY_DIR "ShaderCache" diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index f4f3986b76..08cee6ca3f 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -781,6 +781,7 @@ static void RebuildUserDirectories(unsigned int dir_index) s_user_paths[D_THEMES_IDX] = s_user_paths[D_USER_IDX] + THEMES_DIR DIR_SEP; s_user_paths[D_PIPES_IDX] = s_user_paths[D_USER_IDX] + PIPES_DIR DIR_SEP; s_user_paths[D_WFSROOT_IDX] = s_user_paths[D_USER_IDX] + WFSROOT_DIR DIR_SEP; + s_user_paths[D_BACKUP_IDX] = s_user_paths[D_USER_IDX] + BACKUP_DIR DIR_SEP; s_user_paths[F_DOLPHINCONFIG_IDX] = s_user_paths[D_CONFIG_IDX] + DOLPHIN_CONFIG; s_user_paths[F_DEBUGGERCONFIG_IDX] = s_user_paths[D_CONFIG_IDX] + DEBUGGER_CONFIG; s_user_paths[F_LOGGERCONFIG_IDX] = s_user_paths[D_CONFIG_IDX] + LOGGER_CONFIG; diff --git a/Source/Core/Common/FileUtil.h b/Source/Core/Common/FileUtil.h index bcd28fd968..77228af00e 100644 --- a/Source/Core/Common/FileUtil.h +++ b/Source/Core/Common/FileUtil.h @@ -47,6 +47,7 @@ enum D_PIPES_IDX, D_MEMORYWATCHER_IDX, D_WFSROOT_IDX, + D_BACKUP_IDX, F_DOLPHINCONFIG_IDX, F_DEBUGGERCONFIG_IDX, F_LOGGERCONFIG_IDX, diff --git a/Source/Core/Core/BootManager.cpp b/Source/Core/Core/BootManager.cpp index 8ca31504e2..57c9311632 100644 --- a/Source/Core/Core/BootManager.cpp +++ b/Source/Core/Core/BootManager.cpp @@ -354,6 +354,7 @@ bool BootCore(const std::string& _rFilename) StartUp.bEnableCheats = g_NetPlaySettings.m_EnableCheats; StartUp.bDSPHLE = g_NetPlaySettings.m_DSPHLE; StartUp.bEnableMemcardSdWriting = g_NetPlaySettings.m_WriteToMemcard; + StartUp.bCopyWiiSaveNetplay = g_NetPlaySettings.m_CopyWiiSave; StartUp.iCPUCore = g_NetPlaySettings.m_CPUcore; StartUp.SelectedLanguage = g_NetPlaySettings.m_SelectedLanguage; StartUp.bOverrideGCLanguage = g_NetPlaySettings.m_OverrideGCLanguage; diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index 8aeb3ed5da..55ec14e9b7 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -97,6 +97,7 @@ struct SConfig : NonCopyable bool bHLE_BS2 = true; bool bEnableCheats = false; bool bEnableMemcardSdWriting = true; + bool bCopyWiiSaveNetplay = true; bool bDPL2Decoder = false; int iLatency = 14; diff --git a/Source/Core/Core/HW/HW.cpp b/Source/Core/Core/HW/HW.cpp index d29541c19a..63b0ddd2d2 100644 --- a/Source/Core/Core/HW/HW.cpp +++ b/Source/Core/Core/HW/HW.cpp @@ -22,6 +22,7 @@ #include "Core/HW/VideoInterface.h" #include "Core/HW/WII_IPC.h" #include "Core/IOS/IPC.h" +#include "Core/Movie.h" #include "Core/State.h" #include "Core/WiiRoot.h" #include "DiscIO/NANDContentLoader.h" diff --git a/Source/Core/Core/IOS/ES/ES.cpp b/Source/Core/Core/IOS/ES/ES.cpp index 09c17fbc98..9d07b05a06 100644 --- a/Source/Core/Core/IOS/ES/ES.cpp +++ b/Source/Core/Core/IOS/ES/ES.cpp @@ -58,6 +58,7 @@ #include "Core/IOS/USB/Bluetooth/BTEmu.h" #include "Core/IOS/USB/Bluetooth/WiimoteDevice.h" #include "Core/PowerPC/PowerPC.h" +#include "Core/WiiRoot.h" #include "Core/ec_wii.h" #include "DiscIO/NANDContentLoader.h" #include "DiscIO/Volume.h" diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index 4717ae1ff5..ca4dfb3f58 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -374,6 +374,11 @@ u64 GetTotalLagCount() return s_totalLagCount; } +void SetClearSave(bool enabled) +{ + s_bClearSave = enabled; +} + void SignalDiscChange(const std::string& new_path) { if (Movie::IsRecordingInput()) diff --git a/Source/Core/Core/Movie.h b/Source/Core/Core/Movie.h index 811de415b0..e7da22d12e 100644 --- a/Source/Core/Core/Movie.h +++ b/Source/Core/Core/Movie.h @@ -129,6 +129,7 @@ u64 GetTotalInputCount(); u64 GetCurrentLagCount(); u64 GetTotalLagCount(); +void SetClearSave(bool enabled); void SignalDiscChange(const std::string& new_path); void SetReset(bool reset); diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index db68983004..1c107e1626 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -411,6 +411,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet) packet >> g_NetPlaySettings.m_DSPEnableJIT; packet >> g_NetPlaySettings.m_DSPHLE; packet >> g_NetPlaySettings.m_WriteToMemcard; + packet >> g_NetPlaySettings.m_CopyWiiSave; packet >> g_NetPlaySettings.m_OCEnable; packet >> g_NetPlaySettings.m_OCFactor; diff --git a/Source/Core/Core/NetPlayProto.h b/Source/Core/Core/NetPlayProto.h index cff5d1d00b..3259097046 100644 --- a/Source/Core/Core/NetPlayProto.h +++ b/Source/Core/Core/NetPlayProto.h @@ -21,6 +21,7 @@ struct NetSettings bool m_DSPHLE; bool m_DSPEnableJIT; bool m_WriteToMemcard; + bool m_CopyWiiSave; bool m_OCEnable; float m_OCFactor; TEXIDevices m_EXIDevice[2]; diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 2be0919eb8..19680ade8b 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -807,6 +807,7 @@ bool NetPlayServer::StartGame() *spac << m_settings.m_DSPEnableJIT; *spac << m_settings.m_DSPHLE; *spac << m_settings.m_WriteToMemcard; + *spac << m_settings.m_CopyWiiSave; *spac << m_settings.m_OCEnable; *spac << m_settings.m_OCFactor; *spac << m_settings.m_EXIDevice[0]; diff --git a/Source/Core/Core/WiiRoot.cpp b/Source/Core/Core/WiiRoot.cpp index 7d5061e695..fe52550acd 100644 --- a/Source/Core/Core/WiiRoot.cpp +++ b/Source/Core/Core/WiiRoot.cpp @@ -11,6 +11,7 @@ #include "Common/SysConf.h" #include "Core/ConfigManager.h" #include "Core/Movie.h" +#include "Core/NetPlayClient.h" #include "Core/WiiRoot.h" #ifdef _WIN32 @@ -25,40 +26,29 @@ static void InitializeDeterministicWiiSaves() { std::string save_path = Common::GetTitleDataPath(SConfig::GetInstance().m_title_id, Common::FROM_SESSION_ROOT); - - // TODO: Force the game to save to another location, instead of moving the user's save. - if (Movie::IsPlayingInput() && Movie::IsConfigSaved() && Movie::IsStartingFromClearSave()) + std::string user_save_path = + Common::GetTitleDataPath(SConfig::GetInstance().m_title_id, Common::FROM_CONFIGURED_ROOT); + if (Movie::IsRecordingInput()) { - if (File::Exists(save_path + "banner.bin")) + if (NetPlay::IsNetPlayRunning() && !SConfig::GetInstance().bCopyWiiSaveNetplay) { - if (File::Exists(save_path + "../backup/")) - { - // The last run of this game must have been to play back a movie, so their save is already - // backed up. - File::DeleteDirRecursively(save_path); - } - else - { -#ifdef _WIN32 - MoveFile(UTF8ToTStr(save_path).c_str(), UTF8ToTStr(save_path + "../backup/").c_str()); -#else - File::CopyDir(save_path, save_path + "../backup/"); - File::DeleteDirRecursively(save_path); -#endif - } + Movie::SetClearSave(true); + } + else + { + // TODO: Check for the actual save data + Movie::SetClearSave(!File::Exists(user_save_path + "banner.bin")); } } - else if (File::Exists(save_path + "../backup/")) + + if ((NetPlay::IsNetPlayRunning() && SConfig::GetInstance().bCopyWiiSaveNetplay) || + (Movie::IsMovieActive() && !Movie::IsStartingFromClearSave())) { - // Delete the save made by a previous movie, and copy back the user's save. - if (File::Exists(save_path + "banner.bin")) - File::DeleteDirRecursively(save_path); -#ifdef _WIN32 - MoveFile(UTF8ToTStr(save_path + "../backup/").c_str(), UTF8ToTStr(save_path).c_str()); -#else - File::CopyDir(save_path + "../backup/", save_path); - File::DeleteDirRecursively(save_path + "../backup/"); -#endif + // Copy the current user's save to the Blank NAND + if (File::Exists(user_save_path + "banner.bin")) + { + File::CopyDir(user_save_path, save_path); + } } } @@ -100,6 +90,27 @@ void ShutdownWiiRoot() { if (!s_temp_wii_root.empty()) { + std::string save_path = + Common::GetTitleDataPath(SConfig::GetInstance().m_title_id, Common::FROM_SESSION_ROOT); + std::string user_save_path = + Common::GetTitleDataPath(SConfig::GetInstance().m_title_id, Common::FROM_CONFIGURED_ROOT); + std::string user_backup_path = + File::GetUserPath(D_BACKUP_IDX) + + StringFromFormat("%08x/%08x/", static_cast(SConfig::GetInstance().m_title_id >> 32), + static_cast(SConfig::GetInstance().m_title_id)); + if (File::Exists(save_path + "banner.bin") && SConfig::GetInstance().bEnableMemcardSdWriting) + { + // Backup the existing save just in case it's still needed. + if (File::Exists(user_save_path + "banner.bin")) + { + if (File::Exists(user_backup_path)) + File::DeleteDirRecursively(user_backup_path); + File::CopyDir(user_save_path, user_backup_path); + File::DeleteDirRecursively(user_save_path); + } + File::CopyDir(save_path, user_save_path); + File::DeleteDirRecursively(save_path); + } File::DeleteDirRecursively(s_temp_wii_root); s_temp_wii_root.clear(); } diff --git a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp index f082656a94..516fd276b8 100644 --- a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp @@ -256,12 +256,15 @@ wxSizer* NetPlayDialog::CreateBottomGUI(wxWindow* parent) padbuf_spin->Bind(wxEVT_SPINCTRL, &NetPlayDialog::OnAdjustBuffer, this); padbuf_spin->SetMinSize(WxUtils::GetTextWidgetMinSize(padbuf_spin)); - m_memcard_write = new wxCheckBox(parent, wxID_ANY, _("Write to memory cards/SD")); + m_memcard_write = new wxCheckBox(parent, wxID_ANY, _("Write save/SD data")); + + m_copy_wii_save = new wxCheckBox(parent, wxID_ANY, _("Copy Wii Save")); bottom_szr->Add(m_start_btn, 0, wxALIGN_CENTER_VERTICAL); bottom_szr->Add(buffer_lbl, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, space5); bottom_szr->Add(padbuf_spin, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, space5); bottom_szr->Add(m_memcard_write, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, space5); + bottom_szr->Add(m_copy_wii_save, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, space5); bottom_szr->AddSpacer(space5); } @@ -328,6 +331,7 @@ void NetPlayDialog::GetNetSettings(NetSettings& settings) settings.m_DSPHLE = instance.bDSPHLE; settings.m_DSPEnableJIT = instance.m_DSPEnableJIT; settings.m_WriteToMemcard = m_memcard_write->GetValue(); + settings.m_CopyWiiSave = m_copy_wii_save->GetValue(); settings.m_OCEnable = instance.m_OCEnable; settings.m_OCFactor = instance.m_OCFactor; settings.m_EXIDevice[0] = instance.m_EXIDevice[0]; @@ -406,6 +410,7 @@ void NetPlayDialog::OnMsgStartGame() { m_start_btn->Disable(); m_memcard_write->Disable(); + m_copy_wii_save->Disable(); m_game_btn->Disable(); m_player_config_btn->Disable(); } @@ -421,6 +426,7 @@ void NetPlayDialog::OnMsgStopGame() { m_start_btn->Enable(); m_memcard_write->Enable(); + m_copy_wii_save->Enable(); m_game_btn->Enable(); m_player_config_btn->Enable(); } diff --git a/Source/Core/DolphinWX/NetPlay/NetWindow.h b/Source/Core/DolphinWX/NetPlay/NetWindow.h index 1dd36c52e4..c029c955dc 100644 --- a/Source/Core/DolphinWX/NetPlay/NetWindow.h +++ b/Source/Core/DolphinWX/NetPlay/NetWindow.h @@ -131,6 +131,7 @@ private: wxTextCtrl* m_chat_text; wxTextCtrl* m_chat_msg_text; wxCheckBox* m_memcard_write; + wxCheckBox* m_copy_wii_save; wxCheckBox* m_record_chkbox; std::string m_selected_game;