Support type string in setpath, use new method in several places.

Make SwitchPath check for all directory delimiters when removing trailing delimiter, remove redundant trailing delimiter logic in CFIRMWARE::GetExternalFilePath().
This commit is contained in:
SuuperW 2018-09-04 12:14:02 -05:00
parent 524997e406
commit e2d83f99fe
5 changed files with 26 additions and 51 deletions

View File

@ -603,11 +603,9 @@ std::string CFIRMWARE::GetExternalFilePath()
{
std::string fwPath = CommonSettings.Firmware;
std::string fwFileName = Path::GetFileNameFromPathWithoutExt(fwPath);
char configPath[MAX_PATH] = {0};
path.getpath(path.BATTERY, configPath);
if (configPath[strlen(configPath)-1] == DIRECTORY_DELIMITER_CHAR)
configPath[strlen(configPath)-1] = 0;
std::string finalPath = std::string(configPath) + DIRECTORY_DELIMITER_CHAR + fwFileName + FILE_EXT_DELIMITER_CHAR + FW_CONFIG_FILE_EXT;
std::string configPath = path.getpath(path.BATTERY);
std::string finalPath = configPath + DIRECTORY_DELIMITER_CHAR + fwFileName + FILE_EXT_DELIMITER_CHAR + FW_CONFIG_FILE_EXT;
return finalPath;
}

View File

@ -178,11 +178,8 @@ bool importSave(HWND hwnd, HINSTANCE hAppInst)
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "sav";
ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
char buffer[MAX_PATH] = {0};
ZeroMemory(buffer, sizeof(buffer));
path.getpath(path.BATTERY, buffer);
ofn.lpstrInitialDir = buffer;
std::string dir = path.getpath(path.BATTERY);
ofn.lpstrInitialDir = dir.c_str();
if(!GetOpenFileName(&ofn))
return true;
@ -216,11 +213,8 @@ bool exportSave(HWND hwnd, HINSTANCE hAppInst)
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "sav";
ofn.Flags = OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
char buffer[MAX_PATH] = { 0 };
ZeroMemory(buffer, sizeof(buffer));
path.getpath(path.BATTERY, buffer);
ofn.lpstrInitialDir = buffer;
std::string dir = path.getpath(path.BATTERY);
ofn.lpstrInitialDir = dir.c_str();
if (!GetSaveFileName(&ofn))
return true;

View File

@ -3070,11 +3070,8 @@ LRESULT OpenFile()
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "nds";
ofn.Flags = OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
char buffer[MAX_PATH];
ZeroMemory(buffer, sizeof(buffer));
path.getpath(path.ROMS, buffer);
ofn.lpstrInitialDir = buffer;
std::string dir = path.getpath(path.ROMS);
ofn.lpstrInitialDir = dir.c_str();
if (GetOpenFileName(&ofn) == NULL)
{
@ -3085,14 +3082,9 @@ LRESULT OpenFile()
{
if(path.savelastromvisit)
{
char *lchr, buffer[MAX_PATH];
ZeroMemory(buffer, sizeof(buffer));
lchr = strrchr(filename, '\\');
strncpy(buffer, filename, strlen(filename) - strlen(lchr));
path.setpath(path.ROMS, buffer);
WritePathSettings();
std::string dir = Path::GetFileDirectoryPath(filename);
path.setpath(path.ROMS, dir);
WritePrivateProfileString(SECTION, ROMKEY, dir.c_str(), IniName);
}
}
@ -4660,11 +4652,8 @@ DOKEYDOWN:
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "dst";
ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
char buffer[MAX_PATH];
ZeroMemory(buffer, sizeof(buffer));
path.getpath(path.STATES, buffer);
ofn.lpstrInitialDir = buffer;
std::string dir = path.getpath(path.STATES);
ofn.lpstrInitialDir = dir.c_str();
if(!GetOpenFileName(&ofn))
{
@ -4690,11 +4679,8 @@ DOKEYDOWN:
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = "dst";
ofn.Flags = OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST;
char buffer[MAX_PATH];
ZeroMemory(buffer, sizeof(buffer));
path.getpath(path.STATES, buffer);
ofn.lpstrInitialDir = buffer;
std::string dir = path.getpath(path.STATES);
ofn.lpstrInitialDir = dir.c_str();
if(GetSaveFileName(&ofn))
{
@ -5967,11 +5953,8 @@ LRESULT CALLBACK EmulationSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, L
ofn.nMaxFile = 256;
ofn.lpstrDefExt = "bin";
ofn.Flags = OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
char buffer[MAX_PATH];
ZeroMemory(buffer, sizeof(buffer));
path.getpath(path.FIRMWARE, buffer);
ofn.lpstrInitialDir = buffer;
std::string dir = path.getpath(path.FIRMWARE);
ofn.lpstrInitialDir = dir.c_str();
if(GetOpenFileName(&ofn))
{
@ -6086,11 +6069,8 @@ LRESULT CALLBACK MicrophoneSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
ofn.nMaxFile = 256;
ofn.lpstrDefExt = "wav";
ofn.Flags = OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
char buffer[MAX_PATH];
ZeroMemory(buffer, sizeof(buffer));
path.getpath(path.SOUNDS, buffer);
ofn.lpstrInitialDir = buffer;
std::string dir = path.getpath(path.SOUNDS);
ofn.lpstrInitialDir = dir.c_str();
if(GetOpenFileName(&ofn))
{

View File

@ -344,7 +344,7 @@ void PathInfo::SwitchPath(Action action, KnownPath path, char *buffer)
else if (action == SET)
{
int len = strlen(buffer) - 1;
if (buffer[len] == DIRECTORY_DELIMITER_CHAR)
if (std::string(ALL_DIRECTORY_DELIMITER_STRING).find(buffer[len]) != std::string::npos)
buffer[len] = '\0';
strncpy(pathToCopy, buffer, MAX_PATH);
@ -357,12 +357,15 @@ std::string PathInfo::getpath(KnownPath path)
SwitchPath(GET, path, temp);
return temp;
}
void PathInfo::getpath(KnownPath path, char *buffer)
{
SwitchPath(GET, path, buffer);
}
void PathInfo::setpath(KnownPath path, std::string value)
{
SwitchPath(SET, path, (char*)value.c_str());
}
void PathInfo::setpath(KnownPath path, char *buffer)
{
SwitchPath(SET, path, buffer);

View File

@ -135,9 +135,9 @@ public:
void SwitchPath(Action action, KnownPath path, char *buffer);
std::string getpath(KnownPath path);
void getpath(KnownPath path, char *buffer);
void setpath(KnownPath path, std::string value);
void setpath(KnownPath path, char *buffer);
void getfilename(char *buffer, int maxCount);