Refactor more wstring instances to utf8-encoded string

This commit is contained in:
Exzap 2023-09-28 02:51:40 +02:00
parent f6c3c96d94
commit abce406ee8
26 changed files with 82 additions and 114 deletions

View File

@ -54,7 +54,7 @@ void GraphicPack2::LoadGraphicPack(fs::path graphicPackPath)
if (versionNum > GP_LEGACY_VERSION) if (versionNum > GP_LEGACY_VERSION)
{ {
GraphicPack2::LoadGraphicPack(rulesPath.generic_wstring(), iniParser); GraphicPack2::LoadGraphicPack(_pathToUtf8(rulesPath), iniParser);
return; 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 try
{ {
@ -216,12 +216,6 @@ void GraphicPack2::WaitUntilReady()
std::this_thread::sleep_for(std::chrono::milliseconds(5)); 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<std::string, GraphicPack2::PresetVar> GraphicPack2::ParsePresetVars(IniParser& rules) const std::unordered_map<std::string, GraphicPack2::PresetVar> GraphicPack2::ParsePresetVars(IniParser& rules) const
{ {
ExpressionParser parser; ExpressionParser parser;
@ -255,7 +249,7 @@ std::unordered_map<std::string, GraphicPack2::PresetVar> GraphicPack2::ParsePres
return vars; return vars;
} }
GraphicPack2::GraphicPack2(std::wstring filename, IniParser& rules) GraphicPack2::GraphicPack2(std::string filename, IniParser& rules)
: m_filename(std::move(filename)) : m_filename(std::move(filename))
{ {
// we're already in [Definition] // we're already in [Definition]
@ -265,7 +259,7 @@ GraphicPack2::GraphicPack2(std::wstring filename, IniParser& rules)
m_version = StringHelpers::ToInt(*option_version, -1); m_version = StringHelpers::ToInt(*option_version, -1);
if (m_version < 0) if (m_version < 0)
{ {
cemuLog_log(LogType::Force, L"{}: Invalid version", m_filename); cemuLog_log(LogType::Force, "{}: Invalid version", m_filename);
throw std::exception(); throw std::exception();
} }
@ -839,7 +833,7 @@ void GraphicPack2::LoadReplacedFiles()
return; return;
m_patchedFilesLoaded = true; m_patchedFilesLoaded = true;
fs::path gfxPackPath(m_filename.c_str()); fs::path gfxPackPath = _utf8ToPath(m_filename);
gfxPackPath = gfxPackPath.remove_filename(); gfxPackPath = gfxPackPath.remove_filename();
// /content/ // /content/
@ -892,14 +886,14 @@ bool GraphicPack2::Activate()
return false; return false;
} }
FileStream* fs_rules = FileStream::openFile2({ m_filename }); FileStream* fs_rules = FileStream::openFile2(_utf8ToPath(m_filename));
if (!fs_rules) if (!fs_rules)
return false; return false;
std::vector<uint8> rulesData; std::vector<uint8> rulesData;
fs_rules->extract(rulesData); fs_rules->extract(rulesData);
delete fs_rules; 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 // load rules
try try
@ -953,7 +947,7 @@ bool GraphicPack2::Activate()
else if (anisotropyValue == 16) else if (anisotropyValue == 16)
rule.overwrite_settings.anistropic_value = 4; rule.overwrite_settings.anistropic_value = 4;
else 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); m_texture_rules.emplace_back(rule);
} }

View File

@ -97,13 +97,12 @@ public:
}; };
using PresetPtr = std::shared_ptr<Preset>; using PresetPtr = std::shared_ptr<Preset>;
GraphicPack2(std::wstring filename); GraphicPack2(std::string filename, IniParser& rules);
GraphicPack2(std::wstring filename, IniParser& rules);
bool IsEnabled() const { return m_enabled; } bool IsEnabled() const { return m_enabled; }
bool IsActivated() const { return m_activated; } bool IsActivated() const { return m_activated; }
sint32 GetVersion() const { return m_version; } 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); } const fs::path GetFilename2() const { return fs::path(m_filename); }
bool RequiresRestart(bool changeEnableState, bool changePreset); bool RequiresRestart(bool changeEnableState, bool changePreset);
bool Reload(); bool Reload();
@ -165,7 +164,7 @@ public:
static const std::vector<std::shared_ptr<GraphicPack2>>& GetGraphicPacks() { return s_graphic_packs; } static const std::vector<std::shared_ptr<GraphicPack2>>& GetGraphicPacks() { return s_graphic_packs; }
static const std::vector<std::shared_ptr<GraphicPack2>>& GetActiveGraphicPacks() { return s_active_graphic_packs; } static const std::vector<std::shared_ptr<GraphicPack2>>& GetActiveGraphicPacks() { return s_active_graphic_packs; }
static void LoadGraphicPack(fs::path graphicPackPath); 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<GraphicPack2>& graphic_pack); static bool ActivateGraphicPack(const std::shared_ptr<GraphicPack2>& graphic_pack);
static bool DeactivateGraphicPack(const std::shared_ptr<GraphicPack2>& graphic_pack); static bool DeactivateGraphicPack(const std::shared_ptr<GraphicPack2>& graphic_pack);
static void ClearGraphicPacks(); static void ClearGraphicPacks();
@ -209,7 +208,7 @@ private:
parser.TryAddConstant(var.first, (TType)var.second.second); parser.TryAddConstant(var.first, (TType)var.second.second);
} }
std::wstring m_filename; std::string m_filename;
sint32 m_version; sint32 m_version;
std::string m_name; std::string m_name;

