From 716972cd923973b99128d13e3a1681b0f9ba0ed4 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 3 Feb 2017 22:20:09 -1000 Subject: [PATCH] Windows memory card file creation --- Runtime/CMemoryCardSysOSX.cpp | 5 ---- Runtime/CMemoryCardSysWin.cpp | 49 +++++++++++++++++++++++++++++++++++ kabufuda | 2 +- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/Runtime/CMemoryCardSysOSX.cpp b/Runtime/CMemoryCardSysOSX.cpp index f8e80f6c7..b8390fe56 100644 --- a/Runtime/CMemoryCardSysOSX.cpp +++ b/Runtime/CMemoryCardSysOSX.cpp @@ -36,11 +36,6 @@ kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot sl FILE* fp = hecl::Fopen(path.c_str(), "wb"); if (!fp) return {}; - /* - const u32 fword = 0xffffffff; - for (int i=0 ; i<0x1000000/4 ; ++i) - fwrite(&fword, 1, 4, fp); - */ fclose(fp); return path; diff --git a/Runtime/CMemoryCardSysWin.cpp b/Runtime/CMemoryCardSysWin.cpp index 6e32cb640..9ebdbc216 100644 --- a/Runtime/CMemoryCardSysWin.cpp +++ b/Runtime/CMemoryCardSysWin.cpp @@ -52,4 +52,53 @@ kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlo return path; } +kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot) +{ + /* 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, _S("Software\\Dolphin Emulator"), 0, KEY_QUERY_VALUE, + &hkey) == ERROR_SUCCESS) + { + DWORD size = MAX_PATH; + if (RegQueryValueEx(hkey, _S("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)); + + kabufuda::SystemString path; + if (configPath[0]) /* Case 1 */ + path = configPath; + else if (my_documents_found) /* Case 2 */ + path = kabufuda::SystemString(my_documents) + _S("/Dolphin Emulator"); + else /* Unable to find */ + return {}; + + path += _S("/GC"); + if (hecl::RecursiveMakeDir(path.c_str()) < 0) + return {}; + + path += hecl::SysFormat(_S("/MemoryCard%c.USA.raw"), + slot == kabufuda::ECardSlot::SlotA ? _S('A') : _S('B')); + FILE* fp = hecl::Fopen(path.c_str(), _S("wb")); + if (!fp) + return {}; + fclose(fp); + + return path; +} + } diff --git a/kabufuda b/kabufuda index 537cceca4..bb972f8f3 160000 --- a/kabufuda +++ b/kabufuda @@ -1 +1 @@ -Subproject commit 537cceca49bbcc2a71ec9eafd156b5e2496cc31f +Subproject commit bb972f8f36cfd6b8b65b3e53352880b039a78393