diff --git a/rpcs3/Crypto/unpkg.cpp b/rpcs3/Crypto/unpkg.cpp index 7e1cd31e38..45268062de 100644 --- a/rpcs3/Crypto/unpkg.cpp +++ b/rpcs3/Crypto/unpkg.cpp @@ -5,6 +5,7 @@ #include "util/logs.hpp" #include "Utilities/StrUtil.h" #include "Emu/System.h" +#include "Emu/system_utils.hpp" #include "Emu/VFS.h" #include "unpkg.h" #include "Loader/PSF.h" @@ -590,7 +591,7 @@ package_error package_reader::check_target_app_version() const return package_error::no_error; } - const fs::file installed_sfo_file(Emu.GetHddDir() + "game/" + std::string(title_id) + "/PARAM.SFO"); + const fs::file installed_sfo_file(rpcs3::utils::get_hdd0_dir() + "game/" + std::string(title_id) + "/PARAM.SFO"); if (!installed_sfo_file) { if (!target_app_ver.empty()) @@ -674,7 +675,7 @@ bool package_reader::extract_data(atomic_t& sync) } // Get full path and create the directory - std::string dir = Emulator::GetHddDir(); + std::string dir = rpcs3::utils::get_hdd0_dir(); // Based on https://www.psdevwiki.com/ps3/PKG_files#ContentType switch (m_metadata.content_type) diff --git a/rpcs3/Crypto/unself.cpp b/rpcs3/Crypto/unself.cpp index 647e49dd93..72d5f212a7 100644 --- a/rpcs3/Crypto/unself.cpp +++ b/rpcs3/Crypto/unself.cpp @@ -4,6 +4,7 @@ #include "unself.h" #include "Emu/VFS.h" #include "Emu/System.h" +#include "Emu/system_utils.hpp" #include #include @@ -1320,7 +1321,7 @@ bool SELFDecrypter::GetKeyFromRap(u8* content_id, u8* npdrm_key) // Try to find a matching RAP file under exdata folder. const std::string ci_str = reinterpret_cast(content_id); - const std::string rap_path = Emulator::GetRapFilePath(ci_str); + const std::string rap_path = rpcs3::utils::get_rap_file_path(ci_str); // Open the RAP file and read the key. const fs::file rap_file(rap_path); diff --git a/rpcs3/Emu/CMakeLists.txt b/rpcs3/Emu/CMakeLists.txt index 159d5f88cc..bfd6c0319f 100644 --- a/rpcs3/Emu/CMakeLists.txt +++ b/rpcs3/Emu/CMakeLists.txt @@ -1,9 +1,12 @@ add_library(rpcs3_emu + cache_utils.cpp IdManager.cpp localized_string.cpp System.cpp system_config.cpp system_config_types.cpp + system_progress.cpp + system_utils.cpp VFS.cpp GDB.cpp title.cpp diff --git a/rpcs3/Emu/Cell/Modules/cellGame.cpp b/rpcs3/Emu/Cell/Modules/cellGame.cpp index 1cc08f2391..bb9596ab06 100644 --- a/rpcs3/Emu/Cell/Modules/cellGame.cpp +++ b/rpcs3/Emu/Cell/Modules/cellGame.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "Emu/localized_string.h" #include "Emu/System.h" +#include "Emu/system_utils.hpp" #include "Emu/VFS.h" #include "Emu/IdManager.h" #include "Emu/Cell/ErrorCodes.h" @@ -978,7 +979,7 @@ error_code cellGameDeleteGameData(vm::cptr dirName) } // Actually remove game data - if (!vfs::host::remove_all(dir, Emu.GetHddDir(), &g_mp_sys_dev_hdd0, true)) + if (!vfs::host::remove_all(dir, rpcs3::utils::get_hdd0_dir(), &g_mp_sys_dev_hdd0, true)) { return {CELL_GAME_ERROR_ACCESS_ERROR, dir}; } diff --git a/rpcs3/Emu/Cell/Modules/cellSysCache.cpp b/rpcs3/Emu/Cell/Modules/cellSysCache.cpp index 7999dc0de1..28dd3a1911 100644 --- a/rpcs3/Emu/Cell/Modules/cellSysCache.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSysCache.cpp @@ -1,5 +1,6 @@ #include "stdafx.h" #include "Emu/System.h" +#include "Emu/system_utils.hpp" #include "Emu/VFS.h" #include "Emu/IdManager.h" #include "Emu/Cell/PPUModule.h" @@ -32,7 +33,7 @@ extern lv2_fs_mount_point g_mp_sys_dev_hdd1; struct syscache_info { - const std::string cache_root = Emu.GetHdd1Dir() + "/caches/"; + const std::string cache_root = rpcs3::utils::get_hdd1_dir() + "/caches/"; stx::init_mutex init; diff --git a/rpcs3/Emu/Cell/Modules/cellUserInfo.cpp b/rpcs3/Emu/Cell/Modules/cellUserInfo.cpp index 90757bbb04..960db3b912 100644 --- a/rpcs3/Emu/Cell/Modules/cellUserInfo.cpp +++ b/rpcs3/Emu/Cell/Modules/cellUserInfo.cpp @@ -1,5 +1,6 @@ #include "stdafx.h" #include "Emu/System.h" +#include "Emu/system_utils.hpp" #include "Emu/VFS.h" #include "Emu/IdManager.h" #include "Emu/Cell/PPUModule.h" @@ -22,7 +23,7 @@ std::string get_username(const u32 user_id) { std::string username; - if (const fs::file file{Emulator::GetHddDir() + fmt::format("home/%08d/localusername", user_id)}) + if (const fs::file file{rpcs3::utils::get_hdd0_dir() + fmt::format("home/%08d/localusername", user_id)}) { username = file.to_string(); username.resize(CELL_USERINFO_USERNAME_SIZE); // TODO: investigate @@ -119,7 +120,7 @@ error_code cellUserInfoSelectUser_ListType(vm::ptr listType } std::vector user_ids; - const std::string home_dir = Emulator::GetHddDir() + "home"; + const std::string home_dir = rpcs3::utils::get_hdd0_dir() + "home"; for (const auto& user_folder : fs::dir(home_dir)) { @@ -129,7 +130,7 @@ error_code cellUserInfoSelectUser_ListType(vm::ptr listType } // Is the folder name exactly 8 all-numerical characters long? - const u32 user_id = Emulator::CheckUsr(user_folder.name); + const u32 user_id = rpcs3::utils::check_user(user_folder.name); if (user_id == 0) { @@ -330,7 +331,7 @@ error_code cellUserInfoGetList(vm::ptr listNum, vm::ptr user_ids; for (const auto& user_folder : fs::dir(home_dir)) @@ -341,7 +342,7 @@ error_code cellUserInfoGetList(vm::ptr listNum, vm::ptr k_licensee_addr, vm::cptr drm_pat if (VerifyEDATHeaderWithKLicense(enc_file, enc_drm_path_local, reinterpret_cast(&k_licensee), &contentID)) { - const std::string rap_file = Emulator::GetRapFilePath(contentID); + const std::string rap_file = rpcs3::utils::get_rap_file_path(contentID); npdrmkeys.devKlic = k_licensee; if (fs::is_file(rap_file)) @@ -552,7 +553,7 @@ error_code sceNpDrmVerifyUpgradeLicense(vm::cptr content_id) } const std::string content_str(content_id.get_ptr(), std::find(content_id.get_ptr(), content_id.get_ptr() + 0x2f, '\0')); - const std::string rap_file = Emulator::GetRapFilePath(content_str); + const std::string rap_file = rpcs3::utils::get_rap_file_path(content_str); sceNp.warning(u8"sceNpDrmVerifyUpgradeLicense(): content_id=“%s”", content_id); @@ -576,7 +577,7 @@ error_code sceNpDrmVerifyUpgradeLicense2(vm::cptr content_id) } const std::string content_str(content_id.get_ptr(), std::find(content_id.get_ptr(), content_id.get_ptr() + 0x2f, '\0')); - const std::string rap_file = Emulator::GetRapFilePath(content_str); + const std::string rap_file = rpcs3::utils::get_rap_file_path(content_str); sceNp.warning(u8"sceNpDrmVerifyUpgradeLicense2(): content_id=“%s”", content_id); diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index caa6307f2c..2ce2966e22 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -10,6 +10,8 @@ #include "Emu/Memory/vm_locking.h" #include "Emu/RSX/RSXThread.h" #include "Emu/VFS.h" +#include "Emu/system_progress.hpp" +#include "Emu/system_utils.hpp" #include "PPUThread.h" #include "PPUInterpreter.h" #include "PPUAnalyser.h" @@ -67,8 +69,6 @@ const bool s_use_ssse3 = utils::has_ssse3(); extern atomic_t g_watchdog_hold_ctr; -#include "Emu/system_progress.hpp" - // Should be of the same type using spu_rdata_t = decltype(ppu_thread::rdata); @@ -2999,7 +2999,7 @@ bool ppu_initialize(const ppu_module& info, bool check_only) // Create worker threads for compilation (TODO: how many threads) { - u32 thread_count = Emulator::GetMaxThreads(); + u32 thread_count = rpcs3::utils::get_max_threads(); if (workload.size() < thread_count) { diff --git a/rpcs3/Emu/Cell/SPURecompiler.cpp b/rpcs3/Emu/Cell/SPURecompiler.cpp index 10ef662aab..355ae0eb6f 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.cpp +++ b/rpcs3/Emu/Cell/SPURecompiler.cpp @@ -3,6 +3,9 @@ #include "Emu/System.h" #include "Emu/system_config.h" +#include "Emu/system_progress.hpp" +#include "Emu/system_utils.hpp" +#include "Emu/cache_utils.hpp" #include "Emu/IdManager.h" #include "Emu/Cell/timers.hpp" #include "Crypto/sha1.h" @@ -23,8 +26,6 @@ #include "util/v128sse.hpp" #include "util/sysinfo.hpp" -#include "Emu/system_progress.hpp" - const spu_decoder s_spu_itype; const spu_decoder s_spu_iname; const spu_decoder s_spu_iflag; @@ -368,7 +369,7 @@ void spu_cache::initialize() } } - const std::string ppu_cache = Emu.PPUCache(); + const std::string ppu_cache = rpcs3::cache::get_ppu_cache(); if (ppu_cache.empty()) { @@ -425,7 +426,7 @@ void spu_cache::initialize() g_progr_ptotal += ::size32(func_list); progr.emplace("Building SPU cache..."); - worker_count = Emulator::GetMaxThreads(); + worker_count = rpcs3::utils::get_max_threads(); } named_thread_group workers("SPU Worker ", worker_count, [&]() -> uint @@ -585,7 +586,7 @@ bool spu_program::operator<(const spu_program& rhs) const noexcept spu_runtime::spu_runtime() { // Clear LLVM output - m_cache_path = Emu.PPUCache(); + m_cache_path = rpcs3::cache::get_ppu_cache(); if (m_cache_path.empty()) { diff --git a/rpcs3/Emu/Io/PadHandler.cpp b/rpcs3/Emu/Io/PadHandler.cpp index e3eb3e67af..9bc95a9057 100644 --- a/rpcs3/Emu/Io/PadHandler.cpp +++ b/rpcs3/Emu/Io/PadHandler.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include "PadHandler.h" -#include "Emu/System.h" +#include "Emu/system_utils.hpp" #include "Input/pad_thread.h" #include "Input/product_info.h" @@ -292,16 +292,16 @@ std::string PadHandlerBase::get_config_dir(pad_handler type, const std::string& { if (!title_id.empty()) { - return Emulator::GetCustomInputConfigDir(title_id) + fmt::format("%s", type) + "/"; + return rpcs3::utils::get_custom_input_config_dir(title_id) + fmt::format("%s", type) + "/"; } return fs::get_config_dir() + "/InputConfigs/" + fmt::format("%s", type) + "/"; } std::string PadHandlerBase::get_config_filename(int i, const std::string& title_id) { - if (!title_id.empty() && fs::is_file(Emulator::GetCustomInputConfigPath(title_id))) + if (!title_id.empty() && fs::is_file(rpcs3::utils::get_custom_input_config_path(title_id))) { - const std::string path = Emulator::GetCustomInputConfigDir(title_id) + g_cfg_input.player[i]->handler.to_string() + "/" + g_cfg_input.player[i]->profile.to_string() + ".yml"; + const std::string path = rpcs3::utils::get_custom_input_config_dir(title_id) + g_cfg_input.player[i]->handler.to_string() + "/" + g_cfg_input.player[i]->profile.to_string() + ".yml"; if (fs::is_file(path)) { return path; diff --git a/rpcs3/Emu/Io/pad_config.cpp b/rpcs3/Emu/Io/pad_config.cpp index 79d87d13d7..2d96f509dc 100644 --- a/rpcs3/Emu/Io/pad_config.cpp +++ b/rpcs3/Emu/Io/pad_config.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include "pad_config.h" -#include "Emu/System.h" +#include "Emu/system_utils.hpp" cfg_input::cfg_input() : cfg_name(fs::get_config_dir() + "/config_input.yml") @@ -9,7 +9,7 @@ cfg_input::cfg_input() bool cfg_input::load(const std::string& title_id) { - cfg_name = Emulator::GetCustomInputConfigPath(title_id); + cfg_name = rpcs3::utils::get_custom_input_config_path(title_id); if (!fs::is_file(cfg_name)) { @@ -38,7 +38,7 @@ void cfg_input::save(const std::string& title_id) } else { - cfg_name = Emulator::GetCustomInputConfigPath(title_id); + cfg_name = rpcs3::utils::get_custom_input_config_path(title_id); } fs::file(cfg_name, fs::rewrite).write(to_string()); } diff --git a/rpcs3/Emu/RSX/Common/texture_cache_utils.h b/rpcs3/Emu/RSX/Common/texture_cache_utils.h index c73744b3bc..72657f51d4 100644 --- a/rpcs3/Emu/RSX/Common/texture_cache_utils.h +++ b/rpcs3/Emu/RSX/Common/texture_cache_utils.h @@ -1,11 +1,11 @@ #pragma once -#include "../rsx_cache.h" #include "texture_cache_types.h" #include "texture_cache_predictor.h" #include "TextureUtils.h" #include "Emu/Memory/vm.h" +#include "util/vm.hpp" #include #include diff --git a/rpcs3/Emu/RSX/Overlays/overlay_user_list_dialog.cpp b/rpcs3/Emu/RSX/Overlays/overlay_user_list_dialog.cpp index c2cb355ceb..83709ea20f 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_user_list_dialog.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_user_list_dialog.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "overlay_user_list_dialog.h" -#include "Emu/System.h" #include "Emu/system_config.h" +#include "Emu/system_utils.hpp" #include "Utilities/StrUtil.h" #include "Utilities/Thread.h" @@ -152,7 +152,7 @@ namespace rsx std::vector icon; std::vector> entries; - const std::string home_dir = Emulator::GetHddDir() + "home/"; + const std::string home_dir = rpcs3::utils::get_hdd0_dir() + "home/"; s32 selected_index = 0; for (const auto& id : user_ids) diff --git a/rpcs3/Emu/RSX/rsx_cache.h b/rpcs3/Emu/RSX/rsx_cache.h index a65012ed0d..a09913facf 100644 --- a/rpcs3/Emu/RSX/rsx_cache.h +++ b/rpcs3/Emu/RSX/rsx_cache.h @@ -4,6 +4,7 @@ #include "Utilities/Thread.h" #include "Common/ProgramStateCache.h" #include "Emu/System.h" +#include "Emu/cache_utils.hpp" #include "Common/texture_cache_checker.h" #include "Overlays/Shaders/shader_loading_dialog.h" @@ -11,7 +12,6 @@ #include #include -#include "util/vm.hpp" #include "util/sysinfo.hpp" #include "util/fnv_hash.hpp" @@ -199,7 +199,7 @@ namespace rsx { if (!g_cfg.video.disable_on_disk_shader_cache) { - root_path = Emu.PPUCache() + "shaders_cache"; + root_path = rpcs3::cache::get_ppu_cache() + "shaders_cache"; } } diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 80f8613ace..c7009ea4dc 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -3,6 +3,8 @@ #include "Utilities/bin_patch.h" #include "Emu/Memory/vm.h" #include "Emu/System.h" +#include "Emu/system_progress.hpp" +#include "Emu/system_utils.hpp" #include "Emu/perf_meter.hpp" #include "Emu/Cell/ErrorCodes.h" @@ -15,12 +17,10 @@ #include "Emu/Cell/lv2/sys_sync.h" #include "Emu/Cell/lv2/sys_prx.h" #include "Emu/Cell/lv2/sys_overlay.h" -#include "Emu/Cell/Modules/cellMsgDialog.h" #include "Emu/title.h" #include "Emu/IdManager.h" #include "Emu/RSX/Capture/rsx_replay.h" -#include "Emu/RSX/Overlays/overlay_message_dialog.h" #include "Loader/PSF.h" #include "Loader/ELF.h" @@ -28,17 +28,13 @@ #include "Utilities/StrUtil.h" #include "../Crypto/unself.h" -#include "../Crypto/unpkg.h" -#include "util/sysinfo.hpp" #include "util/yaml.hpp" #include "util/logs.hpp" #include "util/cereal.hpp" -#include #include #include #include -#include #include "Utilities/JIT.h" @@ -75,21 +71,9 @@ atomic_t g_tty_size{0}; std::array, 16> g_tty_input; std::mutex g_tty_mutex; -// Progress display server synchronization variables -atomic_t g_progr{nullptr}; -atomic_t g_progr_ftotal{0}; -atomic_t g_progr_fdone{0}; -atomic_t g_progr_ptotal{0}; -atomic_t g_progr_pdone{0}; - // Report error and call std::abort(), defined in main.cpp [[noreturn]] void report_fatal_error(std::string_view); -namespace -{ - struct progress_dialog_server; -} - namespace atomic_wait { extern void parse_hashtable(bool(*cb)(u64 id, u32 refs, u64 ptr, u32 stats)); @@ -191,8 +175,8 @@ void Emulator::Init(bool add_only) } // Create directories (can be disabled if necessary) - const std::string emu_dir = GetEmuDir(); - const std::string dev_hdd0 = GetHddDir(); + const std::string emu_dir = rpcs3::utils::get_emu_dir(); + const std::string dev_hdd0 = rpcs3::utils::get_hdd0_dir(); const std::string dev_hdd1 = g_cfg.vfs.get(g_cfg.vfs.dev_hdd1, emu_dir); const std::string dev_usb = g_cfg.vfs.get(g_cfg.vfs.dev_usb000, emu_dir); const std::string dev_flsh = g_cfg.vfs.get_dev_flash(); @@ -322,225 +306,17 @@ void Emulator::Init(bool add_only) // Limit cache size if (g_cfg.vfs.limit_cache_size) - LimitCacheSize(); + rpcs3::cache::limit_cache_size(); // Initialize patch engine g_fxo->init()->append_global_patches(); } -namespace rsx::overlays -{ - class progress_dialog : public message_dialog - { - public: - using message_dialog::message_dialog; - }; -} - -namespace -{ - struct progress_dialog_server - { - void operator()() - { - while (thread_ctrl::state() != thread_state::aborting) - { - // Wait for the start condition - auto text0 = +g_progr; - - while (!text0) - { - if (thread_ctrl::state() == thread_state::aborting) - { - break; - } - - std::this_thread::sleep_for(5ms); - text0 = +g_progr; - } - - if (thread_ctrl::state() == thread_state::aborting) - { - break; - } - - // Initialize message dialog - bool skip_this_one = false; // Workaround: do not open a progress dialog if there is already a cell message dialog open. - std::shared_ptr dlg; - std::shared_ptr native_dlg; - - if (const auto renderer = rsx::get_current_renderer(); - renderer && renderer->is_inited) - { - auto manager = g_fxo->try_get(); - skip_this_one = g_fxo->get().skip_the_progress_dialog || (manager && manager->get()); - - if (manager && !skip_this_one) - { - MsgDialogType type{}; - type.se_normal = true; - type.bg_invisible = true; - type.disable_cancel = true; - type.progress_bar_count = 1; - - native_dlg = manager->create(true); - native_dlg->show(false, text0, type, nullptr); - native_dlg->progress_bar_set_message(0, "Please wait"); - } - } - - if (!skip_this_one && !native_dlg) - { - dlg = Emu.GetCallbacks().get_msg_dialog(); - dlg->type.se_normal = true; - dlg->type.bg_invisible = true; - dlg->type.progress_bar_count = 1; - dlg->on_close = [](s32 /*status*/) - { - Emu.CallAfter([]() - { - // Abort everything - Emu.Stop(); - }); - }; - - Emu.CallAfter([dlg, text0]() - { - dlg->Create(text0, text0); - }); - } - - u32 ftotal = 0; - u32 fdone = 0; - u32 ptotal = 0; - u32 pdone = 0; - auto text1 = text0; - - // Update progress - while (thread_ctrl::state() != thread_state::aborting) - { - const auto text_new = g_progr.load(); - - const u32 ftotal_new = g_progr_ftotal; - const u32 fdone_new = g_progr_fdone; - const u32 ptotal_new = g_progr_ptotal; - const u32 pdone_new = g_progr_pdone; - - if (ftotal != ftotal_new || fdone != fdone_new || ptotal != ptotal_new || pdone != pdone_new || text_new != text1) - { - ftotal = ftotal_new; - fdone = fdone_new; - ptotal = ptotal_new; - pdone = pdone_new; - text1 = text_new; - - if (!text_new) - { - // Close dialog - break; - } - - if (skip_this_one) - { - // Do nothing - std::this_thread::sleep_for(10ms); - continue; - } - - // Compute new progress in percents - // Assume not all programs were found if files were not compiled (as it may contain more) - const u64 total = std::max(ptotal, 1) * std::max(ftotal, 1); - const u64 done = pdone * std::max(fdone, 1); - const double value = std::fmin(done * 100. / total, 100.); - - std::string progr = "Progress:"; - - if (ftotal) - fmt::append(progr, " file %u of %u%s", fdone, ftotal, ptotal ? "," : ""); - if (ptotal) - fmt::append(progr, " module %u of %u", pdone, ptotal); - - // Changes detected, send update - if (native_dlg) - { - native_dlg->set_text(text_new); - native_dlg->progress_bar_set_message(0, progr); - native_dlg->progress_bar_set_value(0, std::floor(value)); - } - else if (dlg) - { - Emu.CallAfter([=]() - { - dlg->SetMsg(text_new); - dlg->ProgressBarSetMsg(0, progr); - dlg->ProgressBarSetValue(0, std::floor(value)); - }); - } - } - - std::this_thread::sleep_for(10ms); - } - - if (thread_ctrl::state() == thread_state::aborting) - { - break; - } - - if (skip_this_one) - { - // Do nothing - } - else if (native_dlg) - { - native_dlg->close(false, false); - } - else if (dlg) - { - Emu.CallAfter([=]() - { - dlg->Close(true); - }); - } - - // Cleanup - g_progr_fdone -= fdone; - g_progr_pdone -= pdone; - g_progr_ftotal -= ftotal; - g_progr_ptotal -= ptotal; - g_progr_ptotal.notify_all(); - } - } - - ~progress_dialog_server() - { - g_progr_ftotal.release(0); - g_progr_fdone.release(0); - g_progr_ptotal.release(0); - g_progr_pdone.release(0); - g_progr.release(nullptr); - } - - static auto constexpr thread_name = "Progress Dialog Server"sv; - }; -} - -u32 Emulator::CheckUsr(const std::string& user) -{ - u32 id = 0; - - if (user.size() == 8) - { - std::from_chars(&user.front(), &user.back() + 1, id); - } - - return id; -} - void Emulator::SetUsr(const std::string& user) { sys_log.notice("Setting user ID '%s'", user); - const u32 id = CheckUsr(user); + const u32 id = rpcs3::utils::check_user(user); if (id == 0) { @@ -594,19 +370,6 @@ std::string Emulator::GetBackgroundPicturePath() const return path; } -std::string Emulator::PPUCache() -{ - auto& _main = g_fxo->get(); - - if (!g_fxo->is_init() || _main.cache.empty()) - { - ppu_log.warning("PPU Cache location not initialized."); - return {}; - } - - return _main.cache; -} - bool Emulator::BootRsxCapture(const std::string& path) { fs::file in_file(path); @@ -655,93 +418,6 @@ bool Emulator::BootRsxCapture(const std::string& path) return true; } -void Emulator::LimitCacheSize() -{ - const std::string cache_location = GetHdd1Dir() + "/caches"; - - if (!fs::is_dir(cache_location)) - { - sys_log.warning("Cache does not exist (%s)", cache_location); - return; - } - - const u64 size = fs::get_dir_size(cache_location); - - if (size == umax) - { - sys_log.error("Could not calculate cache directory '%s' size (%s)", cache_location, fs::g_tls_error); - return; - } - - const u64 max_size = static_cast(g_cfg.vfs.cache_max_size) * 1024 * 1024; - - if (max_size == 0) // Everything must go, so no need to do checks - { - fs::remove_all(cache_location, false); - sys_log.success("Cleared disk cache"); - return; - } - - if (size <= max_size) - { - sys_log.trace("Cache size below limit: %llu/%llu", size, max_size); - return; - } - - sys_log.success("Cleaning disk cache..."); - std::vector file_list{}; - fs::dir cache_dir(cache_location); - if (!cache_dir) - { - sys_log.error("Could not open cache directory '%s' (%s)", cache_location, fs::g_tls_error); - return; - } - - // retrieve items to delete - for (const auto &item : cache_dir) - { - if (item.name != "." && item.name != "..") - file_list.push_back(item); - } - - cache_dir.close(); - - // sort oldest first - std::sort(file_list.begin(), file_list.end(), [](auto left, auto right) - { - return left.mtime < right.mtime; - }); - - // keep removing until cache is empty or enough bytes have been cleared - // cache is cleared down to 80% of limit to increase interval between clears - const u64 to_remove = static_cast(size - max_size * 0.8); - u64 removed = 0; - for (const auto &item : file_list) - { - const std::string &name = cache_location + "/" + item.name; - const bool is_dir = fs::is_dir(name); - const u64 item_size = is_dir ? fs::get_dir_size(name) : item.size; - - if (is_dir && item_size == umax) - { - sys_log.error("Failed to calculate '%s' item '%s' size (%s)", cache_location, item.name, fs::g_tls_error); - break; - } - - if (is_dir ? !fs::remove_all(name, true) : !fs::remove_file(name)) - { - sys_log.error("Could not remove cache directory '%s' item '%s' (%s)", cache_location, item.name, fs::g_tls_error); - break; - } - - removed += item_size; - if (removed >= to_remove) - break; - } - - sys_log.success("Cleaned disk cache, removed %.2f MB", size / 1024.0 / 1024.0); -} - game_boot_result Emulator::BootGame(const std::string& path, const std::string& title_id, bool direct, bool add_only, bool force_global_config) { if (!fs::exists(path)) @@ -806,179 +482,6 @@ game_boot_result Emulator::BootGame(const std::string& path, const std::string& return result; } -bool Emulator::InstallPkg(const std::string& path) -{ - sys_log.success("Installing package: %s", path); - - atomic_t progress(0.); - int int_progress = 0; - - // Run PKG unpacking asynchronously - named_thread worker("PKG Installer", [&] - { - package_reader reader(path); - return reader.extract_data(progress); - }); - - { - // Wait for the completion - while (std::this_thread::sleep_for(5ms), worker <= thread_state::aborting) - { - // TODO: update unified progress dialog - double pval = progress; - pval < 0 ? pval += 1. : pval; - pval *= 100.; - - if (static_cast(pval) > int_progress) - { - int_progress = static_cast(pval); - sys_log.success("... %u%%", int_progress); - } - } - } - - return worker(); -} - -std::string Emulator::GetEmuDir() -{ - const std::string& emu_dir_ = g_cfg.vfs.emulator_dir; - return emu_dir_.empty() ? fs::get_config_dir() : emu_dir_; -} - -std::string Emulator::GetHddDir() -{ - return g_cfg.vfs.get(g_cfg.vfs.dev_hdd0, GetEmuDir()); -} - -std::string Emulator::GetHdd1Dir() -{ - return g_cfg.vfs.get(g_cfg.vfs.dev_hdd1, GetEmuDir()); -} - -std::string Emulator::GetCacheDir() -{ - return fs::get_cache_dir() + "cache/"; -} - -#ifdef _WIN32 -std::string Emulator::GetExeDir() -{ - wchar_t buffer[32767]; - GetModuleFileNameW(nullptr, buffer, sizeof(buffer)/2); - - const std::string path_to_exe = wchar_to_utf8(buffer); - const usz last = path_to_exe.find_last_of('\\'); - return last == std::string::npos ? std::string("") : path_to_exe.substr(0, last+1); -} -#endif - -std::string Emulator::GetSfoDirFromGamePath(const std::string& game_path, const std::string& title_id) -{ - if (fs::is_file(game_path + "/PS3_DISC.SFB")) - { - // This is a disc game. - if (!title_id.empty()) - { - for (auto&& entry : fs::dir{game_path}) - { - if (entry.name == "." || entry.name == "..") - { - continue; - } - - const std::string sfo_path = game_path + "/" + entry.name + "/PARAM.SFO"; - - if (entry.is_directory && fs::is_file(sfo_path)) - { - const auto psf = psf::load_object(fs::file(sfo_path)); - const auto serial = psf::get_string(psf, "TITLE_ID"); - if (serial == title_id) - { - return game_path + "/" + entry.name; - } - } - } - } - - return game_path + "/PS3_GAME"; - } - - const auto psf = psf::load_object(fs::file(game_path + "/PARAM.SFO")); - - const auto category = psf::get_string(psf, "CATEGORY"); - const auto content_id = std::string(psf::get_string(psf, "CONTENT_ID")); - - if (category == "HG" && !content_id.empty()) - { - // This is a trial game. Check if the user has a RAP file to unlock it. - if (fs::is_file(game_path + "/C00/PARAM.SFO") && fs::is_file(GetRapFilePath(content_id))) - { - // Load full game data. - sys_log.notice("Found RAP file %s.rap for trial game %s", content_id, title_id); - return game_path + "/C00"; - } - } - - return game_path; -} - -std::string Emulator::GetRapFilePath(const std::string& rap) -{ - const std::string home_dir = GetHddDir() + "/home"; - - for (auto&& entry : fs::dir(home_dir)) - { - if (entry.is_directory && CheckUsr(entry.name)) - { - std::string rap_path = fmt::format("%s/%s/exdata/%s.rap", home_dir, entry.name, rap); - if (fs::is_file(rap_path)) - { - return rap_path; - } - } - } - - return {}; -} - -std::string Emulator::GetCustomConfigDir() -{ -#ifdef _WIN32 - return fs::get_config_dir() + "config/custom_configs/"; -#else - return fs::get_config_dir() + "custom_configs/"; -#endif -} - -std::string Emulator::GetCustomConfigPath(const std::string& title_id, bool get_deprecated_path) -{ - std::string path; - - if (get_deprecated_path) - path = fs::get_config_dir() + "data/" + title_id + "/config.yml"; - else - path = GetCustomConfigDir() + "config_" + title_id + ".yml"; - - return path; -} - -std::string Emulator::GetCustomInputConfigDir(const std::string& title_id) -{ - // Notice: the extra folder for each title id may be removed at a later stage - // Warning: make sure to change any function that removes this directory as well -#ifdef _WIN32 - return fs::get_config_dir() + "config/custom_input_configs/" + title_id + "/"; -#else - return fs::get_config_dir() + "custom_input_configs/" + title_id + "/"; -#endif -} - -std::string Emulator::GetCustomInputConfigPath(const std::string& title_id) -{ - return GetCustomInputConfigDir(title_id) + "/config_input_" + title_id + ".yml"; -} - void Emulator::SetForceBoot(bool force_boot) { m_force_boot = force_boot; @@ -1038,7 +541,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool if (fs::is_dir(m_path)) { // Special case (directory scan) - m_sfo_dir = GetSfoDirFromGamePath(m_path, m_title_id); + m_sfo_dir = rpcs3::utils::get_sfo_dir_from_game_path(m_path, m_title_id); } else if (!disc.empty()) { @@ -1049,16 +552,16 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool } else if (m_cat == "GD") { - m_sfo_dir = GetHddDir() + "game/" + m_title_id; + m_sfo_dir = rpcs3::utils::get_hdd0_dir() + "game/" + m_title_id; } else { - m_sfo_dir = GetSfoDirFromGamePath(disc, m_title_id); + m_sfo_dir = rpcs3::utils::get_sfo_dir_from_game_path(disc, m_title_id); } } else { - m_sfo_dir = GetSfoDirFromGamePath(elf_dir + "/../", m_title_id); + m_sfo_dir = rpcs3::utils::get_sfo_dir_from_game_path(elf_dir + "/../", m_title_id); } _psf = psf::load_object(fs::file(m_sfo_dir + "/PARAM.SFO")); @@ -1085,8 +588,8 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool if (!add_only && !force_global_config && m_config_override_path.empty()) { - const std::string config_path_new = GetCustomConfigPath(m_title_id); - const std::string config_path_old = GetCustomConfigPath(m_title_id, true); + const std::string config_path_new = rpcs3::utils::get_custom_config_path(m_title_id); + const std::string config_path_old = rpcs3::utils::get_custom_config_path(m_title_id, true); // Load custom config-1 if (fs::file cfg_file{ config_path_old }) @@ -1159,7 +662,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool g_fxo->get().append_title_patches(m_title_id); // Mount all devices - const std::string emu_dir = GetEmuDir(); + const std::string emu_dir = rpcs3::utils::get_emu_dir(); std::string bdvd_dir = g_cfg.vfs.dev_bdvd; // Mount default relative path to non-existent directory @@ -1503,7 +1006,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool for (auto&& entry : fs::dir{ins_dir}) { const std::string pkg = ins_dir + entry.name; - if (!entry.is_directory && entry.name.ends_with(".PKG") && !InstallPkg(pkg)) + if (!entry.is_directory && entry.name.ends_with(".PKG") && !rpcs3::utils::install_pkg(pkg)) { sys_log.error("Failed to install %s", pkg); return game_boot_result::install_failed; @@ -1521,7 +1024,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool { const std::string pkg_file = pkg_dir + entry.name + "/INSTALL.PKG"; - if (fs::is_file(pkg_file) && !InstallPkg(pkg_file)) + if (fs::is_file(pkg_file) && !rpcs3::utils::install_pkg(pkg_file)) { sys_log.error("Failed to install %s", pkg_file); return game_boot_result::install_failed; @@ -1540,7 +1043,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool { const std::string pkg_file = extra_dir + entry.name + "/DATA000.PKG"; - if (fs::is_file(pkg_file) && !InstallPkg(pkg_file)) + if (fs::is_file(pkg_file) && !rpcs3::utils::install_pkg(pkg_file)) { sys_log.error("Failed to install %s", pkg_file); return game_boot_result::install_failed; @@ -1838,7 +1341,7 @@ void Emulator::Run(bool start_playtime) m_pause_amend_time = 0; m_state = system_state::running; - ConfigureLogs(); + rpcs3::utils::configure_logs(); // Run main thread idm::check>(ppu_thread::id_base, [](named_thread& cpu) @@ -2137,14 +1640,6 @@ std::string Emulator::GetFormattedTitle(double fps) const return rpcs3::get_formatted_title(title_data); } -u32 Emulator::GetMaxThreads() -{ - const u32 max_threads = static_cast(g_cfg.core.llvm_threads); - const u32 hw_threads = utils::get_thread_count(); - const u32 thread_count = max_threads > 0 ? std::min(max_threads, hw_threads) : hw_threads; - return thread_count; -} - s32 error_code::error_report(const fmt_type_info* sup, u64 arg, const fmt_type_info* sup2, u64 arg2) { static thread_local std::unordered_map g_tls_error_stats; @@ -2199,40 +1694,11 @@ s32 error_code::error_report(const fmt_type_info* sup, u64 arg, const fmt_type_i return static_cast(arg); } -void Emulator::ConfigureLogs() -{ - static bool was_silenced = false; - - const bool silenced = g_cfg.misc.silence_all_logs.get(); - - if (silenced) - { - if (!was_silenced) - { - sys_log.notice("Disabling logging..."); - } - - logs::silence(); - } - else - { - logs::reset(); - logs::set_channel_levels(g_cfg.log.get_map()); - - if (was_silenced) - { - sys_log.notice("Logging enabled"); - } - } - - was_silenced = silenced; -} - void Emulator::ConfigurePPUCache() const { auto& _main = g_fxo->get(); - _main.cache = GetCacheDir(); + _main.cache = rpcs3::utils::get_cache_dir(); if (!m_title_id.empty() && m_cat != "1P") { diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index c3ce87e6ce..268565f106 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -205,8 +205,6 @@ public: return m_usrid; } - static u32 CheckUsr(const std::string& user); - void SetUsr(const std::string& user); std::string GetBackgroundPicturePath() const; @@ -216,27 +214,8 @@ public: return m_pause_amend_time; } - static std::string PPUCache(); - game_boot_result BootGame(const std::string& path, const std::string& title_id = "", bool direct = false, bool add_only = false, bool force_global_config = false); bool BootRsxCapture(const std::string& path); - static bool InstallPkg(const std::string& path); - -#ifdef _WIN32 - static std::string GetExeDir(); -#endif - - static std::string GetEmuDir(); - static std::string GetHddDir(); - static std::string GetHdd1Dir(); - static std::string GetCacheDir(); - static std::string GetSfoDirFromGamePath(const std::string& game_path, const std::string& title_id = ""); - static std::string GetRapFilePath(const std::string& rap); - - static std::string GetCustomConfigDir(); - static std::string GetCustomConfigPath(const std::string& title_id, bool get_deprecated_path = false); - static std::string GetCustomInputConfigDir(const std::string& title_id); - static std::string GetCustomInputConfigPath(const std::string& title_id); void SetForceBoot(bool force_boot); @@ -264,15 +243,9 @@ public: std::string GetFormattedTitle(double fps) const; - static u32 GetMaxThreads(); - - static void ConfigureLogs(); void ConfigurePPUCache() const; std::set GetGameDirs() const; - -private: - static void LimitCacheSize(); }; extern Emulator Emu; diff --git a/rpcs3/Emu/cache_utils.cpp b/rpcs3/Emu/cache_utils.cpp new file mode 100644 index 0000000000..19977da841 --- /dev/null +++ b/rpcs3/Emu/cache_utils.cpp @@ -0,0 +1,112 @@ +#include "stdafx.h" +#include "cache_utils.hpp" +#include "system_utils.hpp" +#include "system_config.h" +#include "IdManager.h" +#include "Emu/Cell/PPUAnalyser.h" +#include "Emu/Cell/PPUThread.h" + +LOG_CHANNEL(sys_log, "SYS"); + +namespace rpcs3::cache +{ + std::string get_ppu_cache() + { + auto& _main = g_fxo->get(); + + if (!g_fxo->is_init() || _main.cache.empty()) + { + ppu_log.warning("PPU Cache location not initialized."); + return {}; + } + + return _main.cache; + } + + void limit_cache_size() + { + const std::string cache_location = rpcs3::utils::get_hdd1_dir() + "/caches"; + + if (!fs::is_dir(cache_location)) + { + sys_log.warning("Cache does not exist (%s)", cache_location); + return; + } + + const u64 size = fs::get_dir_size(cache_location); + + if (size == umax) + { + sys_log.error("Could not calculate cache directory '%s' size (%s)", cache_location, fs::g_tls_error); + return; + } + + const u64 max_size = static_cast(g_cfg.vfs.cache_max_size) * 1024 * 1024; + + if (max_size == 0) // Everything must go, so no need to do checks + { + fs::remove_all(cache_location, false); + sys_log.success("Cleared disk cache"); + return; + } + + if (size <= max_size) + { + sys_log.trace("Cache size below limit: %llu/%llu", size, max_size); + return; + } + + sys_log.success("Cleaning disk cache..."); + std::vector file_list{}; + fs::dir cache_dir(cache_location); + if (!cache_dir) + { + sys_log.error("Could not open cache directory '%s' (%s)", cache_location, fs::g_tls_error); + return; + } + + // retrieve items to delete + for (const auto &item : cache_dir) + { + if (item.name != "." && item.name != "..") + file_list.push_back(item); + } + + cache_dir.close(); + + // sort oldest first + std::sort(file_list.begin(), file_list.end(), [](auto left, auto right) + { + return left.mtime < right.mtime; + }); + + // keep removing until cache is empty or enough bytes have been cleared + // cache is cleared down to 80% of limit to increase interval between clears + const u64 to_remove = static_cast(size - max_size * 0.8); + u64 removed = 0; + for (const auto &item : file_list) + { + const std::string &name = cache_location + "/" + item.name; + const bool is_dir = fs::is_dir(name); + const u64 item_size = is_dir ? fs::get_dir_size(name) : item.size; + + if (is_dir && item_size == umax) + { + sys_log.error("Failed to calculate '%s' item '%s' size (%s)", cache_location, item.name, fs::g_tls_error); + break; + } + + if (is_dir ? !fs::remove_all(name, true) : !fs::remove_file(name)) + { + sys_log.error("Could not remove cache directory '%s' item '%s' (%s)", cache_location, item.name, fs::g_tls_error); + break; + } + + removed += item_size; + if (removed >= to_remove) + break; + } + + sys_log.success("Cleaned disk cache, removed %.2f MB", size / 1024.0 / 1024.0); + } +} diff --git a/rpcs3/Emu/cache_utils.hpp b/rpcs3/Emu/cache_utils.hpp new file mode 100644 index 0000000000..222f3591a0 --- /dev/null +++ b/rpcs3/Emu/cache_utils.hpp @@ -0,0 +1,7 @@ +#pragma once + +namespace rpcs3::cache +{ + std::string get_ppu_cache(); + void limit_cache_size(); +} diff --git a/rpcs3/Emu/system_progress.cpp b/rpcs3/Emu/system_progress.cpp new file mode 100644 index 0000000000..066d8e9149 --- /dev/null +++ b/rpcs3/Emu/system_progress.cpp @@ -0,0 +1,196 @@ +#include "stdafx.h" +#include "system_progress.hpp" +#include "Emu/Cell/Modules/cellMsgDialog.h" +#include "Emu/RSX/RSXThread.h" +#include "Emu/RSX/Overlays/overlay_message_dialog.h" +#include "Emu/System.h" + +// Progress display server synchronization variables +atomic_t g_progr{nullptr}; +atomic_t g_progr_ftotal{0}; +atomic_t g_progr_fdone{0}; +atomic_t g_progr_ptotal{0}; +atomic_t g_progr_pdone{0}; + +namespace rsx::overlays +{ + class progress_dialog : public message_dialog + { + public: + using message_dialog::message_dialog; + }; +} // namespace rsx::overlays + +void progress_dialog_server::operator()() +{ + while (thread_ctrl::state() != thread_state::aborting) + { + // Wait for the start condition + auto text0 = +g_progr; + + while (!text0) + { + if (thread_ctrl::state() == thread_state::aborting) + { + break; + } + + std::this_thread::sleep_for(5ms); + text0 = +g_progr; + } + + if (thread_ctrl::state() == thread_state::aborting) + { + break; + } + + // Initialize message dialog + bool skip_this_one = false; // Workaround: do not open a progress dialog if there is already a cell message dialog open. + std::shared_ptr dlg; + std::shared_ptr native_dlg; + + if (const auto renderer = rsx::get_current_renderer(); + renderer && renderer->is_inited) + { + auto manager = g_fxo->try_get(); + skip_this_one = g_fxo->get().skip_the_progress_dialog || (manager && manager->get()); + + if (manager && !skip_this_one) + { + MsgDialogType type{}; + type.se_normal = true; + type.bg_invisible = true; + type.disable_cancel = true; + type.progress_bar_count = 1; + + native_dlg = manager->create(true); + native_dlg->show(false, text0, type, nullptr); + native_dlg->progress_bar_set_message(0, "Please wait"); + } + } + + if (!skip_this_one && !native_dlg) + { + dlg = Emu.GetCallbacks().get_msg_dialog(); + dlg->type.se_normal = true; + dlg->type.bg_invisible = true; + dlg->type.progress_bar_count = 1; + dlg->on_close = [](s32 /*status*/) { + Emu.CallAfter([]() { + // Abort everything + Emu.Stop(); + }); + }; + + Emu.CallAfter([dlg, text0]() { + dlg->Create(text0, text0); + }); + } + + u32 ftotal = 0; + u32 fdone = 0; + u32 ptotal = 0; + u32 pdone = 0; + auto text1 = text0; + + // Update progress + while (thread_ctrl::state() != thread_state::aborting) + { + const auto text_new = g_progr.load(); + + const u32 ftotal_new = g_progr_ftotal; + const u32 fdone_new = g_progr_fdone; + const u32 ptotal_new = g_progr_ptotal; + const u32 pdone_new = g_progr_pdone; + + if (ftotal != ftotal_new || fdone != fdone_new || ptotal != ptotal_new || pdone != pdone_new || text_new != text1) + { + ftotal = ftotal_new; + fdone = fdone_new; + ptotal = ptotal_new; + pdone = pdone_new; + text1 = text_new; + + if (!text_new) + { + // Close dialog + break; + } + + if (skip_this_one) + { + // Do nothing + std::this_thread::sleep_for(10ms); + continue; + } + + // Compute new progress in percents + // Assume not all programs were found if files were not compiled (as it may contain more) + const u64 total = std::max(ptotal, 1) * std::max(ftotal, 1); + const u64 done = pdone * std::max(fdone, 1); + const double value = std::fmin(done * 100. / total, 100.); + + std::string progr = "Progress:"; + + if (ftotal) + fmt::append(progr, " file %u of %u%s", fdone, ftotal, ptotal ? "," : ""); + if (ptotal) + fmt::append(progr, " module %u of %u", pdone, ptotal); + + // Changes detected, send update + if (native_dlg) + { + native_dlg->set_text(text_new); + native_dlg->progress_bar_set_message(0, progr); + native_dlg->progress_bar_set_value(0, std::floor(value)); + } + else if (dlg) + { + Emu.CallAfter([=]() { + dlg->SetMsg(text_new); + dlg->ProgressBarSetMsg(0, progr); + dlg->ProgressBarSetValue(0, std::floor(value)); + }); + } + } + + std::this_thread::sleep_for(10ms); + } + + if (thread_ctrl::state() == thread_state::aborting) + { + break; + } + + if (skip_this_one) + { + // Do nothing + } + else if (native_dlg) + { + native_dlg->close(false, false); + } + else if (dlg) + { + Emu.CallAfter([=]() { + dlg->Close(true); + }); + } + + // Cleanup + g_progr_fdone -= fdone; + g_progr_pdone -= pdone; + g_progr_ftotal -= ftotal; + g_progr_ptotal -= ptotal; + g_progr_ptotal.notify_all(); + } +} + +progress_dialog_server::~progress_dialog_server() +{ + g_progr_ftotal.release(0); + g_progr_fdone.release(0); + g_progr_ptotal.release(0); + g_progr_pdone.release(0); + g_progr.release(nullptr); +} diff --git a/rpcs3/Emu/system_progress.hpp b/rpcs3/Emu/system_progress.hpp index 8963e57d1c..e4eeb6275c 100644 --- a/rpcs3/Emu/system_progress.hpp +++ b/rpcs3/Emu/system_progress.hpp @@ -30,3 +30,11 @@ public: g_progr.release(m_prev); } }; + +struct progress_dialog_server +{ + void operator()(); + ~progress_dialog_server(); + + static auto constexpr thread_name = "Progress Dialog Server"sv; +}; diff --git a/rpcs3/Emu/system_utils.cpp b/rpcs3/Emu/system_utils.cpp new file mode 100644 index 0000000000..1f693a6129 --- /dev/null +++ b/rpcs3/Emu/system_utils.cpp @@ -0,0 +1,240 @@ +#include "stdafx.h" +#include "system_utils.hpp" +#include "system_config.h" +#include "util/sysinfo.hpp" +#include "Utilities/File.h" +#include "Utilities/StrUtil.h" +#include "Utilities/Thread.h" +#include "Crypto/unpkg.h" + +#include +#include + +#ifdef _WIN32 +#include +#endif + +LOG_CHANNEL(sys_log, "SYS"); + +namespace rpcs3::utils +{ + u32 get_max_threads() + { + const u32 max_threads = static_cast(g_cfg.core.llvm_threads); + const u32 hw_threads = ::utils::get_thread_count(); + const u32 thread_count = max_threads > 0 ? std::min(max_threads, hw_threads) : hw_threads; + return thread_count; + } + + void configure_logs() + { + static bool was_silenced = false; + + const bool silenced = g_cfg.misc.silence_all_logs.get(); + + if (silenced) + { + if (!was_silenced) + { + sys_log.notice("Disabling logging..."); + } + + logs::silence(); + } + else + { + logs::reset(); + logs::set_channel_levels(g_cfg.log.get_map()); + + if (was_silenced) + { + sys_log.notice("Logging enabled"); + } + } + + was_silenced = silenced; + } + + u32 check_user(const std::string& user) + { + u32 id = 0; + + if (user.size() == 8) + { + std::from_chars(&user.front(), &user.back() + 1, id); + } + + return id; + } + + bool install_pkg(const std::string& path) + { + sys_log.success("Installing package: %s", path); + + atomic_t progress(0.); + int int_progress = 0; + + // Run PKG unpacking asynchronously + named_thread worker("PKG Installer", [&] + { + package_reader reader(path); + return reader.extract_data(progress); + }); + + // Wait for the completion + while (std::this_thread::sleep_for(5ms), worker <= thread_state::aborting) + { + // TODO: update unified progress dialog + double pval = progress; + pval < 0 ? pval += 1. : pval; + pval *= 100.; + + if (static_cast(pval) > int_progress) + { + int_progress = static_cast(pval); + sys_log.success("... %u%%", int_progress); + } + } + + return worker(); + } + +#ifdef _WIN32 + std::string get_exe_dir() + { + wchar_t buffer[32767]; + GetModuleFileNameW(nullptr, buffer, sizeof(buffer) / 2); + + const std::string path_to_exe = wchar_to_utf8(buffer); + const usz last = path_to_exe.find_last_of('\\'); + return last == std::string::npos ? std::string("") : path_to_exe.substr(0, last + 1); + } +#endif + + std::string get_emu_dir() + { + const std::string& emu_dir_ = g_cfg.vfs.emulator_dir; + return emu_dir_.empty() ? fs::get_config_dir() : emu_dir_; + } + + std::string get_hdd0_dir() + { + return g_cfg.vfs.get(g_cfg.vfs.dev_hdd0, get_emu_dir()); + } + + std::string get_hdd1_dir() + { + return g_cfg.vfs.get(g_cfg.vfs.dev_hdd1, get_emu_dir()); + } + + std::string get_cache_dir() + { + return fs::get_cache_dir() + "cache/"; + } + + std::string get_rap_file_path(const std::string& rap) + { + const std::string home_dir = get_hdd0_dir() + "/home"; + + for (auto&& entry : fs::dir(home_dir)) + { + if (entry.is_directory && check_user(entry.name)) + { + std::string rap_path = fmt::format("%s/%s/exdata/%s.rap", home_dir, entry.name, rap); + if (fs::is_file(rap_path)) + { + return rap_path; + } + } + } + + return {}; + } + + std::string get_sfo_dir_from_game_path(const std::string& game_path, const std::string& title_id) + { + if (fs::is_file(game_path + "/PS3_DISC.SFB")) + { + // This is a disc game. + if (!title_id.empty()) + { + for (auto&& entry : fs::dir{game_path}) + { + if (entry.name == "." || entry.name == "..") + { + continue; + } + + const std::string sfo_path = game_path + "/" + entry.name + "/PARAM.SFO"; + + if (entry.is_directory && fs::is_file(sfo_path)) + { + const auto psf = psf::load_object(fs::file(sfo_path)); + const auto serial = psf::get_string(psf, "TITLE_ID"); + if (serial == title_id) + { + return game_path + "/" + entry.name; + } + } + } + } + + return game_path + "/PS3_GAME"; + } + + const auto psf = psf::load_object(fs::file(game_path + "/PARAM.SFO")); + + const auto category = psf::get_string(psf, "CATEGORY"); + const auto content_id = std::string(psf::get_string(psf, "CONTENT_ID")); + + if (category == "HG" && !content_id.empty()) + { + // This is a trial game. Check if the user has a RAP file to unlock it. + if (fs::is_file(game_path + "/C00/PARAM.SFO") && fs::is_file(get_rap_file_path(content_id))) + { + // Load full game data. + sys_log.notice("Found RAP file %s.rap for trial game %s", content_id, title_id); + return game_path + "/C00"; + } + } + + return game_path; + } + + std::string get_custom_config_dir() + { +#ifdef _WIN32 + return fs::get_config_dir() + "config/custom_configs/"; +#else + return fs::get_config_dir() + "custom_configs/"; +#endif + } + + std::string get_custom_config_path(const std::string& title_id, bool get_deprecated_path) + { + std::string path; + + if (get_deprecated_path) + path = fs::get_config_dir() + "data/" + title_id + "/config.yml"; + else + path = get_custom_config_dir() + "config_" + title_id + ".yml"; + + return path; + } + + std::string get_custom_input_config_dir(const std::string& title_id) + { + // Notice: the extra folder for each title id may be removed at a later stage + // Warning: make sure to change any function that removes this directory as well +#ifdef _WIN32 + return fs::get_config_dir() + "config/custom_input_configs/" + title_id + "/"; +#else + return fs::get_config_dir() + "custom_input_configs/" + title_id + "/"; +#endif + } + + std::string get_custom_input_config_path(const std::string& title_id) + { + return get_custom_input_config_dir(title_id) + "/config_input_" + title_id + ".yml"; + } +} diff --git a/rpcs3/Emu/system_utils.hpp b/rpcs3/Emu/system_utils.hpp new file mode 100644 index 0000000000..573b083fb9 --- /dev/null +++ b/rpcs3/Emu/system_utils.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include "util/types.hpp" +#include + +namespace rpcs3::utils +{ + u32 get_max_threads(); + + void configure_logs(); + + u32 check_user(const std::string& user); + + bool install_pkg(const std::string& path); + +#ifdef _WIN32 + std::string get_exe_dir(); +#endif + + std::string get_emu_dir(); + std::string get_hdd0_dir(); + std::string get_hdd1_dir(); + std::string get_cache_dir(); + + std::string get_rap_file_path(const std::string& rap); + std::string get_sfo_dir_from_game_path(const std::string& game_path, const std::string& title_id = ""); + + std::string get_custom_config_dir(); + std::string get_custom_config_path(const std::string& title_id, bool get_deprecated_path = false); + std::string get_custom_input_config_dir(const std::string& title_id); + std::string get_custom_input_config_path(const std::string& title_id); +} diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index f2ad25f31c..60b7b6ea78 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -59,6 +59,7 @@ true + @@ -79,6 +80,8 @@ + + @@ -431,6 +434,7 @@ true + @@ -471,6 +475,8 @@ + + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index 66ba91ad47..991ca2b00d 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -992,6 +992,15 @@ Emu\GPU\RSX\Overlays + + Emu + + + Emu + + + Emu + @@ -1939,6 +1948,15 @@ Emu\GPU\RSX\Overlays + + Emu + + + Emu + + + Emu + diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index 1c4400d662..daa71528e9 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -51,6 +51,7 @@ DYNAMIC_IMPORT("ntdll.dll", NtSetTimerResolution, NTSTATUS(ULONG DesiredResoluti #include "Utilities/StrUtil.h" #include "rpcs3_version.h" #include "Emu/System.h" +#include "Emu/system_utils.hpp" #include #include @@ -743,7 +744,7 @@ int main(int argc, char** argv) { active_user = parser.value(arg_user_id).toStdString(); - if (Emulator::CheckUsr(active_user) == 0) + if (rpcs3::utils::check_user(active_user) == 0) { report_fatal_error(fmt::format("Failed to set user ID '%s'.\nThe user ID must consist of 8 digits and cannot be 00000000.", active_user)); } diff --git a/rpcs3/rpcs3qt/curl_handle.cpp b/rpcs3/rpcs3qt/curl_handle.cpp index 280fa36d49..2541cd1b6d 100644 --- a/rpcs3/rpcs3qt/curl_handle.cpp +++ b/rpcs3/rpcs3qt/curl_handle.cpp @@ -1,5 +1,5 @@ #include "curl_handle.h" -#include "Emu/System.h" +#include "Emu/system_utils.hpp" #ifdef _WIN32 #include "Utilities/StrUtil.h" @@ -11,7 +11,7 @@ curl_handle::curl_handle(QObject* parent) : QObject(parent) #ifdef _WIN32 // This shouldn't be needed on linux - const std::string path_to_cert = Emulator::GetExeDir() + "cacert.pem"; + const std::string path_to_cert = rpcs3::utils::get_exe_dir() + "cacert.pem"; const std::string ansi_path = utf8_path_to_ansi_path(path_to_cert); curl_easy_setopt(m_curl, CURLOPT_CAINFO, ansi_path.data()); diff --git a/rpcs3/rpcs3qt/emu_settings.cpp b/rpcs3/rpcs3qt/emu_settings.cpp index e02e275013..063e54bce8 100644 --- a/rpcs3/rpcs3qt/emu_settings.cpp +++ b/rpcs3/rpcs3qt/emu_settings.cpp @@ -8,6 +8,7 @@ #include "Emu/System.h" #include "Emu/system_config.h" +#include "Emu/system_utils.hpp" #include "Emu/Cell/Modules/cellSysutil.h" #include "util/yaml.hpp" @@ -98,7 +99,7 @@ void emu_settings::LoadSettings(const std::string& title_id) m_title_id = title_id; // Create config path if necessary - fs::create_path(title_id.empty() ? fs::get_config_dir() : Emulator::GetCustomConfigDir()); + fs::create_path(title_id.empty() ? fs::get_config_dir() : rpcs3::utils::get_custom_config_dir()); // Load default config auto [default_config, default_error] = yaml_load(g_cfg_defaults); @@ -139,8 +140,8 @@ void emu_settings::LoadSettings(const std::string& title_id) // Otherwise we'll always trigger the "obsolete settings dialog" when editing custom configs. ValidateSettings(true); - const std::string config_path_new = Emulator::GetCustomConfigPath(m_title_id); - const std::string config_path_old = Emulator::GetCustomConfigPath(m_title_id, true); + const std::string config_path_new = rpcs3::utils::get_custom_config_path(m_title_id); + const std::string config_path_old = rpcs3::utils::get_custom_config_path(m_title_id, true); std::string custom_config_path; if (fs::is_file(config_path_new)) @@ -274,7 +275,7 @@ void emu_settings::SaveSettings() const } else { - config_name = Emulator::GetCustomConfigPath(m_title_id); + config_name = rpcs3::utils::get_custom_config_path(m_title_id); } // Save config atomically diff --git a/rpcs3/rpcs3qt/game_list_frame.cpp b/rpcs3/rpcs3qt/game_list_frame.cpp index e21af8f963..bebaacb0e4 100644 --- a/rpcs3/rpcs3qt/game_list_frame.cpp +++ b/rpcs3/rpcs3qt/game_list_frame.cpp @@ -16,6 +16,7 @@ #include "Emu/Memory/vm.h" #include "Emu/System.h" +#include "Emu/system_utils.hpp" #include "Loader/PSF.h" #include "util/types.hpp" #include "Utilities/lockless.h" @@ -394,7 +395,7 @@ QString game_list_frame::GetLastPlayedBySerial(const QString& serial) const std::string game_list_frame::GetCacheDirBySerial(const std::string& serial) { - return Emulator::GetCacheDir() + serial; + return rpcs3::utils::get_cache_dir() + serial; } std::string game_list_frame::GetDataDirBySerial(const std::string& serial) @@ -413,7 +414,7 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after) m_game_data.clear(); m_notes.clear(); - const std::string _hdd = Emulator::GetHddDir(); + const std::string _hdd = rpcs3::utils::get_hdd0_dir(); const std::string cat_unknown = sstr(cat::cat_unknown); const std::string cat_unknown_localized = sstr(localized.category.unknown); @@ -542,7 +543,7 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after) const Localized thread_localized; { - const std::string sfo_dir = Emulator::GetSfoDirFromGamePath(dir); + const std::string sfo_dir = rpcs3::utils::get_sfo_dir_from_game_path(dir); const psf::registry psf = psf::load_object(fs::file(sfo_dir + "/PARAM.SFO")); @@ -654,8 +655,8 @@ void game_list_frame::Refresh(const bool from_drive, const bool scroll_after) const auto compat = m_game_compat->GetCompatibility(game.serial); - const bool hasCustomConfig = fs::is_file(Emulator::GetCustomConfigPath(game.serial)) || fs::is_file(Emulator::GetCustomConfigPath(game.serial, true)); - const bool hasCustomPadConfig = fs::is_file(Emulator::GetCustomInputConfigPath(game.serial)); + const bool hasCustomConfig = fs::is_file(rpcs3::utils::get_custom_config_path(game.serial)) || fs::is_file(rpcs3::utils::get_custom_config_path(game.serial, true)); + const bool hasCustomPadConfig = fs::is_file(rpcs3::utils::get_custom_input_config_path(game.serial)); const bool has_hover_gif = fs::is_file(game_icon_path + game.serial + "/hover.gif"); const QColor color = getGridCompatibilityColor(compat.color); @@ -970,12 +971,12 @@ void game_list_frame::ShowContextMenu(const QPoint &pos) QAction* open_config_dir = menu.addAction(tr("&Open Custom Config Folder")); connect(open_config_dir, &QAction::triggered, [current_game]() { - const std::string new_config_path = Emulator::GetCustomConfigPath(current_game.serial); + const std::string new_config_path = rpcs3::utils::get_custom_config_path(current_game.serial); if (fs::is_file(new_config_path)) gui::utils::open_dir(new_config_path); - const std::string old_config_path = Emulator::GetCustomConfigPath(current_game.serial, true); + const std::string old_config_path = rpcs3::utils::get_custom_config_path(current_game.serial, true); if (fs::is_file(old_config_path)) gui::utils::open_dir(old_config_path); @@ -1346,8 +1347,8 @@ bool game_list_frame::CreatePPUCache(const game_info& game) bool game_list_frame::RemoveCustomConfiguration(const std::string& title_id, const game_info& game, bool is_interactive) { - const std::string config_path_new = Emulator::GetCustomConfigPath(title_id); - const std::string config_path_old = Emulator::GetCustomConfigPath(title_id, true); + const std::string config_path_new = rpcs3::utils::get_custom_config_path(title_id); + const std::string config_path_old = rpcs3::utils::get_custom_config_path(title_id, true); if (!fs::is_file(config_path_new) && !fs::is_file(config_path_old)) return true; @@ -1388,7 +1389,7 @@ bool game_list_frame::RemoveCustomConfiguration(const std::string& title_id, con bool game_list_frame::RemoveCustomPadConfiguration(const std::string& title_id, const game_info& game, bool is_interactive) { - const std::string config_dir = Emulator::GetCustomInputConfigDir(title_id); + const std::string config_dir = rpcs3::utils::get_custom_input_config_dir(title_id); if (!fs::is_dir(config_dir)) return true; diff --git a/rpcs3/rpcs3qt/gui_application.cpp b/rpcs3/rpcs3qt/gui_application.cpp index c07d479f48..5bade1e98b 100644 --- a/rpcs3/rpcs3qt/gui_application.cpp +++ b/rpcs3/rpcs3qt/gui_application.cpp @@ -17,6 +17,7 @@ #include "Emu/Cell/Modules/cellAudio.h" #include "Emu/RSX/Overlays/overlay_perf_metrics.h" +#include "Emu/system_utils.hpp" #include "trophy_notification_helper.h" #include "save_data_dialog.h" #include "msg_dialog_frame.h" @@ -557,7 +558,7 @@ void gui_application::OnEmuSettingsChange() } } - Emulator::ConfigureLogs(); + rpcs3::utils::configure_logs(); audio::configure_audio(); rsx::overlays::reset_performance_overlay(); } diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index 5fca2b7108..6e70e1ca74 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -43,6 +43,7 @@ #include "Emu/IdManager.h" #include "Emu/VFS.h" #include "Emu/system_config.h" +#include "Emu/system_utils.hpp" #include "Crypto/unpkg.h" #include "Crypto/unself.h" @@ -518,7 +519,7 @@ bool main_window::InstallRapFile(const QString& path, const std::string& filenam // Copy file atomically with thread/process-safe error checking for file size - fs::pending_file to(Emulator::GetHddDir() + "/home/" + Emu.GetUsr() + "/exdata/" + filename.substr(0, filename.find_last_of('.')) + ".rap"); + fs::pending_file to(rpcs3::utils::get_hdd0_dir() + "/home/" + Emu.GetUsr() + "/exdata/" + filename.substr(0, filename.find_last_of('.')) + ".rap"); const fs::file from(sstr(path)); if (!to.file || !from) @@ -2573,7 +2574,7 @@ void main_window::SetIconSizeActions(int idx) const void main_window::RemoveDiskCache() { - const std::string cache_dir = Emulator::GetHdd1Dir() + "/caches"; + const std::string cache_dir = rpcs3::utils::get_hdd1_dir() + "/caches"; if (fs::is_dir(cache_dir) && fs::remove_all(cache_dir, false)) { @@ -2587,7 +2588,7 @@ void main_window::RemoveDiskCache() void main_window::RemoveFirmwareCache() { - const std::string cache_dir = Emulator::GetCacheDir(); + const std::string cache_dir = rpcs3::utils::get_cache_dir(); if (!fs::is_dir(cache_dir)) return; diff --git a/rpcs3/rpcs3qt/persistent_settings.cpp b/rpcs3/rpcs3qt/persistent_settings.cpp index 28d5bbb84a..aa173c1878 100644 --- a/rpcs3/rpcs3qt/persistent_settings.cpp +++ b/rpcs3/rpcs3qt/persistent_settings.cpp @@ -1,7 +1,7 @@ #include "persistent_settings.h" #include "util/logs.hpp" -#include "Emu/System.h" +#include "Emu/system_utils.hpp" LOG_CHANNEL(cfg_log, "CFG"); @@ -49,7 +49,7 @@ QString persistent_settings::GetCurrentUser(const QString& fallback) const } // Set user if valid - if (Emulator::CheckUsr(user.toStdString()) > 0) + if (rpcs3::utils::check_user(user.toStdString()) > 0) { return user; } diff --git a/rpcs3/rpcs3qt/qt_utils.cpp b/rpcs3/rpcs3qt/qt_utils.cpp index 268d903663..ae0c817a97 100644 --- a/rpcs3/rpcs3qt/qt_utils.cpp +++ b/rpcs3/rpcs3qt/qt_utils.cpp @@ -8,7 +8,7 @@ #include #include -#include "Emu/System.h" +#include "Emu/system_utils.hpp" #include "Utilities/File.h" inline std::string sstr(const QString& _in) { return _in.toStdString(); } @@ -260,7 +260,7 @@ namespace gui continue; } - const std::string sfo_dir = Emulator::GetSfoDirFromGamePath(pth, title_id); + const std::string sfo_dir = rpcs3::utils::get_sfo_dir_from_game_path(pth, title_id); icon_path = sfo_dir + "/ICON0.PNG"; found_file = fs::is_file(icon_path); diff --git a/rpcs3/rpcs3qt/save_manager_dialog.cpp b/rpcs3/rpcs3qt/save_manager_dialog.cpp index 0334e0735f..24bb3b66a0 100644 --- a/rpcs3/rpcs3qt/save_manager_dialog.cpp +++ b/rpcs3/rpcs3qt/save_manager_dialog.cpp @@ -6,6 +6,7 @@ #include "persistent_settings.h" #include "Emu/System.h" +#include "Emu/system_utils.hpp" #include "Loader/PSF.h" #include @@ -236,7 +237,7 @@ void save_manager_dialog::UpdateList() { if (m_dir.empty()) { - m_dir = Emulator::GetHddDir() + "home/" + Emu.GetUsr() + "/savedata/"; + m_dir = rpcs3::utils::get_hdd0_dir() + "home/" + Emu.GetUsr() + "/savedata/"; } m_save_entries = GetSaveEntries(m_dir); diff --git a/rpcs3/rpcs3qt/screenshot_manager_dialog.cpp b/rpcs3/rpcs3qt/screenshot_manager_dialog.cpp index 613ccff4a9..94ea7ec571 100644 --- a/rpcs3/rpcs3qt/screenshot_manager_dialog.cpp +++ b/rpcs3/rpcs3qt/screenshot_manager_dialog.cpp @@ -3,7 +3,7 @@ #include "qt_utils.h" #include "Utilities/File.h" #include "Emu/VFS.h" -#include "Emu/System.h" +#include "Emu/system_utils.hpp" #include #include @@ -29,7 +29,7 @@ screenshot_manager_dialog::screenshot_manager_dialog(QWidget* parent) : QDialog( m_grid->setGridSize(m_icon_size + QSize(10, 10)); // HACK: dev_hdd0 must be mounted for vfs to work for loading trophies. - vfs::mount("/dev_hdd0", Emulator::GetHddDir()); + vfs::mount("/dev_hdd0", rpcs3::utils::get_hdd0_dir()); const std::string screenshot_path_qt = fs::get_config_dir() + "screenshots/"; const std::string screenshot_path_cell = vfs::get("/dev_hdd0/photo/"); diff --git a/rpcs3/rpcs3qt/trophy_manager_dialog.cpp b/rpcs3/rpcs3qt/trophy_manager_dialog.cpp index 2c362bf7b3..83272d22bc 100644 --- a/rpcs3/rpcs3qt/trophy_manager_dialog.cpp +++ b/rpcs3/rpcs3qt/trophy_manager_dialog.cpp @@ -10,6 +10,7 @@ #include "Utilities/File.h" #include "Emu/VFS.h" #include "Emu/System.h" +#include "Emu/system_utils.hpp" #include "Emu/Cell/Modules/sceNpTrophy.h" #include "Loader/TROPUSR.h" @@ -60,7 +61,7 @@ trophy_manager_dialog::trophy_manager_dialog(std::shared_ptr gui_s m_show_platinum_trophies = m_gui_settings->GetValue(gui::tr_show_platinum).toBool(); // HACK: dev_hdd0 must be mounted for vfs to work for loading trophies. - vfs::mount("/dev_hdd0", Emulator::GetHddDir()); + vfs::mount("/dev_hdd0", rpcs3::utils::get_hdd0_dir()); // Get the currently selected user's trophy path. m_trophy_dir = "/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/"; diff --git a/rpcs3/rpcs3qt/update_manager.cpp b/rpcs3/rpcs3qt/update_manager.cpp index 8f9d19e63b..153ca7ea44 100644 --- a/rpcs3/rpcs3qt/update_manager.cpp +++ b/rpcs3/rpcs3qt/update_manager.cpp @@ -6,6 +6,7 @@ #include "Utilities/StrUtil.h" #include "Utilities/File.h" #include "Emu/System.h" +#include "Emu/system_utils.hpp" #include "util/logs.hpp" #include @@ -284,7 +285,7 @@ bool update_manager::handle_rpcs3(const QByteArray& data) #ifdef _WIN32 // Get executable path - const std::string orig_path = Emulator::GetExeDir() + "rpcs3.exe"; + const std::string orig_path = rpcs3::utils::get_exe_dir() + "rpcs3.exe"; std::wstring wchar_orig_path; const auto tmp_size = MultiByteToWideChar(CP_UTF8, 0, orig_path.c_str(), -1, nullptr, 0); @@ -390,7 +391,7 @@ bool update_manager::handle_rpcs3(const QByteArray& data) usz outBufferSize = 0; // Creates temp folder for moving active files - const std::string tmp_folder = Emulator::GetEmuDir() + "rpcs3_old/"; + const std::string tmp_folder = rpcs3::utils::get_emu_dir() + "rpcs3_old/"; fs::create_dir(tmp_folder); for (UInt32 i = 0; i < db.NumFiles; i++) @@ -423,7 +424,7 @@ bool update_manager::handle_rpcs3(const QByteArray& data) temp_u8[index] = static_cast(temp_u16[index]); } temp_u8[len] = 0; - const std::string name = Emulator::GetEmuDir() + std::string(reinterpret_cast(temp_u8)); + const std::string name = rpcs3::utils::get_emu_dir() + std::string(reinterpret_cast(temp_u8)); if (!isDir) { diff --git a/rpcs3/rpcs3qt/user_account.cpp b/rpcs3/rpcs3qt/user_account.cpp index 39babb0a98..16360ea803 100644 --- a/rpcs3/rpcs3qt/user_account.cpp +++ b/rpcs3/rpcs3qt/user_account.cpp @@ -1,6 +1,6 @@ #include "user_account.h" -#include "Emu/System.h" +#include "Emu/system_utils.hpp" #include "Utilities/File.h" #include "util/logs.hpp" @@ -12,7 +12,7 @@ user_account::user_account(const std::string& user_id) m_user_id = user_id; // Setting userDir. - m_user_dir = Emulator::GetHddDir() + "home/" + m_user_id + "/"; + m_user_dir = rpcs3::utils::get_hdd0_dir() + "home/" + m_user_id + "/"; // Setting userName. if (fs::file file; file.open(m_user_dir + "localusername", fs::read)) @@ -46,7 +46,7 @@ std::map user_account::GetUserAccounts(const std::string& bas } // Is the folder name exactly 8 all-numerical characters long? - const u32 key = Emulator::CheckUsr(user_folder.name); + const u32 key = rpcs3::utils::check_user(user_folder.name); if (key == 0) { diff --git a/rpcs3/rpcs3qt/user_manager_dialog.cpp b/rpcs3/rpcs3qt/user_manager_dialog.cpp index df70f14922..490e089aa6 100644 --- a/rpcs3/rpcs3qt/user_manager_dialog.cpp +++ b/rpcs3/rpcs3qt/user_manager_dialog.cpp @@ -19,6 +19,7 @@ #include "persistent_settings.h" #include "Emu/System.h" +#include "Emu/system_utils.hpp" #include "Utilities/StrUtil.h" #include "Utilities/File.h" @@ -167,7 +168,7 @@ void user_manager_dialog::UpdateTable(bool mark_only) // Get the user folders in the home directory and the currently logged in user. m_user_list.clear(); - m_user_list = user_account::GetUserAccounts(Emulator::GetHddDir() + "home"); + m_user_list = user_account::GetUserAccounts(rpcs3::utils::get_hdd0_dir() + "home"); // Clear and then repopulate the table with the list gathered above. m_table->setRowCount(static_cast(m_user_list.size())); @@ -232,10 +233,10 @@ void user_manager_dialog::OnUserRemove() void user_manager_dialog::GenerateUser(const std::string& user_id, const std::string& username) { - ensure(Emulator::CheckUsr(user_id) > 0); + ensure(rpcs3::utils::check_user(user_id) > 0); // Create user folders and such. - const std::string home_dir = Emulator::GetHddDir() + "home/"; + const std::string home_dir = rpcs3::utils::get_hdd0_dir() + "home/"; const std::string user_dir = home_dir + user_id; fs::create_dir(home_dir); fs::create_dir(user_dir + "/"); @@ -285,7 +286,7 @@ void user_manager_dialog::OnUserRename() continue; } - const std::string username_file = Emulator::GetHddDir() + "home/" + user_id + "/localusername"; + const std::string username_file = rpcs3::utils::get_hdd0_dir() + "home/" + user_id + "/localusername"; const std::string new_username = text_to_validate.toStdString(); if (fs::write_file(username_file, fs::rewrite, new_username)) @@ -324,7 +325,7 @@ void user_manager_dialog::OnUserCreate() } const std::string next_user_id = fmt::format("%08d", smallest); - ensure(Emulator::CheckUsr(next_user_id) > 0); + ensure(rpcs3::utils::check_user(next_user_id) > 0); QInputDialog* dialog = new QInputDialog(this); dialog->setWindowTitle(tr("New User"));