View File

@ -83,7 +83,7 @@ bool GraphicPack2::LoadCemuPatches()
}; };
bool foundPatches = false; bool foundPatches = false;
fs::path path(m_filename); fs::path path(_utf8ToPath(m_filename));
path.remove_filename(); path.remove_filename();
for (auto& p : fs::directory_iterator(path)) for (auto& p : fs::directory_iterator(path))
{ {
@ -91,10 +91,10 @@ bool GraphicPack2::LoadCemuPatches()
if (fs::is_regular_file(p.status()) && path.has_filename()) if (fs::is_regular_file(p.status()) && path.has_filename())
{ {
// check if filename matches // check if filename matches
std::wstring filename = path.filename().generic_wstring(); std::string filename = _pathToUtf8(path.filename());
if (boost::istarts_with(filename, L"patch_") && boost::iends_with(filename, L".asm")) 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) if (patchFile)
{ {
// read file // read file
@ -126,27 +126,20 @@ void GraphicPack2::LoadPatchFiles()
// order of loading patches: // order of loading patches:
// 1) Load Cemu-style patches (patch_<name>.asm), stop here if at least one patch file exists // 1) Load Cemu-style patches (patch_<name>.asm), stop here if at least one patch file exists
// 2) Load Cemuhook patches.txt // 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()) if (LoadCemuPatches())
return; // exit if at least one Cemu style patch file was found return; // exit if at least one Cemu style patch file was found
// fall back to Cemuhook patches.txt to guarantee backward compatibility // 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.remove_filename();
path.append("patches.txt"); path.append("patches.txt");
FileStream* patchFile = FileStream::openFile2(path);
FileStream* patchFile = FileStream::openFile(path.generic_wstring().c_str());
if (patchFile == nullptr) if (patchFile == nullptr)
return; return;
// read file // read file
std::vector<uint8> fileData; std::vector<uint8> fileData;
patchFile->extract(fileData); patchFile->extract(fileData);
delete patchFile; delete patchFile;
cemu_assert_debug(list_patchGroups.empty()); cemu_assert_debug(list_patchGroups.empty());
// parse // parse
MemStreamReader patchesStream(fileData.data(), (sint32)fileData.size()); MemStreamReader patchesStream(fileData.data(), (sint32)fileData.size());
ParseCemuhookPatchesTxtInternal(patchesStream); ParseCemuhookPatchesTxtInternal(patchesStream);

View File

@ -25,7 +25,7 @@ sint32 GraphicPack2::GetLengthWithoutComment(const char* str, size_t length)
void GraphicPack2::LogPatchesSyntaxError(sint32 lineNumber, std::string_view errorMsg) 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) if(lineNumber >= 0)
cemuLog_log(LogType::Force, fmt::format("Line {0}: {1}", lineNumber, errorMsg)); cemuLog_log(LogType::Force, fmt::format("Line {0}: {1}", lineNumber, errorMsg));
else else

View File

@ -511,9 +511,9 @@ void debugger_enterTW(PPCInterpreter_t* hCPU)
{ {
if (bp->bpType == DEBUGGER_BP_T_LOGGING && bp->enabled) 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::string logName = !bp->comment.empty() ? "Breakpoint '"+boost::nowide::narrow(bp->comment)+"'" : fmt::format("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""); std::string logContext = fmt::format("Thread: {:08x} LR: 0x{:08x}", coreinitThread_getCurrentThreadMPTRDepr(hCPU), hCPU->spr.LR, cemuLog_advancedPPCLoggingEnabled() ? " Stack Trace:" : "");
cemuLog_log(LogType::Force, L"[Debugger] {} was executed! {}", logName, logContext); cemuLog_log(LogType::Force, "[Debugger] {} was executed! {}", logName, logContext);
if (cemuLog_advancedPPCLoggingEnabled()) if (cemuLog_advancedPPCLoggingEnabled())
DebugLogStackTrace(coreinitThread_getCurrentThreadDepr(hCPU), hCPU->gpr[1]); DebugLogStackTrace(coreinitThread_getCurrentThreadDepr(hCPU), hCPU->gpr[1]);
break; break;

View File

@ -440,7 +440,7 @@ void RendererShaderVk::ShaderCacheLoading_begin(uint64 cacheTitleId)
} }
uint32 spirvCacheMagic = GeneratePrecompiledCacheId(); uint32 spirvCacheMagic = GeneratePrecompiledCacheId();
const std::string cacheFilename = fmt::format("{:016x}_spirv.bin", cacheTitleId); 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); s_spirvCache = FileCache::Open(cachePath, true, spirvCacheMagic);
if (s_spirvCache == nullptr) if (s_spirvCache == nullptr)
cemuLog_log(LogType::Force, "Unable to open SPIR-V cache {}", cacheFilename); cemuLog_log(LogType::Force, "Unable to open SPIR-V cache {}", cacheFilename);

View File

@ -59,10 +59,10 @@ uint32 VulkanPipelineStableCache::BeginLoading(uint64 cacheTitleId)
// open cache file or create it // open cache file or create it
cemu_assert_debug(s_cache == nullptr); 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) 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; return 0;
} }
else else

View File

@ -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; _actAccountDataInitialized = true;
} }

