diff --git a/FModel/MainWindow.xaml.cs b/FModel/MainWindow.xaml.cs index c196f25b..e0e1fc7a 100644 --- a/FModel/MainWindow.xaml.cs +++ b/FModel/MainWindow.xaml.cs @@ -35,7 +35,7 @@ using System.Windows.Controls; using System.Windows.Input; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; -using PropertyInfo = FModel.PakReader.IO.PropertyInfo; +using System.Net.NetworkInformation; namespace FModel { @@ -106,43 +106,41 @@ namespace FModel private async void LoadMappings() { - try - { -#if DEBUG - string rawMappings = null; - string rawEnumMappings = null; - try - { - rawMappings = await File.ReadAllTextAsync(@"C:\Users\GMatrixGames\Desktop\FTest\FortniteTypeMappings\TypeMappings.json"); - rawEnumMappings = await File.ReadAllTextAsync(@"C:\Users\GMatrixGames\Desktop\FTest\FortniteTypeMappings\EnumMappings.json"); - } - catch - { - rawMappings ??= await Endpoints.GetStringEndpoint(Endpoints.FORTNITE_TYPE_MAPPINGS); - rawEnumMappings ??= await Endpoints.GetStringEndpoint(Endpoints.FORTNITE_ENUM_MAPPINGS); - } -#else - var rawMappings = await Endpoints.GetStringEndpoint(Endpoints.FORTNITE_TYPE_MAPPINGS); - var rawEnumMappings = await Endpoints.GetStringEndpoint(Endpoints.FORTNITE_ENUM_MAPPINGS); -#endif - var serializerSettings = new JsonSerializerSettings - { - ContractResolver = new DefaultContractResolver - { NamingStrategy = new CamelCaseNamingStrategy(false, false) } - }; - Globals.TypeMappings = - JsonConvert.DeserializeObject>>(rawMappings, - serializerSettings); - Globals.EnumMappings = JsonConvert.DeserializeObject>>(rawEnumMappings, - serializerSettings); + string rawMappings = "{}"; + string rawEnumMappings = "{}"; - } - catch (Exception exception) +#if DEBUG + if (File.Exists("TypeMappings.json")) { - DebugHelper.WriteException(exception, "Failed to load Mappings"); - Globals.TypeMappings ??= new Dictionary>(); - Globals.EnumMappings ??= new Dictionary>(); + rawMappings = await File.ReadAllTextAsync("TypeMappings.json"); } + else if (NetworkInterface.GetIsNetworkAvailable()) + { + rawMappings = await Endpoints.GetStringEndpoint(Endpoints.FORTNITE_TYPE_MAPPINGS); + } + + if (File.Exists("EnumMappings.json")) + { + rawEnumMappings = await File.ReadAllTextAsync("EnumMappings.json"); + } + else if (NetworkInterface.GetIsNetworkAvailable()) + { + rawEnumMappings = await Endpoints.GetStringEndpoint(Endpoints.FORTNITE_ENUM_MAPPINGS); + } +#else + rawMappings = await Endpoints.GetStringEndpoint(Endpoints.FORTNITE_TYPE_MAPPINGS); + rawEnumMappings = await Endpoints.GetStringEndpoint(Endpoints.FORTNITE_ENUM_MAPPINGS); +#endif + + var serializerSettings = new JsonSerializerSettings + { + ContractResolver = new DefaultContractResolver + { + NamingStrategy = new CamelCaseNamingStrategy(false, false) + } + }; + Globals.TypeMappings = JsonConvert.DeserializeObject>>(rawMappings, serializerSettings); + Globals.EnumMappings = JsonConvert.DeserializeObject>>(rawEnumMappings, serializerSettings); } public void ReloadMappings(object sender, RoutedEventArgs e)