From 16e4f4cfe2566a69667dac18568cc026323dcdc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= Date: Tue, 5 Apr 2022 06:27:45 +0300 Subject: [PATCH 1/1] Windows: Directory for temporary files --- src/app.c | 5 ++++- src/win32.c | 16 ++++++++++++++++ src/win32.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/app.c b/src/app.c index 2b256025..1c782173 100644 --- a/src/app.c +++ b/src/app.c @@ -1277,7 +1277,10 @@ const iString *downloadPathForUrl_App(const iString *url, const iString *mime) { const iString *temporaryPathForUrl_App(const iString *url, const iString *mime) { iApp *d = &app_; -#if defined (P_tmpdir) +#if defined (iPlatformMsys) + iString * tmpPath = collectNew_String(); + const iRangecc tmpDir = range_String(collect_String(tempDirectory_Win32())); +#elif defined (P_tmpdir) iString * tmpPath = collectNew_String(); const iRangecc tmpDir = range_CStr(P_tmpdir); #else diff --git a/src/win32.c b/src/win32.c index f5aba1ed..287c11e9 100644 --- a/src/win32.c +++ b/src/win32.c @@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "prefs.h" #include "app.h" +#include #include #include @@ -245,6 +246,21 @@ iString *windowsDirectory_Win32(void) { return newUtf16_String(winDir); } +iString *tempDirectory_Win32(void) { + /* Calling GetTempPathW would just return C:\WINDOWS? A local config issue? */ + WCHAR buf[32768]; + if (GetEnvironmentVariableW(L"TMP", buf, sizeof(buf))) { + return newUtf16_String(buf); + } + if (GetEnvironmentVariableW(L"TEMP", buf, sizeof(buf))) { + return newUtf16_String(buf); + } + if (GetEnvironmentVariableW(L"USERPROFILE", buf, sizeof(buf))) { + return concatCStr_Path(collect_String(newUtf16_String(buf)), "AppData\\Local\\Temp"); + } + return concatCStr_Path(collect_String(windowsDirectory_Win32()), "Temp"); +} + void useExecutableIconResource_SDLWindow(SDL_Window *win) { HINSTANCE handle = GetModuleHandle(NULL); HICON icon = LoadIcon(handle, "IDI_ICON1"); diff --git a/src/win32.h b/src/win32.h index 1732f305..6e7882a9 100644 --- a/src/win32.h +++ b/src/win32.h @@ -35,6 +35,7 @@ void useExecutableIconResource_SDLWindow(SDL_Window *); void enableDarkMode_SDLWindow(SDL_Window *); void handleCommand_Win32(const char *cmd); iString *windowsDirectory_Win32(void); +iString *tempDirectory_Win32(void); #if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) iInt2 cursor_Win32(void); -- 2.34.1