Move ES_DIVerify's Movie-related code to a more logical place

This commit is contained in:
JosJuice 2017-01-14 20:10:44 +01:00
parent 6aa41ebc55
commit e572fb102f
2 changed files with 50 additions and 43 deletions

View File

@ -57,16 +57,11 @@
#include "Core/IOS/ES/Formats.h" #include "Core/IOS/ES/Formats.h"
#include "Core/IOS/USB/Bluetooth/BTEmu.h" #include "Core/IOS/USB/Bluetooth/BTEmu.h"
#include "Core/IOS/USB/Bluetooth/WiimoteDevice.h" #include "Core/IOS/USB/Bluetooth/WiimoteDevice.h"
#include "Core/Movie.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "Core/ec_wii.h" #include "Core/ec_wii.h"
#include "DiscIO/NANDContentLoader.h" #include "DiscIO/NANDContentLoader.h"
#include "DiscIO/Volume.h" #include "DiscIO/Volume.h"
#ifdef _WIN32
#include <Windows.h>
#endif
namespace IOS namespace IOS
{ {
namespace HLE namespace HLE
@ -1316,44 +1311,6 @@ u32 ES::ES_DIVerify(const std::vector<u8>& tmd)
File::CreateFullPath(tmd_path); File::CreateFullPath(tmd_path);
File::CreateFullPath(Common::GetTitleDataPath(tmd_title_id, Common::FROM_SESSION_ROOT)); File::CreateFullPath(Common::GetTitleDataPath(tmd_title_id, Common::FROM_SESSION_ROOT));
std::string save_path = Common::GetTitleDataPath(tmd_title_id, Common::FROM_SESSION_ROOT);
// TODO: There's not supposed to be a whole load of Movie code in IOS HLE.
// TODO: Force the game to save to another location, instead of moving the user's save.
if (Movie::IsPlayingInput() && Movie::IsConfigSaved() && Movie::IsStartingFromClearSave())
{
if (File::Exists(save_path + "banner.bin"))
{
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
}
}
}
else if (File::Exists(save_path + "../backup/"))
{
// 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
}
if (!File::Exists(tmd_path)) if (!File::Exists(tmd_path))
{ {
File::IOFile tmd_file(tmd_path, "wb"); File::IOFile tmd_file(tmd_path, "wb");

View File

@ -9,15 +9,63 @@
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/NandPaths.h" #include "Common/NandPaths.h"
#include "Common/SysConf.h" #include "Common/SysConf.h"
#include "Core/ConfigManager.h"
#include "Core/Movie.h"
#include "Core/WiiRoot.h" #include "Core/WiiRoot.h"
#ifdef _WIN32
#include <Windows.h>
#endif
namespace Core namespace Core
{ {
static std::string s_temp_wii_root; static std::string s_temp_wii_root;
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())
{
if (File::Exists(save_path + "banner.bin"))
{
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
}
}
}
else if (File::Exists(save_path + "../backup/"))
{
// 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
}
}
void InitializeWiiRoot(bool use_temporary) void InitializeWiiRoot(bool use_temporary)
{ {
ShutdownWiiRoot(); ShutdownWiiRoot();
if (use_temporary) if (use_temporary)
{ {
s_temp_wii_root = File::CreateTempDir(); s_temp_wii_root = File::CreateTempDir();
@ -44,6 +92,8 @@ void InitializeWiiRoot(bool use_temporary)
{ {
File::SetUserPath(D_SESSION_WIIROOT_IDX, File::GetUserPath(D_WIIROOT_IDX)); File::SetUserPath(D_SESSION_WIIROOT_IDX, File::GetUserPath(D_WIIROOT_IDX));
} }
InitializeDeterministicWiiSaves();
} }
void ShutdownWiiRoot() void ShutdownWiiRoot()