MINGW-packages/mingw-w64-supercollider/003-mingw-filesystem.patch
2025-08-04 20:32:21 +02:00

71 lines
2.2 KiB
Diff

diff --git a/common/SC_Filesystem_win.cpp b/common/SC_Filesystem_win.cpp
index 9873a05..62c4b02 100644
--- a/common/SC_Filesystem_win.cpp
+++ b/common/SC_Filesystem_win.cpp
@@ -33,7 +33,8 @@
# include <filesystem>
// system
-# include <Shlobj.h> // SHGetKnownFolderPath
+# include <shlobj.h> // SHGetKnownFolderPath
+# include <shlwapi.h> // PathRemoveFileSpec
using Path = SC_Filesystem::Path;
using DirName = SC_Filesystem::DirName;
@@ -124,21 +125,38 @@ bool SC_Filesystem::isNonHostPlatformDirectoryName(const std::string& s) {
}
Path SC_Filesystem::defaultSystemAppSupportDirectory() {
+#ifdef _MSC_VER
PWSTR wptr = nullptr;
const HRESULT hr = SHGetKnownFolderPath(FOLDERID_ProgramData, 0, nullptr, &wptr);
return FAILED(hr) ? Path() : Path(wptr) / SC_FOLDERNAME_APPLICATION_NAME;
+#else
+ WCHAR buf[MAX_PATH];
+ GetModuleFileNameW(nullptr, buf, MAX_PATH-1);
+ PathRemoveFileSpecW(buf);
+ return Path(buf).parent_path() / "share" / SC_FOLDERNAME_APPLICATION_NAME;
+#endif
}
Path SC_Filesystem::defaultUserHomeDirectory() {
+#ifdef _MSC_VER
PWSTR wptr = nullptr;
const HRESULT hr = SHGetKnownFolderPath(FOLDERID_Profile, 0, nullptr, &wptr);
return FAILED(hr) ? Path() : Path(wptr);
+#else
+ const char* home = getenv("HOME");
+ return Path(home);
+#endif
}
Path SC_Filesystem::defaultUserAppSupportDirectory() {
+#ifdef _MSC_VER
PWSTR wptr = nullptr;
const HRESULT hr = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &wptr);
return FAILED(hr) ? Path() : Path(wptr) / SC_FOLDERNAME_APPLICATION_NAME;
+#else
+ const char* home = getenv("HOME");
+ return Path(home) / "supercollider";
+#endif
}
Path SC_Filesystem::defaultUserConfigDirectory() { return defaultUserAppSupportDirectory(); }
@@ -150,9 +168,16 @@ Path SC_Filesystem::defaultMyDocumentsDirectory() {
}
Path SC_Filesystem::defaultResourceDirectory() {
+#ifdef _MSC_VER
WCHAR buf[MAX_PATH];
GetModuleFileNameW(nullptr, buf, MAX_PATH);
return Path(buf).parent_path();
+#else
+ WCHAR buf[MAX_PATH];
+ GetModuleFileNameW(nullptr, buf, MAX_PATH-1);
+ PathRemoveFileSpecW(buf);
+ return Path(buf).parent_path() / "share" / SC_FOLDERNAME_APPLICATION_NAME;
+#endif
}
#endif // _WIN32