[desktop] Fix migration options (#220)
All checks were successful
eden-build / source (push) Successful in 3m29s
eden-build / android (push) Successful in 24m37s
eden-build / linux (push) Successful in 22m0s
eden-build / windows (msvc) (push) Successful in 30m15s

Signed-off-by: crueter <swurl@swurl.xyz>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/220
Co-authored-by: crueter <swurl@swurl.xyz>
Co-committed-by: crueter <swurl@swurl.xyz>
This commit is contained in:
crueter 2025-06-27 06:03:19 +00:00 committed by crueter
parent 3f03ff46b4
commit e7ddc647f3
3 changed files with 37 additions and 14 deletions

View file

@ -1,9 +1,13 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#include "migration_worker.h" #include "migration_worker.h"
#include <QMap> #include <QMap>
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include <filesystem> #include <filesystem>
#include <qdebug.h>
#include "common/fs/path_util.h" #include "common/fs/path_util.h"
@ -19,16 +23,17 @@ MigrationWorker::MigrationWorker(const Emulator selected_legacy_emu_,
void MigrationWorker::process() void MigrationWorker::process()
{ {
namespace fs = std::filesystem; namespace fs = std::filesystem;
const auto copy_options = fs::copy_options::update_existing | fs::copy_options::recursive; constexpr auto copy_options = fs::copy_options::update_existing | fs::copy_options::recursive;
std::string legacy_user_dir = selected_legacy_emu.get_user_dir(); const fs::path legacy_user_dir = selected_legacy_emu.get_user_dir();
std::string legacy_config_dir = selected_legacy_emu.get_config_dir(); const fs::path legacy_config_dir = selected_legacy_emu.get_config_dir();
std::string legacy_cache_dir = selected_legacy_emu.get_cache_dir(); const fs::path legacy_cache_dir = selected_legacy_emu.get_cache_dir();
fs::path eden_dir = Common::FS::GetEdenPath(Common::FS::EdenPath::EdenDir); // TODO(crueter): Make these constexpr since they're defaulted
fs::path config_dir = Common::FS::GetEdenPath(Common::FS::EdenPath::ConfigDir); const fs::path eden_dir = Common::FS::GetEdenPath(Common::FS::EdenPath::EdenDir);
fs::path cache_dir = Common::FS::GetEdenPath(Common::FS::EdenPath::CacheDir); const fs::path config_dir = Common::FS::GetEdenPath(Common::FS::EdenPath::ConfigDir);
fs::path shader_dir = Common::FS::GetEdenPath(Common::FS::EdenPath::ShaderDir); const fs::path cache_dir = Common::FS::GetEdenPath(Common::FS::EdenPath::CacheDir);
const fs::path shader_dir = Common::FS::GetEdenPath(Common::FS::EdenPath::ShaderDir);
try { try {
fs::remove_all(eden_dir); fs::remove_all(eden_dir);
@ -61,6 +66,14 @@ void MigrationWorker::process()
fs::create_directory_symlink(legacy_cache_dir, cache_dir); fs::create_directory_symlink(legacy_cache_dir, cache_dir);
} }
#endif #endif
success_text.append(tr("\n\nNote that your configuration and data will be shared with %1.\n"
"If this is not desirable, delete the following files:\n%2\n%3\n%4")
.arg(tr(selected_legacy_emu.name),
QString::fromStdString(eden_dir.string()),
QString::fromStdString(config_dir.string()),
QString::fromStdString(cache_dir.string())));
break; break;
case MigrationStrategy::Move: case MigrationStrategy::Move:
// Rename directories if deletion is requested (achieves the same result) // Rename directories if deletion is requested (achieves the same result)
@ -83,6 +96,9 @@ void MigrationWorker::process()
// Default behavior: copy // Default behavior: copy
fs::copy(legacy_user_dir, eden_dir, copy_options); fs::copy(legacy_user_dir, eden_dir, copy_options);
// Windows doesn't need any more copies, because cache and config
// are already children of the root directory
#ifndef WIN32
if (fs::is_directory(legacy_config_dir)) { if (fs::is_directory(legacy_config_dir)) {
fs::copy(legacy_config_dir, config_dir, copy_options); fs::copy(legacy_config_dir, config_dir, copy_options);
} }
@ -90,11 +106,12 @@ void MigrationWorker::process()
if (fs::is_directory(legacy_cache_dir)) { if (fs::is_directory(legacy_cache_dir)) {
fs::copy(legacy_cache_dir, cache_dir, copy_options); fs::copy(legacy_cache_dir, cache_dir, copy_options);
} }
#endif
success_text.append(tr("\n\nIf you wish to clean up the files which were left in the old " success_text.append(tr("\n\nIf you wish to clean up the files which were left in the old "
"data location, you can do so by deleting the following directory:\n" "data location, you can do so by deleting the following directory:\n"
"%1") "%1")
.arg(QString::fromStdString(legacy_user_dir))); .arg(QString::fromStdString(legacy_user_dir.string())));
break; break;
} }
@ -104,5 +121,5 @@ void MigrationWorker::process()
fs::create_directory(shader_dir); fs::create_directory(shader_dir);
} }
emit finished(success_text, legacy_user_dir); emit finished(success_text, legacy_user_dir.string());
} }

View file

@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef MIGRATION_WORKER_H #ifndef MIGRATION_WORKER_H
#define MIGRATION_WORKER_H #define MIGRATION_WORKER_H

View file

@ -85,9 +85,11 @@ void UserDataMigrator::ShowMigrationPrompt(QMainWindow *main_window)
BUTTON(QCheckBox, clear_shaders, "Clear Shader Cache", clear_shader_tooltip, true) BUTTON(QCheckBox, clear_shaders, "Clear Shader Cache", clear_shader_tooltip, true)
u32 id = 0;
#define RADIO(name, text, tooltip, checkState) \ #define RADIO(name, text, tooltip, checkState) \
BUTTON(QRadioButton, name, text, tooltip, checkState) \ BUTTON(QRadioButton, name, text, tooltip, checkState) \
group->addButton(name); group->addButton(name, ++id);
RADIO(keep_old, "Keep Old Data", keep_old_data_tooltip, true) RADIO(keep_old, "Keep Old Data", keep_old_data_tooltip, true)
RADIO(clear_old, "Clear Old Data", clear_old_data_tooltip, false) RADIO(clear_old, "Clear Old Data", clear_old_data_tooltip, false)
@ -136,16 +138,17 @@ void UserDataMigrator::ShowMigrationPrompt(QMainWindow *main_window)
} }
MigrationWorker::MigrationStrategy strategy; MigrationWorker::MigrationStrategy strategy;
switch (group->checkedId()) { switch (group->checkedId()) {
default: default:
[[fallthrough]]; [[fallthrough]];
case 0: case 1:
strategy = MigrationWorker::MigrationStrategy::Copy; strategy = MigrationWorker::MigrationStrategy::Copy;
break; break;
case 1: case 2:
strategy = MigrationWorker::MigrationStrategy::Move; strategy = MigrationWorker::MigrationStrategy::Move;
break; break;
case 2: case 3:
strategy = MigrationWorker::MigrationStrategy::Link; strategy = MigrationWorker::MigrationStrategy::Link;
break; break;
} }