diff --git a/ZenovaLauncher/App.xaml.cs b/ZenovaLauncher/App.xaml.cs index 09b8f62..fb5cfd6 100644 --- a/ZenovaLauncher/App.xaml.cs +++ b/ZenovaLauncher/App.xaml.cs @@ -31,9 +31,9 @@ public void AppStart(object sender, StartupEventArgs e) Task loadTask = Task.Run(async () => { await AccountManager.instance.AddAccounts(); - Preferences.LoadPreferences(DataDirectory); await VersionManager.instance.LoadMinecraftVersions(); ProfileManager.instance.AddProfiles(); + Preferences.LoadPreferences(DataDirectory); }); loadTask.Wait(); Trace.WriteLine("AppStart Finished"); diff --git a/ZenovaLauncher/Pages/PlayPage.xaml b/ZenovaLauncher/Pages/PlayPage.xaml index c44dbaa..f6d59a8 100644 --- a/ZenovaLauncher/Pages/PlayPage.xaml +++ b/ZenovaLauncher/Pages/PlayPage.xaml @@ -154,7 +154,7 @@ HorizontalContentAlignment="Left" Background="Transparent" BorderThickness="0" - SelectedIndex="0"> + SelectedItem="{Binding SelectedProfile}"> diff --git a/ZenovaLauncher/Pages/PlayPage.xaml.cs b/ZenovaLauncher/Pages/PlayPage.xaml.cs index 9ca1c5e..ba65e4a 100644 --- a/ZenovaLauncher/Pages/PlayPage.xaml.cs +++ b/ZenovaLauncher/Pages/PlayPage.xaml.cs @@ -11,8 +11,10 @@ public partial class PlayPage : Page public PlayPage() { InitializeComponent(); - ProfileBox.ItemsSource = ProfileManager.instance; + DataContext = ProfileLauncher.instance; + ProfileBox.ItemsSource = ProfileManager.instance; + ProfileBox.DataContext = ProfileManager.instance; } private void PlayButtonClick(object sender, RoutedEventArgs e) diff --git a/ZenovaLauncher/Profiles/ProfileManager.cs b/ZenovaLauncher/Profiles/ProfileManager.cs index 0c66f01..0f62d1b 100644 --- a/ZenovaLauncher/Profiles/ProfileManager.cs +++ b/ZenovaLauncher/Profiles/ProfileManager.cs @@ -1,10 +1,12 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Linq; +using System.Windows; namespace ZenovaLauncher { @@ -72,28 +74,36 @@ public void LoadProfiles() camelCaseSerialization = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; if (File.Exists(Path.Combine(_profilesDir, _profilesFile))) { - Dictionary profileList = JsonConvert.DeserializeObject>(File.ReadAllText(Path.Combine(_profilesDir, _profilesFile)), camelCaseSerialization); - foreach (var p in profileList) + try { - if (p.Key == p.Value.Hash) + Dictionary profileList = JsonConvert.DeserializeObject>(File.ReadAllText(Path.Combine(_profilesDir, _profilesFile)), camelCaseSerialization); + foreach (var p in profileList) { - switch (p.Value.Type) + if (p.Key == p.Value.Hash) { - case Profile.ProfileType.Custom: - Add(p.Value); - break; - case Profile.ProfileType.LatestBeta: - LatestBeta = p.Value; - break; - case Profile.ProfileType.LatestRelease: - LatestRelease = p.Value; - break; + switch (p.Value.Type) + { + case Profile.ProfileType.Custom: + Add(p.Value); + break; + case Profile.ProfileType.LatestBeta: + LatestBeta = p.Value; + break; + case Profile.ProfileType.LatestRelease: + LatestRelease = p.Value; + break; + } + } + else + { + Trace.WriteLine("Failed to load profile due to incorrect hash: " + p.Key); } } - else - { - Trace.WriteLine("Failed to load profile due to incorrect hash: " + p.Key); - } + } + catch(Exception e) + { + Trace.WriteLine("Profile JSON Deserialize Failed: " + e.ToString()); + MessageBox.Show("Profile JSON Deserialize Failed: " + e.ToString()); } } //} diff --git a/ZenovaLauncher/Utils/Preferences.cs b/ZenovaLauncher/Utils/Preferences.cs index a37ad4e..7ab8a94 100644 --- a/ZenovaLauncher/Utils/Preferences.cs +++ b/ZenovaLauncher/Utils/Preferences.cs @@ -1,9 +1,11 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Newtonsoft.Json.Serialization; +using System; using System.Diagnostics; using System.IO; using System.Linq; +using System.Windows; namespace ZenovaLauncher { @@ -30,6 +32,11 @@ public string SelectedAccount get { return AccountManager.instance.SelectedAccount.AccountName; } set { AccountManager.instance.SelectedAccount = AccountManager.instance.FirstOrDefault(a => a.AccountName == value); } } + public string SelectedProfile + { + get { return ProfileManager.instance.SelectedProfile.Hash; } + set { ProfileManager.instance.SelectedProfile = ProfileManager.instance.FirstOrDefault(p => p.Hash == value); } + } public static void LoadPreferences(string dataDir) @@ -38,9 +45,22 @@ public static void LoadPreferences(string dataDir) _preferencesFile = Path.Combine(dataDir, _preferencesFile); camelCaseSerialization = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; if (File.Exists(_preferencesFile)) - instance = JsonConvert.DeserializeObject(File.ReadAllText(_preferencesFile), camelCaseSerialization); + { + try + { + instance = JsonConvert.DeserializeObject(File.ReadAllText(_preferencesFile), camelCaseSerialization); + } + catch (Exception e) + { + Trace.WriteLine("Preferences JSON Deserialize Failed: " + e.ToString()); + MessageBox.Show("Preferences JSON Deserialize Failed: " + e.ToString()); + } + } else + { instance = new Preferences(); + } + Trace.WriteLine("Loaded Preferences"); } diff --git a/ZenovaLauncher/Utils/Utils.cs b/ZenovaLauncher/Utils/Utils.cs index 3ae36ba..82cabcd 100644 --- a/ZenovaLauncher/Utils/Utils.cs +++ b/ZenovaLauncher/Utils/Utils.cs @@ -28,7 +28,7 @@ public static string ComputeHash(object objectToHash) StringBuilder sb = new StringBuilder(); for (int i = 0; i < result.Length; i++) { - sb.Append(result[i].ToString("X2")); + sb.Append(result[i].ToString("x2")); } return sb.ToString();