View File

@ -615,10 +615,10 @@ void iosuCrypto_init()
iosuCrypto_loadSSLCertificates(); 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); const auto path = ActiveSettings::GetMlcPath(mlcSubpath);
additionalErrorInfo_filePath = path.generic_wstring(); additionalErrorInfo_filePath = _pathToUtf8(path);
sint32 fileDataSize = 0; sint32 fileDataSize = 0;
auto fileData = FileStream::LoadIntoMemory(path); auto fileData = FileStream::LoadIntoMemory(path);
if (!fileData) if (!fileData)
@ -626,7 +626,7 @@ bool iosuCrypto_checkRequirementMLCFile(std::string_view mlcSubpath, std::wstrin
return true; return true;
} }
sint32 iosuCrypt_checkRequirementsForOnlineMode(std::wstring& additionalErrorInfo) sint32 iosuCrypt_checkRequirementsForOnlineMode(std::string& additionalErrorInfo)
{ {
std::error_code ec; std::error_code ec;
// check if otp.bin is present // check if otp.bin is present

View File

@ -74,7 +74,7 @@ enum
IOS_CRYPTO_ONLINE_REQ_MISSING_FILE 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); void iosuCrypto_readOtpData(void* output, sint32 wordIndex, sint32 size);
std::vector<const wchar_t*> iosuCrypt_getCertificateKeys(); std::vector<const wchar_t*> iosuCrypt_getCertificateKeys();

View File

@ -180,7 +180,7 @@ struct
bool hasOpenApplicationArea; // set to true if application area was opened or created bool hasOpenApplicationArea; // set to true if application area was opened or created
// currently active Amiibo // currently active Amiibo
bool hasActiveAmiibo; bool hasActiveAmiibo;
std::wstring amiiboPath; fs::path amiiboPath;
bool hasInvalidHMAC; bool hasInvalidHMAC;
uint32 amiiboTouchTime; uint32 amiiboTouchTime;
AmiiboRawNFCData amiiboNFCData; // raw data AmiiboRawNFCData amiiboNFCData; // raw data
@ -188,7 +188,6 @@ struct
AmiiboProcessedData amiiboProcessedData; AmiiboProcessedData amiiboProcessedData;
}nfp_data = { 0 }; }nfp_data = { 0 };
bool nnNfp_touchNfcTagFromFile(const wchar_t* filePath, uint32* nfcError);
bool nnNfp_writeCurrentAmiibo(); bool nnNfp_writeCurrentAmiibo();
#include "AmiiboCrypto.h" #include "AmiiboCrypto.h"
@ -770,7 +769,7 @@ void nnNfp_unloadAmiibo()
nnNfpUnlock(); nnNfpUnlock();
} }
bool nnNfp_touchNfcTagFromFile(const wchar_t* filePath, uint32* nfcError) bool nnNfp_touchNfcTagFromFile(const fs::path& filePath, uint32* nfcError)
{ {
AmiiboRawNFCData rawData = { 0 }; AmiiboRawNFCData rawData = { 0 };
auto nfcData = FileStream::LoadIntoMemory(filePath); 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)); memcpy(&nfp_data.amiiboNFCData, &rawData, sizeof(AmiiboRawNFCData));
// decrypt amiibo // decrypt amiibo
amiiboDecrypt(); amiiboDecrypt();
nfp_data.amiiboPath = std::wstring(filePath); nfp_data.amiiboPath = filePath;
nfp_data.hasActiveAmiibo = true; nfp_data.hasActiveAmiibo = true;
if (nfp_data.activateEvent) if (nfp_data.activateEvent)
{ {
coreinit::OSEvent* osEvent = (coreinit::OSEvent*)memory_getPointerFromVirtualOffset(nfp_data.activateEvent); MEMPTR<coreinit::OSEvent> osEvent(nfp_data.activateEvent);
coreinit::OSSignalEvent(osEvent); coreinit::OSSignalEvent(osEvent);
} }
nfp_data.amiiboTouchTime = GetTickCount(); nfp_data.amiiboTouchTime = GetTickCount();

