From e24ada37bfd758263561a68771476f63b1db85e3 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Wed, 5 May 2021 10:42:12 +0300 Subject: [PATCH] fs: implement fs::get_temp_dir() (Win32) Trying to workaround issues with sparse files (#10231) --- Utilities/File.cpp | 26 ++++++++++++++++++++++++++ Utilities/File.h | 3 +++ rpcs3/Emu/Memory/vm.cpp | 4 ++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index 5356dbe6c1..b8ef0a3ccc 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -1729,6 +1729,32 @@ const std::string& fs::get_cache_dir() return s_dir; } +const std::string& fs::get_temp_dir() +{ + static const std::string s_dir = [] + { + std::string dir; + +#ifdef _WIN32 + wchar_t buf[MAX_PATH + 2]{}; + if (GetTempPathW(MAX_PATH + 1, buf) - 1 > MAX_PATH) + { + MessageBoxA(nullptr, fmt::format("GetTempPath() failed: error %u.", GetLastError()).c_str(), "fs::get_temp_dir()", MB_ICONERROR); + return dir; // empty + } + + to_utf8(dir, buf); +#else + // TODO + dir = get_cache_dir(); +#endif + + return dir; + }(); + + return s_dir; +} + bool fs::remove_all(const std::string& path, bool remove_root) { if (const auto root_dir = dir(path)) diff --git a/Utilities/File.h b/Utilities/File.h index 8a9f3e1162..3749069a4d 100644 --- a/Utilities/File.h +++ b/Utilities/File.h @@ -636,6 +636,9 @@ namespace fs // Get common cache directory const std::string& get_cache_dir(); + // Temporary directory + const std::string& get_temp_dir(); + // Unique pending file creation destined to be renamed to the destination file struct pending_file { diff --git a/rpcs3/Emu/Memory/vm.cpp b/rpcs3/Emu/Memory/vm.cpp index 6aae06d09d..93c30f146d 100644 --- a/rpcs3/Emu/Memory/vm.cpp +++ b/rpcs3/Emu/Memory/vm.cpp @@ -1128,7 +1128,7 @@ namespace vm if (flags & page_size_4k || flags & preallocated) { // Special path for whole-allocated areas allowing 4k granularity - m_common = std::make_shared(size, fs::get_cache_dir() + std::to_string(utils::get_unique_tsc())); + m_common = std::make_shared(size); m_common->map_critical(vm::base(addr), utils::protection::no); m_common->map_critical(vm::get_super_ptr(addr)); } @@ -1632,7 +1632,7 @@ namespace vm inline namespace ps3_ { - static utils::shm s_hook{0x800000000, fs::get_cache_dir() + "hook.dat"}; + static utils::shm s_hook{0x800000000, fmt::format("%s/rpcs3_vm_hook_%s", fs::get_temp_dir(), fmt::base57(utils::get_unique_tsc()))}; void init() {