1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

Move unspecific Emulator code out of System.cpp

This commit is contained in:
Megamouse 2021-04-21 22:12:21 +02:00 committed by Ivan
parent 4c2a11b6d0
commit 1caf81811a
38 changed files with 729 additions and 652 deletions

View File

@ -5,6 +5,7 @@
#include "util/logs.hpp" #include "util/logs.hpp"
#include "Utilities/StrUtil.h" #include "Utilities/StrUtil.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include "Emu/VFS.h" #include "Emu/VFS.h"
#include "unpkg.h" #include "unpkg.h"
#include "Loader/PSF.h" #include "Loader/PSF.h"
@ -590,7 +591,7 @@ package_error package_reader::check_target_app_version() const
return package_error::no_error; 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 (!installed_sfo_file)
{ {
if (!target_app_ver.empty()) if (!target_app_ver.empty())
@ -674,7 +675,7 @@ bool package_reader::extract_data(atomic_t<double>& sync)
} }
// Get full path and create the directory // 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 // Based on https://www.psdevwiki.com/ps3/PKG_files#ContentType
switch (m_metadata.content_type) switch (m_metadata.content_type)

View File

@ -4,6 +4,7 @@
#include "unself.h" #include "unself.h"
#include "Emu/VFS.h" #include "Emu/VFS.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include <algorithm> #include <algorithm>
#include <zlib.h> #include <zlib.h>
@ -1320,7 +1321,7 @@ bool SELFDecrypter::GetKeyFromRap(u8* content_id, u8* npdrm_key)
// Try to find a matching RAP file under exdata folder. // Try to find a matching RAP file under exdata folder.
const std::string ci_str = reinterpret_cast<const char*>(content_id); const std::string ci_str = reinterpret_cast<const char*>(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. // Open the RAP file and read the key.
const fs::file rap_file(rap_path); const fs::file rap_file(rap_path);

View File

@ -1,9 +1,12 @@
add_library(rpcs3_emu add_library(rpcs3_emu
cache_utils.cpp
IdManager.cpp IdManager.cpp
localized_string.cpp localized_string.cpp
System.cpp System.cpp
system_config.cpp system_config.cpp
system_config_types.cpp system_config_types.cpp
system_progress.cpp
system_utils.cpp
VFS.cpp VFS.cpp
GDB.cpp GDB.cpp
title.cpp title.cpp

View File

@ -1,6 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "Emu/localized_string.h" #include "Emu/localized_string.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include "Emu/VFS.h" #include "Emu/VFS.h"
#include "Emu/IdManager.h" #include "Emu/IdManager.h"
#include "Emu/Cell/ErrorCodes.h" #include "Emu/Cell/ErrorCodes.h"
@ -978,7 +979,7 @@ error_code cellGameDeleteGameData(vm::cptr<char> dirName)
} }
// Actually remove game data // 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}; return {CELL_GAME_ERROR_ACCESS_ERROR, dir};
} }

View File

@ -1,5 +1,6 @@
#include "stdafx.h" #include "stdafx.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include "Emu/VFS.h" #include "Emu/VFS.h"
#include "Emu/IdManager.h" #include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h" #include "Emu/Cell/PPUModule.h"
@ -32,7 +33,7 @@ extern lv2_fs_mount_point g_mp_sys_dev_hdd1;
struct syscache_info 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; stx::init_mutex init;

View File

