From abce406ee8640d0fa28a6ee95dde3712e8d613be Mon Sep 17 00:00:00 2001 From: Exzap <13877693+Exzap@users.noreply.github.com> Date: Thu, 28 Sep 2023 02:51:40 +0200 Subject: [PATCH] Refactor more wstring instances to utf8-encoded string --- src/Cafe/GraphicPack/GraphicPack2.cpp | 22 ++++------ src/Cafe/GraphicPack/GraphicPack2.h | 9 ++-- src/Cafe/GraphicPack/GraphicPack2Patches.cpp | 19 +++------ .../GraphicPack/GraphicPack2PatchesParser.cpp | 2 +- src/Cafe/HW/Espresso/Debugger/Debugger.cpp | 6 +-- .../Renderer/Vulkan/RendererShaderVk.cpp | 2 +- .../Vulkan/VulkanPipelineStableCache.cpp | 4 +- src/Cafe/IOSU/legacy/iosu_act.cpp | 2 +- src/Cafe/IOSU/legacy/iosu_crypto.cpp | 6 +-- src/Cafe/IOSU/legacy/iosu_crypto.h | 2 +- src/Cafe/OS/libs/nn_nfp/nn_nfp.cpp | 9 ++-- src/Cafe/OS/libs/nn_nfp/nn_nfp.h | 2 +- src/Cemu/Logging/CemuLogging.cpp | 8 ---- src/Cemu/Logging/CemuLogging.h | 1 - .../Tools/DownloadManager/DownloadManager.cpp | 2 +- src/Common/unix/FileStream_unix.cpp | 1 - src/config/ActiveSettings.cpp | 2 +- src/config/CemuConfig.cpp | 26 +++++------- src/config/CemuConfig.h | 10 ++--- src/gui/CemuApp.cpp | 6 +-- src/gui/GeneralSettings2.cpp | 4 +- src/gui/GettingStartedDialog.cpp | 4 +- src/gui/GraphicPacksWindow2.cpp | 2 +- src/gui/MainWindow.cpp | 41 +++++++++---------- src/gui/MainWindow.h | 2 +- src/gui/components/wxTitleManagerList.cpp | 2 +- 26 files changed, 82 insertions(+), 114 deletions(-) diff --git a/src/Cafe/GraphicPack/GraphicPack2.cpp b/src/Cafe/GraphicPack/GraphicPack2.cpp index 4594aed0..72e301c4 100644 --- a/src/Cafe/GraphicPack/GraphicPack2.cpp +++ b/src/Cafe/GraphicPack/GraphicPack2.cpp @@ -54,7 +54,7 @@ void GraphicPack2::LoadGraphicPack(fs::path graphicPackPath) if (versionNum > GP_LEGACY_VERSION) { - GraphicPack2::LoadGraphicPack(rulesPath.generic_wstring(), iniParser); + GraphicPack2::LoadGraphicPack(_pathToUtf8(rulesPath), iniParser); return; } } @@ -79,7 +79,7 @@ void GraphicPack2::LoadAll() } } -bool GraphicPack2::LoadGraphicPack(const std::wstring& filename, IniParser& rules) +bool GraphicPack2::LoadGraphicPack(const std::string& filename, IniParser& rules) { try { @@ -216,12 +216,6 @@ void GraphicPack2::WaitUntilReady() std::this_thread::sleep_for(std::chrono::milliseconds(5)); } -GraphicPack2::GraphicPack2(std::wstring filename) - : m_filename(std::move(filename)) -{ - // unused for now -} - std::unordered_map GraphicPack2::ParsePresetVars(IniParser& rules) const { ExpressionParser parser; @@ -255,7 +249,7 @@ std::unordered_map GraphicPack2::ParsePres return vars; } -GraphicPack2::GraphicPack2(std::wstring filename, IniParser& rules) +GraphicPack2::GraphicPack2(std::string filename, IniParser& rules) : m_filename(std::move(filename)) { // we're already in [Definition] @@ -265,7 +259,7 @@ GraphicPack2::GraphicPack2(std::wstring filename, IniParser& rules) m_version = StringHelpers::ToInt(*option_version, -1); if (m_version < 0) { - cemuLog_log(LogType::Force, L"{}: Invalid version", m_filename); + cemuLog_log(LogType::Force, "{}: Invalid version", m_filename); throw std::exception(); } @@ -839,7 +833,7 @@ void GraphicPack2::LoadReplacedFiles() return; m_patchedFilesLoaded = true; - fs::path gfxPackPath(m_filename.c_str()); + fs::path gfxPackPath = _utf8ToPath(m_filename); gfxPackPath = gfxPackPath.remove_filename(); // /content/ @@ -892,14 +886,14 @@ bool GraphicPack2::Activate() return false; } - FileStream* fs_rules = FileStream::openFile2({ m_filename }); + FileStream* fs_rules = FileStream::openFile2(_utf8ToPath(m_filename)); if (!fs_rules) return false; std::vector rulesData; fs_rules->extract(rulesData); delete fs_rules; - IniParser rules({ (char*)rulesData.data(), rulesData.size()}, boost::nowide::narrow(m_filename)); + IniParser rules({ (char*)rulesData.data(), rulesData.size()}, m_filename); // load rules try @@ -953,7 +947,7 @@ bool GraphicPack2::Activate() else if (anisotropyValue == 16) rule.overwrite_settings.anistropic_value = 4; else - cemuLog_log(LogType::Force, fmt::format(L"Invalid value {} for overwriteAnisotropy in graphic pack {}. Only the values 1, 2, 4, 8 or 16 are allowed.", anisotropyValue, m_filename)); + cemuLog_log(LogType::Force, "Invalid value {} for overwriteAnisotropy in graphic pack {}. Only the values 1, 2, 4, 8 or 16 are allowed.", anisotropyValue, m_filename); } m_texture_rules.emplace_back(rule); } diff --git a/src/Cafe/GraphicPack/GraphicPack2.h b/src/Cafe/GraphicPack/GraphicPack2.h index a087f757..6396ecc7 100644 --- a/src/Cafe/GraphicPack/GraphicPack2.h +++ b/src/Cafe/GraphicPack/GraphicPack2.h @@ -97,13 +97,12 @@ public: }; using PresetPtr = std::shared_ptr; - GraphicPack2(std::wstring filename); - GraphicPack2(std::wstring filename, IniParser& rules); + GraphicPack2(std::string filename, IniParser& rules); bool IsEnabled() const { return m_enabled; } bool IsActivated() const { return m_activated; } sint32 GetVersion() const { return m_version; } - const std::wstring& GetFilename() const { return m_filename; } + const std::string& GetFilename() const { return m_filename; } const fs::path GetFilename2() const { return fs::path(m_filename); } bool RequiresRestart(bool changeEnableState, bool changePreset); bool Reload(); @@ -165,7 +164,7 @@ public: static const std::vector>& GetGraphicPacks() { return s_graphic_packs; } static const std::vector>& GetActiveGraphicPacks() { return s_active_graphic_packs; } static void LoadGraphicPack(fs::path graphicPackPath); - static bool LoadGraphicPack(const std::wstring& filename, class IniParser& rules); + static bool LoadGraphicPack(const std::string& filename, class IniParser& rules); static bool ActivateGraphicPack(const std::shared_ptr& graphic_pack); static bool DeactivateGraphicPack(const std::shared_ptr& graphic_pack); static void ClearGraphicPacks(); @@ -209,7 +208,7 @@ private: parser.TryAddConstant(var.first, (TType)var.second.second); } - std::wstring m_filename; + std::string m_filename; sint32 m_version; std::string m_name; diff --git a/src/Cafe/GraphicPack/GraphicPack2Patches.cpp b/src/Cafe/GraphicPack/GraphicPack2Patches.cpp index 7fa1e7fe..5c79630c 100644 --- a/src/Cafe/GraphicPack/GraphicPack2Patches.cpp +++ b/src/Cafe/GraphicPack/GraphicPack2Patches.cpp @@ -83,7 +83,7 @@ bool GraphicPack2::LoadCemuPatches() }; bool foundPatches = false; - fs::path path(m_filename); + fs::path path(_utf8ToPath(m_filename)); path.remove_filename(); for (auto& p : fs::directory_iterator(path)) { @@ -91,10 +91,10 @@ bool GraphicPack2::LoadCemuPatches() if (fs::is_regular_file(p.status()) && path.has_filename()) { // check if filename matches - std::wstring filename = path.filename().generic_wstring(); - if (boost::istarts_with(filename, L"patch_") && boost::iends_with(filename, L".asm")) + std::string filename = _pathToUtf8(path.filename()); + if (boost::istarts_with(filename, "patch_") && boost::iends_with(filename, ".asm")) { - FileStream* patchFile = FileStream::openFile(path.generic_wstring().c_str()); + FileStream* patchFile = FileStream::openFile2(path); if (patchFile) { // read file @@ -126,27 +126,20 @@ void GraphicPack2::LoadPatchFiles() // order of loading patches: // 1) Load Cemu-style patches (patch_.asm), stop here if at least one patch file exists // 2) Load Cemuhook patches.txt - - // update: As of 1.20.2b Cemu always takes over patching since Cemuhook patching broke due to other internal changes (memory allocation changed and some reordering on when graphic packs get loaded) if (LoadCemuPatches()) return; // exit if at least one Cemu style patch file was found // fall back to Cemuhook patches.txt to guarantee backward compatibility - fs::path path(m_filename); + fs::path path(_utf8ToPath(m_filename)); path.remove_filename(); path.append("patches.txt"); - - FileStream* patchFile = FileStream::openFile(path.generic_wstring().c_str()); - + FileStream* patchFile = FileStream::openFile2(path); if (patchFile == nullptr) return; - // read file std::vector fileData; patchFile->extract(fileData); delete patchFile; - cemu_assert_debug(list_patchGroups.empty()); - // parse MemStreamReader patchesStream(fileData.data(), (sint32)fileData.size()); ParseCemuhookPatchesTxtInternal(patchesStream); diff --git a/src/Cafe/GraphicPack/GraphicPack2PatchesParser.cpp b/src/Cafe/GraphicPack/GraphicPack2PatchesParser.cpp index ce04bf93..d011a10b 100644 --- a/src/Cafe/GraphicPack/GraphicPack2PatchesParser.cpp +++ b/src/Cafe/GraphicPack/GraphicPack2PatchesParser.cpp @@ -25,7 +25,7 @@ sint32 GraphicPack2::GetLengthWithoutComment(const char* str, size_t length) void GraphicPack2::LogPatchesSyntaxError(sint32 lineNumber, std::string_view errorMsg) { - cemuLog_log(LogType::Force, fmt::format(L"Syntax error while parsing patch for graphic pack '{}':", this->GetFilename())); + cemuLog_log(LogType::Force, "Syntax error while parsing patch for graphic pack '{}':", this->GetFilename()); if(lineNumber >= 0) cemuLog_log(LogType::Force, fmt::format("Line {0}: {1}", lineNumber, errorMsg)); else diff --git a/src/Cafe/HW/Espresso/Debugger/Debugger.cpp b/src/Cafe/HW/Espresso/Debugger/Debugger.cpp index 0883c436..6c15f26e 100644 --- a/src/Cafe/HW/Espresso/Debugger/Debugger.cpp +++ b/src/Cafe/HW/Espresso/Debugger/Debugger.cpp @@ -511,9 +511,9 @@ void debugger_enterTW(PPCInterpreter_t* hCPU) { if (bp->bpType == DEBUGGER_BP_T_LOGGING && bp->enabled) { - std::wstring logName = !bp->comment.empty() ? L"Breakpoint '"+bp->comment+L"'" : fmt::format(L"Breakpoint at 0x{:08X} (no comment)", bp->address); - std::wstring logContext = fmt::format(L"Thread: {:08x} LR: 0x{:08x}", coreinitThread_getCurrentThreadMPTRDepr(hCPU), hCPU->spr.LR, cemuLog_advancedPPCLoggingEnabled() ? L" Stack Trace:" : L""); - cemuLog_log(LogType::Force, L"[Debugger] {} was executed! {}", logName, logContext); + std::string logName = !bp->comment.empty() ? "Breakpoint '"+boost::nowide::narrow(bp->comment)+"'" : fmt::format("Breakpoint at 0x{:08X} (no comment)", bp->address); + std::string logContext = fmt::format("Thread: {:08x} LR: 0x{:08x}", coreinitThread_getCurrentThreadMPTRDepr(hCPU), hCPU->spr.LR, cemuLog_advancedPPCLoggingEnabled() ? " Stack Trace:" : ""); + cemuLog_log(LogType::Force, "[Debugger] {} was executed! {}", logName, logContext); if (cemuLog_advancedPPCLoggingEnabled()) DebugLogStackTrace(coreinitThread_getCurrentThreadDepr(hCPU), hCPU->gpr[1]); break; diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp index 4061be33..e4c87d62 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/RendererShaderVk.cpp @@ -440,7 +440,7 @@ void RendererShaderVk::ShaderCacheLoading_begin(uint64 cacheTitleId) } uint32 spirvCacheMagic = GeneratePrecompiledCacheId(); const std::string cacheFilename = fmt::format("{:016x}_spirv.bin", cacheTitleId); - const std::wstring cachePath = ActiveSettings::GetCachePath("shaderCache/precompiled/{}", cacheFilename).generic_wstring(); + const fs::path cachePath = ActiveSettings::GetCachePath("shaderCache/precompiled/{}", cacheFilename); s_spirvCache = FileCache::Open(cachePath, true, spirvCacheMagic); if (s_spirvCache == nullptr) cemuLog_log(LogType::Force, "Unable to open SPIR-V cache {}", cacheFilename); diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanPipelineStableCache.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanPipelineStableCache.cpp index 74247b9a..0ee9f023 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanPipelineStableCache.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanPipelineStableCache.cpp @@ -59,10 +59,10 @@ uint32 VulkanPipelineStableCache::BeginLoading(uint64 cacheTitleId) // open cache file or create it cemu_assert_debug(s_cache == nullptr); - s_cache = FileCache::Open(pathCacheFile.generic_wstring(), true, LatteShaderCache_getPipelineCacheExtraVersion(cacheTitleId)); + s_cache = FileCache::Open(pathCacheFile, true, LatteShaderCache_getPipelineCacheExtraVersion(cacheTitleId)); if (!s_cache) { - cemuLog_log(LogType::Force, "Failed to open or create Vulkan pipeline cache file: {}", pathCacheFile.generic_string()); + cemuLog_log(LogType::Force, "Failed to open or create Vulkan pipeline cache file: {}", _pathToUtf8(pathCacheFile)); return 0; } else diff --git a/src/Cafe/IOSU/legacy/iosu_act.cpp b/src/Cafe/IOSU/legacy/iosu_act.cpp index 919b7b0f..e7418e8f 100644 --- a/src/Cafe/IOSU/legacy/iosu_act.cpp +++ b/src/Cafe/IOSU/legacy/iosu_act.cpp @@ -113,7 +113,7 @@ void iosuAct_loadAccounts() // } //} - cemuLog_log(LogType::Force, L"IOSU_ACT: using account {} in first slot", first_acc.GetMiiName()); + cemuLog_log(LogType::Force, "IOSU_ACT: using account {} in first slot", boost::nowide::narrow(first_acc.GetMiiName())); _actAccountDataInitialized = true; } diff --git a/src/Cafe/IOSU/legacy/iosu_crypto.cpp b/src/Cafe/IOSU/legacy/iosu_crypto.cpp index 9d7ab875..80eb2f01 100644 --- a/src/Cafe/IOSU/legacy/iosu_crypto.cpp +++ b/src/Cafe/IOSU/legacy/iosu_crypto.cpp @@ -615,10 +615,10 @@ void iosuCrypto_init() iosuCrypto_loadSSLCertificates(); } -bool iosuCrypto_checkRequirementMLCFile(std::string_view mlcSubpath, std::wstring& additionalErrorInfo_filePath) +bool iosuCrypto_checkRequirementMLCFile(std::string_view mlcSubpath, std::string& additionalErrorInfo_filePath) { const auto path = ActiveSettings::GetMlcPath(mlcSubpath); - additionalErrorInfo_filePath = path.generic_wstring(); + additionalErrorInfo_filePath = _pathToUtf8(path); sint32 fileDataSize = 0; auto fileData = FileStream::LoadIntoMemory(path); if (!fileData) @@ -626,7 +626,7 @@ bool iosuCrypto_checkRequirementMLCFile(std::string_view mlcSubpath, std::wstrin return true; } -sint32 iosuCrypt_checkRequirementsForOnlineMode(std::wstring& additionalErrorInfo) +sint32 iosuCrypt_checkRequirementsForOnlineMode(std::string& additionalErrorInfo) { std::error_code ec; // check if otp.bin is present diff --git a/src/Cafe/IOSU/legacy/iosu_crypto.h b/src/Cafe/IOSU/legacy/iosu_crypto.h index bf3d7e2f..9f1429c7 100644 --- a/src/Cafe/IOSU/legacy/iosu_crypto.h +++ b/src/Cafe/IOSU/legacy/iosu_crypto.h @@ -74,7 +74,7 @@ enum IOS_CRYPTO_ONLINE_REQ_MISSING_FILE }; -sint32 iosuCrypt_checkRequirementsForOnlineMode(std::wstring& additionalErrorInfo); +sint32 iosuCrypt_checkRequirementsForOnlineMode(std::string& additionalErrorInfo); void iosuCrypto_readOtpData(void* output, sint32 wordIndex, sint32 size); std::vector iosuCrypt_getCertificateKeys(); diff --git a/src/Cafe/OS/libs/nn_nfp/nn_nfp.cpp b/src/Cafe/OS/libs/nn_nfp/nn_nfp.cpp index 27a858c1..ad2ea203 100644 --- a/src/Cafe/OS/libs/nn_nfp/nn_nfp.cpp +++ b/src/Cafe/OS/libs/nn_nfp/nn_nfp.cpp @@ -180,7 +180,7 @@ struct bool hasOpenApplicationArea; // set to true if application area was opened or created // currently active Amiibo bool hasActiveAmiibo; - std::wstring amiiboPath; + fs::path amiiboPath; bool hasInvalidHMAC; uint32 amiiboTouchTime; AmiiboRawNFCData amiiboNFCData; // raw data @@ -188,7 +188,6 @@ struct AmiiboProcessedData amiiboProcessedData; }nfp_data = { 0 }; -bool nnNfp_touchNfcTagFromFile(const wchar_t* filePath, uint32* nfcError); bool nnNfp_writeCurrentAmiibo(); #include "AmiiboCrypto.h" @@ -770,7 +769,7 @@ void nnNfp_unloadAmiibo() nnNfpUnlock(); } -bool nnNfp_touchNfcTagFromFile(const wchar_t* filePath, uint32* nfcError) +bool nnNfp_touchNfcTagFromFile(const fs::path& filePath, uint32* nfcError) { AmiiboRawNFCData rawData = { 0 }; auto nfcData = FileStream::LoadIntoMemory(filePath); @@ -847,11 +846,11 @@ bool nnNfp_touchNfcTagFromFile(const wchar_t* filePath, uint32* nfcError) memcpy(&nfp_data.amiiboNFCData, &rawData, sizeof(AmiiboRawNFCData)); // decrypt amiibo amiiboDecrypt(); - nfp_data.amiiboPath = std::wstring(filePath); + nfp_data.amiiboPath = filePath; nfp_data.hasActiveAmiibo = true; if (nfp_data.activateEvent) { - coreinit::OSEvent* osEvent = (coreinit::OSEvent*)memory_getPointerFromVirtualOffset(nfp_data.activateEvent); + MEMPTR osEvent(nfp_data.activateEvent); coreinit::OSSignalEvent(osEvent); } nfp_data.amiiboTouchTime = GetTickCount(); diff --git a/src/Cafe/OS/libs/nn_nfp/nn_nfp.h b/src/Cafe/OS/libs/nn_nfp/nn_nfp.h index 793b3bc3..e8a1c55f 100644 --- a/src/Cafe/OS/libs/nn_nfp/nn_nfp.h +++ b/src/Cafe/OS/libs/nn_nfp/nn_nfp.h @@ -8,7 +8,7 @@ namespace nn::nfp void nnNfp_load(); void nnNfp_update(); -bool nnNfp_touchNfcTagFromFile(const wchar_t* filePath, uint32* nfcError); +bool nnNfp_touchNfcTagFromFile(const fs::path& filePath, uint32* nfcError); #define NFP_STATE_NONE (0) #define NFP_STATE_INIT (1) diff --git a/src/Cemu/Logging/CemuLogging.cpp b/src/Cemu/Logging/CemuLogging.cpp index ac228530..f8ce7265 100644 --- a/src/Cemu/Logging/CemuLogging.cpp +++ b/src/Cemu/Logging/CemuLogging.cpp @@ -157,14 +157,6 @@ bool cemuLog_log(LogType type, std::u8string_view text) return cemuLog_log(type, s); } -bool cemuLog_log(LogType type, std::wstring_view text) -{ - if (!cemuLog_isLoggingEnabled(type)) - return false; - - return cemuLog_log(type, boost::nowide::narrow(text.data(), text.size())); -} - void cemuLog_waitForFlush() { cemuLog_createLogFile(false); diff --git a/src/Cemu/Logging/CemuLogging.h b/src/Cemu/Logging/CemuLogging.h index e6599c5a..8983c847 100644 --- a/src/Cemu/Logging/CemuLogging.h +++ b/src/Cemu/Logging/CemuLogging.h @@ -68,7 +68,6 @@ inline bool cemuLog_isLoggingEnabled(LogType type) bool cemuLog_log(LogType type, std::string_view text); bool cemuLog_log(LogType type, std::u8string_view text); -bool cemuLog_log(LogType type, std::wstring_view text); void cemuLog_waitForFlush(); // wait until all log lines are written template diff --git a/src/Cemu/Tools/DownloadManager/DownloadManager.cpp b/src/Cemu/Tools/DownloadManager/DownloadManager.cpp index ec39b928..09093792 100644 --- a/src/Cemu/Tools/DownloadManager/DownloadManager.cpp +++ b/src/Cemu/Tools/DownloadManager/DownloadManager.cpp @@ -1541,7 +1541,7 @@ void DownloadManager::runManager() auto cacheFilePath = ActiveSettings::GetMlcPath("usr/save/system/nim/nup/"); fs::create_directories(cacheFilePath); cacheFilePath /= "cemu_cache.dat"; - s_nupFileCache = FileCache::Open(cacheFilePath.generic_wstring(), true); + s_nupFileCache = FileCache::Open(cacheFilePath, true); // launch worker thread std::thread t(&DownloadManager::threadFunc, this); t.detach(); diff --git a/src/Common/unix/FileStream_unix.cpp b/src/Common/unix/FileStream_unix.cpp index c65a3219..2dba17b7 100644 --- a/src/Common/unix/FileStream_unix.cpp +++ b/src/Common/unix/FileStream_unix.cpp @@ -33,7 +33,6 @@ FileStream* FileStream::openFile(const wchar_t* path, bool allowWrite) FileStream* FileStream::openFile2(const fs::path& path, bool allowWrite) { - //return openFile(path.generic_wstring().c_str(), allowWrite); FileStream* fs = new FileStream(path, true, allowWrite); if (fs->m_isValid) return fs; diff --git a/src/config/ActiveSettings.cpp b/src/config/ActiveSettings.cpp index af7f521e..2049bd65 100644 --- a/src/config/ActiveSettings.cpp +++ b/src/config/ActiveSettings.cpp @@ -40,7 +40,7 @@ ActiveSettings::LoadOnce( g_config.SetFilename(GetConfigPath("settings.xml").generic_wstring()); g_config.Load(); LaunchSettings::ChangeNetworkServiceURL(GetConfig().account.active_service); - std::wstring additionalErrorInfo; + std::string additionalErrorInfo; s_has_required_online_files = iosuCrypt_checkRequirementsForOnlineMode(additionalErrorInfo) == IOS_CRYPTO_ONLINE_REQ_OK; return failed_write_access; } diff --git a/src/config/CemuConfig.cpp b/src/config/CemuConfig.cpp index 220a2295..1801759a 100644 --- a/src/config/CemuConfig.cpp +++ b/src/config/CemuConfig.cpp @@ -110,7 +110,7 @@ void CemuConfig::Load(XMLConfigParser& parser) try { - recent_launch_files.emplace_back(boost::nowide::widen(path)); + recent_launch_files.emplace_back(path); } catch (const std::exception&) { @@ -125,10 +125,9 @@ void CemuConfig::Load(XMLConfigParser& parser) const std::string path = element.value(""); if (path.empty()) continue; - try { - recent_nfc_files.emplace_back(boost::nowide::widen(path)); + recent_nfc_files.emplace_back(path); } catch (const std::exception&) { @@ -143,10 +142,9 @@ void CemuConfig::Load(XMLConfigParser& parser) const std::string path = element.value(""); if (path.empty()) continue; - try { - game_paths.emplace_back(boost::nowide::widen(path)); + game_paths.emplace_back(path); } catch (const std::exception&) { @@ -402,20 +400,20 @@ void CemuConfig::Save(XMLConfigParser& parser) auto launch_files_parser = config.set("RecentLaunchFiles"); for (const auto& entry : recent_launch_files) { - launch_files_parser.set("Entry", boost::nowide::narrow(entry).c_str()); + launch_files_parser.set("Entry", entry.c_str()); } auto nfc_files_parser = config.set("RecentNFCFiles"); for (const auto& entry : recent_nfc_files) { - nfc_files_parser.set("Entry", boost::nowide::narrow(entry).c_str()); + nfc_files_parser.set("Entry", entry.c_str()); } // game paths auto game_path_parser = config.set("GamePaths"); for (const auto& entry : game_paths) { - game_path_parser.set("Entry", boost::nowide::narrow(entry).c_str()); + game_path_parser.set("Entry", entry.c_str()); } // game list cache @@ -593,22 +591,18 @@ void CemuConfig::SetGameListCustomName(uint64 titleId, std::string customName) gameEntry->custom_name = std::move(customName); } -void CemuConfig::AddRecentlyLaunchedFile(std::wstring_view file) +void CemuConfig::AddRecentlyLaunchedFile(std::string_view file) { - // insert into front - recent_launch_files.insert(recent_launch_files.begin(), std::wstring{ file }); + recent_launch_files.insert(recent_launch_files.begin(), std::string(file)); RemoveDuplicatesKeepOrder(recent_launch_files); - // keep maximum of entries while(recent_launch_files.size() > kMaxRecentEntries) recent_launch_files.pop_back(); } -void CemuConfig::AddRecentNfcFile(std::wstring_view file) +void CemuConfig::AddRecentNfcFile(std::string_view file) { - // insert into front - recent_nfc_files.insert(recent_nfc_files.begin(), std::wstring{ file }); + recent_nfc_files.insert(recent_nfc_files.begin(), std::string(file)); RemoveDuplicatesKeepOrder(recent_nfc_files); - // keep maximum of entries while (recent_nfc_files.size() > kMaxRecentEntries) recent_nfc_files.pop_back(); } diff --git a/src/config/CemuConfig.h b/src/config/CemuConfig.h index ea6c3f2c..eb552fce 100644 --- a/src/config/CemuConfig.h +++ b/src/config/CemuConfig.h @@ -379,7 +379,7 @@ struct CemuConfig ConfigValue disable_screensaver{DISABLE_SCREENSAVER_DEFAULT}; #undef DISABLE_SCREENSAVER_DEFAULT - std::vector game_paths; + std::vector game_paths; std::mutex game_cache_entries_mutex; std::vector game_cache_entries; @@ -399,8 +399,8 @@ struct CemuConfig // max 15 entries static constexpr size_t kMaxRecentEntries = 15; - std::vector recent_launch_files; - std::vector recent_nfc_files; + std::vector recent_launch_files; + std::vector recent_nfc_files; Vector2i window_position{-1,-1}; Vector2i window_size{ -1,-1 }; @@ -499,8 +499,8 @@ struct CemuConfig void Load(XMLConfigParser& parser); void Save(XMLConfigParser& parser); - void AddRecentlyLaunchedFile(std::wstring_view file); - void AddRecentNfcFile(std::wstring_view file); + void AddRecentlyLaunchedFile(std::string_view file); + void AddRecentNfcFile(std::string_view file); bool IsGameListFavorite(uint64 titleId); void SetGameListFavorite(uint64 titleId, bool isFavorite); diff --git a/src/gui/CemuApp.cpp b/src/gui/CemuApp.cpp index 74ef6848..04823ca4 100644 --- a/src/gui/CemuApp.cpp +++ b/src/gui/CemuApp.cpp @@ -198,9 +198,9 @@ void CemuApp::OnAssertFailure(const wxChar* file, int line, const wxChar* func, { cemuLog_createLogFile(false); cemuLog_log(LogType::Force, "Encountered wxWidgets assert!"); - cemuLog_log(LogType::Force, fmt::format(L"File: {0} Line: {1}", std::wstring_view(file), line)); - cemuLog_log(LogType::Force, fmt::format(L"Func: {0} Cond: {1}", func, std::wstring_view(cond))); - cemuLog_log(LogType::Force, fmt::format(L"Message: {}", std::wstring_view(msg))); + cemuLog_log(LogType::Force, "File: {0} Line: {1}", wxString(file).utf8_string(), line); + cemuLog_log(LogType::Force, "Func: {0} Cond: {1}", wxString(func).utf8_string(), wxString(cond).utf8_string()); + cemuLog_log(LogType::Force, "Message: {}", wxString(msg).utf8_string()); #if BOOST_OS_WINDOWS DumpThreadStackTrace(); diff --git a/src/gui/GeneralSettings2.cpp b/src/gui/GeneralSettings2.cpp index e069c10a..4dd3f9a3 100644 --- a/src/gui/GeneralSettings2.cpp +++ b/src/gui/GeneralSettings2.cpp @@ -923,7 +923,7 @@ void GeneralSettings2::StoreConfig() config.game_paths.clear(); for (auto& path : m_game_paths->GetStrings()) - config.game_paths.emplace_back(path); + config.game_paths.emplace_back(path.utf8_string()); auto selection = m_language->GetSelection(); if (selection == 0) @@ -1530,7 +1530,7 @@ void GeneralSettings2::ApplyConfig() for (auto& path : config.game_paths) { - m_game_paths->Append(path); + m_game_paths->Append(to_wxString(path)); } const auto app = (CemuApp*)wxTheApp; diff --git a/src/gui/GettingStartedDialog.cpp b/src/gui/GettingStartedDialog.cpp index 69f429b0..91cc3a11 100644 --- a/src/gui/GettingStartedDialog.cpp +++ b/src/gui/GettingStartedDialog.cpp @@ -229,7 +229,7 @@ void GettingStartedDialog::OnClose(wxCloseEvent& event) const auto it = std::find(config.game_paths.cbegin(), config.game_paths.cend(), gamePath); if (it == config.game_paths.cend()) { - config.game_paths.emplace_back(gamePath.generic_wstring()); + config.game_paths.emplace_back(_pathToUtf8(gamePath)); m_game_path_changed = true; } } @@ -248,7 +248,7 @@ void GettingStartedDialog::OnClose(wxCloseEvent& event) CafeTitleList::ClearScanPaths(); for (auto& it : GetConfig().game_paths) - CafeTitleList::AddScanPath(it); + CafeTitleList::AddScanPath(_utf8ToPath(it)); CafeTitleList::Refresh(); } diff --git a/src/gui/GraphicPacksWindow2.cpp b/src/gui/GraphicPacksWindow2.cpp index 2b618e86..13fec49a 100644 --- a/src/gui/GraphicPacksWindow2.cpp +++ b/src/gui/GraphicPacksWindow2.cpp @@ -329,7 +329,7 @@ void GraphicPacksWindow2::SaveStateToConfig() for (const auto& gp : GraphicPack2::GetGraphicPacks()) { - auto filename = MakeRelativePath(ActiveSettings::GetUserDataPath(), gp->GetFilename()).lexically_normal(); + auto filename = MakeRelativePath(ActiveSettings::GetUserDataPath(), _utf8ToPath(gp->GetFilename())).lexically_normal(); if (gp->IsEnabled()) { data.graphic_pack_entries.try_emplace(filename); diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 69159df2..d9c5f4fb 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -248,7 +248,7 @@ public: bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) override { if(!m_window->IsGameLaunched() && filenames.GetCount() == 1) - return m_window->FileLoad(filenames[0].wc_str(), wxLaunchGameEvent::INITIATED_BY::DRAG_AND_DROP); + return m_window->FileLoad(_utf8ToPath(filenames[0].utf8_string()), wxLaunchGameEvent::INITIATED_BY::DRAG_AND_DROP); return false; } @@ -265,11 +265,11 @@ public: { if (!m_window->IsGameLaunched() || filenames.GetCount() != 1) return false; - uint32 nfcError; - if (nnNfp_touchNfcTagFromFile(filenames[0].wc_str(), &nfcError)) + std::string path = filenames[0].utf8_string(); + if (nnNfp_touchNfcTagFromFile(_utf8ToPath(path), &nfcError)) { - GetConfig().AddRecentNfcFile((wchar_t*)filenames[0].wc_str()); + GetConfig().AddRecentNfcFile(path); m_window->UpdateNFCMenu(); return true; } @@ -493,9 +493,8 @@ bool MainWindow::InstallUpdate(const fs::path& metaFilePath) return false; } -bool MainWindow::FileLoad(std::wstring fileName, wxLaunchGameEvent::INITIATED_BY initiatedBy) +bool MainWindow::FileLoad(const fs::path launchPath, wxLaunchGameEvent::INITIATED_BY initiatedBy) { - const fs::path launchPath = fs::path(fileName); TitleInfo launchTitle{ launchPath }; if (launchTitle.IsValid()) { @@ -518,14 +517,14 @@ bool MainWindow::FileLoad(std::wstring fileName, wxLaunchGameEvent::INITIATED_BY else if (r == CafeSystem::STATUS_CODE::UNABLE_TO_MOUNT) { wxString t = _("Unable to mount title.\nMake sure the configured game paths are still valid and refresh the game list.\n\nFile which failed to load:\n"); - t.append(fileName); + t.append(_pathToUtf8(launchPath)); wxMessageBox(t, _("Error"), wxOK | wxCENTRE | wxICON_ERROR); return false; } else if (r != CafeSystem::STATUS_CODE::SUCCESS) { wxString t = _("Failed to launch game."); - t.append(fileName); + t.append(_pathToUtf8(launchPath)); wxMessageBox(t, _("Error"), wxOK | wxCENTRE | wxICON_ERROR); return false; } @@ -542,7 +541,7 @@ bool MainWindow::FileLoad(std::wstring fileName, wxLaunchGameEvent::INITIATED_BY { cemu_assert_debug(false); // todo wxString t = _("Failed to launch executable. Path: "); - t.append(fileName); + t.append(_pathToUtf8(launchPath)); wxMessageBox(t, _("Error"), wxOK | wxCENTRE | wxICON_ERROR); return false; } @@ -550,7 +549,7 @@ bool MainWindow::FileLoad(std::wstring fileName, wxLaunchGameEvent::INITIATED_BY else if (initiatedBy == wxLaunchGameEvent::INITIATED_BY::GAME_LIST) { wxString t = _("Unable to launch title.\nMake sure the configured game paths are still valid and refresh the game list.\n\nPath which failed to load:\n"); - t.append(fileName); + t.append(_pathToUtf8(launchPath)); wxMessageBox(t, _("Error"), wxOK | wxCENTRE | wxICON_ERROR); return false; } @@ -558,7 +557,7 @@ bool MainWindow::FileLoad(std::wstring fileName, wxLaunchGameEvent::INITIATED_BY initiatedBy == wxLaunchGameEvent::INITIATED_BY::COMMAND_LINE) { wxString t = _("Unable to launch game\nPath:\n"); - t.append(fileName); + t.append(_pathToUtf8(launchPath)); if(launchTitle.GetInvalidReason() == TitleInfo::InvalidReason::NO_DISC_KEY) { t.append(_("\n\n")); @@ -575,16 +574,16 @@ bool MainWindow::FileLoad(std::wstring fileName, wxLaunchGameEvent::INITIATED_BY else { wxString t = _("Unable to launch game\nPath:\n"); - t.append(fileName); + t.append(_pathToUtf8(launchPath)); wxMessageBox(t, _("Error"), wxOK | wxCENTRE | wxICON_ERROR); return false; } } if(launchTitle.IsValid()) - GetConfig().AddRecentlyLaunchedFile(launchTitle.GetPath().generic_wstring()); + GetConfig().AddRecentlyLaunchedFile(_pathToUtf8(launchTitle.GetPath())); else - GetConfig().AddRecentlyLaunchedFile(fileName); + GetConfig().AddRecentlyLaunchedFile(_pathToUtf8(launchPath)); wxWindowUpdateLocker lock(this); @@ -640,7 +639,7 @@ void MainWindow::OnLaunchFromFile(wxLaunchGameEvent& event) { if (event.GetPath().empty()) return; - FileLoad(event.GetPath().generic_wstring(), event.GetInitiatedBy()); + FileLoad(event.GetPath(), event.GetInitiatedBy()); } void MainWindow::OnFileMenu(wxCommandEvent& event) @@ -669,7 +668,7 @@ void MainWindow::OnFileMenu(wxCommandEvent& event) return; const wxString wxStrFilePath = openFileDialog.GetPath(); - FileLoad(wxStrFilePath.wc_str(), wxLaunchGameEvent::INITIATED_BY::MENU); + FileLoad(_utf8ToPath(wxStrFilePath.utf8_string()), wxLaunchGameEvent::INITIATED_BY::MENU); } else if (menuId >= MAINFRAME_MENU_ID_FILE_RECENT_0 && menuId <= MAINFRAME_MENU_ID_FILE_RECENT_LAST) { @@ -749,7 +748,7 @@ void MainWindow::OnNFCMenu(wxCommandEvent& event) return; wxString wxStrFilePath = openFileDialog.GetPath(); uint32 nfcError; - if (nnNfp_touchNfcTagFromFile(wxStrFilePath.wc_str(), &nfcError) == false) + if (nnNfp_touchNfcTagFromFile(_utf8ToPath(wxStrFilePath.utf8_string()), &nfcError) == false) { if (nfcError == NFC_ERROR_NO_ACCESS) wxMessageBox(_("Cannot open file")); @@ -758,7 +757,7 @@ void MainWindow::OnNFCMenu(wxCommandEvent& event) } else { - GetConfig().AddRecentNfcFile((wchar_t*)wxStrFilePath.wc_str()); + GetConfig().AddRecentNfcFile(wxStrFilePath.utf8_string()); UpdateNFCMenu(); } } @@ -772,7 +771,7 @@ void MainWindow::OnNFCMenu(wxCommandEvent& event) if (!path.empty()) { uint32 nfcError = 0; - if (nnNfp_touchNfcTagFromFile(path.c_str(), &nfcError) == false) + if (nnNfp_touchNfcTagFromFile(_utf8ToPath(path), &nfcError) == false) { if (nfcError == NFC_ERROR_NO_ACCESS) wxMessageBox(_("Cannot open file")); @@ -1766,7 +1765,7 @@ void MainWindow::UpdateNFCMenu() if (recentFileIndex == 0) m_nfcMenuSeparator0 = m_nfcMenu->AppendSeparator(); - m_nfcMenu->Append(MAINFRAME_MENU_ID_NFC_RECENT_0 + i, fmt::format(L"{}. {}", recentFileIndex, entry )); + m_nfcMenu->Append(MAINFRAME_MENU_ID_NFC_RECENT_0 + i, to_wxString(fmt::format("{}. {}", recentFileIndex, entry))); recentFileIndex++; if (recentFileIndex >= 12) @@ -2106,7 +2105,7 @@ void MainWindow::RecreateMenu() if (recentFileIndex == 0) m_fileMenuSeparator0 = m_fileMenu->AppendSeparator(); - m_fileMenu->Append(MAINFRAME_MENU_ID_FILE_RECENT_0 + i, fmt::format(L"{}. {}", recentFileIndex, entry)); + m_fileMenu->Append(MAINFRAME_MENU_ID_FILE_RECENT_0 + i, to_wxString(fmt::format("{}. {}", recentFileIndex, entry))); recentFileIndex++; if (recentFileIndex >= 8) diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index c1762867..1c4b5235 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -65,7 +65,7 @@ public: void UpdateSettingsAfterGameLaunch(); void RestoreSettingsAfterGameExited(); - bool FileLoad(std::wstring fileName, wxLaunchGameEvent::INITIATED_BY initiatedBy); + bool FileLoad(const fs::path launchPath, wxLaunchGameEvent::INITIATED_BY initiatedBy); [[nodiscard]] bool IsGameLaunched() const { return m_game_launched; } diff --git a/src/gui/components/wxTitleManagerList.cpp b/src/gui/components/wxTitleManagerList.cpp index c65459aa..93f86fdd 100644 --- a/src/gui/components/wxTitleManagerList.cpp +++ b/src/gui/components/wxTitleManagerList.cpp @@ -352,7 +352,7 @@ void wxTitleManagerList::OnConvertToCompressedFormat(uint64 titleId, uint64 righ boost::replace_all(shortName, ":", ""); } // for the default output directory we use the first game path configured by the user - std::wstring defaultDir = L""; + std::string defaultDir = ""; if (!GetConfig().game_paths.empty()) defaultDir = GetConfig().game_paths.front(); // get the short name, which we will use as a suggested default file name