From 2bd54afffb8de56bdc711fc2d4bb347d1fea8965 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sat, 8 Jun 2013 06:01:17 +0000 Subject: [PATCH] win32-when being run from a subdirectory of %temp%, store user files in local appdata, in effort to shut up remaining pokemon gamers running desmume from zipfiles. --- desmume/src/path.h | 24 +++++----- desmume/src/windows/pathsettings.cpp | 6 ++- desmume/src/windows/winutil.cpp | 66 ++++++++++++++++++++++------ 3 files changed, 67 insertions(+), 29 deletions(-) diff --git a/desmume/src/path.h b/desmume/src/path.h index 7f97aca2e..3180a5f43 100644 --- a/desmume/src/path.h +++ b/desmume/src/path.h @@ -144,6 +144,12 @@ public: p = pathToModule + lstrlen(pathToModule); while (p >= pathToModule && *p != DIRECTORY_DELIMITER_CHAR) p--; if (++p >= pathToModule) *p = 0; + + extern char* _hack_alternateModulePath; + if(_hack_alternateModulePath) + { + strcpy(pathToModule,_hack_alternateModulePath); + } #elif defined(DESMUME_COCOA) std::string pathStr = Path::GetFileDirectoryPath(path); @@ -383,25 +389,15 @@ public: enum R4Format { -#if defined(_WINDOWS) && !defined(WXPORT) - R4_CHEAT_DAT = IDC_R4TYPE1, - R4_USRCHEAT_DAT = IDC_R4TYPE2 -#else - R4_CHEAT_DAT, - R4_USRCHEAT_DAT -#endif + R4_CHEAT_DAT = 0, + R4_USRCHEAT_DAT = 1 }; R4Format r4Format; enum ImageFormat { -#if defined(_WINDOWS) && !defined(WXPORT) - PNG = IDC_PNG, - BMP = IDC_BMP -#else - PNG, - BMP -#endif + PNG = 0, + BMP = 1 }; ImageFormat currentimageformat; diff --git a/desmume/src/windows/pathsettings.cpp b/desmume/src/windows/pathsettings.cpp index 2ebfaa348..3e81ae224 100644 --- a/desmume/src/windows/pathsettings.cpp +++ b/desmume/src/windows/pathsettings.cpp @@ -147,8 +147,10 @@ BOOL PathSettings_OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lParam) CheckDlgButton(hDlg, IDC_USELASTVISIT, (path.savelastromvisit) ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hDlg, IDC_ASSOCIATE, (associate) ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hDlg, IDC_AUTOLOADLUA, (autoLoadLua) ? BST_CHECKED : BST_UNCHECKED); - CheckRadioButton(hDlg, IDC_PNG, IDC_BMP, (int)path.imageformat()); - CheckRadioButton(hDlg, IDC_R4TYPE1, IDC_R4TYPE2, (int)path.r4Format); + static const int imageFormatMap[] = { IDC_PNG, IDC_BMP }; + static const int r4TypeMap[] = { IDC_R4TYPE1, IDC_R4TYPE2 }; + CheckRadioButton(hDlg, IDC_PNG, IDC_BMP, imageFormatMap[(int)path.imageformat()]); + CheckRadioButton(hDlg, IDC_R4TYPE1, IDC_R4TYPE2, r4TypeMap[(int)path.r4Format]); // IDC_FORMATEDIT setup SetDlgItemText(hDlg, IDC_FORMATEDIT, path.screenshotFormat); diff --git a/desmume/src/windows/winutil.cpp b/desmume/src/windows/winutil.cpp index a623c0f6a..7bd6d7105 100644 --- a/desmume/src/windows/winutil.cpp +++ b/desmume/src/windows/winutil.cpp @@ -15,29 +15,67 @@ along with the this software. If not, see . */ +#include "common.h" +#include "path.h" #include "winutil.h" #include #include #include #include +#include + char IniName[MAX_PATH]; +char* _hack_alternateModulePath; + + +static char vPath[MAX_PATH*2], *szPath; + void GetINIPath() { - char vPath[MAX_PATH], *szPath; - /*if (*vPath) - szPath = vPath; - else - {*/ - char *p; - ZeroMemory(vPath, sizeof(vPath)); - GetModuleFileName(NULL, vPath, sizeof(vPath)); - p = vPath + lstrlen(vPath); - while (p >= vPath && *p != '\\') p--; - if (++p >= vPath) *p = 0; - szPath = vPath; - //} + + bool useModulePath = true; + + //check if desmume is running from the temp directory. + { + //DebugBreak(); + wchar_t tempPath[MAX_PATH]; + GetTempPathW(MAX_PATH,tempPath); + wchar_t modulePath[MAX_PATH]; + GetModuleFileNameW(NULL, modulePath, MAX_PATH); + if(!_wcsnicmp(tempPath,modulePath,wcslen(tempPath))) + { + //running from temp dir + + //decided not to warn user + //GetPrivateProfileBool("General","Temp Directory Warning", false, IniName)) + //MessageBox(NULL,"You are running DeSmuME from your temp directory, probably by running straight from an archive instead of dearchiving to your disk manually...... + + //use an alternate path + useModulePath = false; + static char userpath[MAX_PATH]; + SHGetFolderPath(NULL,CSIDL_LOCAL_APPDATA,NULL,0,userpath); + _snprintf(vPath,MAX_PATH,"%s\\%s",userpath,"DeSmuME"); + szPath = vPath; + _hack_alternateModulePath = szPath; + + //not so sure about this.. but lets go for it. + SetCurrentDirectory(userpath); + } + } + + + if(useModulePath) + { + char *p; + ZeroMemory(vPath, sizeof(vPath)); + GetModuleFileName(NULL, vPath, sizeof(vPath)); + p = vPath + lstrlen(vPath); + while (p >= vPath && *p != '\\') p--; + if (++p >= vPath) *p = 0; + szPath = vPath; + } if (strlen(szPath) + strlen("\\desmume.ini") < MAX_PATH) { sprintf(IniName, "%s\\desmume.ini",szPath); @@ -47,6 +85,8 @@ void GetINIPath() { memset(IniName,0,MAX_PATH) ; } + + FCEUD_MakePathDirs(IniName); } void PreventScreensaver()