@ -1,5 +1,6 @@
#include "stdafx.h" #include "stdafx.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include "Emu/VFS.h" #include "Emu/VFS.h"
#include "Emu/IdManager.h" #include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h" #include "Emu/Cell/PPUModule.h"
@ -22,7 +23,7 @@ std::string get_username(const u32 user_id)
{ {
std::string username; 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 = file.to_string();
username.resize(CELL_USERINFO_USERNAME_SIZE); // TODO: investigate username.resize(CELL_USERINFO_USERNAME_SIZE); // TODO: investigate
@ -119,7 +120,7 @@ error_code cellUserInfoSelectUser_ListType(vm::ptr<CellUserInfoTypeSet> listType
} }
std::vector<u32> user_ids; std::vector<u32> 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)) for (const auto& user_folder : fs::dir(home_dir))
{ {
@ -129,7 +130,7 @@ error_code cellUserInfoSelectUser_ListType(vm::ptr<CellUserInfoTypeSet> listType
} }
// Is the folder name exactly 8 all-numerical characters long? // 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) if (user_id == 0)
{ {
@ -330,7 +331,7 @@ error_code cellUserInfoGetList(vm::ptr<u32> listNum, vm::ptr<CellUserInfoUserLis
} }
} }
const std::string home_dir = Emulator::GetHddDir() + "home"; const std::string home_dir = rpcs3::utils::get_hdd0_dir() + "home";
std::vector<u32> user_ids; std::vector<u32> user_ids;
for (const auto& user_folder : fs::dir(home_dir)) for (const auto& user_folder : fs::dir(home_dir))
@ -341,7 +342,7 @@ error_code cellUserInfoGetList(vm::ptr<u32> listNum, vm::ptr<CellUserInfoUserLis
} }
// Is the folder name exactly 8 all-numerical characters long? // 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) if (user_id == 0)
{ {

View File

@ -1,5 +1,6 @@
#include "stdafx.h" #include "stdafx.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include "Emu/VFS.h" #include "Emu/VFS.h"
#include "Emu/Cell/PPUModule.h" #include "Emu/Cell/PPUModule.h"
@ -506,7 +507,7 @@ error_code npDrmIsAvailable(vm::cptr<u8> k_licensee_addr, vm::cptr<char> drm_pat
if (VerifyEDATHeaderWithKLicense(enc_file, enc_drm_path_local, reinterpret_cast<u8*>(&k_licensee), &contentID)) if (VerifyEDATHeaderWithKLicense(enc_file, enc_drm_path_local, reinterpret_cast<u8*>(&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; npdrmkeys.devKlic = k_licensee;
if (fs::is_file(rap_file)) if (fs::is_file(rap_file))
@ -552,7 +553,7 @@ error_code sceNpDrmVerifyUpgradeLicense(vm::cptr<char> 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 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); sceNp.warning(u8"sceNpDrmVerifyUpgradeLicense(): content_id=“%s”", content_id);
@ -576,7 +577,7 @@ error_code sceNpDrmVerifyUpgradeLicense2(vm::cptr<char> 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 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); sceNp.warning(u8"sceNpDrmVerifyUpgradeLicense2(): content_id=“%s”", content_id);

View File

@ -10,6 +10,8 @@
#include "Emu/Memory/vm_locking.h" #include "Emu/Memory/vm_locking.h"
#include "Emu/RSX/RSXThread.h" #include "Emu/RSX/RSXThread.h"
#include "Emu/VFS.h" #include "Emu/VFS.h"
#include "Emu/system_progress.hpp"
#include "Emu/system_utils.hpp"
#include "PPUThread.h" #include "PPUThread.h"
#include "PPUInterpreter.h" #include "PPUInterpreter.h"
#include "PPUAnalyser.h" #include "PPUAnalyser.h"
@ -67,8 +69,6 @@ const bool s_use_ssse3 = utils::has_ssse3();
extern atomic_t<u64> g_watchdog_hold_ctr; extern atomic_t<u64> g_watchdog_hold_ctr;
#include "Emu/system_progress.hpp"
// Should be of the same type // Should be of the same type
using spu_rdata_t = decltype(ppu_thread::rdata); 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) // 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) if (workload.size() < thread_count)
{ {

View File

@ -3,6 +3,9 @@
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_config.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/IdManager.h"
#include "Emu/Cell/timers.hpp" #include "Emu/Cell/timers.hpp"
#include "Crypto/sha1.h" #include "Crypto/sha1.h"
@ -23,8 +26,6 @@
#include "util/v128sse.hpp" #include "util/v128sse.hpp"
#include "util/sysinfo.hpp" #include "util/sysinfo.hpp"
#include "Emu/system_progress.hpp"
const spu_decoder<spu_itype> s_spu_itype; const spu_decoder<spu_itype> s_spu_itype;
const spu_decoder<spu_iname> s_spu_iname; const spu_decoder<spu_iname> s_spu_iname;
const spu_decoder<spu_iflag> s_spu_iflag; const spu_decoder<spu_iflag> 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()) if (ppu_cache.empty())
{ {
@ -425,7 +426,7 @@ void spu_cache::initialize()
g_progr_ptotal += ::size32(func_list); g_progr_ptotal += ::size32(func_list);
progr.emplace("Building SPU cache..."); 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 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() spu_runtime::spu_runtime()
{ {
// Clear LLVM output // Clear LLVM output
m_cache_path = Emu.PPUCache(); m_cache_path = rpcs3::cache::get_ppu_cache();
if (m_cache_path.empty()) if (m_cache_path.empty())
{ {

View File

@ -1,6 +1,6 @@
#include "stdafx.h" #include "stdafx.h"
#include "PadHandler.h" #include "PadHandler.h"
#include "Emu/System.h" #include "Emu/system_utils.hpp"
#include "Input/pad_thread.h" #include "Input/pad_thread.h"
#include "Input/product_info.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()) 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) + "/"; return fs::get_config_dir() + "/InputConfigs/" + fmt::format("%s", type) + "/";
} }
std::string PadHandlerBase::get_config_filename(int i, const std::string& title_id) 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)) if (fs::is_file(path))
{ {
return path; return path;

View File

@ -1,6 +1,6 @@
#include "stdafx.h" #include "stdafx.h"
#include "pad_config.h" #include "pad_config.h"
#include "Emu/System.h" #include "Emu/system_utils.hpp"
cfg_input::cfg_input() cfg_input::cfg_input()
: cfg_name(fs::get_config_dir() + "/config_input.yml") : 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) 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)) if (!fs::is_file(cfg_name))
{ {
@ -38,7 +38,7 @@ void cfg_input::save(const std::string& title_id)
} }
else 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()); fs::file(cfg_name, fs::rewrite).write(to_string());
} }

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include "../rsx_cache.h"
#include "texture_cache_types.h" #include "texture_cache_types.h"
#include "texture_cache_predictor.h" #include "texture_cache_predictor.h"
#include "TextureUtils.h" #include "TextureUtils.h"
#include "Emu/Memory/vm.h" #include "Emu/Memory/vm.h"
#include "util/vm.hpp"
#include <list> #include <list>
#include <unordered_set> #include <unordered_set>

View File

@ -1,7 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "overlay_user_list_dialog.h" #include "overlay_user_list_dialog.h"
#include "Emu/System.h"
#include "Emu/system_config.h" #include "Emu/system_config.h"
#include "Emu/system_utils.hpp"
#include "Utilities/StrUtil.h" #include "Utilities/StrUtil.h"
#include "Utilities/Thread.h" #include "Utilities/Thread.h"
@ -152,7 +152,7 @@ namespace rsx
std::vector<u8> icon; std::vector<u8> icon;
std::vector<std::unique_ptr<overlay_element>> entries; std::vector<std::unique_ptr<overlay_element>> entries;
const std::string home_dir = Emulator::GetHddDir() + "home/"; const std::string home_dir = rpcs3::utils::get_hdd0_dir() + "home/";
s32 selected_index = 0; s32 selected_index = 0;
for (const auto& id : user_ids) for (const auto& id : user_ids)

View File

@ -4,6 +4,7 @@
#include "Utilities/Thread.h" #include "Utilities/Thread.h"
#include "Common/ProgramStateCache.h" #include "Common/ProgramStateCache.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/cache_utils.hpp"
#include "Common/texture_cache_checker.h" #include "Common/texture_cache_checker.h"
#include "Overlays/Shaders/shader_loading_dialog.h" #include "Overlays/Shaders/shader_loading_dialog.h"
@ -11,7 +12,6 @@
#include <chrono> #include <chrono>
#include <unordered_map> #include <unordered_map>
#include "util/vm.hpp"
#include "util/sysinfo.hpp" #include "util/sysinfo.hpp"
#include "util/fnv_hash.hpp" #include "util/fnv_hash.hpp"
@ -199,7 +199,7 @@ namespace rsx
{ {
if (!g_cfg.video.disable_on_disk_shader_cache) if (!g_cfg.video.disable_on_disk_shader_cache)
{ {
root_path = Emu.PPUCache() + "shaders_cache"; root_path = rpcs3::cache::get_ppu_cache() + "shaders_cache";
} }
} }

View File

@ -3,6 +3,8 @@
#include "Utilities/bin_patch.h" #include "Utilities/bin_patch.h"
#include "Emu/Memory/vm.h" #include "Emu/Memory/vm.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_progress.hpp"
#include "Emu/system_utils.hpp"
#include "Emu/perf_meter.hpp" #include "Emu/perf_meter.hpp"
#include "Emu/Cell/ErrorCodes.h" #include "Emu/Cell/ErrorCodes.h"
@ -15,12 +17,10 @@
#include "Emu/Cell/lv2/sys_sync.h" #include "Emu/Cell/lv2/sys_sync.h"
#include "Emu/Cell/lv2/sys_prx.h" #include "Emu/Cell/lv2/sys_prx.h"
#include "Emu/Cell/lv2/sys_overlay.h" #include "Emu/Cell/lv2/sys_overlay.h"
#include "Emu/Cell/Modules/cellMsgDialog.h"
#include "Emu/title.h" #include "Emu/title.h"
#include "Emu/IdManager.h" #include "Emu/IdManager.h"
#include "Emu/RSX/Capture/rsx_replay.h" #include "Emu/RSX/Capture/rsx_replay.h"
#include "Emu/RSX/Overlays/overlay_message_dialog.h"
#include "Loader/PSF.h" #include "Loader/PSF.h"
#include "Loader/ELF.h" #include "Loader/ELF.h"
@ -28,17 +28,13 @@
#include "Utilities/StrUtil.h" #include "Utilities/StrUtil.h"
#include "../Crypto/unself.h" #include "../Crypto/unself.h"
#include "../Crypto/unpkg.h"
#include "util/sysinfo.hpp"
#include "util/yaml.hpp" #include "util/yaml.hpp"
#include "util/logs.hpp" #include "util/logs.hpp"
#include "util/cereal.hpp" #include "util/cereal.hpp"
#include <thread>
#include <fstream> #include <fstream>
#include <memory> #include <memory>
#include <regex> #include <regex>
#include <charconv>
#include "Utilities/JIT.h" #include "Utilities/JIT.h"
@ -75,21 +71,9 @@ atomic_t<s64> g_tty_size{0};
std::array<std::deque<std::string>, 16> g_tty_input; std::array<std::deque<std::string>, 16> g_tty_input;
std::mutex g_tty_mutex; std::mutex g_tty_mutex;
// Progress display server synchronization variables
atomic_t<const char*> g_progr{nullptr};
atomic_t<u32> g_progr_ftotal{0};
atomic_t<u32> g_progr_fdone{0};
atomic_t<u32> g_progr_ptotal{0};
atomic_t<u32> g_progr_pdone{0};
// Report error and call std::abort(), defined in main.cpp // Report error and call std::abort(), defined in main.cpp
[[noreturn]] void report_fatal_error(std::string_view); [[noreturn]] void report_fatal_error(std::string_view);
namespace
{
struct progress_dialog_server;
}
namespace atomic_wait namespace atomic_wait
{ {
extern void parse_hashtable(bool(*cb)(u64 id, u32 refs, u64 ptr, u32 stats)); 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) // Create directories (can be disabled if necessary)
const std::string emu_dir = GetEmuDir(); const std::string emu_dir = rpcs3::utils::get_emu_dir();
const std::string dev_hdd0 = GetHddDir(); 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_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_usb = g_cfg.vfs.get(g_cfg.vfs.dev_usb000, emu_dir);
const std::string dev_flsh = g_cfg.vfs.get_dev_flash(); const std::string dev_flsh = g_cfg.vfs.get_dev_flash();
@ -322,225 +306,17 @@ void Emulator::Init(bool add_only)
// Limit cache size // Limit cache size
if (g_cfg.vfs.limit_cache_size) if (g_cfg.vfs.limit_cache_size)
LimitCacheSize(); rpcs3::cache::limit_cache_size();
// Initialize patch engine // Initialize patch engine
g_fxo->init<patch_engine>()->append_global_patches(); g_fxo->init<patch_engine>()->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<MsgDialogBase> dlg;
std::shared_ptr<rsx::overlays::progress_dialog> native_dlg;
if (const auto renderer = rsx::get_current_renderer();
renderer && renderer->is_inited)
{
auto manager = g_fxo->try_get<rsx::overlays::display_manager>();
skip_this_one = g_fxo->get<progress_dialog_workaround>().skip_the_progress_dialog || (manager && manager->get<rsx::overlays::message_dialog>());
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<rsx::overlays::progress_dialog>(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<u64>(ptotal, 1) * std::max<u64>(ftotal, 1);
const u64 done = pdone * std::max<u64>(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) void Emulator::SetUsr(const std::string& user)
{ {
sys_log.notice("Setting user ID '%s'", 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) if (id == 0)
{ {
@ -594,19 +370,6 @@ std::string Emulator::GetBackgroundPicturePath() const
return path; return path;
} }
std::string Emulator::PPUCache()
{
auto& _main = g_fxo->get<ppu_module>();
if (!g_fxo->is_init<ppu_module>() || _main.cache.empty())
{
ppu_log.warning("PPU Cache location not initialized.");
return {};
}
return _main.cache;
}
bool Emulator::BootRsxCapture(const std::string& path) bool Emulator::BootRsxCapture(const std::string& path)
{ {
fs::file in_file(path); fs::file in_file(path);
@ -655,93 +418,6 @@ bool Emulator::BootRsxCapture(const std::string& path)
return true; 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<u64>(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<fs::dir_entry> 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<u64>(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) 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)) if (!fs::exists(path))
@ -806,179 +482,6 @@ game_boot_result Emulator::BootGame(const std::string& path, const std::string&
return result; return result;
} }
bool Emulator::InstallPkg(const std::string& path)
{
sys_log.success("Installing package: %s", path);
atomic_t<double> 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<int>(pval) > int_progress)
{
int_progress = static_cast<int>(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) void Emulator::SetForceBoot(bool force_boot)
{ {
m_force_boot = 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)) if (fs::is_dir(m_path))
{ {
// Special case (directory scan) // 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()) 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") 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 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 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")); _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()) 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_new = rpcs3::utils::get_custom_config_path(m_title_id);
const std::string config_path_old = GetCustomConfigPath(m_title_id, true); const std::string config_path_old = rpcs3::utils::get_custom_config_path(m_title_id, true);
// Load custom config-1 // Load custom config-1
if (fs::file cfg_file{ config_path_old }) 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<patch_engine>().append_title_patches(m_title_id); g_fxo->get<patch_engine>().append_title_patches(m_title_id);
// Mount all devices // 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; std::string bdvd_dir = g_cfg.vfs.dev_bdvd;
// Mount default relative path to non-existent directory // 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}) for (auto&& entry : fs::dir{ins_dir})
{ {
const std::string pkg = ins_dir + entry.name; 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); sys_log.error("Failed to install %s", pkg);
return game_boot_result::install_failed; 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"; 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); sys_log.error("Failed to install %s", pkg_file);
return game_boot_result::install_failed; 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"; 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); sys_log.error("Failed to install %s", pkg_file);
return game_boot_result::install_failed; return game_boot_result::install_failed;
@ -1838,7 +1341,7 @@ void Emulator::Run(bool start_playtime)
m_pause_amend_time = 0; m_pause_amend_time = 0;
m_state = system_state::running; m_state = system_state::running;
ConfigureLogs(); rpcs3::utils::configure_logs();
// Run main thread // Run main thread
idm::check<named_thread<ppu_thread>>(ppu_thread::id_base, [](named_thread<ppu_thread>& cpu) idm::check<named_thread<ppu_thread>>(ppu_thread::id_base, [](named_thread<ppu_thread>& cpu)
@ -2137,14 +1640,6 @@ std::string Emulator::GetFormattedTitle(double fps) const
return rpcs3::get_formatted_title(title_data); return rpcs3::get_formatted_title(title_data);
} }
u32 Emulator::GetMaxThreads()
{
const u32 max_threads = static_cast<u32>(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) 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<std::string, usz> g_tls_error_stats; static thread_local std::unordered_map<std::string, usz> 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<s32>(arg); return static_cast<s32>(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 void Emulator::ConfigurePPUCache() const
{ {
auto& _main = g_fxo->get<ppu_module>(); auto& _main = g_fxo->get<ppu_module>();
_main.cache = GetCacheDir(); _main.cache = rpcs3::utils::get_cache_dir();
if (!m_title_id.empty() && m_cat != "1P") if (!m_title_id.empty() && m_cat != "1P")
{ {

View File

@ -205,8 +205,6 @@ public:
return m_usrid; return m_usrid;
} }
static u32 CheckUsr(const std::string& user);
void SetUsr(const std::string& user); void SetUsr(const std::string& user);
std::string GetBackgroundPicturePath() const; std::string GetBackgroundPicturePath() const;
@ -216,27 +214,8 @@ public:
return m_pause_amend_time; 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); 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); 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); void SetForceBoot(bool force_boot);
@ -264,15 +243,9 @@ public:
std::string GetFormattedTitle(double fps) const; std::string GetFormattedTitle(double fps) const;
static u32 GetMaxThreads();
static void ConfigureLogs();
void ConfigurePPUCache() const; void ConfigurePPUCache() const;
std::set<std::string> GetGameDirs() const; std::set<std::string> GetGameDirs() const;
private:
static void LimitCacheSize();
}; };
extern Emulator Emu; extern Emulator Emu;

112
rpcs3/Emu/cache_utils.cpp Normal file
View File

@ -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<ppu_module>();
if (!g_fxo->is_init<ppu_module>() || _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<u64>(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<fs::dir_entry> 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<u64>(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);
}
}

View File

@ -0,0 +1,7 @@
#pragma once
namespace rpcs3::cache
{
std::string get_ppu_cache();
void limit_cache_size();
}

View File

@ -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<const char*> g_progr{nullptr};
atomic_t<u32> g_progr_ftotal{0};
atomic_t<u32> g_progr_fdone{0};
atomic_t<u32> g_progr_ptotal{0};
atomic_t<u32> 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<MsgDialogBase> dlg;
std::shared_ptr<rsx::overlays::progress_dialog> native_dlg;
if (const auto renderer = rsx::get_current_renderer();
renderer && renderer->is_inited)
{
auto manager = g_fxo->try_get<rsx::overlays::display_manager>();
skip_this_one = g_fxo->get<progress_dialog_workaround>().skip_the_progress_dialog || (manager && manager->get<rsx::overlays::message_dialog>());
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<rsx::overlays::progress_dialog>(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<u64>(ptotal, 1) * std::max<u64>(ftotal, 1);
const u64 done = pdone * std::max<u64>(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);
}

View File

@ -30,3 +30,11 @@ public:
g_progr.release(m_prev); g_progr.release(m_prev);
} }
}; };
struct progress_dialog_server
{
void operator()();
~progress_dialog_server();
static auto constexpr thread_name = "Progress Dialog Server"sv;
};

240
rpcs3/Emu/system_utils.cpp Normal file
View File

@ -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 <charconv>
#include <thread>
#ifdef _WIN32
#include <windows.h>
#endif
LOG_CHANNEL(sys_log, "SYS");
namespace rpcs3::utils
{
u32 get_max_threads()
{
const u32 max_threads = static_cast<u32>(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<double> 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<int>(pval) > int_progress)
{
int_progress = static_cast<int>(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";
}
}

View File

@ -0,0 +1,32 @@
#pragma once
#include "util/types.hpp"
#include <string>
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);
}

View File

@ -59,6 +59,7 @@
<ClCompile Include="Emu\Audio\Pulse\PulseBackend.cpp"> <ClCompile Include="Emu\Audio\Pulse\PulseBackend.cpp">
<ExcludedFromBuild>true</ExcludedFromBuild> <ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="Emu\cache_utils.cpp" />
<ClCompile Include="Emu\Cell\Modules\sys_crashdump.cpp" /> <ClCompile Include="Emu\Cell\Modules\sys_crashdump.cpp" />
<ClCompile Include="Emu\Io\Turntable.cpp" /> <ClCompile Include="Emu\Io\Turntable.cpp" />
<ClCompile Include="Emu\Io\GHLtar.cpp" /> <ClCompile Include="Emu\Io\GHLtar.cpp" />
@ -79,6 +80,8 @@
<ClCompile Include="Emu\RSX\RSXDisAsm.cpp" /> <ClCompile Include="Emu\RSX\RSXDisAsm.cpp" />
<ClCompile Include="Emu\system_config_types.cpp" /> <ClCompile Include="Emu\system_config_types.cpp" />
<ClCompile Include="Emu\perf_meter.cpp" /> <ClCompile Include="Emu\perf_meter.cpp" />
<ClCompile Include="Emu\system_progress.cpp" />
<ClCompile Include="Emu\system_utils.cpp" />
<ClCompile Include="Emu\title.cpp" /> <ClCompile Include="Emu\title.cpp" />
<ClCompile Include="Emu\system_config.cpp" /> <ClCompile Include="Emu\system_config.cpp" />
<ClCompile Include="Emu\NP\fb_helpers.cpp" /> <ClCompile Include="Emu\NP\fb_helpers.cpp" />
@ -431,6 +434,7 @@
<ClInclude Include="Emu\Audio\Pulse\PulseBackend.h"> <ClInclude Include="Emu\Audio\Pulse\PulseBackend.h">
<ExcludedFromBuild>true</ExcludedFromBuild> <ExcludedFromBuild>true</ExcludedFromBuild>
</ClInclude> </ClInclude>
<ClInclude Include="Emu\cache_utils.hpp" />
<ClInclude Include="Emu\Cell\lv2\sys_crypto_engine.h" /> <ClInclude Include="Emu\Cell\lv2\sys_crypto_engine.h" />
<ClInclude Include="Emu\Cell\Modules\cellCrossController.h" /> <ClInclude Include="Emu\Cell\Modules\cellCrossController.h" />
<ClInclude Include="Emu\Cell\Modules\cellRemotePlay.h" /> <ClInclude Include="Emu\Cell\Modules\cellRemotePlay.h" />
@ -471,6 +475,8 @@
<ClInclude Include="Emu\RSX\Overlays\Shaders\shader_loading_dialog.h" /> <ClInclude Include="Emu\RSX\Overlays\Shaders\shader_loading_dialog.h" />
<ClInclude Include="Emu\RSX\Overlays\Shaders\shader_loading_dialog_native.h" /> <ClInclude Include="Emu\RSX\Overlays\Shaders\shader_loading_dialog_native.h" />
<ClInclude Include="Emu\RSX\RSXDisAsm.h" /> <ClInclude Include="Emu\RSX\RSXDisAsm.h" />
<ClInclude Include="Emu\system_progress.hpp" />
<ClInclude Include="Emu\system_utils.hpp" />
<ClInclude Include="Emu\title.h" /> <ClInclude Include="Emu\title.h" />
<ClInclude Include="Emu\system_config.h" /> <ClInclude Include="Emu\system_config.h" />
<ClInclude Include="Emu\system_config_types.h" /> <ClInclude Include="Emu\system_config_types.h" />

View File

@ -992,6 +992,15 @@
<ClCompile Include="Emu\RSX\Overlays\overlay_user_list_dialog.cpp"> <ClCompile Include="Emu\RSX\Overlays\overlay_user_list_dialog.cpp">
<Filter>Emu\GPU\RSX\Overlays</Filter> <Filter>Emu\GPU\RSX\Overlays</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Emu\system_utils.cpp">
<Filter>Emu</Filter>
</ClCompile>
<ClCompile Include="Emu\cache_utils.cpp">
<Filter>Emu</Filter>
</ClCompile>
<ClCompile Include="Emu\system_progress.cpp">
<Filter>Emu</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Crypto\aes.h"> <ClInclude Include="Crypto\aes.h">
@ -1939,6 +1948,15 @@
<ClInclude Include="Emu\RSX\Overlays\overlay_user_list_dialog.h"> <ClInclude Include="Emu\RSX\Overlays\overlay_user_list_dialog.h">
<Filter>Emu\GPU\RSX\Overlays</Filter> <Filter>Emu\GPU\RSX\Overlays</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Emu\system_utils.hpp">
<Filter>Emu</Filter>
</ClInclude>
<ClInclude Include="Emu\cache_utils.hpp">
<Filter>Emu</Filter>
</ClInclude>
<ClInclude Include="Emu\system_progress.hpp">
<Filter>Emu</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Emu\RSX\Common\Interpreter\FragmentInterpreter.glsl"> <None Include="Emu\RSX\Common\Interpreter\FragmentInterpreter.glsl">

View File

@ -51,6 +51,7 @@ DYNAMIC_IMPORT("ntdll.dll", NtSetTimerResolution, NTSTATUS(ULONG DesiredResoluti
#include "Utilities/StrUtil.h" #include "Utilities/StrUtil.h"
#include "rpcs3_version.h" #include "rpcs3_version.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include <thread> #include <thread>
#include <charconv> #include <charconv>
@ -743,7 +744,7 @@ int main(int argc, char** argv)
{ {
active_user = parser.value(arg_user_id).toStdString(); 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)); 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));
} }

View File

@ -1,5 +1,5 @@
#include "curl_handle.h" #include "curl_handle.h"
#include "Emu/System.h" #include "Emu/system_utils.hpp"
#ifdef _WIN32 #ifdef _WIN32
#include "Utilities/StrUtil.h" #include "Utilities/StrUtil.h"
@ -11,7 +11,7 @@ curl_handle::curl_handle(QObject* parent) : QObject(parent)
#ifdef _WIN32 #ifdef _WIN32
// This shouldn't be needed on linux // 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); const std::string ansi_path = utf8_path_to_ansi_path(path_to_cert);
curl_easy_setopt(m_curl, CURLOPT_CAINFO, ansi_path.data()); curl_easy_setopt(m_curl, CURLOPT_CAINFO, ansi_path.data());

View File

@ -8,6 +8,7 @@
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_config.h" #include "Emu/system_config.h"
#include "Emu/system_utils.hpp"
#include "Emu/Cell/Modules/cellSysutil.h" #include "Emu/Cell/Modules/cellSysutil.h"
#include "util/yaml.hpp" #include "util/yaml.hpp"
@ -98,7 +99,7 @@ void emu_settings::LoadSettings(const std::string& title_id)
m_title_id = title_id; m_title_id = title_id;
// Create config path if necessary // 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 // Load default config
auto [default_config, default_error] = yaml_load(g_cfg_defaults); 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. // Otherwise we'll always trigger the "obsolete settings dialog" when editing custom configs.
ValidateSettings(true); ValidateSettings(true);
const std::string config_path_new = Emulator::GetCustomConfigPath(m_title_id); const std::string config_path_new = rpcs3::utils::get_custom_config_path(m_title_id);
const std::string config_path_old = Emulator::GetCustomConfigPath(m_title_id, true); const std::string config_path_old = rpcs3::utils::get_custom_config_path(m_title_id, true);
std::string custom_config_path; std::string custom_config_path;
if (fs::is_file(config_path_new)) if (fs::is_file(config_path_new))
@ -274,7 +275,7 @@ void emu_settings::SaveSettings() const
} }
else else
{ {
config_name = Emulator::GetCustomConfigPath(m_title_id); config_name = rpcs3::utils::get_custom_config_path(m_title_id);
} }
// Save config atomically // Save config atomically

View File

@ -16,6 +16,7 @@
#include "Emu/Memory/vm.h" #include "Emu/Memory/vm.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include "Loader/PSF.h" #include "Loader/PSF.h"
#include "util/types.hpp" #include "util/types.hpp"
#include "Utilities/lockless.h" #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) 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) 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_game_data.clear();
m_notes.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 = sstr(cat::cat_unknown);
const std::string cat_unknown_localized = sstr(localized.category.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 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")); 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 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 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(Emulator::GetCustomInputConfigPath(game.serial)); 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 bool has_hover_gif = fs::is_file(game_icon_path + game.serial + "/hover.gif");
const QColor color = getGridCompatibilityColor(compat.color); 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")); QAction* open_config_dir = menu.addAction(tr("&Open Custom Config Folder"));
connect(open_config_dir, &QAction::triggered, [current_game]() 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)) if (fs::is_file(new_config_path))
gui::utils::open_dir(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)) if (fs::is_file(old_config_path))
gui::utils::open_dir(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) 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_new = rpcs3::utils::get_custom_config_path(title_id);
const std::string config_path_old = Emulator::GetCustomConfigPath(title_id, true); 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)) if (!fs::is_file(config_path_new) && !fs::is_file(config_path_old))
return true; 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) 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)) if (!fs::is_dir(config_dir))
return true; return true;

