SDL: winrt: Implemented SDL_GetUserFolder() for WinRT/UWP.

From 3f4ac1a3c7769d645cbd947834ca7a2c12529914 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Sat, 13 Apr 2024 08:05:16 -0400
Subject: [PATCH] winrt: Implemented SDL_GetUserFolder() for WinRT/UWP.

---
 include/SDL3/SDL_filesystem.h              | 26 ++++++++++-----------
 src/filesystem/winrt/SDL_sysfilesystem.cpp | 27 +++++++++++++++++++---
 2 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/include/SDL3/SDL_filesystem.h b/include/SDL3/SDL_filesystem.h
index 268fae02eaace..9cefc75555c7d 100644
--- a/include/SDL3/SDL_filesystem.h
+++ b/include/SDL3/SDL_filesystem.h
@@ -148,19 +148,19 @@ extern DECLSPEC char *SDLCALL SDL_GetPrefPath(const char *org, const char *app);
  *
  * The folders supported per platform are:
  *
- * |             | Windows | macOS/iOS | tvOS | Unix (XDG) | Haiku | Emscripten |
- * | ----------- | ------- | --------- | ---- | ---------- | ----- | ---------- |
- * | HOME        | X       | X         |      | X          | X     | X          |
- * | DESKTOP     | X       | X         |      | X          | X     |            |
- * | DOCUMENTS   | X       | X         |      | X          |       |            |
- * | DOWNLOADS   | Vista+  | X         |      | X          |       |            |
- * | MUSIC       | X       | X         |      | X          |       |            |
- * | PICTURES    | X       | X         |      | X          |       |            |
- * | PUBLICSHARE |         | X         |      | X          |       |            |
- * | SAVEDGAMES  | Vista+  |           |      |            |       |            |
- * | SCREENSHOTS | Vista+  |           |      |            |       |            |
- * | TEMPLATES   | X       | X         |      | X          |       |            |
- * | VIDEOS      | X       | X*        |      | X          |       |            |
+ * |             | Windows | WinRT/UWP |macOS/iOS | tvOS | Unix (XDG) | Haiku | Emscripten |
+ * | ----------- | ------- | --------- |--------- | ---- | ---------- | ----- | ---------- |
+ * | HOME        | X       | X         | X        |      | X          | X     | X          |
+ * | DESKTOP     | X       | X         | X        |      | X          | X     |            |
+ * | DOCUMENTS   | X       | X         | X        |      | X          |       |            |
+ * | DOWNLOADS   | Vista+  | X         | X        |      | X          |       |            |
+ * | MUSIC       | X       | X         | X        |      | X          |       |            |
+ * | PICTURES    | X       | X         | X        |      | X          |       |            |
+ * | PUBLICSHARE |         |           | X        |      | X          |       |            |
+ * | SAVEDGAMES  | Vista+  |           |          |      |            |       |            |
+ * | SCREENSHOTS | Vista+  | X         |          |      |            |       |            |
+ * | TEMPLATES   | X       | X         | X        |      | X          |       |            |
+ * | VIDEOS      | X       | X         | X*       |      | X          |       |            |
  *
  * Note that on macOS/iOS, the Videos folder is called "Movies".
  *
diff --git a/src/filesystem/winrt/SDL_sysfilesystem.cpp b/src/filesystem/winrt/SDL_sysfilesystem.cpp
index a21679993a15f..d903e2a50c419 100644
--- a/src/filesystem/winrt/SDL_sysfilesystem.cpp
+++ b/src/filesystem/winrt/SDL_sysfilesystem.cpp
@@ -229,11 +229,32 @@ SDL_GetPrefPath(const char *org, const char *app)
     return retval;
 }
 
-/* TODO */
 char *SDL_GetUserFolder(SDL_Folder folder)
 {
-    SDL_Unsupported();
-    return NULL;
+    wstring wpath;
+
+    switch (folder) {
+        #define CASEPATH(sym, var) case sym: wpath = Windows::Storage::UserDataPaths::GetDefault()->var->Data(); break
+        CASEPATH(SDL_FOLDER_HOME, Profile);
+        CASEPATH(SDL_FOLDER_DESKTOP, Desktop);
+        CASEPATH(SDL_FOLDER_DOCUMENTS, Documents);
+        CASEPATH(SDL_FOLDER_DOWNLOADS, Downloads);
+        CASEPATH(SDL_FOLDER_MUSIC, Music);
+        CASEPATH(SDL_FOLDER_PICTURES, Pictures);
+        CASEPATH(SDL_FOLDER_SCREENSHOTS, Screenshots);
+        CASEPATH(SDL_FOLDER_TEMPLATES, Templates);
+        CASEPATH(SDL_FOLDER_VIDEOS, Videos);
+        #undef CASEPATH
+        #define UNSUPPPORTED_CASEPATH(sym) SDL_SetError("The %s folder is unsupported on WinRT", #sym); return NULL;
+        UNSUPPPORTED_CASEPATH(SDL_FOLDER_PUBLICSHARE);
+        UNSUPPPORTED_CASEPATH(SDL_FOLDER_SAVEDGAMES);
+        #undef UNSUPPPORTED_CASEPATH
+        default:
+            SDL_SetError("Invalid SDL_Folder: %d", (int)folder);
+            return NULL;
+    };
+
+    return WIN_StringToUTF8(wpath.c_str());
 }
 
 #endif /* SDL_PLATFORM_WINRT */