Set default directories "battery" and "savestates".
Code cleanup. Automatically & silently create directories in a relative path. git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@774 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
parent
00163834e1
commit
83a3996168
|
@ -23,9 +23,6 @@
|
||||||
#include "Reg.h"
|
#include "Reg.h"
|
||||||
#include "WinResUtil.h"
|
#include "WinResUtil.h"
|
||||||
|
|
||||||
#include <shlobj.h>
|
|
||||||
#include <shlwapi.h>
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define new DEBUG_NEW
|
#define new DEBUG_NEW
|
||||||
#undef THIS_FILE
|
#undef THIS_FILE
|
||||||
|
@ -97,11 +94,11 @@ BOOL Directories::OnInitDialog()
|
||||||
if(!p.IsEmpty())
|
if(!p.IsEmpty())
|
||||||
GetDlgItem(IDC_GBROM_PATH)->SetWindowText(p);
|
GetDlgItem(IDC_GBROM_PATH)->SetWindowText(p);
|
||||||
|
|
||||||
p = regQueryStringValue("batteryDir", NULL);
|
p = regQueryStringValue("batteryDir", DEFAULT_BATTERY_DIR);
|
||||||
if(!p.IsEmpty())
|
if(!p.IsEmpty())
|
||||||
GetDlgItem(IDC_BATTERY_PATH)->SetWindowText( p);
|
GetDlgItem(IDC_BATTERY_PATH)->SetWindowText( p);
|
||||||
|
|
||||||
p = regQueryStringValue("saveDir", NULL);
|
p = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR);
|
||||||
if(!p.IsEmpty())
|
if(!p.IsEmpty())
|
||||||
GetDlgItem(IDC_SAVE_PATH)->SetWindowText(p);
|
GetDlgItem(IDC_SAVE_PATH)->SetWindowText(p);
|
||||||
|
|
||||||
|
@ -171,86 +168,37 @@ void Directories::OnOK()
|
||||||
{
|
{
|
||||||
CDialog::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;
|
CString buffer;
|
||||||
|
|
||||||
m_romPath.GetWindowText(buffer);
|
m_romPath.GetWindowText(buffer);
|
||||||
if( !buffer.IsEmpty() )
|
if( !buffer.IsEmpty() )
|
||||||
regSetStringValue( "romdir", buffer );
|
regSetStringValue( "romdir", buffer );
|
||||||
if( buffer[0] == '.' ) {
|
treatRelativePath( buffer );
|
||||||
strcpy( temp, baseDir );
|
|
||||||
strcat( temp, "\\" );
|
|
||||||
strcat( temp, buffer );
|
|
||||||
buffer = temp;
|
|
||||||
}
|
|
||||||
if( !directoryDoesExist( buffer ) )
|
|
||||||
SHCreateDirectoryEx( NULL, buffer, NULL );
|
|
||||||
|
|
||||||
m_gbcromPath.GetWindowText(buffer);
|
m_gbcromPath.GetWindowText(buffer);
|
||||||
if( !buffer.IsEmpty() )
|
if( !buffer.IsEmpty() )
|
||||||
regSetStringValue( "gbcromdir", buffer );
|
regSetStringValue( "gbcromdir", buffer );
|
||||||
if( buffer[0] == '.' ) {
|
treatRelativePath( buffer );
|
||||||
strcpy( temp, baseDir );
|
|
||||||
strcat( temp, "\\" );
|
|
||||||
strcat( temp, buffer );
|
|
||||||
buffer = temp;
|
|
||||||
}
|
|
||||||
if( !directoryDoesExist( buffer ) )
|
|
||||||
SHCreateDirectoryEx( NULL, buffer, NULL );
|
|
||||||
|
|
||||||
m_gbromPath.GetWindowText(buffer);
|
m_gbromPath.GetWindowText(buffer);
|
||||||
if( !buffer.IsEmpty() )
|
if( !buffer.IsEmpty() )
|
||||||
regSetStringValue( "gbromdir", buffer );
|
regSetStringValue( "gbromdir", buffer );
|
||||||
if( buffer[0] == '.' ) {
|
treatRelativePath( buffer );
|
||||||
strcpy( temp, baseDir );
|
|
||||||
strcat( temp, "\\" );
|
|
||||||
strcat( temp, buffer );
|
|
||||||
buffer = temp;
|
|
||||||
}
|
|
||||||
if( !directoryDoesExist( buffer ) )
|
|
||||||
SHCreateDirectoryEx( NULL, buffer, NULL );
|
|
||||||
|
|
||||||
m_batteryPath.GetWindowText(buffer);
|
m_batteryPath.GetWindowText(buffer);
|
||||||
if( !buffer.IsEmpty() )
|
if( !buffer.IsEmpty() )
|
||||||
regSetStringValue( "batteryDir", buffer );
|
regSetStringValue( "batteryDir", buffer );
|
||||||
if( buffer[0] == '.' ) {
|
treatRelativePath( buffer );
|
||||||
strcpy( temp, baseDir );
|
|
||||||
strcat( temp, "\\" );
|
|
||||||
strcat( temp, buffer );
|
|
||||||
buffer = temp;
|
|
||||||
}
|
|
||||||
if( !directoryDoesExist( buffer ) )
|
|
||||||
SHCreateDirectoryEx( NULL, buffer, NULL );
|
|
||||||
|
|
||||||
m_savePath.GetWindowText(buffer);
|
m_savePath.GetWindowText(buffer);
|
||||||
if( !buffer.IsEmpty() )
|
if( !buffer.IsEmpty() )
|
||||||
regSetStringValue( "saveDir", buffer );
|
regSetStringValue( "saveDir", buffer );
|
||||||
if( buffer[0] == '.' ) {
|
treatRelativePath( buffer );
|
||||||
strcpy( temp, baseDir );
|
|
||||||
strcat( temp, "\\" );
|
|
||||||
strcat( temp, buffer );
|
|
||||||
buffer = temp;
|
|
||||||
}
|
|
||||||
if( !directoryDoesExist( buffer ) )
|
|
||||||
SHCreateDirectoryEx( NULL, buffer, NULL );
|
|
||||||
|
|
||||||
m_capturePath.GetWindowText(buffer);
|
m_capturePath.GetWindowText(buffer);
|
||||||
if( !buffer.IsEmpty() )
|
if( !buffer.IsEmpty() )
|
||||||
regSetStringValue( "captureDir", buffer );
|
regSetStringValue( "captureDir", buffer );
|
||||||
if( buffer[0] == '.' ) {
|
treatRelativePath( buffer );
|
||||||
strcpy( temp, baseDir );
|
|
||||||
strcat( temp, "\\" );
|
|
||||||
strcat( temp, buffer );
|
|
||||||
buffer = temp;
|
|
||||||
}
|
|
||||||
if( !directoryDoesExist( buffer ) )
|
|
||||||
SHCreateDirectoryEx( NULL, buffer, NULL );
|
|
||||||
|
|
||||||
EndDialog(TRUE);
|
EndDialog(TRUE);
|
||||||
}
|
}
|
||||||
|
@ -285,20 +233,3 @@ CString Directories::browseForDir(CString title)
|
||||||
}
|
}
|
||||||
return res;
|
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -50,5 +50,4 @@ private:
|
||||||
CString initialFolderDir;
|
CString initialFolderDir;
|
||||||
|
|
||||||
CString browseForDir(CString title);
|
CString browseForDir(CString title);
|
||||||
bool directoryDoesExist(const char *directory);
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -189,7 +189,7 @@ int FileDlg::getFilterIndex()
|
||||||
int FileDlg::DoModal()
|
int FileDlg::DoModal()
|
||||||
{
|
{
|
||||||
BOOL res = isSave ? GetSaveFileName(&m_ofn) :
|
BOOL res = isSave ? GetSaveFileName(&m_ofn) :
|
||||||
GetOpenFileName(&m_ofn);
|
GetOpenFileName(&m_ofn);
|
||||||
|
|
||||||
return res ? IDOK : IDCANCEL;
|
return res ? IDOK : IDCANCEL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#include "MainWnd.h"
|
#include "MainWnd.h"
|
||||||
|
|
||||||
#include <winsock.h>
|
#include <winsock.h>
|
||||||
#include <shlwapi.h>
|
|
||||||
|
|
||||||
#include "FileDlg.h"
|
#include "FileDlg.h"
|
||||||
#include "Reg.h"
|
#include "Reg.h"
|
||||||
|
@ -818,17 +817,8 @@ void MainWnd::winSaveCheatListDefault()
|
||||||
name = theApp.filename.Right(theApp.filename.GetLength()-index-1);
|
name = theApp.filename.Right(theApp.filename.GetLength()-index-1);
|
||||||
else
|
else
|
||||||
name = theApp.filename;
|
name = theApp.filename;
|
||||||
CString dir = regQueryStringValue("saveDir", NULL);
|
CString dir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR);
|
||||||
if( dir[0] == '.' ) {
|
treatRelativePath( dir );
|
||||||
// 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())
|
if(!dir.GetLength())
|
||||||
dir = getDirFromFile(filename);
|
dir = getDirFromFile(filename);
|
||||||
|
@ -860,17 +850,8 @@ void MainWnd::winLoadCheatListDefault()
|
||||||
name = theApp.filename.Right(theApp.filename.GetLength()-index-1);
|
name = theApp.filename.Right(theApp.filename.GetLength()-index-1);
|
||||||
else
|
else
|
||||||
name = theApp.filename;
|
name = theApp.filename;
|
||||||
CString dir = regQueryStringValue("saveDir", NULL);
|
CString dir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR);
|
||||||
if( dir[0] == '.' ) {
|
treatRelativePath( dir );
|
||||||
// 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())
|
if(!dir.GetLength())
|
||||||
dir = getDirFromFile(filename);
|
dir = getDirFromFile(filename);
|
||||||
|
@ -932,17 +913,8 @@ void MainWnd::writeBatteryFile()
|
||||||
else
|
else
|
||||||
buffer = theApp.filename;
|
buffer = theApp.filename;
|
||||||
|
|
||||||
CString saveDir = regQueryStringValue("batteryDir", NULL);
|
CString saveDir = regQueryStringValue("batteryDir", DEFAULT_BATTERY_DIR);
|
||||||
if( saveDir[0] == '.' ) {
|
treatRelativePath( saveDir );
|
||||||
// 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())
|
if(saveDir.IsEmpty())
|
||||||
saveDir = getDirFromFile(theApp.filename);
|
saveDir = getDirFromFile(theApp.filename);
|
||||||
|
@ -969,17 +941,8 @@ void MainWnd::readBatteryFile()
|
||||||
else
|
else
|
||||||
buffer = theApp.filename;
|
buffer = theApp.filename;
|
||||||
|
|
||||||
CString saveDir = regQueryStringValue("batteryDir", NULL);
|
CString saveDir = regQueryStringValue("batteryDir", DEFAULT_BATTERY_DIR);
|
||||||
if( saveDir[0] == '.' ) {
|
treatRelativePath( saveDir );
|
||||||
// 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())
|
if(saveDir.IsEmpty())
|
||||||
saveDir = getDirFromFile(theApp.filename);
|
saveDir = getDirFromFile(theApp.filename);
|
||||||
|
@ -1069,16 +1032,7 @@ bool MainWnd::fileOpenSelect( int system )
|
||||||
theApp.dir = initialDir;
|
theApp.dir = initialDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( initialDir[0] == '.' ) {
|
treatRelativePath( initialDir );
|
||||||
// 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("");
|
theApp.szFile = _T("");
|
||||||
|
|
||||||
|
@ -1130,16 +1084,8 @@ void MainWnd::screenCapture(int captureNumber)
|
||||||
CString buffer;
|
CString buffer;
|
||||||
|
|
||||||
CString captureDir = regQueryStringValue("captureDir", "");
|
CString captureDir = regQueryStringValue("captureDir", "");
|
||||||
if( captureDir[0] == '.' ) {
|
treatRelativePath( captureDir );
|
||||||
// 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('\\');
|
int index = theApp.filename.ReverseFind('\\');
|
||||||
|
|
||||||
CString name;
|
CString name;
|
||||||
|
|
|
@ -85,7 +85,7 @@ void MainWnd::OnCheatsLoadcheatlist()
|
||||||
else
|
else
|
||||||
buffer = theApp.filename;
|
buffer = theApp.filename;
|
||||||
|
|
||||||
CString saveDir = regQueryStringValue("saveDir", NULL);
|
CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR);
|
||||||
|
|
||||||
if(saveDir.IsEmpty())
|
if(saveDir.IsEmpty())
|
||||||
saveDir = getDirFromFile(theApp.filename);
|
saveDir = getDirFromFile(theApp.filename);
|
||||||
|
@ -123,7 +123,7 @@ void MainWnd::OnCheatsSavecheatlist()
|
||||||
else
|
else
|
||||||
buffer = theApp.filename;
|
buffer = theApp.filename;
|
||||||
|
|
||||||
CString saveDir = regQueryStringValue("saveDir", NULL);
|
CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR);
|
||||||
|
|
||||||
if(saveDir.IsEmpty())
|
if(saveDir.IsEmpty())
|
||||||
saveDir = getDirFromFile(theApp.filename);
|
saveDir = getDirFromFile(theApp.filename);
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "MainWnd.h"
|
#include "MainWnd.h"
|
||||||
|
|
||||||
#include <shlwapi.h>
|
|
||||||
|
|
||||||
#include "ExportGSASnapshot.h"
|
#include "ExportGSASnapshot.h"
|
||||||
#include "FileDlg.h"
|
#include "FileDlg.h"
|
||||||
#include "GSACodeSelect.h"
|
#include "GSACodeSelect.h"
|
||||||
|
@ -193,17 +191,8 @@ void MainWnd::OnFileLoad()
|
||||||
else
|
else
|
||||||
buffer = theApp.filename;
|
buffer = theApp.filename;
|
||||||
|
|
||||||
CString saveDir = regQueryStringValue("saveDir", NULL);
|
CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR);
|
||||||
if( saveDir[0] == '.' ) {
|
treatRelativePath( saveDir );
|
||||||
// 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())
|
if(saveDir.IsEmpty())
|
||||||
saveDir = getDirFromFile(theApp.filename);
|
saveDir = getDirFromFile(theApp.filename);
|
||||||
|
@ -250,17 +239,8 @@ BOOL MainWnd::OnFileLoadSlot(UINT nID)
|
||||||
else
|
else
|
||||||
buffer = theApp.filename;
|
buffer = theApp.filename;
|
||||||
|
|
||||||
CString saveDir = regQueryStringValue("saveDir", NULL);
|
CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR);
|
||||||
if( saveDir[0] == '.' ) {
|
treatRelativePath( saveDir );
|
||||||
// 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())
|
if(saveDir.IsEmpty())
|
||||||
saveDir = getDirFromFile(theApp.filename);
|
saveDir = getDirFromFile(theApp.filename);
|
||||||
|
@ -301,17 +281,8 @@ void MainWnd::OnFileSave()
|
||||||
else
|
else
|
||||||
buffer = theApp.filename;
|
buffer = theApp.filename;
|
||||||
|
|
||||||
CString saveDir = regQueryStringValue("saveDir", NULL);
|
CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR);
|
||||||
if( saveDir[0] == '.' ) {
|
treatRelativePath( saveDir );
|
||||||
// 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())
|
if(saveDir.IsEmpty())
|
||||||
saveDir = getDirFromFile(theApp.filename);
|
saveDir = getDirFromFile(theApp.filename);
|
||||||
|
@ -353,17 +324,8 @@ BOOL MainWnd::OnFileSaveSlot(UINT nID)
|
||||||
else
|
else
|
||||||
buffer = theApp.filename;
|
buffer = theApp.filename;
|
||||||
|
|
||||||
CString saveDir = regQueryStringValue("saveDir", NULL);
|
CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR);
|
||||||
if( saveDir[0] == '.' ) {
|
treatRelativePath( saveDir );
|
||||||
// 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())
|
if(saveDir.IsEmpty())
|
||||||
saveDir = getDirFromFile(theApp.filename);
|
saveDir = getDirFromFile(theApp.filename);
|
||||||
|
@ -391,17 +353,8 @@ void MainWnd::OnFileImportBatteryfile()
|
||||||
CString filter = winLoadFilter(IDS_FILTER_SAV);
|
CString filter = winLoadFilter(IDS_FILTER_SAV);
|
||||||
CString title = winResLoadString(IDS_SELECT_BATTERY_FILE);
|
CString title = winResLoadString(IDS_SELECT_BATTERY_FILE);
|
||||||
|
|
||||||
CString saveDir = regQueryStringValue("batteryDir", NULL);
|
CString saveDir = regQueryStringValue("batteryDir", DEFAULT_BATTERY_DIR);
|
||||||
if( saveDir[0] == '.' ) {
|
treatRelativePath( saveDir );
|
||||||
// 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())
|
if(saveDir.IsEmpty())
|
||||||
saveDir = getDirFromFile(theApp.filename);
|
saveDir = getDirFromFile(theApp.filename);
|
||||||
|
@ -515,17 +468,8 @@ void MainWnd::OnFileExportBatteryfile()
|
||||||
CString filter = winLoadFilter(IDS_FILTER_SAV);
|
CString filter = winLoadFilter(IDS_FILTER_SAV);
|
||||||
CString title = winResLoadString(IDS_SELECT_BATTERY_FILE);
|
CString title = winResLoadString(IDS_SELECT_BATTERY_FILE);
|
||||||
|
|
||||||
CString saveDir = regQueryStringValue("batteryDir", NULL);
|
CString saveDir = regQueryStringValue("batteryDir", DEFAULT_BATTERY_DIR);
|
||||||
if( saveDir[0] == '.' ) {
|
treatRelativePath( saveDir );
|
||||||
// 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())
|
if(saveDir.IsEmpty())
|
||||||
saveDir = getDirFromFile(theApp.filename);
|
saveDir = getDirFromFile(theApp.filename);
|
||||||
|
@ -621,16 +565,8 @@ void MainWnd::OnFileScreencapture()
|
||||||
name = theApp.filename;
|
name = theApp.filename;
|
||||||
|
|
||||||
CString capdir = regQueryStringValue("captureDir", "");
|
CString capdir = regQueryStringValue("captureDir", "");
|
||||||
if( capdir[0] == '.' ) {
|
treatRelativePath( capdir );
|
||||||
// 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())
|
if(capdir.IsEmpty())
|
||||||
capdir = getDirFromFile(theApp.filename);
|
capdir = getDirFromFile(theApp.filename);
|
||||||
|
|
||||||
|
@ -775,17 +711,8 @@ void MainWnd::OnFileSavegameOldestslot()
|
||||||
else
|
else
|
||||||
filename = theApp.filename;
|
filename = theApp.filename;
|
||||||
|
|
||||||
CString saveDir = regQueryStringValue("saveDir", NULL);
|
CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR);
|
||||||
if( saveDir[0] == '.' ) {
|
treatRelativePath( saveDir );
|
||||||
// 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())
|
if(saveDir.IsEmpty())
|
||||||
saveDir = getDirFromFile(theApp.filename);
|
saveDir = getDirFromFile(theApp.filename);
|
||||||
|
@ -829,17 +756,8 @@ void MainWnd::OnUpdateFileSavegameOldestslot(CCmdUI* pCmdUI)
|
||||||
else
|
else
|
||||||
filename = theApp.filename;
|
filename = theApp.filename;
|
||||||
|
|
||||||
CString saveDir = regQueryStringValue("saveDir", NULL);
|
CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR);
|
||||||
if( saveDir[0] == '.' ) {
|
treatRelativePath( saveDir );
|
||||||
// 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())
|
if(saveDir.IsEmpty())
|
||||||
saveDir = getDirFromFile(theApp.filename);
|
saveDir = getDirFromFile(theApp.filename);
|
||||||
|
@ -881,17 +799,8 @@ void MainWnd::OnFileLoadgameMostrecent()
|
||||||
else
|
else
|
||||||
filename = theApp.filename;
|
filename = theApp.filename;
|
||||||
|
|
||||||
CString saveDir = regQueryStringValue("saveDir", NULL);
|
CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR);
|
||||||
if( saveDir[0] == '.' ) {
|
treatRelativePath( saveDir );
|
||||||
// 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())
|
if(saveDir.IsEmpty())
|
||||||
saveDir = getDirFromFile(theApp.filename);
|
saveDir = getDirFromFile(theApp.filename);
|
||||||
|
@ -935,17 +844,8 @@ void MainWnd::OnUpdateFileLoadgameMostrecent(CCmdUI* pCmdUI)
|
||||||
else
|
else
|
||||||
filename = theApp.filename;
|
filename = theApp.filename;
|
||||||
|
|
||||||
CString saveDir = regQueryStringValue("saveDir", NULL);
|
CString saveDir = regQueryStringValue("saveDir", DEFAULT_SAVESTATES_DIR);
|
||||||
if( saveDir[0] == '.' ) {
|
treatRelativePath( saveDir );
|
||||||
// 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())
|
if(saveDir.IsEmpty())
|
||||||
saveDir = getDirFromFile(theApp.filename);
|
saveDir = getDirFromFile(theApp.filename);
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
|
#include <shlobj.h> // for SHCreateDirectoryEx
|
||||||
|
|
||||||
#include "AVIWrite.h"
|
#include "AVIWrite.h"
|
||||||
#include "LangSelect.h"
|
#include "LangSelect.h"
|
||||||
|
@ -2780,3 +2781,34 @@ 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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -64,6 +64,9 @@ enum pixelFilterType
|
||||||
|
|
||||||
#define REWIND_SIZE 400000
|
#define REWIND_SIZE 400000
|
||||||
|
|
||||||
|
#define DEFAULT_BATTERY_DIR ".\\battery"
|
||||||
|
#define DEFAULT_SAVESTATES_DIR ".\\savestates"
|
||||||
|
|
||||||
class AVIWrite;
|
class AVIWrite;
|
||||||
class WavWriter;
|
class WavWriter;
|
||||||
|
|
||||||
|
@ -284,3 +287,5 @@ extern int emulating;
|
||||||
#ifdef MMX
|
#ifdef MMX
|
||||||
extern "C" bool cpu_mmx;
|
extern "C" bool cpu_mmx;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void treatRelativePath( CString & path );
|
||||||
|
|
Loading…
Reference in New Issue