View File

@ -17,6 +17,7 @@
#include "Emu/Cell/Modules/cellAudio.h" #include "Emu/Cell/Modules/cellAudio.h"
#include "Emu/RSX/Overlays/overlay_perf_metrics.h" #include "Emu/RSX/Overlays/overlay_perf_metrics.h"
#include "Emu/system_utils.hpp"
#include "trophy_notification_helper.h" #include "trophy_notification_helper.h"
#include "save_data_dialog.h" #include "save_data_dialog.h"
#include "msg_dialog_frame.h" #include "msg_dialog_frame.h"
@ -557,7 +558,7 @@ void gui_application::OnEmuSettingsChange()
} }
} }
Emulator::ConfigureLogs(); rpcs3::utils::configure_logs();
audio::configure_audio(); audio::configure_audio();
rsx::overlays::reset_performance_overlay(); rsx::overlays::reset_performance_overlay();
} }

View File

@ -43,6 +43,7 @@
#include "Emu/IdManager.h" #include "Emu/IdManager.h"
#include "Emu/VFS.h" #include "Emu/VFS.h"
#include "Emu/system_config.h" #include "Emu/system_config.h"
#include "Emu/system_utils.hpp"
#include "Crypto/unpkg.h" #include "Crypto/unpkg.h"
#include "Crypto/unself.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 // 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)); const fs::file from(sstr(path));
if (!to.file || !from) if (!to.file || !from)
@ -2573,7 +2574,7 @@ void main_window::SetIconSizeActions(int idx) const
void main_window::RemoveDiskCache() 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)) if (fs::is_dir(cache_dir) && fs::remove_all(cache_dir, false))
{ {
@ -2587,7 +2588,7 @@ void main_window::RemoveDiskCache()
void main_window::RemoveFirmwareCache() 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)) if (!fs::is_dir(cache_dir))
return; return;

