diff --git a/desmume/src/firmware.cpp b/desmume/src/firmware.cpp index 3fba948a1..94f3e9ca2 100644 --- a/desmume/src/firmware.cpp +++ b/desmume/src/firmware.cpp @@ -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; } diff --git a/desmume/src/frontend/windows/importSave.cpp b/desmume/src/frontend/windows/importSave.cpp index f79db1d4a..afd1ccc88 100644 --- a/desmume/src/frontend/windows/importSave.cpp +++ b/desmume/src/frontend/windows/importSave.cpp @@ -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; diff --git a/desmume/src/frontend/windows/main.cpp b/desmume/src/frontend/windows/main.cpp index 96e7818e7..c400d258b 100755 --- a/desmume/src/frontend/windows/main.cpp +++ b/desmume/src/frontend/windows/main.cpp @@ -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)) { diff --git a/desmume/src/path.cpp b/desmume/src/path.cpp index b31117539..3beeee4e9 100644 --- a/desmume/src/path.cpp +++ b/desmume/src/path.cpp @@ -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); diff --git a/desmume/src/path.h b/desmume/src/path.h index bea561432..275730028 100644 --- a/desmume/src/path.h +++ b/desmume/src/path.h @@ -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);