From 9d8332d671343c528bcc6e41dc4ef15953578cdb Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 6 Apr 2021 15:09:48 -0400 Subject: [PATCH] winport - fix #441 (nonsense japanese directory creation on open rom file dialog and other cases probably) --- desmume/src/path.cpp | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/desmume/src/path.cpp b/desmume/src/path.cpp index babd51b99..2fcdaec5a 100644 --- a/desmume/src/path.cpp +++ b/desmume/src/path.cpp @@ -143,38 +143,29 @@ std::string Path::GetFileExt(std::string fileName) //----------------------------------- #ifdef HOST_WINDOWS -void FCEUD_MakePathDirs(const char *fname) +//https://stackoverflow.com/questions/1530760/how-do-i-recursively-create-a-folder-in-win32 +BOOL DirectoryExists(LPCTSTR szPath) { - char path[MAX_PATH]; - const char* div = fname; + DWORD dwAttrib = GetFileAttributes(szPath); + return (dwAttrib != INVALID_FILE_ATTRIBUTES && + (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); +} + +void createDirectoryRecursively(std::wstring path) +{ + signed int pos = 0; do { - const char* fptr = strchr(div, '\\'); + pos = path.find_first_of(L"\\/", pos + 1); + CreateDirectoryW(path.substr(0, pos).c_str(), NULL); + } while (pos != std::wstring::npos); +} - if(!fptr) - { - fptr = strchr(div, '/'); - } - if(!fptr) - { - break; - } - - int off = fptr - fname; - strncpy(path, fname, off); - path[off] = '\0'; - mkdir(path,0); - - div = fptr + 1; - - while(div[0] == '\\' || div[0] == '/') - { - div++; - } - - } while(1); +void FCEUD_MakePathDirs(const char *fname) +{ + createDirectoryRecursively(mbstowcs(fname)); } #endif //------------------------------