GBA Config: Check current directory for portable.ini
Jeffrey Pfau jeffrey@endrift.com
Wed, 01 Jul 2015 21:30:14 -0700
3 files changed,
28 insertions(+),
6 deletions(-)
M
CHANGES
→
CHANGES
@@ -22,6 +22,7 @@ - Finer control over FPS target
- Holdable shortcut for rewinding one frame at a time - Ability to boot directly into the BIOS - Preliminary support for yanking out the game pak while a game is running + - Thumb-drive mode by putting a file called portable.ini in the same folder Bugfixes: - ARM7: Fix SWI and IRQ timings - GBA Audio: Force audio FIFOs to 32-bit
M
CMakeLists.txt
→
CMakeLists.txt
@@ -168,7 +168,7 @@ # Platform support
if(WIN32) set(WIN32_VERSION "${LIB_VERSION_MAJOR},${LIB_VERSION_MINOR},${LIB_VERSION_PATCH}") add_definitions(-D_WIN32_WINNT=0x0600) - list(APPEND OS_LIB ws2_32) + list(APPEND OS_LIB ws2_32 shlwapi) list(APPEND VFS_SRC ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_SOURCE_DIR}/src/util/vfs/vfs-dirent.c) file(GLOB OS_SRC ${CMAKE_SOURCE_DIR}/src/platform/windows/*.c) source_group("Windows-specific code" FILES ${OS_SRC})
M
src/gba/supervisor/config.c
→
src/gba/supervisor/config.c
@@ -13,6 +13,7 @@ #include <sys/stat.h>
#ifdef _WIN32 #include <windows.h> +#include <shlwapi.h> #include <shlobj.h> #include <strsafe.h> #endif@@ -126,21 +127,41 @@ return ConfigurationWrite(&config->configTable, path);
} void GBAConfigDirectory(char* out, size_t outLength) { + struct VFile* portable; #ifndef _WIN32 + getcwd(out, outLength); + strncat(out, PATH_SEP "portable.ini", outLength - strlen(out)); + portable = VFileOpen(out, O_RDONLY); + if (portable) { + getcwd(out, outLength); + portable->close(portable); + return; + } + char* home = getenv("HOME"); snprintf(out, outLength, "%s/.config", home); mkdir(out, 0755); snprintf(out, outLength, "%s/.config/%s", home, binaryName); mkdir(out, 0755); #else - wchar_t* home; wchar_t wpath[MAX_PATH]; wchar_t wprojectName[MAX_PATH]; - SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &home); MultiByteToWideChar(CP_UTF8, 0, projectName, -1, wprojectName, MAX_PATH); - StringCchPrintfW(wpath, MAX_PATH, L"%ws\\%ws", home, wprojectName); - CoTaskMemFree(home); - CreateDirectoryW(wpath, NULL); + HMODULE hModule = GetModuleHandleW(NULL); + GetModuleFileNameW(hModule, wpath, MAX_PATH); + PathRemoveFileSpecW(wpath); + WideCharToMultiByte(CP_UTF8, 0, wpath, -1, out, outLength, 0, 0); + StringCchCatA(out, outLength, "\\portable.ini"); + portable = VFileOpen(out, O_RDONLY); + if (portable) { + portable->close(portable); + } else { + wchar_t* home; + SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &home); + StringCchPrintfW(wpath, MAX_PATH, L"%ws\\%ws", home, wprojectName); + CoTaskMemFree(home); + CreateDirectoryW(wpath, NULL); + } WideCharToMultiByte(CP_UTF8, 0, wpath, -1, out, outLength, 0, 0); #endif }