SDL: winrt: Remove SDL_WinRTGetFSPathUNICODE, rename SDL_WinRTGetFSPathUTF8.

From 98e9f361a8cbfbabdac1c5013bade2bbee50ddaa Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Sat, 13 Apr 2024 08:18:08 -0400
Subject: [PATCH] winrt: Remove SDL_WinRTGetFSPathUNICODE, rename
 SDL_WinRTGetFSPathUTF8.

Fixes #9470.
---
 build-scripts/SDL_migration.cocci          |  5 ++++
 docs/README-migration.md                   |  4 ++++
 docs/README-winrt.md                       |  3 +--
 include/SDL3/SDL_oldnames.h                |  6 +++++
 include/SDL3/SDL_system.h                  | 27 +---------------------
 src/core/SDL_core_unsupported.c            | 12 ++--------
 src/dynapi/SDL_dynapi.sym                  |  3 +--
 src/dynapi/SDL_dynapi_overrides.h          |  3 +--
 src/dynapi/SDL_dynapi_procs.h              |  3 +--
 src/filesystem/winrt/SDL_sysfilesystem.cpp | 14 ++++-------
 10 files changed, 27 insertions(+), 53 deletions(-)

diff --git a/build-scripts/SDL_migration.cocci b/build-scripts/SDL_migration.cocci
index 5cbb520800867..e24f31fb47ba0 100644
--- a/build-scripts/SDL_migration.cocci
+++ b/build-scripts/SDL_migration.cocci
@@ -3129,3 +3129,8 @@ typedef SDL_Colour, SDL_Color;
 @@
 - SDL_Colour
 + SDL_Color
+@@
+@@
+- SDL_WinRTGetFSPathUTF8
++ SDL_WinRTGetFSPath
+  (...)
diff --git a/docs/README-migration.md b/docs/README-migration.md
index 3871a9c3ad23b..64d53b8905d75 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -1491,6 +1491,10 @@ The following functions have been removed:
 * SDL_RenderGetD3D11Device() - replaced with the "SDL.renderer.d3d11.device" property
 * SDL_RenderGetD3D12Device() - replaced with the "SDL.renderer.d3d12.device" property
 * SDL_RenderGetD3D9Device() - replaced with the "SDL.renderer.d3d9.device" property
+* SDL_WinRTGetFSPathUNICODE() - Use SDL_WinRTGetFSPath() and SDL_iconv_string to convert from UTF-8 to UTF-16.
+
+The following functions have been renamed:
+* SDL_WinRTGetFSPathUTF8() => SDL_WinRTGetFSPath()
 
 ## SDL_syswm.h
 
diff --git a/docs/README-winrt.md b/docs/README-winrt.md
index 7ef21be69e27b..340af8bcbeb74 100644
--- a/docs/README-winrt.md
+++ b/docs/README-winrt.md
@@ -129,8 +129,7 @@ SDL_GetPrefPath(), starting with SDL 2.0.4, addresses these by:
    (and which require less work to use safely, in terms of data integrity).
 
 Apps that wish to get their Roaming folder's path can do so either by using
-SDL_WinRTGetFSPathUTF8(), SDL_WinRTGetFSPathUNICODE() (which returns a
-UCS-2/wide-char string), or directly through the WinRT class,
+SDL_WinRTGetFSPath(), or directly through the WinRT class,
 Windows.Storage.ApplicationData.
 
 
diff --git a/include/SDL3/SDL_oldnames.h b/include/SDL3/SDL_oldnames.h
index 482d2890a56df..4da32c1c8add4 100644
--- a/include/SDL3/SDL_oldnames.h
+++ b/include/SDL3/SDL_oldnames.h
@@ -511,6 +511,9 @@
 #define SDL_UpperBlit SDL_BlitSurface
 #define SDL_UpperBlitScaled SDL_BlitSurfaceScaled
 
+/* ##SDL_system.h */
+#define SDL_WinRTGetFSPathUTF8 SDL_WinRTGetFSPath
+
 /* ##SDL_thread.h */
 #define SDL_TLSCleanup SDL_CleanupTLS
 #define SDL_TLSCreate SDL_CreateTLS
@@ -1012,6 +1015,9 @@
 #define SDL_UpperBlit SDL_UpperBlit_renamed_SDL_BlitSurface
 #define SDL_UpperBlitScaled SDL_UpperBlitScaled_renamed_SDL_BlitSurfaceScaled
 
