sdl2-compat: winrt: Updated for SDL_WinRTGetFSPath* updates in SDL3.

From e17992cf2226bc6110317e0460b16dabc7734ce5 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Sat, 13 Apr 2024 08:45:58 -0400
Subject: [PATCH] winrt: Updated for SDL_WinRTGetFSPath* updates in SDL3.

---
 src/sdl2_compat.c          | 25 +++++++++++++++++++++++++
 src/sdl3_include_wrapper.h | 11 +++--------
 src/sdl3_syms.h            |  3 +--
 3 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 920c35b..2ae2086 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -8165,6 +8165,31 @@ SDL_AndroidRequestPermission(const char *permission)
 }
 #endif
 
+#ifdef SDL_PLATFORM_WINRT
+static wchar_t *winrt_getfspath_cached_strings[4];  // these need to be saved here, since we return a const string. These strings' memory leaks!
+
+DECLSPEC const wchar_t* SDLCALL
+SDL_WinRTGetFSPathUNICODE(int SDL_WinRT_Path pathType)
+{
+    wchar_t *wstr = NULL;
+
+    if (((int) a) >= SDL_arraysize(winrt_getfspath_cached_strings)) {  // in case something new is added in SDL3...
+        SDL3_SetError("Unsupported SDL_WinRT_Path %d", (int) a);
+    } else {
+        wstr = winrt_getfspath_cached_strings[a];
+        if (!wstr) {
+            const char *utf8 = SDL3_WinRTGetFSPath(a);
+            if (utf8) {
+                wstr = (wchar_t *) SDL_iconv_string("UTF-16LE", "UTF-8", (const char *)(utf8), SDL_strlen(utf8) + 1);
+                winrt_getfspath_cached_strings[a] = wstr;
+            }
+        }
+    }
+
+    return wstr;
+}
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index b5bb633..84237ba 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -869,8 +869,7 @@
 #define SDL_WarpMouseInWindow IGNORE_THIS_VERSION_OF_SDL_WarpMouseInWindow
 #define SDL_WasInit IGNORE_THIS_VERSION_OF_SDL_WasInit
 #define SDL_WinRTGetDeviceFamily IGNORE_THIS_VERSION_OF_SDL_WinRTGetDeviceFamily
-#define SDL_WinRTGetFSPathUNICODE IGNORE_THIS_VERSION_OF_SDL_WinRTGetFSPathUNICODE
-#define SDL_WinRTGetFSPathUTF8 IGNORE_THIS_VERSION_OF_SDL_WinRTGetFSPathUTF8
+#define SDL_WinRTGetFSPath IGNORE_THIS_VERSION_OF_SDL_WinRTGetFSPath
 #define SDL_WindowHasSurface IGNORE_THIS_VERSION_OF_SDL_WindowHasSurface
 #define SDL_WriteIO IGNORE_THIS_VERSION_OF_SDL_WriteIO
 #define SDL_WriteS16BE IGNORE_THIS_VERSION_OF_SDL_WriteS16BE
@@ -4415,12 +4414,8 @@
 #undef SDL_WinRTGetDeviceFamily
 #endif
 
-#ifdef SDL_WinRTGetFSPathUNICODE
-#undef SDL_WinRTGetFSPathUNICODE
-#endif
-
-#ifdef SDL_WinRTGetFSPathUTF8
-#undef SDL_WinRTGetFSPathUTF8
+#ifdef SDL_WinRTGetFSPath
+#undef SDL_WinRTGetFSPath
 #endif
 
 #ifdef SDL_WindowHasSurface
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index e29b817..bb67013 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -70,8 +70,7 @@ SDL3_SYM_PASSTHROUGH(int,GDKGetDefaultUser,(XUserHandle *a),(a),return)
 #endif
 
 #ifdef SDL_PLATFORM_WINRT
-SDL3_SYM_PASSTHROUGH(const wchar_t*,WinRTGetFSPathUNICODE,(SDL_WinRT_Path a),(a),return)
-SDL3_SYM_PASSTHROUGH(const char*,WinRTGetFSPathUTF8,(SDL_WinRT_Path a),(a),return)
+SDL3_SYM_RENAMED(const char*,WinRTGetFSPathUTF8,WinRTGetFSPath,(SDL_WinRT_Path a),(a),return)
 SDL3_SYM_PASSTHROUGH(SDL_WinRT_DeviceFamily,WinRTGetDeviceFamily,(void),(),return)
 #endif