This commit is contained in:
parent
6c75bd7d4a
commit
67f3dfd8ce
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -30,4 +30,5 @@ private:
|
|||
CString initialFolderDir;
|
||||
|
||||
CString browseForDir(CString title);
|
||||
bool directoryDoesExist(const char *directory);
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -30,9 +30,6 @@ public:
|
|||
void winSaveCheatList(const char *name);
|
||||
void winSaveCheatListDefault();
|
||||
|
||||
private:
|
||||
bool fileExists( LPCTSTR lpFileName );
|
||||
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -262,5 +262,3 @@ class VBA : public CWinApp
|
|||
#ifdef MMX
|
||||
extern "C" bool cpu_mmx;
|
||||
#endif
|
||||
|
||||
void treatRelativePath( CString & path );
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue