From 758e7e8df753a9b63782ff2964c26c0b0a4015fe Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Thu, 6 Dec 2018 14:33:51 -0500
Subject: [PATCH] SL-10174: LOCALAPPDATA bad? Try
 SHGetFolderPath(CSIDL_LOCAL_APPDATA).

This logic is essentially copy-and-edited from the same suspenders-and-belt
concerning APPDATA and CSIDL_APPDATA for SL-10153.
---
 indra/llvfs/lldir_win32.cpp | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/indra/llvfs/lldir_win32.cpp b/indra/llvfs/lldir_win32.cpp
index 3e48e086d7f..f972f27fd01 100644
--- a/indra/llvfs/lldir_win32.cpp
+++ b/indra/llvfs/lldir_win32.cpp
@@ -90,6 +90,19 @@ LLDir_Win32::LLDir_Win32()
 	// We used to store the cache in AppData\Roaming, and the installer
 	// cleans up that version on upgrade.  JC
 	mOSCacheDir = ll_safe_string(getenv("LOCALAPPDATA"));
+	// Windows really does not deal well with pathnames containing non-ASCII
+	// characters. See above remarks about APPDATA.
+	if (utf8string_to_wstring(mOSCacheDir).find(llwchar('?')) != LLWString::npos)
+	{
+		if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, w_str)))
+		{
+			// But of course, only update mOSCacheDir if SHGetFolderPathW() works.
+			mOSCacheDir = utf16str_to_utf8str(llutf16string(w_str));
+			// Update our environment so that child processes will see a
+			// reasonable value as well.
+			_putenv_s("LOCALAPPDATA", mOSCacheDir.c_str());
+		}
+	}
 
 	if (GetTempPath(MAX_PATH, w_str))
 	{
-- 
GitLab