From 8490e67305fa9a4dc410d032bd5ff28d17bd4a61 Mon Sep 17 00:00:00 2001 From: Christopher Madi Date: Fri, 1 Nov 2019 17:08:11 +0200 Subject: [PATCH] Get automatic gamefiles location from user --- FModel/Forms/FModel_Settings.xaml.cs | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/FModel/Forms/FModel_Settings.xaml.cs b/FModel/Forms/FModel_Settings.xaml.cs index 4b9e671a..f458df43 100644 --- a/FModel/Forms/FModel_Settings.xaml.cs +++ b/FModel/Forms/FModel_Settings.xaml.cs @@ -102,9 +102,40 @@ namespace FModel.Forms SetUserSettings(); Close(); } + + private string GetEpicDirectory() => Directory.Exists(@"C:\ProgramData\Epic") ? @"C:\ProgramData\Epic" : Directory.Exists(@"D:\ProgramData\Epic") ? @"D:\ProgramData\Epic" : @"E:\ProgramData\Epic"; + + private bool DatFileExists() => File.Exists($@"{GetEpicDirectory()}\UnrealEngineLauncher\LauncherInstalled.dat"); + + private string GetGameFiles() + { + if(DatFileExists()) + { + var games = JsonConvert.DeserializeObject(File.ReadAllText($@"{GetEpicDirectory()}\UnrealEngineLauncher\LauncherInstalled.dat")).List; + List AllGames = new List(); + foreach (var game in games) + { + AllGames.Add(game.installlocation); + } + return $@"{AllGames.Where(x => x.Contains("Fortnite")).FirstOrDefault()}\FortniteGame\Content\Paks"; + } + return null; + } + + + private class ParseDatFile + { + [JsonProperty("InstallationList")] public InstallationList[] List { get; set; } + } + private class InstallationList + { + [JsonProperty("InstallLocation")] public string installlocation { get; set; } + } private async void GetUserSettings() { + string AutoPath = GetGameFiles(); + FProp.Default.FPak_Path = string.IsNullOrEmpty(FProp.Default.FPak_Path) && DatFileExists() && AutoPath != null ? AutoPath : FProp.Default.FPak_Path; InputTextBox.Text = FProp.Default.FPak_Path; bDiffFileSize.IsChecked = FProp.Default.FDiffFileSize; OutputTextBox.Text = FProp.Default.FOutput_Path;