From 4d4f53425e7a42f08e06b44104e94ecc92dee7e2 Mon Sep 17 00:00:00 2001 From: spacy51 Date: Sat, 15 Aug 2009 17:43:53 +0000 Subject: [PATCH] If vba.ini exists in executable's folder, use it. Else create/use one in %appdata% folder. --- src/Util.cpp | 12 ++++++++++++ src/Util.h | 1 + src/win32/Reg.cpp | 9 +++++++++ 3 files changed, 22 insertions(+) diff --git a/src/Util.cpp b/src/Util.cpp index c3bcd8b3..85c75598 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -654,3 +654,15 @@ void utilUpdateSystemColorMaps() break; } } + +// Check for existence of file. +bool utilFileExists( const char *filename ) +{ + FILE *f = fopen( filename, "r" ); + if( f == NULL ) { + return false; + } else { + fclose( f ); + return true; + } +} diff --git a/src/Util.h b/src/Util.h index ca367e68..07e7eb1f 100644 --- a/src/Util.h +++ b/src/Util.h @@ -41,5 +41,6 @@ z_off_t utilGzSeek(gzFile file, z_off_t offset, int whence); long utilGzMemTell(gzFile file); void utilGBAFindSave(const u8 *, const int); void utilUpdateSystemColorMaps(); +bool utilFileExists( const char *filename ); #endif // UTIL_H diff --git a/src/win32/Reg.cpp b/src/win32/Reg.cpp index 8af13e61..303c8b86 100644 --- a/src/win32/Reg.cpp +++ b/src/win32/Reg.cpp @@ -27,8 +27,17 @@ void regInit(const char *path) delete regVbaPath; regVbaPath = NULL; } + + // If vba.ini exists in executable's folder, use it. Else create/use one in %appdata% folder. regVbaPath = new CString(); regVbaPath->Format(MakeInstanceFilename("%s\\vba.ini"), path); + if( !utilFileExists( regVbaPath->GetString() ) ) { + TCHAR appdata[MAX_PATH+1]; + SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appdata ); + regVbaPath->Format( "%s\\VBA-M", appdata ); + SHCreateDirectoryEx( NULL, regVbaPath->GetString(), NULL ); + regVbaPath->Append( "\\vba.ini" ); + } } void regShutdown()