mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-06-03 22:45:00 -06:00
Implement save migration (#4496)
* Implement save migration * Slightly cursed macro programming * Line break * add const * Remove std::filesystem redefine --------- Co-authored-by: Stephen Miller <56742918+StevenMiller123@users.noreply.github.com>
This commit is contained in:
parent
5f89834cb5
commit
2736ce8c2e
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <SDL3/SDL_messagebox.h>
|
||||||
#include <common/assert.h>
|
#include <common/assert.h>
|
||||||
#include <common/path_util.h>
|
#include <common/path_util.h>
|
||||||
#include "emulator_settings.h"
|
#include "emulator_settings.h"
|
||||||
@ -10,6 +11,8 @@
|
|||||||
#include "user_manager.h"
|
#include "user_manager.h"
|
||||||
#include "user_settings.h"
|
#include "user_settings.h"
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
bool UserManager::AddUser(const User& user) {
|
bool UserManager::AddUser(const User& user) {
|
||||||
for (const auto& u : m_users.user) {
|
for (const auto& u : m_users.user) {
|
||||||
if (u.user_id == user.user_id)
|
if (u.user_id == user.user_id)
|
||||||
@ -143,6 +146,80 @@ Users UserManager::CreateDefaultUsers() {
|
|||||||
std::filesystem::create_directory(user_dir / "savedata");
|
std::filesystem::create_directory(user_dir / "savedata");
|
||||||
std::filesystem::create_directory(user_dir / "trophy");
|
std::filesystem::create_directory(user_dir / "trophy");
|
||||||
std::filesystem::create_directory(user_dir / "inputs");
|
std::filesystem::create_directory(user_dir / "inputs");
|
||||||
|
auto const old_save_dir =
|
||||||
|
Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "savedata" / "1";
|
||||||
|
if (u.user_id == 1000 && std::filesystem::exists(old_save_dir) &&
|
||||||
|
!std::filesystem::is_empty(old_save_dir)) {
|
||||||
|
auto const new_save_dir = user_dir / "savedata";
|
||||||
|
#ifndef _WIN32
|
||||||
|
SDL_MessageBoxButtonData btns[4]
|
||||||
|
#else
|
||||||
|
SDL_MessageBoxButtonData btns[3]
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
{0, 0, "Copy"},
|
||||||
|
{0, 1, "Move"},
|
||||||
|
#ifndef _WIN32
|
||||||
|
{0, 2, "Move and link back"},
|
||||||
|
#endif
|
||||||
|
{0, 3, "Do nothing"},
|
||||||
|
};
|
||||||
|
SDL_MessageBoxData msg_box{
|
||||||
|
0,
|
||||||
|
nullptr,
|
||||||
|
"Save Migration",
|
||||||
|
"The shadPS4 save location has been updated, and save files have been detected "
|
||||||
|
"in the old location.\nDo you wish to copy them over, move them over, "
|
||||||
|
#ifndef _WIN32
|
||||||
|
"move and link back to the original the original location, "
|
||||||
|
#endif
|
||||||
|
"or continue without doing anything?",
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
4,
|
||||||
|
#else
|
||||||
|
3,
|
||||||
|
#endif
|
||||||
|
btns,
|
||||||
|
nullptr,
|
||||||
|
};
|
||||||
|
int result = 3;
|
||||||
|
SDL_ShowMessageBox(&msg_box, &result);
|
||||||
|
try {
|
||||||
|
switch (result) {
|
||||||
|
case 0:
|
||||||
|
std::filesystem::copy(old_save_dir, new_save_dir,
|
||||||
|
std::filesystem::copy_options::recursive);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
try {
|
||||||
|
std::filesystem::rename(old_save_dir, new_save_dir);
|
||||||
|
} catch (...) {
|
||||||
|
std::filesystem::copy(old_save_dir, new_save_dir,
|
||||||
|
std::filesystem::copy_options::recursive);
|
||||||
|
std::filesystem::remove_all(old_save_dir);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
try {
|
||||||
|
std::filesystem::rename(old_save_dir, new_save_dir);
|
||||||
|
} catch (...) {
|
||||||
|
std::filesystem::copy(old_save_dir, new_save_dir,
|
||||||
|
std::filesystem::copy_options::recursive);
|
||||||
|
std::filesystem::remove_all(old_save_dir);
|
||||||
|
}
|
||||||
|
std::filesystem::create_directory_symlink(new_save_dir, old_save_dir);
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
case 3:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
} catch (std::exception const& e) {
|
||||||
|
UNREACHABLE_MSG("Error while migrating saves: {}", e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user