Skip to content

Commit

Permalink
Fixed yet another startup crash, added some smaller features to osu! …
Browse files Browse the repository at this point in the history
…auto detect
  • Loading branch information
BlackTasty committed Aug 15, 2018
1 parent 26d12c1 commit 355faa1
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 25 deletions.
31 changes: 26 additions & 5 deletions Osmo/Core/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion Osmo/Core/Objects/OsmoMessageBoxButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
4 changes: 4 additions & 0 deletions Osmo/Core/Objects/OsmoMessageBoxResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
//
Expand Down
5 changes: 4 additions & 1 deletion Osmo/Localisation/StringResources.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<system:String o:Freeze="True" x:Key="yes">_YES</system:String>
<system:String o:Freeze="True" x:Key="no">_NO</system:String>
<system:String o:Freeze="True" x:Key="import">_IMPORT</system:String>
<system:String o:Freeze="True" x:Key="retry">_RETRY</system:String>
<system:String o:Freeze="True" x:Key="loadTemplate">_LOAD TEMPLATE</system:String>
<system:String o:Freeze="True" x:Key="newTemplate">_NEW TEMPLATE</system:String>
<system:String o:Freeze="True" x:Key="loadSkin">_LOAD SKIN</system:String>
Expand Down Expand Up @@ -148,10 +149,12 @@
<system:String o:Freeze="True" x:Key="settings_header_editor">Editor</system:String>
<system:String o:Freeze="True" x:Key="settings_header_shortcuts">Keyboard shortcuts</system:String>
<system:String o:Freeze="True" x:Key="settings_header_shortcutsCheatSheet">Cheat sheet</system:String>
<system:String o:Freeze="True" x:Key="settings_title_autodetectNoOsuInstalled">osu! is not installed!</system:String>
<system:String o:Freeze="True" x:Key="settings_descr_autodetectNoOsuInstalled">Should osu! be installed make sure it has been installed correctly, otherwise select it manually.</system:String>
<system:String o:Freeze="True" x:Key="settings_title_autodetectOsu">Auto-detect osu! folder</system:String>
<system:String o:Freeze="True" x:Key="settings_descr_autodetectOsu">Do you wish for Osmo to find your osu! installation folder?</system:String>
<system:String o:Freeze="True" x:Key="settings_title_autodetectFailed">Auto-detect failed!</system:String>
<system:String o:Freeze="True" x:Key="settings_descr_autodetectFailed">Are you sure you have osu! installed?</system:String>
<system:String o:Freeze="True" x:Key="settings_descr_autodetectFailed">Are you sure you have osu! installed correctly?</system:String>
<system:String o:Freeze="True" x:Key="settings_unsavedChangesDescription">You have unsaved changes to your settings! Do you want to save them first? (Selecting No reverts all changes to your settings)</system:String>

<!--DragDropArea-->
Expand Down
4 changes: 2 additions & 2 deletions Osmo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<Window.DataContext>
<vm:OsmoViewModel/>
</Window.DataContext>
Expand All @@ -34,7 +34,7 @@
</metro:MetroWindow.WindowButtonCommands>

<!--SnackbarMessageQueue="{Binding ElementName=MainSnackbar, Path=MessageQueue}"-->
<material:DialogHost Identifier="RootDialog">
<material:DialogHost Identifier="RootDialog" Loaded="DialogHost_Loaded">
<material:DialogHost.DialogContent>
<ui:NewSkinDialog x:Name="dialg_newSkin" Margin="16"/>
</material:DialogHost.DialogContent>
Expand Down
2 changes: 1 addition & 1 deletion Osmo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions Osmo/UI/MaterialMessageBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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:
Expand Down
55 changes: 40 additions & 15 deletions Osmo/UI/Settings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 355faa1

Please sign in to comment.