View File

@ -1,7 +1,7 @@
#include "persistent_settings.h" #include "persistent_settings.h"
#include "util/logs.hpp" #include "util/logs.hpp"
#include "Emu/System.h" #include "Emu/system_utils.hpp"
LOG_CHANNEL(cfg_log, "CFG"); LOG_CHANNEL(cfg_log, "CFG");
@ -49,7 +49,7 @@ QString persistent_settings::GetCurrentUser(const QString& fallback) const
} }
// Set user if valid // Set user if valid
if (Emulator::CheckUsr(user.toStdString()) > 0) if (rpcs3::utils::check_user(user.toStdString()) > 0)
{ {
return user; return user;
} }

View File

@ -8,7 +8,7 @@
#include <QScreen> #include <QScreen>
#include <QUrl> #include <QUrl>
#include "Emu/System.h" #include "Emu/system_utils.hpp"
#include "Utilities/File.h" #include "Utilities/File.h"
inline std::string sstr(const QString& _in) { return _in.toStdString(); } inline std::string sstr(const QString& _in) { return _in.toStdString(); }
@ -260,7 +260,7 @@ namespace gui
continue; 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"; icon_path = sfo_dir + "/ICON0.PNG";
found_file = fs::is_file(icon_path); found_file = fs::is_file(icon_path);

