From 6892bc2a47ee172b5226b697b62d8a41d7abe852 Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Tue, 25 May 2021 10:13:53 +0200 Subject: [PATCH] Added Uninstall feature, made everything async c: --- EZPPClient Installer/MainWindow.xaml.cs | 118 +++++++++++++++++------- 1 file changed, 85 insertions(+), 33 deletions(-) diff --git a/EZPPClient Installer/MainWindow.xaml.cs b/EZPPClient Installer/MainWindow.xaml.cs index 8aaa255..8bb3a0b 100644 --- a/EZPPClient Installer/MainWindow.xaml.cs +++ b/EZPPClient Installer/MainWindow.xaml.cs @@ -61,11 +61,17 @@ namespace EZPPClient_Installer InstallerWindow.Title = "EZPPClient Installer " + versionString.Replace(",", "."); string osuPath = ""; - + bool isValidFolder = await isValidOsuFolder(osuPath); UpdateInstallButton(!string.IsNullOrEmpty(osuPath)); - - if (!string.IsNullOrEmpty(osuPath)) + + if(!string.IsNullOrEmpty(osuPath) && isValidFolder) + { + bool foundInstall = await isEZPPClientInstallationFound(osuPath); + if(foundInstall) + InstallButton.Content = "Uninstall"; + folderTextbox.Text = osuPath; + } else await new ContentDialog() { @@ -138,11 +144,25 @@ namespace EZPPClient_Installer private void UpdateInstallButton(bool enable) { InstallButton.IsEnabled = enable; + linkFoldersCheckbox.IsEnabled = enable; } - private void Install_Click(object sender, RoutedEventArgs e) + private async void Install_Click(object sender, RoutedEventArgs e) { - + string osuFolder = folderTextbox.Text; + bool isValid = await isValidOsuFolder(osuFolder); + if (!isValid) + { + await new ContentDialog() + { + Title = "Hmmm..", + Content = "It seems like the selected folder is not a osu! installation.", + PrimaryButtonText = "Okay qwq" + }.ShowAsync(); + return; + } + + } private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) @@ -151,7 +171,7 @@ namespace EZPPClient_Installer e.Handled = true; } - private void Browse_Click(object sender, RoutedEventArgs e) + private async void Browse_Click(object sender, RoutedEventArgs e) { using (var fbd = new FolderBrowserDialog()) { @@ -159,48 +179,80 @@ namespace EZPPClient_Installer if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) { - string[] files = Directory.GetFiles(fbd.SelectedPath, "*"); - string[] subDirs = Directory.GetDirectories(fbd.SelectedPath, "*"); - bool hasSongsFolder = false; - bool hasSkinsFolder = false; - bool hasOsuExecutable = false; - foreach(string file in files) - { - if (file.Contains("osu!.exe")) - { - hasOsuExecutable = true; - break; - } - } + bool isValid = await isValidOsuFolder(fbd.SelectedPath); - foreach (string dir in subDirs) + if (!isValid) { - if (dir.Contains("Songs") && !hasSongsFolder) - hasSongsFolder = true; - if (dir.Contains("Skins") && !hasSkinsFolder) - hasSkinsFolder = true; - - if (hasSkinsFolder && hasSongsFolder) - break; - } - - if (!hasSongsFolder || !hasSkinsFolder || !hasOsuExecutable) - { - new ContentDialog() + await new ContentDialog() { Title = "Hmmm..", - Content = "It seems like this Folder is not a osu! Installation.", + Content = "It seems like this folder is not a osu! installation.", PrimaryButtonText = "Okay qwq" }.ShowAsync(); } else { + bool foundInstall = await isEZPPClientInstallationFound(fbd.SelectedPath); folderTextbox.Text = fbd.SelectedPath; + + if(foundInstall) + InstallButton.Content = "Uninstall"; + UpdateInstallButton(true); } } } } + + private async Task isEZPPClientInstallationFound(string folder) + { + string[] subDirs = Directory.GetDirectories(folder, "*"); + bool doesExist = false; + + foreach (string dir in subDirs) + { + if(dir.Contains("EZPPClient")) + { + doesExist = true; + break; + } + } + + return doesExist; + } + + private async Task isValidOsuFolder(string folder) + { + if(string.IsNullOrEmpty(folder) || string.IsNullOrWhiteSpace(folder)) + return false; + string[] files = Directory.GetFiles(folder, "*"); + string[] subDirs = Directory.GetDirectories(folder, "*"); + bool hasSongsFolder = false; + bool hasSkinsFolder = false; + bool hasOsuExecutable = false; + foreach(string file in files) + { + if (file.Contains("osu!.exe")) + { + hasOsuExecutable = true; + break; + } + } + + foreach (string dir in subDirs) + { + if (dir.Contains("Songs") && !hasSongsFolder) + hasSongsFolder = true; + if (dir.Contains("Skins") && !hasSkinsFolder) + hasSkinsFolder = true; + + if (hasSkinsFolder && hasSongsFolder) + break; + } + + return hasOsuExecutable && hasSkinsFolder && hasSongsFolder; + } + private enum SymbolicLink { File,