From 06f02ef8731fa998f2db870a783930503e980281 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 1 Jul 2015 21:30:14 -0700 Subject: [PATCH] GBA Config: Check current directory for portable.ini --- CHANGES | 1 + CMakeLists.txt | 2 +- src/gba/supervisor/config.c | 31 ++++++++++++++++++++++++++----- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 1e1c088c4..52dcfe157 100644 --- a/CHANGES +++ b/CHANGES @@ -22,6 +22,7 @@ Features: - 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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fbeb04be..d3fdfd13e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,7 +168,7 @@ find_feature(USE_MAGICK "MagickWand") 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}) diff --git a/src/gba/supervisor/config.c b/src/gba/supervisor/config.c index e812b30e0..c32d72e42 100644 --- a/src/gba/supervisor/config.c +++ b/src/gba/supervisor/config.c @@ -13,6 +13,7 @@ #ifdef _WIN32 #include +#include #include #include #endif @@ -126,21 +127,41 @@ bool GBAConfigSave(const struct GBAConfig* config) { } 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 }