BeardedManStudios / ForgeNetworkingRemastered

See various forks, also please join the Forge Community fork of Forge Alloy! -> https://github.com/ForgeAlloyCommunity/ForgeAlloy
https://twitter.com/FarrisFaulds
Apache License 2.0
1.49k stars 311 forks source link

Fix log folder generation failing with UnauthorizedAccessError on UWP #390

Open NoTuxNoBux opened 3 years ago

NoTuxNoBux commented 3 years ago

This happens immediately on startup, even if nothing is logged, because the folders are created and their path is inside the application directory in e.g. Data/Logs, which is read-only for security reasons on UWP - and will likely also be read-only when an app is installed versions on Linux distributions.

The exact error is:

UnauthorizedAccessException: Access to the path "C:/data/Programs/WindowsApps/unity-app_1.0.0.0_foo_abcdefghijk/Data/Logs" is denied.`

System.IO.Directory.CreateDirectoriesInternal (System.String path) <...>
System.IO.Directory.CreateDirectory (System.String path) <...>
BMSLogger.Init () <...>

This changes the path to use the persistent data path, which is writable, and on Windows something like LocalAppData\unity-app_1.0.0.0_foo__abcdefghijk\LocalState\Logs\bmslog.txt.