View File

@ -6,6 +6,7 @@
#include "persistent_settings.h" #include "persistent_settings.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include "Loader/PSF.h" #include "Loader/PSF.h"
#include <QtConcurrent> #include <QtConcurrent>
@ -236,7 +237,7 @@ void save_manager_dialog::UpdateList()
{ {
if (m_dir.empty()) 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); m_save_entries = GetSaveEntries(m_dir);

View File

@ -3,7 +3,7 @@
#include "qt_utils.h" #include "qt_utils.h"
#include "Utilities/File.h" #include "Utilities/File.h"
#include "Emu/VFS.h" #include "Emu/VFS.h"
#include "Emu/System.h" #include "Emu/system_utils.hpp"
#include <QApplication> #include <QApplication>
#include <QDir> #include <QDir>
@ -29,7 +29,7 @@ screenshot_manager_dialog::screenshot_manager_dialog(QWidget* parent) : QDialog(
m_grid->setGridSize(m_icon_size + QSize(10, 10)); m_grid->setGridSize(m_icon_size + QSize(10, 10));
// HACK: dev_hdd0 must be mounted for vfs to work for loading trophies. // 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_qt = fs::get_config_dir() + "screenshots/";
const std::string screenshot_path_cell = vfs::get("/dev_hdd0/photo/"); const std::string screenshot_path_cell = vfs::get("/dev_hdd0/photo/");

View File

@ -10,6 +10,7 @@
#include "Utilities/File.h" #include "Utilities/File.h"
#include "Emu/VFS.h" #include "Emu/VFS.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include "Emu/Cell/Modules/sceNpTrophy.h" #include "Emu/Cell/Modules/sceNpTrophy.h"
#include "Loader/TROPUSR.h" #include "Loader/TROPUSR.h"
@ -60,7 +61,7 @@ trophy_manager_dialog::trophy_manager_dialog(std::shared_ptr<gui_settings> gui_s
m_show_platinum_trophies = m_gui_settings->GetValue(gui::tr_show_platinum).toBool(); 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. // 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. // Get the currently selected user's trophy path.
m_trophy_dir = "/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/"; m_trophy_dir = "/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/";

View File

@ -6,6 +6,7 @@
#include "Utilities/StrUtil.h" #include "Utilities/StrUtil.h"
#include "Utilities/File.h" #include "Utilities/File.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include "util/logs.hpp" #include "util/logs.hpp"
#include <QApplication> #include <QApplication>
@ -284,7 +285,7 @@ bool update_manager::handle_rpcs3(const QByteArray& data)
#ifdef _WIN32 #ifdef _WIN32
// Get executable path // 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; std::wstring wchar_orig_path;
const auto tmp_size = MultiByteToWideChar(CP_UTF8, 0, orig_path.c_str(), -1, nullptr, 0); 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; usz outBufferSize = 0;
// Creates temp folder for moving active files // 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); fs::create_dir(tmp_folder);
for (UInt32 i = 0; i < db.NumFiles; i++) 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<u8>(temp_u16[index]); temp_u8[index] = static_cast<u8>(temp_u16[index]);
} }
temp_u8[len] = 0; temp_u8[len] = 0;
const std::string name = Emulator::GetEmuDir() + std::string(reinterpret_cast<char*>(temp_u8)); const std::string name = rpcs3::utils::get_emu_dir() + std::string(reinterpret_cast<char*>(temp_u8));
if (!isDir) if (!isDir)
{ {

View File

@ -1,6 +1,6 @@
#include "user_account.h" #include "user_account.h"
#include "Emu/System.h" #include "Emu/system_utils.hpp"
#include "Utilities/File.h" #include "Utilities/File.h"
#include "util/logs.hpp" #include "util/logs.hpp"
@ -12,7 +12,7 @@ user_account::user_account(const std::string& user_id)
m_user_id = user_id; m_user_id = user_id;
// Setting userDir. // 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. // Setting userName.
if (fs::file file; file.open(m_user_dir + "localusername", fs::read)) if (fs::file file; file.open(m_user_dir + "localusername", fs::read))
@ -46,7 +46,7 @@ std::map<u32, user_account> user_account::GetUserAccounts(const std::string& bas
} }
// Is the folder name exactly 8 all-numerical characters long? // 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) if (key == 0)
{ {

View File

@ -19,6 +19,7 @@
#include "persistent_settings.h" #include "persistent_settings.h"
#include "Emu/System.h" #include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include "Utilities/StrUtil.h" #include "Utilities/StrUtil.h"
#include "Utilities/File.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. // Get the user folders in the home directory and the currently logged in user.
m_user_list.clear(); 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. // Clear and then repopulate the table with the list gathered above.
m_table->setRowCount(static_cast<int>(m_user_list.size())); m_table->setRowCount(static_cast<int>(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) 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. // 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; const std::string user_dir = home_dir + user_id;
fs::create_dir(home_dir); fs::create_dir(home_dir);
fs::create_dir(user_dir + "/"); fs::create_dir(user_dir + "/");
@ -285,7 +286,7 @@ void user_manager_dialog::OnUserRename()
continue; 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(); const std::string new_username = text_to_validate.toStdString();
if (fs::write_file(username_file, fs::rewrite, new_username)) 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); 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); QInputDialog* dialog = new QInputDialog(this);
dialog->setWindowTitle(tr("New User")); dialog->setWindowTitle(tr("New User"));