View File

@ -8,7 +8,7 @@ namespace nn::nfp
void nnNfp_load(); void nnNfp_load();
void nnNfp_update(); 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_NONE (0)
#define NFP_STATE_INIT (1) #define NFP_STATE_INIT (1)

View File

@ -157,14 +157,6 @@ bool cemuLog_log(LogType type, std::u8string_view text)
return cemuLog_log(type, s); 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() void cemuLog_waitForFlush()
{ {
cemuLog_createLogFile(false); cemuLog_createLogFile(false);

View File

@ -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::string_view text);
bool cemuLog_log(LogType type, std::u8string_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 void cemuLog_waitForFlush(); // wait until all log lines are written
template <typename T> template <typename T>

View File

@ -1541,7 +1541,7 @@ void DownloadManager::runManager()
auto cacheFilePath = ActiveSettings::GetMlcPath("usr/save/system/nim/nup/"); auto cacheFilePath = ActiveSettings::GetMlcPath("usr/save/system/nim/nup/");
fs::create_directories(cacheFilePath); fs::create_directories(cacheFilePath);
cacheFilePath /= "cemu_cache.dat"; cacheFilePath /= "cemu_cache.dat";
s_nupFileCache = FileCache::Open(cacheFilePath.generic_wstring(), true); s_nupFileCache = FileCache::Open(cacheFilePath, true);
// launch worker thread // launch worker thread
std::thread t(&DownloadManager::threadFunc, this); std::thread t(&DownloadManager::threadFunc, this);
t.detach(); t.detach();

View File

@ -33,7 +33,6 @@ FileStream* FileStream::openFile(const wchar_t* path, bool allowWrite)
FileStream* FileStream::openFile2(const fs::path& 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); FileStream* fs = new FileStream(path, true, allowWrite);
if (fs->m_isValid) if (fs->m_isValid)
return fs; return fs;

View File

@ -40,7 +40,7 @@ ActiveSettings::LoadOnce(
g_config.SetFilename(GetConfigPath("settings.xml").generic_wstring()); g_config.SetFilename(GetConfigPath("settings.xml").generic_wstring());
g_config.Load(); g_config.Load();
LaunchSettings::ChangeNetworkServiceURL(GetConfig().account.active_service); 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; s_has_required_online_files = iosuCrypt_checkRequirementsForOnlineMode(additionalErrorInfo) == IOS_CRYPTO_ONLINE_REQ_OK;
return failed_write_access; return failed_write_access;
} }

View File

@ -110,7 +110,7 @@ void CemuConfig::Load(XMLConfigParser& parser)
try try
{ {
recent_launch_files.emplace_back(boost::nowide::widen(path)); recent_launch_files.emplace_back(path);
} }
catch (const std::exception&) catch (const std::exception&)
{ {
@ -125,10 +125,9 @@ void CemuConfig::Load(XMLConfigParser& parser)
const std::string path = element.value(""); const std::string path = element.value("");
if (path.empty()) if (path.empty())
continue; continue;
try try
{ {
recent_nfc_files.emplace_back(boost::nowide::widen(path)); recent_nfc_files.emplace_back(path);
} }
catch (const std::exception&) catch (const std::exception&)
{ {
@ -143,10 +142,9 @@ void CemuConfig::Load(XMLConfigParser& parser)
const std::string path = element.value(""); const std::string path = element.value("");
if (path.empty()) if (path.empty())
continue; continue;
try try
{ {
game_paths.emplace_back(boost::nowide::widen(path)); game_paths.emplace_back(path);
} }
catch (const std::exception&) catch (const std::exception&)
{ {
@ -402,20 +400,20 @@ void CemuConfig::Save(XMLConfigParser& parser)
auto launch_files_parser = config.set("RecentLaunchFiles"); auto launch_files_parser = config.set("RecentLaunchFiles");
for (const auto& entry : recent_launch_files) 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"); auto nfc_files_parser = config.set("RecentNFCFiles");
for (const auto& entry : recent_nfc_files) 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 // game paths
auto game_path_parser = config.set("GamePaths"); auto game_path_parser = config.set("GamePaths");
for (const auto& entry : game_paths) 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 // game list cache
@ -593,22 +591,18 @@ void CemuConfig::SetGameListCustomName(uint64 titleId, std::string customName)
gameEntry->custom_name = std::move(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::string(file));
recent_launch_files.insert(recent_launch_files.begin(), std::wstring{ file });
RemoveDuplicatesKeepOrder(recent_launch_files); RemoveDuplicatesKeepOrder(recent_launch_files);
// keep maximum of entries
while(recent_launch_files.size() > kMaxRecentEntries) while(recent_launch_files.size() > kMaxRecentEntries)
recent_launch_files.pop_back(); 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::string(file));
recent_nfc_files.insert(recent_nfc_files.begin(), std::wstring{ file });
RemoveDuplicatesKeepOrder(recent_nfc_files); RemoveDuplicatesKeepOrder(recent_nfc_files);
// keep maximum of entries
while (recent_nfc_files.size() > kMaxRecentEntries) while (recent_nfc_files.size() > kMaxRecentEntries)
recent_nfc_files.pop_back(); recent_nfc_files.pop_back();
} }

View File

@ -379,7 +379,7 @@ struct CemuConfig
ConfigValue<bool> disable_screensaver{DISABLE_SCREENSAVER_DEFAULT}; ConfigValue<bool> disable_screensaver{DISABLE_SCREENSAVER_DEFAULT};
#undef DISABLE_SCREENSAVER_DEFAULT #undef DISABLE_SCREENSAVER_DEFAULT
std::vector<std::wstring> game_paths; std::vector<std::string> game_paths;
std::mutex game_cache_entries_mutex; std::mutex game_cache_entries_mutex;
std::vector<GameEntry> game_cache_entries; std::vector<GameEntry> game_cache_entries;
@ -399,8 +399,8 @@ struct CemuConfig
// max 15 entries // max 15 entries
static constexpr size_t kMaxRecentEntries = 15; static constexpr size_t kMaxRecentEntries = 15;
std::vector<std::wstring> recent_launch_files; std::vector<std::string> recent_launch_files;
std::vector<std::wstring> recent_nfc_files; std::vector<std::string> recent_nfc_files;
Vector2i window_position{-1,-1}; Vector2i window_position{-1,-1};
Vector2i window_size{ -1,-1 }; Vector2i window_size{ -1,-1 };
@ -499,8 +499,8 @@ struct CemuConfig
void Load(XMLConfigParser& parser); void Load(XMLConfigParser& parser);
void Save(XMLConfigParser& parser); void Save(XMLConfigParser& parser);
void AddRecentlyLaunchedFile(std::wstring_view file); void AddRecentlyLaunchedFile(std::string_view file);
void AddRecentNfcFile(std::wstring_view file); void AddRecentNfcFile(std::string_view file);
bool IsGameListFavorite(uint64 titleId); bool IsGameListFavorite(uint64 titleId);
void SetGameListFavorite(uint64 titleId, bool isFavorite); void SetGameListFavorite(uint64 titleId, bool isFavorite);

View File

@ -198,9 +198,9 @@ void CemuApp::OnAssertFailure(const wxChar* file, int line, const wxChar* func,
{ {
cemuLog_createLogFile(false); cemuLog_createLogFile(false);
cemuLog_log(LogType::Force, "Encountered wxWidgets assert!"); 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, "File: {0} Line: {1}", wxString(file).utf8_string(), line);
cemuLog_log(LogType::Force, fmt::format(L"Func: {0} Cond: {1}", func, std::wstring_view(cond))); cemuLog_log(LogType::Force, "Func: {0} Cond: {1}", wxString(func).utf8_string(), wxString(cond).utf8_string());
cemuLog_log(LogType::Force, fmt::format(L"Message: {}", std::wstring_view(msg))); cemuLog_log(LogType::Force, "Message: {}", wxString(msg).utf8_string());
#if BOOST_OS_WINDOWS #if BOOST_OS_WINDOWS
DumpThreadStackTrace(); DumpThreadStackTrace();

View File

@ -923,7 +923,7 @@ void GeneralSettings2::StoreConfig()
config.game_paths.clear(); config.game_paths.clear();
for (auto& path : m_game_paths->GetStrings()) 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(); auto selection = m_language->GetSelection();
if (selection == 0) if (selection == 0)
@ -1530,7 +1530,7 @@ void GeneralSettings2::ApplyConfig()
for (auto& path : config.game_paths) for (auto& path : config.game_paths)
{ {
m_game_paths->Append(path); m_game_paths->Append(to_wxString(path));
} }
const auto app = (CemuApp*)wxTheApp; const auto app = (CemuApp*)wxTheApp;

View File

@ -229,7 +229,7 @@ void GettingStartedDialog::OnClose(wxCloseEvent& event)
const auto it = std::find(config.game_paths.cbegin(), config.game_paths.cend(), gamePath); const auto it = std::find(config.game_paths.cbegin(), config.game_paths.cend(), gamePath);
if (it == config.game_paths.cend()) 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; m_game_path_changed = true;
} }
} }
@ -248,7 +248,7 @@ void GettingStartedDialog::OnClose(wxCloseEvent& event)
CafeTitleList::ClearScanPaths(); CafeTitleList::ClearScanPaths();
for (auto& it : GetConfig().game_paths) for (auto& it : GetConfig().game_paths)
CafeTitleList::AddScanPath(it); CafeTitleList::AddScanPath(_utf8ToPath(it));
CafeTitleList::Refresh(); CafeTitleList::Refresh();
} }