+/* ##SDL_system.h */
+#define SDL_WinRTGetFSPathUTF8 SDL_WinRTGetFSPathUTF8_renamed_SDL_WinRTGetFSPath
+
 /* ##SDL_thread.h */
 #define SDL_TLSCleanup SDL_TLSCleanup_renamed_SDL_CleanupTLS
 #define SDL_TLSCreate SDL_TLSCreate_renamed_SDL_CreateTLS
diff --git a/include/SDL3/SDL_system.h b/include/SDL3/SDL_system.h
index e80e0e29ffe6f..b6976ea746fd9 100644
--- a/include/SDL3/SDL_system.h
+++ b/include/SDL3/SDL_system.h
@@ -527,29 +527,6 @@ typedef enum SDL_WinRT_DeviceFamily
 } SDL_WinRT_DeviceFamily;
 
 
-/**
- * Retrieve a WinRT defined path on the local file system.
- *
- * Not all paths are available on all versions of Windows. This is especially
- * true on Windows Phone. Check the documentation for the given SDL_WinRT_Path
- * for more information on which path types are supported where.
- *
- * Documentation on most app-specific path types on WinRT can be found on
- * MSDN, at the URL:
- *
- * https://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
- *
- * \param pathType the type of path to retrieve, one of SDL_WinRT_Path
- * \returns a UCS-2 string (16-bit, wide-char) containing the path, or NULL if
- *          the path is not available for any reason; call SDL_GetError() for
- *          more information.
- *
- * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_WinRTGetFSPathUTF8
- */
-extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType);
-
 /**
  * Retrieve a WinRT defined path on the local file system.
  *
@@ -568,10 +545,8 @@ extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path
  *          more information.
  *
  * \since This function is available since SDL 3.0.0.
- *
- * \sa SDL_WinRTGetFSPathUNICODE
  */
-extern DECLSPEC const char * SDLCALL SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType);
+extern DECLSPEC const char * SDLCALL SDL_WinRTGetFSPath(SDL_WinRT_Path pathType);
 
 /**
  * Detects the device family of WinRT platform at runtime.
diff --git a/src/core/SDL_core_unsupported.c b/src/core/SDL_core_unsupported.c
index 2196aa40447f0..ec9887bc16d3b 100644
--- a/src/core/SDL_core_unsupported.c
+++ b/src/core/SDL_core_unsupported.c
@@ -102,16 +102,8 @@ int SDL_WinRTGetDeviceFamily()
     return 0; /* SDL_WINRT_DEVICEFAMILY_UNKNOWN */
 }
 
