diff --git a/src/common/platform/posix/cocoa/i_system.mm b/src/common/platform/posix/cocoa/i_system.mm index 6d50e718d..e67ffe0a0 100644 --- a/src/common/platform/posix/cocoa/i_system.mm +++ b/src/common/platform/posix/cocoa/i_system.mm @@ -186,20 +186,3 @@ void I_OpenShellFolder(const char* folder) chdir(curdir); } -void I_OpenShellFile(const char* file) -{ - char curdir[256]; - if (!getcwd (curdir, countof(curdir))) - { - Printf ("Current path too long\n"); - return; - } - - std::string folder = file; - folder.erase(folder.find_last_of('/'), std::string::npos); - chdir(folder.c_str()); - Printf("Opening folder: %s\n", folder.c_str()); - std::system("open ."); - chdir(curdir); -} - diff --git a/src/common/platform/posix/i_system.h b/src/common/platform/posix/i_system.h index 48c56956e..fdba79add 100644 --- a/src/common/platform/posix/i_system.h +++ b/src/common/platform/posix/i_system.h @@ -70,6 +70,5 @@ inline int I_GetNumaNodeThreadCount(int numaNode) { return std::max(std::th inline void I_SetThreadNumaNode(std::thread &thread, int numaNode) { } void I_OpenShellFolder(const char*); -void I_OpenShellFile(const char*); #endif diff --git a/src/common/platform/posix/sdl/i_system.cpp b/src/common/platform/posix/sdl/i_system.cpp index 68b6bd12d..0697d1140 100644 --- a/src/common/platform/posix/sdl/i_system.cpp +++ b/src/common/platform/posix/sdl/i_system.cpp @@ -447,20 +447,3 @@ void I_OpenShellFolder(const char* folder) chdir(curdir); } -void I_OpenShellFile(const char* file) -{ - char curdir[256]; - if (!getcwd (curdir, countof(curdir))) - { - Printf ("Current path too long\n"); - return; - } - - std::string folder = file; - folder.erase(folder.find_last_of('/'), std::string::npos); - chdir(folder.c_str()); - Printf("Opening folder: %s\n", folder.c_str()); - std::system("xdg-open ."); - chdir(curdir); -} - diff --git a/src/common/platform/win32/i_system.cpp b/src/common/platform/win32/i_system.cpp index 120f9818c..cc31739a5 100644 --- a/src/common/platform/win32/i_system.cpp +++ b/src/common/platform/win32/i_system.cpp @@ -963,47 +963,21 @@ void I_SetThreadNumaNode(std::thread &thread, int numaNode) void I_OpenShellFolder(const char* infolder) { - LPWSTR curdir = new wchar_t[MAX_PATH]; - if (!GetCurrentDirectoryW(MAX_PATH, curdir)) + auto len = GetCurrentDirectoryW(0, nullptr); + TArray curdir(len + 1, true); + if (!GetCurrentDirectoryW(len + 1, curdir.Data())) { - Printf ("Current path too long\n"); - return; + Printf("Unable to retrieve current directory\n"); } - std::wstring_convert> converter; - std::wstring folder = converter.from_bytes(infolder); - SetCurrentDirectoryW(folder.c_str()); - Printf("Opening folder: %s\n", infolder); - ShellExecuteW(NULL, L"open", L"explorer.exe", L".", NULL, SW_SHOWNORMAL); - SetCurrentDirectoryW(curdir); - delete curdir; -} - -void I_OpenShellFile(const char* file) -{ - LPWSTR curdir = new wchar_t[MAX_PATH]; - if (!GetCurrentDirectoryW(MAX_PATH, curdir)) + else if (SetCurrentDirectoryW(WideString(infolder).c_str())) { - Printf ("Current path too long\n"); - return; + Printf("Opening folder: %s\n", infolder); + ShellExecuteW(NULL, L"open", L"explorer.exe", L".", NULL, SW_SHOWNORMAL); + SetCurrentDirectoryW(curdir.Data()); } - - std::string infolder = file; - std::string toreplace = "\\"; - std::string replacewith = "/"; - std::size_t pos = infolder.find(toreplace); - while(pos != std::string::npos) + else { - infolder.replace(pos, toreplace.length(), replacewith); - pos = infolder.find(toreplace); + Printf("Unable to open directory '%s\n", infolder); } - infolder.erase(infolder.find_last_of('/'), std::string::npos); - - std::wstring_convert> converter; - std::wstring folder = converter.from_bytes(infolder); - SetCurrentDirectoryW(folder.c_str()); - Printf("Opening folder: %s\n", infolder.c_str()); - ShellExecuteW(NULL, L"open", L"explorer.exe", L".", NULL, SW_SHOWNORMAL); - SetCurrentDirectoryW(curdir); - delete curdir; } diff --git a/src/common/platform/win32/i_system.h b/src/common/platform/win32/i_system.h index 277bcca57..441a0d3fd 100644 --- a/src/common/platform/win32/i_system.h +++ b/src/common/platform/win32/i_system.h @@ -80,6 +80,5 @@ int I_GetNumaNodeThreadCount(int numaNode); void I_SetThreadNumaNode(std::thread &thread, int numaNode); void I_OpenShellFolder(const char*); -void I_OpenShellFile(const char*); #endif diff --git a/src/m_misc.cpp b/src/m_misc.cpp index bbe4e1207..11001255e 100644 --- a/src/m_misc.cpp +++ b/src/m_misc.cpp @@ -316,7 +316,7 @@ UNSAFE_CCMD (writeini) CCMD(openconfig) { M_SaveDefaults(nullptr); - I_OpenShellFile(GameConfig->GetPathName()); + I_OpenShellFolder(ExtractFilePath(GameConfig->GetPathName())); } //