From ad404dd5828c1df4546ad144b5520b635c19a26c Mon Sep 17 00:00:00 2001 From: squall-leonhart Date: Tue, 24 Mar 2009 05:15:25 +0000 Subject: [PATCH] Code reverted to prior to spacy's relative directories. Maybe we can do this properly in the future, but for now it was causing issues for people who like to keep saves with the roms, as well as breaking the rom open dialogues. git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@870 a31d4220-a93d-0410-bf67-fe4944624d44 --- src/win32/Directories.cpp | 6 +- src/win32/MainWnd.cpp | 65 ++++++++++++++--- src/win32/MainWndCheats.cpp | 4 +- src/win32/MainWndFile.cpp | 141 ++++++++++++++++++++++++++++++------ src/win32/VBA.cpp | 1 - src/win32/VBA.h | 4 - 6 files changed, 180 insertions(+), 41 deletions(-) diff --git a/src/win32/Directories.cpp b/src/win32/Directories.cpp index eb7bc72f..ba086ab6 100644 --- a/src/win32/Directories.cpp +++ b/src/win32/Directories.cpp @@ -75,15 +75,15 @@ BOOL Directories::OnInitDialog() if(!p.IsEmpty()) GetDlgItem(IDC_GBROM_PATH)->SetWindowText(p); - p = regQueryStringValue("batteryDir", DEFAULT_BATTERY_DIR); + p = regQueryStringValue("batteryDir", NULL); if(!p.IsEmpty()) GetDlgItem(IDC_BATTERY_PATH)->SetWindowText( p); - p = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR); + p = regQueryStringValue("saveDir", NULL); if(!p.IsEmpty()) GetDlgItem(IDC_SAVE_PATH)->SetWindowText(p); - p = regQueryStringValue("captureDir", DEFAULT_SCREENSHOTS_DIR); + p = regQueryStringValue("captureDir", NULL); if(!p.IsEmpty()) GetDlgItem(IDC_CAPTURE_PATH)->SetWindowText(p); diff --git a/src/win32/MainWnd.cpp b/src/win32/MainWnd.cpp index 19b6cc29..5a12e6b2 100644 --- a/src/win32/MainWnd.cpp +++ b/src/win32/MainWnd.cpp @@ -800,8 +800,17 @@ void MainWnd::winSaveCheatListDefault() name = theApp.filename.Right(theApp.filename.GetLength()-index-1); else name = theApp.filename; - CString dir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR); - treatRelativePath( dir ); + CString dir = regQueryStringValue("saveDir", NULL); + if( dir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, dir ); + dir = baseDir; + } if(!dir.GetLength()) dir = getDirFromFile(filename); @@ -833,8 +842,17 @@ void MainWnd::winLoadCheatListDefault() name = theApp.filename.Right(theApp.filename.GetLength()-index-1); else name = theApp.filename; - CString dir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR); - treatRelativePath( dir ); + CString dir = regQueryStringValue("saveDir", NULL); + if( dir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, dir ); + dir = baseDir; + } if(!dir.GetLength()) dir = getDirFromFile(filename); @@ -896,8 +914,17 @@ void MainWnd::writeBatteryFile() else buffer = theApp.filename; - CString saveDir = regQueryStringValue("batteryDir", DEFAULT_BATTERY_DIR); - treatRelativePath( saveDir ); + CString saveDir = regQueryStringValue("batteryDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -924,8 +951,17 @@ void MainWnd::readBatteryFile() else buffer = theApp.filename; - CString saveDir = regQueryStringValue("batteryDir", DEFAULT_BATTERY_DIR); - treatRelativePath( saveDir ); + CString saveDir = regQueryStringValue("batteryDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -1078,8 +1114,17 @@ void MainWnd::screenCapture(int captureNumber) { CString buffer; - CString captureDir = regQueryStringValue("captureDir", DEFAULT_SCREENSHOTS_DIR); - treatRelativePath( captureDir ); + CString captureDir = regQueryStringValue("captureDir", ""); + if( captureDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, captureDir ); + captureDir = baseDir; + } int index = theApp.filename.ReverseFind('\\'); diff --git a/src/win32/MainWndCheats.cpp b/src/win32/MainWndCheats.cpp index e270910f..31114b8f 100644 --- a/src/win32/MainWndCheats.cpp +++ b/src/win32/MainWndCheats.cpp @@ -67,7 +67,7 @@ void MainWnd::OnCheatsLoadcheatlist() else buffer = theApp.filename; - CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR); + CString saveDir = regQueryStringValue("saveDir", NULL); if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -105,7 +105,7 @@ void MainWnd::OnCheatsSavecheatlist() else buffer = theApp.filename; - CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR); + CString saveDir = regQueryStringValue("saveDir", NULL); if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); diff --git a/src/win32/MainWndFile.cpp b/src/win32/MainWndFile.cpp index 89042423..df87aaed 100644 --- a/src/win32/MainWndFile.cpp +++ b/src/win32/MainWndFile.cpp @@ -166,8 +166,17 @@ void MainWnd::OnFileLoad() else buffer = theApp.filename; - CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR); - treatRelativePath( saveDir ); + CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -214,8 +223,17 @@ BOOL MainWnd::OnFileLoadSlot(UINT nID) else buffer = theApp.filename; - CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR); - treatRelativePath( saveDir ); + CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -256,8 +274,17 @@ void MainWnd::OnFileSave() else buffer = theApp.filename; - CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR); - treatRelativePath( saveDir ); + CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -299,8 +326,17 @@ BOOL MainWnd::OnFileSaveSlot(UINT nID) else buffer = theApp.filename; - CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR); - treatRelativePath( saveDir ); + CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -328,8 +364,17 @@ void MainWnd::OnFileImportBatteryfile() CString filter = winLoadFilter(IDS_FILTER_SAV); CString title = winResLoadString(IDS_SELECT_BATTERY_FILE); - CString saveDir = regQueryStringValue("batteryDir", DEFAULT_BATTERY_DIR); - treatRelativePath( saveDir ); + CString saveDir = regQueryStringValue("batteryDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -444,7 +489,16 @@ void MainWnd::OnFileExportBatteryfile() CString title = winResLoadString(IDS_SELECT_BATTERY_FILE); CString saveDir = regQueryStringValue("batteryDir", DEFAULT_BATTERY_DIR); - treatRelativePath( saveDir ); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -539,8 +593,17 @@ void MainWnd::OnFileScreencapture() else name = theApp.filename; - CString capdir = regQueryStringValue("captureDir", DEFAULT_SCREENSHOTS_DIR); - treatRelativePath( capdir ); + CString capdir = regQueryStringValue("captureDir", ""); + if( capdir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, capdir ); + capdir = baseDir; + } if(capdir.IsEmpty()) capdir = getDirFromFile(theApp.filename); @@ -686,8 +749,17 @@ void MainWnd::OnFileSavegameOldestslot() else filename = theApp.filename; - CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR); - treatRelativePath( saveDir ); + CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -731,8 +803,17 @@ void MainWnd::OnUpdateFileSavegameOldestslot(CCmdUI* pCmdUI) else filename = theApp.filename; - CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR); - treatRelativePath( saveDir ); + CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -774,8 +855,17 @@ void MainWnd::OnFileLoadgameMostrecent() else filename = theApp.filename; - CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR); - treatRelativePath( saveDir ); + CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); @@ -819,8 +909,17 @@ void MainWnd::OnUpdateFileLoadgameMostrecent(CCmdUI* pCmdUI) else filename = theApp.filename; - CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR); - treatRelativePath( saveDir ); + CString saveDir = regQueryStringValue("saveDir", NULL); + if( saveDir[0] == '.' ) { + // handle as relative path + char baseDir[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + strcat( baseDir, "\\" ); + strcat( baseDir, saveDir ); + saveDir = baseDir; + } if(saveDir.IsEmpty()) saveDir = getDirFromFile(theApp.filename); diff --git a/src/win32/VBA.cpp b/src/win32/VBA.cpp index 8716fe2e..ca08bde5 100644 --- a/src/win32/VBA.cpp +++ b/src/win32/VBA.cpp @@ -6,7 +6,6 @@ #include "stdafx.h" #include -#include // for SHCreateDirectoryEx #include "AVIWrite.h" #include "LangSelect.h" diff --git a/src/win32/VBA.h b/src/win32/VBA.h index 3832f334..60a507a8 100644 --- a/src/win32/VBA.h +++ b/src/win32/VBA.h @@ -51,10 +51,6 @@ enum AUDIO_API { #define REWIND_SIZE 400000 -#define DEFAULT_BATTERY_DIR ".\\battery" -#define DEFAULT_SAVESTATES_DIR ".\\savestates" -#define DEFAULT_SCREENSHOTS_DIR ".\\screenshots" - class AVIWrite; class WavWriter;