mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-08 21:47:42 +00:00
New code style refactor
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
#include "CMemoryCardSys.hpp"
|
||||
#include <shlobj.h>
|
||||
|
||||
namespace urde
|
||||
{
|
||||
namespace urde {
|
||||
|
||||
#if WINDOWS_STORE
|
||||
using namespace Windows::Storage;
|
||||
@@ -11,108 +10,102 @@ 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)
|
||||
{
|
||||
kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlot slot) {
|
||||
#if !WINDOWS_STORE
|
||||
/* Detect where the User directory is. There are two different cases
|
||||
* 1. HKCU\Software\Dolphin Emulator\UserConfigPath exists
|
||||
* -> Use this as the user directory path
|
||||
* 2. My Documents exists
|
||||
* -> Use My Documents\Dolphin Emulator as the User directory path
|
||||
*/
|
||||
/* Detect where the User directory is. There are two different cases
|
||||
* 1. HKCU\Software\Dolphin Emulator\UserConfigPath exists
|
||||
* -> Use this as the user directory path
|
||||
* 2. My Documents exists
|
||||
* -> Use My Documents\Dolphin Emulator as the User directory path
|
||||
*/
|
||||
|
||||
/* 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)
|
||||
{
|
||||
DWORD size = MAX_PATH;
|
||||
if (RegQueryValueEx(hkey, _SYS_STR("UserConfigPath"), nullptr, nullptr, (LPBYTE)configPath,
|
||||
&size) != ERROR_SUCCESS)
|
||||
configPath[0] = 0;
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
/* 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) {
|
||||
DWORD size = MAX_PATH;
|
||||
if (RegQueryValueEx(hkey, _SYS_STR("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];
|
||||
bool my_documents_found = SUCCEEDED(
|
||||
SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, my_documents));
|
||||
/* Get My Documents path in case we need it. */
|
||||
kabufuda::SystemChar my_documents[MAX_PATH];
|
||||
bool my_documents_found =
|
||||
SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, my_documents));
|
||||
|
||||
kabufuda::SystemString path;
|
||||
if (configPath[0]) /* Case 1 */
|
||||
path = configPath;
|
||||
else if (my_documents_found) /* Case 2 */
|
||||
path = kabufuda::SystemString(my_documents) + _SYS_STR("/Dolphin Emulator");
|
||||
else /* Unable to find */
|
||||
return {};
|
||||
kabufuda::SystemString path;
|
||||
if (configPath[0]) /* Case 1 */
|
||||
path = configPath;
|
||||
else if (my_documents_found) /* Case 2 */
|
||||
path = kabufuda::SystemString(my_documents) + _SYS_STR("/Dolphin Emulator");
|
||||
else /* Unable to find */
|
||||
return {};
|
||||
#else
|
||||
StorageFolder^ localFolder = ApplicationData::Current->LocalFolder;
|
||||
kabufuda::SystemString path(localFolder->Path->Data());
|
||||
StorageFolder ^ localFolder = ApplicationData::Current->LocalFolder;
|
||||
kabufuda::SystemString path(localFolder->Path->Data());
|
||||
#endif
|
||||
|
||||
path += hecl::SysFormat(_SYS_STR("/GC/MemoryCard%c.USA.raw"),
|
||||
slot == kabufuda::ECardSlot::SlotA ? _SYS_STR('A') : _SYS_STR('B'));
|
||||
path += hecl::SysFormat(_SYS_STR("/GC/MemoryCard%c.USA.raw"),
|
||||
slot == kabufuda::ECardSlot::SlotA ? _SYS_STR('A') : _SYS_STR('B'));
|
||||
|
||||
hecl::Sstat theStat;
|
||||
if (hecl::Stat(path.c_str(), &theStat) || !S_ISREG(theStat.st_mode))
|
||||
return {};
|
||||
hecl::Sstat theStat;
|
||||
if (hecl::Stat(path.c_str(), &theStat) || !S_ISREG(theStat.st_mode))
|
||||
return {};
|
||||
|
||||
return path;
|
||||
return path;
|
||||
}
|
||||
|
||||
kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot)
|
||||
{
|
||||
kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot) {
|
||||
#if !WINDOWS_STORE
|
||||
/* Detect where the User directory is. There are two different cases
|
||||
* 1. HKCU\Software\Dolphin Emulator\UserConfigPath exists
|
||||
* -> Use this as the user directory path
|
||||
* 2. My Documents exists
|
||||
* -> Use My Documents\Dolphin Emulator as the User directory path
|
||||
*/
|
||||
/* Detect where the User directory is. There are two different cases
|
||||
* 1. HKCU\Software\Dolphin Emulator\UserConfigPath exists
|
||||
* -> Use this as the user directory path
|
||||
* 2. My Documents exists
|
||||
* -> Use My Documents\Dolphin Emulator as the User directory path
|
||||
*/
|
||||
|
||||
/* 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)
|
||||
{
|
||||
DWORD size = MAX_PATH;
|
||||
if (RegQueryValueEx(hkey, _SYS_STR("UserConfigPath"), nullptr, nullptr, (LPBYTE)configPath,
|
||||
&size) != ERROR_SUCCESS)
|
||||
configPath[0] = 0;
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
/* 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) {
|
||||
DWORD size = MAX_PATH;
|
||||
if (RegQueryValueEx(hkey, _SYS_STR("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];
|
||||
bool my_documents_found = SUCCEEDED(
|
||||
SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, my_documents));
|
||||
/* Get My Documents path in case we need it. */
|
||||
kabufuda::SystemChar my_documents[MAX_PATH];
|
||||
bool my_documents_found =
|
||||
SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_MYDOCUMENTS, nullptr, SHGFP_TYPE_CURRENT, my_documents));
|
||||
|
||||
kabufuda::SystemString path;
|
||||
if (configPath[0]) /* Case 1 */
|
||||
path = configPath;
|
||||
else if (my_documents_found) /* Case 2 */
|
||||
path = kabufuda::SystemString(my_documents) + _SYS_STR("/Dolphin Emulator");
|
||||
else /* Unable to find */
|
||||
return {};
|
||||
kabufuda::SystemString path;
|
||||
if (configPath[0]) /* Case 1 */
|
||||
path = configPath;
|
||||
else if (my_documents_found) /* Case 2 */
|
||||
path = kabufuda::SystemString(my_documents) + _SYS_STR("/Dolphin Emulator");
|
||||
else /* Unable to find */
|
||||
return {};
|
||||
#else
|
||||
StorageFolder^ localFolder = ApplicationData::Current->LocalFolder;
|
||||
kabufuda::SystemString path(localFolder->Path->Data());
|
||||
StorageFolder ^ localFolder = ApplicationData::Current->LocalFolder;
|
||||
kabufuda::SystemString path(localFolder->Path->Data());
|
||||
#endif
|
||||
|
||||
path += _SYS_STR("/GC");
|
||||
if (hecl::RecursiveMakeDir(path.c_str()) < 0)
|
||||
return {};
|
||||
path += _SYS_STR("/GC");
|
||||
if (hecl::RecursiveMakeDir(path.c_str()) < 0)
|
||||
return {};
|
||||
|
||||
path += hecl::SysFormat(_SYS_STR("/MemoryCard%c.USA.raw"),
|
||||
slot == kabufuda::ECardSlot::SlotA ? _SYS_STR('A') : _SYS_STR('B'));
|
||||
FILE* fp = hecl::Fopen(path.c_str(), _SYS_STR("wb"));
|
||||
if (!fp)
|
||||
return {};
|
||||
fclose(fp);
|
||||
path += hecl::SysFormat(_SYS_STR("/MemoryCard%c.USA.raw"),
|
||||
slot == kabufuda::ECardSlot::SlotA ? _SYS_STR('A') : _SYS_STR('B'));
|
||||
FILE* fp = hecl::Fopen(path.c_str(), _SYS_STR("wb"));
|
||||
if (!fp)
|
||||
return {};
|
||||
fclose(fp);
|
||||
|
||||
return path;
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace urde
|
||||
|
||||
Reference in New Issue
Block a user