From 355faa1f36d517d2892ce97e69532e2b0b8106ea Mon Sep 17 00:00:00 2001 From: Raphael Winkler Date: Wed, 15 Aug 2018 06:07:40 +0200 Subject: [PATCH] Fixed yet another startup crash, added some smaller features to osu! auto detect --- Osmo/Core/Helper.cs | 31 ++++++++++--- Osmo/Core/Objects/OsmoMessageBoxButton.cs | 6 ++- Osmo/Core/Objects/OsmoMessageBoxResult.cs | 4 ++ Osmo/Localisation/StringResources.xaml | 5 ++- Osmo/MainWindow.xaml | 4 +- Osmo/MainWindow.xaml.cs | 2 +- Osmo/UI/MaterialMessageBox.xaml.cs | 9 ++++ Osmo/UI/Settings.xaml.cs | 55 ++++++++++++++++------- 8 files changed, 91 insertions(+), 25 deletions(-) diff --git a/Osmo/Core/Helper.cs b/Osmo/Core/Helper.cs index 1666203..3883974 100644 --- a/Osmo/Core/Helper.cs +++ b/Osmo/Core/Helper.cs @@ -150,14 +150,35 @@ public static string FindString(string targetName) public static string FindOsuInstallation() { - string path; RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Classes\\osu\\DefaultIcon"); - path = key.GetValue("").ToString(); - path = path.Replace("\"", ""); - path = path.Remove(path.LastIndexOf('\\')) + "\\Skins"; + if (key != null) + { + string path; + path = key.GetValue("").ToString(); + path = path.Replace("\"", ""); + path = path.Remove(path.LastIndexOf('\\')) + "\\Skins"; + + if (Directory.Exists(path)) + { + return path; + } + else + { + return null; + } + } + else + { + return null; + } + } + + public static bool IsOsuInstalled() + { + return Registry.LocalMachine.OpenSubKey("SOFTWARE\\Classes\\osu\\DefaultIcon") != null; - return path; } + public static string NormalizePath(string path) { return Path.GetFullPath(new Uri(path).LocalPath) diff --git a/Osmo/Core/Objects/OsmoMessageBoxButton.cs b/Osmo/Core/Objects/OsmoMessageBoxButton.cs index 10bd435..e659837 100644 --- a/Osmo/Core/Objects/OsmoMessageBoxButton.cs +++ b/Osmo/Core/Objects/OsmoMessageBoxButton.cs @@ -20,7 +20,11 @@ public enum OsmoMessageBoxButton YesNo = 4, // // Summary: + // The message box displays OK and Retry buttons. + OKRetry = 5, + // + // Summary: // The message box displays custom buttons. - Custom = 5 + Custom = 6 } } diff --git a/Osmo/Core/Objects/OsmoMessageBoxResult.cs b/Osmo/Core/Objects/OsmoMessageBoxResult.cs index 0b6c1c1..8c73c7b 100644 --- a/Osmo/Core/Objects/OsmoMessageBoxResult.cs +++ b/Osmo/Core/Objects/OsmoMessageBoxResult.cs @@ -16,6 +16,10 @@ public enum OsmoMessageBoxResult Cancel = 2, // // Summary: + // The result value of the message box is Retry. + Retry = 3, + // + // Summary: // The result value of the message box is Yes. Yes = 6, // diff --git a/Osmo/Localisation/StringResources.xaml b/Osmo/Localisation/StringResources.xaml index 3ea2451..661ceb1 100644 --- a/Osmo/Localisation/StringResources.xaml +++ b/Osmo/Localisation/StringResources.xaml @@ -38,6 +38,7 @@ _YES _NO _IMPORT + _RETRY _LOAD TEMPLATE _NEW TEMPLATE _LOAD SKIN @@ -148,10 +149,12 @@ Editor Keyboard shortcuts Cheat sheet + osu! is not installed! + Should osu! be installed make sure it has been installed correctly, otherwise select it manually. Auto-detect osu! folder Do you wish for Osmo to find your osu! installation folder? Auto-detect failed! - Are you sure you have osu! installed? + Are you sure you have osu! installed correctly? You have unsaved changes to your settings! Do you want to save them first? (Selecting No reverts all changes to your settings) diff --git a/Osmo/MainWindow.xaml b/Osmo/MainWindow.xaml index 6929e51..4efc5c9 100644 --- a/Osmo/MainWindow.xaml +++ b/Osmo/MainWindow.xaml @@ -17,7 +17,7 @@ TextElement.FontSize="14" AllowDrop="True" FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto" Closing="MetroWindow_Closing" DragEnter="MetroWindow_DragEnter" - PreviewKeyUp="MetroWindow_PreviewKeyUp" Loaded="MetroWindow_Loaded"> + PreviewKeyUp="MetroWindow_PreviewKeyUp"> @@ -34,7 +34,7 @@ - + diff --git a/Osmo/MainWindow.xaml.cs b/Osmo/MainWindow.xaml.cs index 203208c..198fa8f 100644 --- a/Osmo/MainWindow.xaml.cs +++ b/Osmo/MainWindow.xaml.cs @@ -354,7 +354,7 @@ private void FolderPicker_DialogClosed(object sender, RoutedEventArgs e) } } - private void MetroWindow_Loaded(object sender, RoutedEventArgs e) + private void DialogHost_Loaded(object sender, RoutedEventArgs e) { #if !DEBUG ShowDisclaimer(); diff --git a/Osmo/UI/MaterialMessageBox.xaml.cs b/Osmo/UI/MaterialMessageBox.xaml.cs index 208e45b..ea50d2d 100644 --- a/Osmo/UI/MaterialMessageBox.xaml.cs +++ b/Osmo/UI/MaterialMessageBox.xaml.cs @@ -62,6 +62,11 @@ public OsmoMessageBoxButton Buttons vm.ButtonTwoText = Helper.FindString("no"); vm.ButtonThreeText = Helper.FindString("yes"); break; + case OsmoMessageBoxButton.OKRetry: + vm.ButtonOneText = ""; + vm.ButtonTwoText = Helper.FindString("retry"); + vm.ButtonThreeText = Helper.FindString("ok"); + break; case OsmoMessageBoxButton.Custom: vm.ButtonOneText = buttonOneCustomText; vm.ButtonTwoText = buttonTwoCustomText; @@ -170,6 +175,9 @@ private void ButtonTwo_Click(object sender, RoutedEventArgs e) case OsmoMessageBoxButton.OKCancel: Result = OsmoMessageBoxResult.Cancel; break; + case OsmoMessageBoxButton.OKRetry: + Result = OsmoMessageBoxResult.Retry; + break; case OsmoMessageBoxButton.YesNo: case OsmoMessageBoxButton.YesNoCancel: Result = OsmoMessageBoxResult.No; @@ -186,6 +194,7 @@ private void ButtonThree_Click(object sender, RoutedEventArgs e) { case OsmoMessageBoxButton.OK: case OsmoMessageBoxButton.OKCancel: + case OsmoMessageBoxButton.OKRetry: Result = OsmoMessageBoxResult.OK; break; case OsmoMessageBoxButton.YesNo: diff --git a/Osmo/UI/Settings.xaml.cs b/Osmo/UI/Settings.xaml.cs index 98deb61..687d38d 100644 --- a/Osmo/UI/Settings.xaml.cs +++ b/Osmo/UI/Settings.xaml.cs @@ -84,31 +84,56 @@ public static void ChangeLanguage(Language lang) private async void Settings_Loaded(object sender, RoutedEventArgs e) { - SettingsViewModel vm = DataContext as SettingsViewModel; - if (string.IsNullOrWhiteSpace(vm.OsuDirectory) || !Directory.Exists(vm.OsuDirectory)) + bool exitAutoDetect; + do { - var msgBox = MaterialMessageBox.Show(Helper.FindString("settings_title_autodetectOsu"), - Helper.FindString("settings_descr_autodetectOsu"), OsmoMessageBoxButton.YesNo); - - await DialogHelper.Instance.ShowDialog(msgBox); - - if (msgBox.Result == OsmoMessageBoxResult.Yes) + exitAutoDetect = true; + SettingsViewModel vm = DataContext as SettingsViewModel; + if (string.IsNullOrWhiteSpace(vm.OsuDirectory) || !Directory.Exists(vm.OsuDirectory)) { - string osuPath = Helper.FindOsuInstallation(); - - if (!string.IsNullOrWhiteSpace(osuPath)) + if (Helper.IsOsuInstalled()) { - vm.OsuDirectory = osuPath; + var msgBox = MaterialMessageBox.Show(Helper.FindString("settings_title_autodetectOsu"), + Helper.FindString("settings_descr_autodetectOsu"), OsmoMessageBoxButton.YesNo); + + await DialogHelper.Instance.ShowDialog(msgBox); + + if (msgBox.Result == OsmoMessageBoxResult.Yes) + { + string osuPath = Helper.FindOsuInstallation(); + + if (!string.IsNullOrWhiteSpace(osuPath)) + { + vm.OsuDirectory = osuPath; + } + else + { + msgBox = MaterialMessageBox.Show(Helper.FindString("settings_title_autodetectFailed"), + Helper.FindString("settings_descr_autodetectFailed"), OsmoMessageBoxButton.OKRetry); + + await DialogHelper.Instance.ShowDialog(msgBox); + + if (msgBox.Result == OsmoMessageBoxResult.Retry) + { + exitAutoDetect = false; + } + } + } } else { - msgBox = MaterialMessageBox.Show(Helper.FindString("settings_title_autodetectFailed"), - Helper.FindString("settings_descr_autodetectFailed"), OsmoMessageBoxButton.OK); + var msgBox = MaterialMessageBox.Show(Helper.FindString("settings_title_autodetectNoOsuInstalled"), + Helper.FindString("settings_descr_autodetectNoOsuInstalled"), OsmoMessageBoxButton.OKRetry); await DialogHelper.Instance.ShowDialog(msgBox); + + if (msgBox.Result == OsmoMessageBoxResult.Retry) + { + exitAutoDetect = false; + } } } - } + } while (!exitAutoDetect); } private void Abort_Click(object sender, RoutedEventArgs e)