From 3f6d634c00ac3ca902da7b11e379646cfd8f702b Mon Sep 17 00:00:00 2001 From: GMatrixGames Date: Thu, 1 Oct 2020 21:19:38 -0400 Subject: [PATCH] Proper UWP support from LukeFZ's fork --- FModel/Utils/Paks.cs | 58 +++++++++++++---------- FModel/Windows/Launcher/FLauncher.xaml.cs | 2 +- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/FModel/Utils/Paks.cs b/FModel/Utils/Paks.cs index aa5d1344..50b4473f 100644 --- a/FModel/Utils/Paks.cs +++ b/FModel/Utils/Paks.cs @@ -5,6 +5,7 @@ using PakReader.Parsers.Objects; using System.Collections.Generic; using System.IO; using System; +using Windows.Management.Deployment; namespace FModel.Utils { @@ -46,30 +47,28 @@ namespace FModel.Utils } // This method is in testing and is not recommended to be used other than for development purposes - public static (string, string) GetUWPPakFilesPath(string game) + public static string GetUWPPakFilesPath(string game) { - var dir = "C:\\Program Files\\WindowsApps\\"; try { - if (Directory.Exists(dir)) + foreach (var pkg in new PackageManager().FindPackagesForUser(string.Empty, game)) { - DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[WindowsApps]", "Folder as been found"); - foreach (var directory in Directory.GetDirectories(dir)) - if (directory.Equals(game)) - return (game, directory); - - DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[WindowsApps]", $"{game} not found"); - return (string.Empty, string.Empty); + DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[Microsoft Store]", $"UWP Game {game} found at {pkg.EffectiveLocation.Name}"); + return pkg.EffectivePath; } } catch (UnauthorizedAccessException) { - DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[WindowsApps]", - $"{dir} can't be accessed without permission changes to the folder."); + DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[Microsoft Store]", + $"The WindowsApps folder can't be accessed without permission changes to the folder."); + } + catch + { + DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[Microsoft Store]", $"An expected error has ocurred."); } - DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[WindowsApps]", "Folder not found"); - return (string.Empty, string.Empty); + DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[Microsoft Store]", $"{game} cannot be found on this system."); + return string.Empty; } public static string GetFortnitePakFilesPath() @@ -109,17 +108,20 @@ namespace FModel.Utils public static string GetStateOfDecay2PakFilesPath() { // WIP - (_, string sod2UWPPakFilesPath) = (string.Empty, string.Empty); - (_, string _, string sod2PakFilesPath) = (string.Empty, string.Empty, string.Empty); - if (!GetUWPPakFilesPath("Microsoft.Dayton_1.3544.68.2_x64__8wekyb3d8bbwe").Equals(null)) - (_, sod2UWPPakFilesPath) = GetUWPPakFilesPath("Microsoft.Dayton_1.3544.68.2_x64__8wekyb3d8bbwe"); - else - (_, _, sod2PakFilesPath) = GetUEGameFilesPath(""); - - if (!string.IsNullOrEmpty(sod2PakFilesPath)) - return $"{sod2PakFilesPath}\\StateOfDecay2\\Content\\Paks"; - else if (!string.IsNullOrEmpty(sod2UWPPakFilesPath)) + var sod2UWPPakFilesPath = GetUWPPakFilesPath("Microsoft.Dayton_8wekyb3d8bbwe"); + if (!string.IsNullOrEmpty(sod2UWPPakFilesPath)) + { return $"{sod2UWPPakFilesPath}\\StateOfDecay2\\Content\\Paks"; + } + else + { + (_, string _, string sod2PakFilesPath) = GetUEGameFilesPath(""); + if (!string.IsNullOrEmpty(sod2PakFilesPath)) + { + return $"{sod2PakFilesPath}\\StateOfDecay2\\Content\\Paks"; + } + } + return string.Empty; } @@ -158,6 +160,14 @@ namespace FModel.Utils "Minecraft Dungeons not found"); } + DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[launcher_settings.json]", "Launcher version not found, attempting to find Microsoft Store installation."); + + var mcDungeonsUWPPath = GetUWPPakFilesPath("Microsoft.Lovika_8wekyb3d8bbwe"); + if (!string.IsNullOrEmpty(mcDungeonsUWPPath)) + { + return $"{mcDungeonsUWPPath}\\Dungeons\\Content\\Paks"; + } + return string.Empty; } diff --git a/FModel/Windows/Launcher/FLauncher.xaml.cs b/FModel/Windows/Launcher/FLauncher.xaml.cs index 6484d6f8..0b339158 100644 --- a/FModel/Windows/Launcher/FLauncher.xaml.cs +++ b/FModel/Windows/Launcher/FLauncher.xaml.cs @@ -101,7 +101,7 @@ namespace FModel.Windows.Launcher if (!string.IsNullOrEmpty(sod2Path)) { // WIP - DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[WindowsApps]", $"State of Decay 2 found at {sod2Path}"); + DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[UWP / LauncherInstalled.dat]", $"State of Decay 2 found at {sod2Path}"); Globals.gNotifier.ShowCustomMessage("State of Decay 2", Properties.Resources.PathAutoDetected, "/FModel;component/Resources/sod2.ico"); ComboBoxVm.gamesCbViewModel.Add(new ComboBoxViewModel { Id = i++, Content = "State of Decay 2", Property = sod2Path }); }