-DECLSPEC const wchar_t *SDLCALL SDL_WinRTGetFSPathUNICODE(int pathType); /* SDL_WinRT_Path pathType */
-const wchar_t *SDL_WinRTGetFSPathUNICODE(int pathType)
-{
-    (void)pathType;
-    SDL_Unsupported();
-    return NULL;
-}
-
-DECLSPEC const char *SDLCALL SDL_WinRTGetFSPathUTF8(int pathType); /* SDL_WinRT_Path pathType */
-const char *SDL_WinRTGetFSPathUTF8(int pathType)
+DECLSPEC const char *SDLCALL SDL_WinRTGetFSPath(int pathType); /* SDL_WinRT_Path pathType */
+const char *SDL_WinRTGetFSPath(int pathType)
 {
     (void)pathType;
     SDL_Unsupported();
diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym
index 9f940757e2527..2e9b6d0963869 100644
--- a/src/dynapi/SDL_dynapi.sym
+++ b/src/dynapi/SDL_dynapi.sym
@@ -838,8 +838,7 @@ SDL3_0.0.0 {
     SDL_WarpMouseInWindow;
     SDL_WasInit;
     SDL_WinRTGetDeviceFamily;
-    SDL_WinRTGetFSPathUNICODE;
-    SDL_WinRTGetFSPathUTF8;
+    SDL_WinRTGetFSPath;
     SDL_WindowHasSurface;
     SDL_WriteIO;
     SDL_WriteS16BE;
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index b03ffe9e5f902..7b1ffe0828e1f 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -862,8 +862,7 @@
 #define SDL_WarpMouseInWindow SDL_WarpMouseInWindow_REAL
 #define SDL_WasInit SDL_WasInit_REAL
 #define SDL_WinRTGetDeviceFamily    SDL_WinRTGetDeviceFamily_REAL
-#define SDL_WinRTGetFSPathUNICODE   SDL_WinRTGetFSPathUNICODE_REAL
-#define SDL_WinRTGetFSPathUTF8  SDL_WinRTGetFSPathUTF8_REAL
+#define SDL_WinRTGetFSPath  SDL_WinRTGetFSPath_REAL
 #define SDL_WindowHasSurface SDL_WindowHasSurface_REAL
 #define SDL_WriteIO SDL_WriteIO_REAL
 #define SDL_WriteS16BE SDL_WriteS16BE_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 7089f76290277..bde24c188bcd2 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -882,8 +882,7 @@ SDL_DYNAPI_PROC(int,SDL_WarpMouseGlobal,(float a, float b),(a,b),return)
 SDL_DYNAPI_PROC(void,SDL_WarpMouseInWindow,(SDL_Window *a, float b, float c),(a,b,c),)
 SDL_DYNAPI_PROC(Uint32,SDL_WasInit,(Uint32 a),(a),return)
 SDL_DYNAPI_PROC(SDL_WinRT_DeviceFamily,SDL_WinRTGetDeviceFamily,(void),(),return)
-SDL_DYNAPI_PROC(const wchar_t*,SDL_WinRTGetFSPathUNICODE,(SDL_WinRT_Path a),(a),return)
-SDL_DYNAPI_PROC(const char*,SDL_WinRTGetFSPathUTF8,(SDL_WinRT_Path a),(a),return)
+SDL_DYNAPI_PROC(const char*,SDL_WinRTGetFSPath,(SDL_WinRT_Path a),(a),return)
 SDL_DYNAPI_PROC(SDL_bool,SDL_WindowHasSurface,(SDL_Window *a),(a),return)
 SDL_DYNAPI_PROC(size_t,SDL_WriteIO,(SDL_IOStream *a, const void *b, size_t c),(a,b,c),return)
 SDL_DYNAPI_PROC(SDL_bool,SDL_WriteS16BE,(SDL_IOStream *a, Sint16 b),(a,b),return)
diff --git a/src/filesystem/winrt/SDL_sysfilesystem.cpp b/src/filesystem/winrt/SDL_sysfilesystem.cpp
index d903e2a50c419..0a6fcdc76acd1 100644
--- a/src/filesystem/winrt/SDL_sysfilesystem.cpp
+++ b/src/filesystem/winrt/SDL_sysfilesystem.cpp
@@ -35,8 +35,7 @@ extern "C" {
 using namespace std;
 using namespace Windows::Storage;
 
-extern "C" const wchar_t *
-SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType)
+static const wchar_t *SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType)
 {
     switch (pathType) {
     case SDL_WINRT_PATH_INSTALLED_LOCATION:
@@ -94,8 +93,7 @@ SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType)
     return NULL;
 }
 
-extern "C" const char *
-SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
+extern "C" const char *SDL_WinRTGetFSPath(SDL_WinRT_Path pathType)
 {
     typedef unordered_map<SDL_WinRT_Path, string> UTF8PathMap;
     static UTF8PathMap utf8Paths;
@@ -116,10 +114,9 @@ SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType)
     return utf8Paths[pathType].c_str();
 }
 
-extern "C" char *
-SDL_GetBasePath(void)
+extern "C" char *SDL_GetBasePath(void)
 {
-    const char *srcPath = SDL_WinRTGetFSPathUTF8(SDL_WINRT_PATH_INSTALLED_LOCATION);
+    const char *srcPath = SDL_WinRTGetFSPath(SDL_WINRT_PATH_INSTALLED_LOCATION);
     size_t destPathLen;
     char *destPath = NULL;
 
@@ -138,8 +135,7 @@ SDL_GetBasePath(void)
     return destPath;
 }
 
-extern "C" char *
-SDL_GetPrefPath(const char *org, const char *app)
+extern "C" char *SDL_GetPrefPath(const char *org, const char *app)
 {
     /* WinRT note: The 'SHGetFolderPath' API that is used in Windows 7 and
      * earlier is not available on WinRT or Windows Phone.  WinRT provides