diff --git a/src/win32/Directories.cpp b/src/win32/Directories.cpp index 3563ea64..eb7bc72f 100644 --- a/src/win32/Directories.cpp +++ b/src/win32/Directories.cpp @@ -149,37 +149,86 @@ void Directories::OnOK() { CDialog::OnOK(); + char baseDir[MAX_PATH+1]; + char temp[MAX_PATH+1]; + GetModuleFileName( NULL, baseDir, MAX_PATH ); + baseDir[MAX_PATH] = '\0'; // for security reasons + PathRemoveFileSpec( baseDir ); // removes the trailing file name and backslash + + CString buffer; m_romPath.GetWindowText(buffer); if( !buffer.IsEmpty() ) regSetStringValue( "romdir", buffer ); - treatRelativePath( buffer ); + if( buffer[0] == '.' ) { + strcpy( temp, baseDir ); + strcat( temp, "\\" ); + strcat( temp, buffer ); + buffer = temp; + } + if( !directoryDoesExist( buffer ) ) + SHCreateDirectoryEx( NULL, buffer, NULL ); m_gbcromPath.GetWindowText(buffer); if( !buffer.IsEmpty() ) regSetStringValue( "gbcromdir", buffer ); - treatRelativePath( buffer ); + if( buffer[0] == '.' ) { + strcpy( temp, baseDir ); + strcat( temp, "\\" ); + strcat( temp, buffer ); + buffer = temp; + } + if( !directoryDoesExist( buffer ) ) + SHCreateDirectoryEx( NULL, buffer, NULL ); m_gbromPath.GetWindowText(buffer); if( !buffer.IsEmpty() ) regSetStringValue( "gbromdir", buffer ); - treatRelativePath( buffer ); + if( buffer[0] == '.' ) { + strcpy( temp, baseDir ); + strcat( temp, "\\" ); + strcat( temp, buffer ); + buffer = temp; + } + if( !directoryDoesExist( buffer ) ) + SHCreateDirectoryEx( NULL, buffer, NULL ); m_batteryPath.GetWindowText(buffer); if( !buffer.IsEmpty() ) regSetStringValue( "batteryDir", buffer ); - treatRelativePath( buffer ); + if( buffer[0] == '.' ) { + strcpy( temp, baseDir ); + strcat( temp, "\\" ); + strcat( temp, buffer ); + buffer = temp; + } + if( !directoryDoesExist( buffer ) ) + SHCreateDirectoryEx( NULL, buffer, NULL ); m_savePath.GetWindowText(buffer); if( !buffer.IsEmpty() ) regSetStringValue( "saveDir", buffer ); - treatRelativePath( buffer ); + if( buffer[0] == '.' ) { + strcpy( temp, baseDir ); + strcat( temp, "\\" ); + strcat( temp, buffer ); + buffer = temp; + } + if( !directoryDoesExist( buffer ) ) + SHCreateDirectoryEx( NULL, buffer, NULL ); m_capturePath.GetWindowText(buffer); if( !buffer.IsEmpty() ) regSetStringValue( "captureDir", buffer ); - treatRelativePath( buffer ); + if( buffer[0] == '.' ) { + strcpy( temp, baseDir ); + strcat( temp, "\\" ); + strcat( temp, buffer ); + buffer = temp; + } + if( !directoryDoesExist( buffer ) ) + SHCreateDirectoryEx( NULL, buffer, NULL ); EndDialog(TRUE); } @@ -214,3 +263,20 @@ CString Directories::browseForDir(CString title) } return res; } + +// returns true if the directory does exist +bool Directories::directoryDoesExist(const char *directory) +{ + HANDLE hDir; + hDir = CreateFile( + directory, + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + NULL, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, + NULL ); + bool retval = (hDir == INVALID_HANDLE_VALUE) ? false : true; + CloseHandle( hDir ); + return retval; +} diff --git a/src/win32/Directories.h b/src/win32/Directories.h index 879a44c6..5cb8bc82 100644 --- a/src/win32/Directories.h +++ b/src/win32/Directories.h @@ -30,4 +30,5 @@ private: CString initialFolderDir; CString browseForDir(CString title); + bool directoryDoesExist(const char *directory); }; diff --git a/src/win32/MainWnd.cpp b/src/win32/MainWnd.cpp index 2b942273..19b6cc29 100644 --- a/src/win32/MainWnd.cpp +++ b/src/win32/MainWnd.cpp @@ -33,6 +33,7 @@ static char THIS_FILE[] = __FILE__; #endif extern void remoteCleanUp(); +extern int gbHardware; ///////////////////////////////////////////////////////////////////////////// // MainWnd @@ -47,12 +48,6 @@ MainWnd::~MainWnd() { } -bool MainWnd::fileExists( LPCTSTR lpFileName ) -{ - // check if file exists - return GetFileAttributes( lpFileName ) != INVALID_FILE_ATTRIBUTES; -} - BEGIN_MESSAGE_MAP(MainWnd, CWnd) //{{AFX_MSG_MAP(MainWnd) @@ -1022,7 +1017,16 @@ bool MainWnd::fileOpenSelect( int system ) theApp.dir = initialDir; } - treatRelativePath( initialDir ); + if( initialDir[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, initialDir ); + initialDir = baseDir; + } theApp.szFile = _T(""); @@ -1105,7 +1109,9 @@ void MainWnd::screenCapture(int captureNumber) captureNumber, ext); - if( fileExists( buffer ) ) { + // check if file exists + DWORD dwAttr = GetFileAttributes( buffer ); + if( dwAttr != INVALID_FILE_ATTRIBUTES ) { // screenshot file already exists screenCapture(++captureNumber); // this will recursively use the first non-existent screenshot number diff --git a/src/win32/MainWnd.h b/src/win32/MainWnd.h index b1fa8d8d..48b39998 100644 --- a/src/win32/MainWnd.h +++ b/src/win32/MainWnd.h @@ -30,9 +30,6 @@ public: void winSaveCheatList(const char *name); void winSaveCheatListDefault(); -private: - bool fileExists( LPCTSTR lpFileName ); - DECLARE_MESSAGE_MAP() diff --git a/src/win32/VBA.cpp b/src/win32/VBA.cpp index 6973e3d2..8716fe2e 100644 --- a/src/win32/VBA.cpp +++ b/src/win32/VBA.cpp @@ -2658,34 +2658,3 @@ void Sm60FPS_Sleep() } } } - - -void treatRelativePath( CString & path ) -{ - if( path.GetLength() > 1 ) { - if( path.GetAt( 0 ) == '.' ) { - // treat as relative path - char baseDir[MAX_PATH + 1]; - GetModuleFileName( NULL, baseDir, MAX_PATH ); - baseDir[MAX_PATH] = '\0'; // for security reasons - CString temp = baseDir; - int pos = temp.ReverseFind( '\\' ); - temp.Truncate( pos + 1 ); - path.Insert( 0, temp ); - - // create directories if path does not exist - SHCreateDirectoryEx( NULL, path, NULL ); - /* Spacy's implementation: - while( ERROR_PATH_NOT_FOUND == CreateDirectory( path, NULL ) ) { - temp = path; - while( ERROR_PATH_NOT_FOUND == CreateDirectory( temp, NULL ) ) { - pos = temp.ReverseFind( '\\' ); - ASSERT( pos != -1 ); - if( pos == -1 ) break; // something has gone wrong, abort - temp.Truncate( pos ); - } - } - */ - } - } -} diff --git a/src/win32/VBA.h b/src/win32/VBA.h index d6e5fe4e..3832f334 100644 --- a/src/win32/VBA.h +++ b/src/win32/VBA.h @@ -262,5 +262,3 @@ class VBA : public CWinApp #ifdef MMX extern "C" bool cpu_mmx; #endif - -void treatRelativePath( CString & path ); diff --git a/src/win32/resource.h b/src/win32/resource.h index 9b5a40ea..e295744a 100644 --- a/src/win32/resource.h +++ b/src/win32/resource.h @@ -50,7 +50,7 @@ #define IDS_TOOLTIP_ENHANCE_SOUND 43 #define IDS_TOOLTIP_SURROUND 44 #define IDS_TOOLTIP_DECLICKING 45 -#define IDS_FILTER_ALLROM 46 +#define IDS_FILTER_COMPRESSED_FILES 46 #define IDI_MAINICON 101 #define IDD_REGISTERS 102 #define IDD_DEBUG 103