We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5345

Summary: [Patch] Add mod support to WinRT SDL_GetBasePath
Product: SDL Reporter: Ethan Lee <flibitijibibo>
Component: fileAssignee: Ethan Lee <flibitijibibo>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: enhancement    
Priority: P2 Keywords: target-2.0.14
Version: HG 2.0   
Hardware: All   
OS: Windows 10   
Attachments: Mod support for SDL-UWP
SDK minimum enforcement for EffectiveLocation
Check the NTDDI define before comparing it

Description Ethan Lee 2020-11-09 22:13:49 UTC
Created attachment 4509 [details]
Mod support for SDL-UWP

Certain applications on the Windows Store are given permission to make their app "modifiable", which in the Xbox world means adding mod support. The change is very simple: Instead of using InstalledPath, use either MutablePath or EffectivePath, the latter of which automatically chooses between Installed and Mutable depending on whether the user has turned on mod support in the Xbox app. However, this feature is only available on Windows 1903 or newer, so we need to check for the API before attempting to use it. For older systems that don't have mod support we fall back to InstalledPath.
Comment 1 Sam Lantinga 2020-11-12 03:06:10 UTC
Maybe you mean for this to apply to SDL_GetPrefPath()?

SDL_GetBasePath() is the directory where the executable resides. SDL_GetPrefPath() is the directory where you can save data.
Comment 2 Ethan Lee 2020-11-12 05:18:22 UTC
In this case no - per MSDN:

https://docs.microsoft.com/en-us/uwp/api/windows.applicationmodel.package.effectivelocation?view=winrt-19041

InstalledLocation is the sandboxed path that's read-only, and MutableLocation is the virtual path that allows users to modify base install data for mod support.
Comment 3 Sam Lantinga 2020-11-24 05:39:45 UTC
SDL_GetBasePath() returns a read-only location. SDL_GetPrefPath() returns a writeable location. It seems like the current code is correct, right?
Comment 4 Ethan Lee 2020-11-24 15:12:39 UTC
Let me try a different angle for a second: This patch is currently already shipping in Celeste for Windows 10 and will be used to advertise modding support in the future.

Returning to the code: As far as the game is concerned, _both_ Installed and Mutable are read-only. The EffectiveLocation is just a virtualized install directory to allow end users to modify the install content outside of the program itself, without having to decrypt the UWP app bundle. The save directory is _completely_ different and is 100% unrelated to this change.
Comment 5 Sam Lantinga 2020-11-24 15:35:12 UTC
Ahhh, thank you for clarifying. Your patch is in, thanks!
https://hg.libsdl.org/SDL/rev/16bae903b2de
Comment 6 Sam Lantinga 2020-12-13 10:07:01 UTC
This fails on older SDKs

UWP:
1>..\..\src\filesystem\winrt\SDL_sysfilesystem.cpp(53): error C2039: 'EffectiveLocation': is not a member of 'Windows::ApplicationModel::Package'
1>..\..\src\filesystem\winrt\SDL_sysfilesystem.cpp(53): error C2227: left of '->Path' must point to class/struct/union/generic type
1>..\..\src\filesystem\winrt\SDL_sysfilesystem.cpp(53): error C2227: left of '->Data' must point to class/struct/union/generic type

Windows Phone:
1>..\..\src\filesystem\winrt\SDL_sysfilesystem.cpp(52): error C3083: 'ApiInformation': the symbol to the left of a '::' must be a type
1>..\..\src\filesystem\winrt\SDL_sysfilesystem.cpp(52): error C2039: 'IsApiContractPresent' : is not a member of 'Windows::Foundation::Metadata'
1>..\..\src\filesystem\winrt\SDL_sysfilesystem.cpp(52): error C3861: 'IsApiContractPresent': identifier not found
1>..\..\src\filesystem\winrt\SDL_sysfilesystem.cpp(53): error C2039: 'EffectiveLocation' : is not a member of 'Windows::ApplicationModel::Package'
1>          c:\program files (x86)\windows phone kits\8.1\references\commonconfiguration\neutral\windows.winmd : see declaration of 'Windows::ApplicationModel::Package'
1>..\..\src\filesystem\winrt\SDL_sysfilesystem.cpp(53): error C2227: left of '->Path' must point to class/struct/union/generic type
1>..\..\src\filesystem\winrt\SDL_sysfilesystem.cpp(53): error C2227: left of '->Data' must point to class/struct/union/generic type
Comment 7 Sam Lantinga 2020-12-13 10:07:46 UTC
Ethan, can you take a look and see how to fix this for older SDK builds?
Comment 8 Ethan Lee 2020-12-13 17:03:57 UTC
I think it just needs to be guarded with an SDK version ifdef, but there's like 30 Windows version defs now because of 10 so this will take a minute. Ping this again if a patch isn't posted by Tuesday.
Comment 9 Sam Lantinga 2020-12-13 19:49:20 UTC
Okay, this is one of the last things needed for the release. I'll leave it waiting here until you have a chance to post a fix.

Thanks!
Comment 10 Ethan Lee 2020-12-14 16:55:02 UTC
Created attachment 4580 [details]
SDK minimum enforcement for EffectiveLocation

Attached is the patch that I believe will cover this. At minimum it should fix the buildbot while also making our own builds work. It's unfortunately very VERY hard to tell how UWP SDK versions are done, so the best I could find is NTDDI, which still seems off but it should at least cover the two existing cases I'm aware of (one being the lowest SDK in existence and the other being the one that Microsoft forces you to use for submission).
Comment 11 Sam Lantinga 2020-12-14 17:26:24 UTC
Patch added, thanks!
https://hg.libsdl.org/SDL/rev/862fcd397b18
Comment 12 Ethan Lee 2020-12-14 17:37:52 UTC
Created attachment 4581 [details]
Check the NTDDI define before comparing it

Sometimes I forget how old the SDKs can get... another patch, for SDKs that pre-date the NTDDI define we need.
Comment 13 Sam Lantinga 2020-12-14 18:02:50 UTC
Added!
https://hg.libsdl.org/SDL/rev/5ed723908e1c