View File

@ -329,7 +329,7 @@ void GraphicPacksWindow2::SaveStateToConfig()
for (const auto& gp : GraphicPack2::GetGraphicPacks()) 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()) if (gp->IsEnabled())
{ {
data.graphic_pack_entries.try_emplace(filename); data.graphic_pack_entries.try_emplace(filename);

View File

@ -248,7 +248,7 @@ public:
bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) override bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) override
{ {
if(!m_window->IsGameLaunched() && filenames.GetCount() == 1) 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; return false;
} }
@ -265,11 +265,11 @@ public:
{ {
if (!m_window->IsGameLaunched() || filenames.GetCount() != 1) if (!m_window->IsGameLaunched() || filenames.GetCount() != 1)
return false; return false;
uint32 nfcError; 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(); m_window->UpdateNFCMenu();
return true; return true;
} }
@ -493,9 +493,8 @@ bool MainWindow::InstallUpdate(const fs::path& metaFilePath)
return false; 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 }; TitleInfo launchTitle{ launchPath };
if (launchTitle.IsValid()) 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) 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"); 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); wxMessageBox(t, _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
return false; return false;
} }
else if (r != CafeSystem::STATUS_CODE::SUCCESS) else if (r != CafeSystem::STATUS_CODE::SUCCESS)
{ {
wxString t = _("Failed to launch game."); wxString t = _("Failed to launch game.");
t.append(fileName); t.append(_pathToUtf8(launchPath));
wxMessageBox(t, _("Error"), wxOK | wxCENTRE | wxICON_ERROR); wxMessageBox(t, _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
return false; return false;
} }
@ -542,7 +541,7 @@ bool MainWindow::FileLoad(std::wstring fileName, wxLaunchGameEvent::INITIATED_BY
{ {
cemu_assert_debug(false); // todo cemu_assert_debug(false); // todo
wxString t = _("Failed to launch executable. Path: "); wxString t = _("Failed to launch executable. Path: ");
t.append(fileName); t.append(_pathToUtf8(launchPath));
wxMessageBox(t, _("Error"), wxOK | wxCENTRE | wxICON_ERROR); wxMessageBox(t, _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
return false; return false;
} }
@ -550,7 +549,7 @@ bool MainWindow::FileLoad(std::wstring fileName, wxLaunchGameEvent::INITIATED_BY
else if (initiatedBy == wxLaunchGameEvent::INITIATED_BY::GAME_LIST) 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"); 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); wxMessageBox(t, _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
return false; return false;
} }
@ -558,7 +557,7 @@ bool MainWindow::FileLoad(std::wstring fileName, wxLaunchGameEvent::INITIATED_BY
initiatedBy == wxLaunchGameEvent::INITIATED_BY::COMMAND_LINE) initiatedBy == wxLaunchGameEvent::INITIATED_BY::COMMAND_LINE)
{ {
wxString t = _("Unable to launch game\nPath:\n"); wxString t = _("Unable to launch game\nPath:\n");
t.append(fileName); t.append(_pathToUtf8(launchPath));
if(launchTitle.GetInvalidReason() == TitleInfo::InvalidReason::NO_DISC_KEY) if(launchTitle.GetInvalidReason() == TitleInfo::InvalidReason::NO_DISC_KEY)
{ {
t.append(_("\n\n")); t.append(_("\n\n"));
@ -575,16 +574,16 @@ bool MainWindow::FileLoad(std::wstring fileName, wxLaunchGameEvent::INITIATED_BY
else else
{ {
wxString t = _("Unable to launch game\nPath:\n"); wxString t = _("Unable to launch game\nPath:\n");
t.append(fileName); t.append(_pathToUtf8(launchPath));
wxMessageBox(t, _("Error"), wxOK | wxCENTRE | wxICON_ERROR); wxMessageBox(t, _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
return false; return false;
} }
} }
if(launchTitle.IsValid()) if(launchTitle.IsValid())
GetConfig().AddRecentlyLaunchedFile(launchTitle.GetPath().generic_wstring()); GetConfig().AddRecentlyLaunchedFile(_pathToUtf8(launchTitle.GetPath()));
else else
GetConfig().AddRecentlyLaunchedFile(fileName); GetConfig().AddRecentlyLaunchedFile(_pathToUtf8(launchPath));
wxWindowUpdateLocker lock(this); wxWindowUpdateLocker lock(this);
@ -640,7 +639,7 @@ void MainWindow::OnLaunchFromFile(wxLaunchGameEvent& event)
{ {
if (event.GetPath().empty()) if (event.GetPath().empty())
return; return;
FileLoad(event.GetPath().generic_wstring(), event.GetInitiatedBy()); FileLoad(event.GetPath(), event.GetInitiatedBy());
} }
void MainWindow::OnFileMenu(wxCommandEvent& event) void MainWindow::OnFileMenu(wxCommandEvent& event)
@ -669,7 +668,7 @@ void MainWindow::OnFileMenu(wxCommandEvent& event)
return; return;
const wxString wxStrFilePath = openFileDialog.GetPath(); 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) 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; return;
wxString wxStrFilePath = openFileDialog.GetPath(); wxString wxStrFilePath = openFileDialog.GetPath();
uint32 nfcError; 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) if (nfcError == NFC_ERROR_NO_ACCESS)
wxMessageBox(_("Cannot open file")); wxMessageBox(_("Cannot open file"));
@ -758,7 +757,7 @@ void MainWindow::OnNFCMenu(wxCommandEvent& event)
} }
else else
{ {
GetConfig().AddRecentNfcFile((wchar_t*)wxStrFilePath.wc_str()); GetConfig().AddRecentNfcFile(wxStrFilePath.utf8_string());
UpdateNFCMenu(); UpdateNFCMenu();
} }
} }
@ -772,7 +771,7 @@ void MainWindow::OnNFCMenu(wxCommandEvent& event)
if (!path.empty()) if (!path.empty())
{ {
uint32 nfcError = 0; uint32 nfcError = 0;
if (nnNfp_touchNfcTagFromFile(path.c_str(), &nfcError) == false) if (nnNfp_touchNfcTagFromFile(_utf8ToPath(path), &nfcError) == false)
{ {
if (nfcError == NFC_ERROR_NO_ACCESS) if (nfcError == NFC_ERROR_NO_ACCESS)
wxMessageBox(_("Cannot open file")); wxMessageBox(_("Cannot open file"));
@ -1766,7 +1765,7 @@ void MainWindow::UpdateNFCMenu()
if (recentFileIndex == 0) if (recentFileIndex == 0)
m_nfcMenuSeparator0 = m_nfcMenu->AppendSeparator(); 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++; recentFileIndex++;
if (recentFileIndex >= 12) if (recentFileIndex >= 12)
@ -2106,7 +2105,7 @@ void MainWindow::RecreateMenu()
if (recentFileIndex == 0) if (recentFileIndex == 0)
m_fileMenuSeparator0 = m_fileMenu->AppendSeparator(); 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++; recentFileIndex++;
if (recentFileIndex >= 8) if (recentFileIndex >= 8)

View File

@ -65,7 +65,7 @@ public:
void UpdateSettingsAfterGameLaunch(); void UpdateSettingsAfterGameLaunch();
void RestoreSettingsAfterGameExited(); 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; } [[nodiscard]] bool IsGameLaunched() const { return m_game_launched; }

View File

@ -352,7 +352,7 @@ void wxTitleManagerList::OnConvertToCompressedFormat(uint64 titleId, uint64 righ
boost::replace_all(shortName, ":", ""); boost::replace_all(shortName, ":", "");
} }
// for the default output directory we use the first game path configured by the user // 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()) if (!GetConfig().game_paths.empty())
defaultDir = GetConfig().game_paths.front(); defaultDir = GetConfig().game_paths.front();
// get the short name, which we will use as a suggested default file name // get the short name, which we will use as a suggested default file name