mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-11 15:01:49 +00:00
Use UTF-8 exclusively internally
This removes SystemString, SystemChar, etc. All filepaths and log strings are assumed to be UTF-8, with conversions to UTF-16 for Windows APIs as appropriate. Updates amuse, athena, boo, kabufua and nod
This commit is contained in:
@@ -14,7 +14,7 @@ using namespace Windows::Storage;
|
||||
/* Partial path-selection logic from
|
||||
* https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/UICommon/UICommon.cpp
|
||||
* Modified to not use dolphin-binary-relative paths. */
|
||||
kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlot slot) {
|
||||
std::string CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlot slot) {
|
||||
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
|
||||
#if !WINDOWS_STORE
|
||||
/* Detect where the User directory is. There are two different cases
|
||||
@@ -26,35 +26,32 @@ kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlo
|
||||
|
||||
/* Check our registry keys */
|
||||
HKEY hkey;
|
||||
kabufuda::SystemChar configPath[MAX_PATH] = {0};
|
||||
if (RegOpenKeyEx(HKEY_CURRENT_USER, _SYS_STR("Software\\Dolphin Emulator"), 0, KEY_QUERY_VALUE, &hkey) ==
|
||||
ERROR_SUCCESS) {
|
||||
wchar_t configPath[MAX_PATH] = {0};
|
||||
if (RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Dolphin Emulator", 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) {
|
||||
DWORD size = MAX_PATH;
|
||||
if (RegQueryValueEx(hkey, _SYS_STR("UserConfigPath"), nullptr, nullptr, (LPBYTE)configPath, &size) !=
|
||||
ERROR_SUCCESS)
|
||||
if (RegQueryValueEx(hkey, L"UserConfigPath", nullptr, nullptr, (LPBYTE)configPath, &size) != ERROR_SUCCESS)
|
||||
configPath[0] = 0;
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
|
||||
/* Get My Documents path in case we need it. */
|
||||
kabufuda::SystemChar my_documents[MAX_PATH];
|
||||
wchar_t my_documents[MAX_PATH];
|
||||
bool my_documents_found =
|
||||
SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, my_documents));
|
||||
|
||||
kabufuda::SystemString path;
|
||||
std::string path;
|
||||
if (configPath[0]) /* Case 1 */
|
||||
path = configPath;
|
||||
path = nowide::narrow(configPath);
|
||||
else if (my_documents_found) /* Case 2 */
|
||||
path = kabufuda::SystemString(my_documents) + _SYS_STR("/Dolphin Emulator");
|
||||
path = nowide::narrow(my_documents) + "/Dolphin Emulator";
|
||||
else /* Unable to find */
|
||||
return {};
|
||||
#else
|
||||
StorageFolder ^ localFolder = ApplicationData::Current->LocalFolder;
|
||||
kabufuda::SystemString path(localFolder->Path->Data());
|
||||
std::string path(localFolder->Path->Data());
|
||||
#endif
|
||||
|
||||
path += fmt::format(FMT_STRING(_SYS_STR("/GC/MemoryCard{}.USA.raw")),
|
||||
slot == kabufuda::ECardSlot::SlotA ? _SYS_STR('A') : _SYS_STR('B'));
|
||||
path += fmt::format(FMT_STRING("/GC/MemoryCard{}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
|
||||
|
||||
hecl::Sstat theStat;
|
||||
if (hecl::Stat(path.c_str(), &theStat) || !S_ISREG(theStat.st_mode))
|
||||
@@ -65,7 +62,7 @@ kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlo
|
||||
return {};
|
||||
}
|
||||
|
||||
kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot, bool dolphin) {
|
||||
std::string CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot, bool dolphin) {
|
||||
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
|
||||
if (dolphin) {
|
||||
#if !WINDOWS_STORE
|
||||
@@ -78,54 +75,51 @@ kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot sl
|
||||
|
||||
/* Check our registry keys */
|
||||
HKEY hkey;
|
||||
kabufuda::SystemChar configPath[MAX_PATH] = {0};
|
||||
if (RegOpenKeyEx(HKEY_CURRENT_USER, _SYS_STR("Software\\Dolphin Emulator"), 0, KEY_QUERY_VALUE, &hkey) ==
|
||||
ERROR_SUCCESS) {
|
||||
wchar_t configPath[MAX_PATH] = {0};
|
||||
if (RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Dolphin Emulator", 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) {
|
||||
DWORD size = MAX_PATH;
|
||||
if (RegQueryValueEx(hkey, _SYS_STR("UserConfigPath"), nullptr, nullptr, (LPBYTE)configPath, &size) !=
|
||||
ERROR_SUCCESS)
|
||||
if (RegQueryValueEx(hkey, L"UserConfigPath", nullptr, nullptr, (LPBYTE)configPath, &size) != ERROR_SUCCESS)
|
||||
configPath[0] = 0;
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
|
||||
/* Get My Documents path in case we need it. */
|
||||
kabufuda::SystemChar my_documents[MAX_PATH];
|
||||
wchar_t my_documents[MAX_PATH];
|
||||
bool my_documents_found =
|
||||
SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, my_documents));
|
||||
|
||||
kabufuda::SystemString path;
|
||||
std::string path;
|
||||
if (configPath[0]) /* Case 1 */
|
||||
path = configPath;
|
||||
path = nowide::narrow(configPath);
|
||||
else if (my_documents_found) /* Case 2 */
|
||||
path = kabufuda::SystemString(my_documents) + _SYS_STR("/Dolphin Emulator");
|
||||
path = nowide::narrow(my_documents) + "/Dolphin Emulator";
|
||||
else /* Unable to find */
|
||||
return {};
|
||||
#else
|
||||
StorageFolder ^ localFolder = ApplicationData::Current->LocalFolder;
|
||||
kabufuda::SystemString path(localFolder->Path->Data());
|
||||
std::string path(localFolder->Path->Data());
|
||||
#endif
|
||||
|
||||
path += _SYS_STR("/GC");
|
||||
path += "/GC";
|
||||
if (hecl::RecursiveMakeDir(path.c_str()) < 0)
|
||||
return {};
|
||||
|
||||
path += fmt::format(FMT_STRING(_SYS_STR("/MemoryCard{}.USA.raw")),
|
||||
slot == kabufuda::ECardSlot::SlotA ? _SYS_STR('A') : _SYS_STR('B'));
|
||||
const auto fp = hecl::FopenUnique(path.c_str(), _SYS_STR("wb"));
|
||||
path += fmt::format(FMT_STRING("/MemoryCard{}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
|
||||
const auto fp = hecl::FopenUnique(path.c_str(), "wb");
|
||||
if (fp == nullptr) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return path;
|
||||
} else {
|
||||
kabufuda::SystemString path = _GetDolphinCardPath(slot);
|
||||
std::string path = _GetDolphinCardPath(slot);
|
||||
hecl::SanitizePath(path);
|
||||
if (path.find('/') == kabufuda::SystemString::npos) {
|
||||
path = hecl::GetcwdStr() + _SYS_STR("/") + _GetDolphinCardPath(slot);
|
||||
if (path.find('/') == std::string::npos) {
|
||||
path = hecl::GetcwdStr() + "/" + _GetDolphinCardPath(slot);
|
||||
}
|
||||
hecl::SystemString tmpPath = path.substr(0, path.find_last_of(_SYS_STR("/")));
|
||||
std::string tmpPath = path.substr(0, path.find_last_of("/"));
|
||||
hecl::RecursiveMakeDir(tmpPath.c_str());
|
||||
const auto fp = hecl::FopenUnique(path.c_str(), _SYS_STR("wb"));
|
||||
const auto fp = hecl::FopenUnique(path.c_str(), "wb");
|
||||
if (fp) {
|
||||
return path;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user