Fixed a issue where the Installer crashed when a invalid path is in registry.

This commit is contained in:
HorizonCode 2021-06-19 22:12:44 +02:00
parent e43782cfd6
commit 236de72895
2 changed files with 24 additions and 9 deletions

View File

@ -107,12 +107,15 @@ namespace EZPPClient_Installer
folderTextbox.Text = osuPath; folderTextbox.Text = osuPath;
} }
else else
{
folderTextbox.Text = "";
await new ContentDialog() await new ContentDialog()
{ {
Title = "Hmmm..", Title = "Hmmm..",
Content = "We failed to locate your osu! Installation path, please define it manually qwq", Content = "We failed to locate your osu! Installation path, please define it manually qwq",
PrimaryButtonText = "Okay qwq" PrimaryButtonText = "Okay qwq"
}.ShowAsync(); }.ShowAsync();
}
} }
@ -633,7 +636,7 @@ namespace EZPPClient_Installer
private async Task<bool> isValidOsuFolder(string folder) private async Task<bool> isValidOsuFolder(string folder)
{ {
if (string.IsNullOrEmpty(folder) || string.IsNullOrWhiteSpace(folder)) if (string.IsNullOrEmpty(folder) || string.IsNullOrWhiteSpace(folder) || !Directory.Exists(folder))
return false; return false;
string[] files = Directory.GetFiles(folder, "*"); string[] files = Directory.GetFiles(folder, "*");
string[] subDirs = Directory.GetDirectories(folder, "*"); string[] subDirs = Directory.GetDirectories(folder, "*");

View File

@ -12,10 +12,14 @@ namespace EZPPClient_Installer
string second_registry_key = @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"; string second_registry_key = @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key)) using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
{
if (key != null && key.GetSubKeyNames() != null)
{ {
foreach (string subkey_name in key.GetSubKeyNames()) foreach (string subkey_name in key.GetSubKeyNames())
{ {
using (RegistryKey subkey = key.OpenSubKey(subkey_name)) using (RegistryKey subkey = key.OpenSubKey(subkey_name))
{
if (subkey != null)
{ {
if ((string)subkey.GetValue("DisplayName") == "osu!") if ((string)subkey.GetValue("DisplayName") == "osu!")
{ {
@ -24,14 +28,20 @@ namespace EZPPClient_Installer
} }
} }
} }
}
}
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
{ {
using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(second_registry_key)) using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(second_registry_key))
{
if (key != null && key.GetSubKeyNames() != null)
{ {
foreach (string subkey_name in key.GetSubKeyNames()) foreach (string subkey_name in key.GetSubKeyNames())
{ {
using (RegistryKey subkey = key.OpenSubKey(subkey_name)) using (RegistryKey subkey = key.OpenSubKey(subkey_name))
{
if (subkey != null)
{ {
if ((string)subkey.GetValue("DisplayName") == "osu!") if ((string)subkey.GetValue("DisplayName") == "osu!")
{ {
@ -41,6 +51,8 @@ namespace EZPPClient_Installer
} }
} }
} }
}
}
return path; return path;
} }