Added Uninstall feature, made everything async c:

This commit is contained in:
HorizonCode 2021-05-25 10:13:53 +02:00
parent b39ca245c3
commit 6892bc2a47

View File

@ -61,11 +61,17 @@ namespace EZPPClient_Installer
InstallerWindow.Title = "EZPPClient Installer " + versionString.Replace(",", "."); InstallerWindow.Title = "EZPPClient Installer " + versionString.Replace(",", ".");
string osuPath = ""; string osuPath = "";
bool isValidFolder = await isValidOsuFolder(osuPath);
UpdateInstallButton(!string.IsNullOrEmpty(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; folderTextbox.Text = osuPath;
}
else else
await new ContentDialog() await new ContentDialog()
{ {
@ -138,10 +144,24 @@ namespace EZPPClient_Installer
private void UpdateInstallButton(bool enable) private void UpdateInstallButton(bool enable)
{ {
InstallButton.IsEnabled = 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;
}
} }
@ -151,7 +171,7 @@ namespace EZPPClient_Installer
e.Handled = true; 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()) using (var fbd = new FolderBrowserDialog())
{ {
@ -159,8 +179,54 @@ namespace EZPPClient_Installer
if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
{ {
string[] files = Directory.GetFiles(fbd.SelectedPath, "*"); bool isValid = await isValidOsuFolder(fbd.SelectedPath);
string[] subDirs = Directory.GetDirectories(fbd.SelectedPath, "*");
if (!isValid)
{
await new ContentDialog()
{
Title = "Hmmm..",
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<bool> 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<bool> 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 hasSongsFolder = false;
bool hasSkinsFolder = false; bool hasSkinsFolder = false;
bool hasOsuExecutable = false; bool hasOsuExecutable = false;
@ -184,23 +250,9 @@ namespace EZPPClient_Installer
break; break;
} }
if (!hasSongsFolder || !hasSkinsFolder || !hasOsuExecutable) return hasOsuExecutable && hasSkinsFolder && hasSongsFolder;
{
new ContentDialog()
{
Title = "Hmmm..",
Content = "It seems like this Folder is not a osu! Installation.",
PrimaryButtonText = "Okay qwq"
}.ShowAsync();
}
else
{
folderTextbox.Text = fbd.SelectedPath;
UpdateInstallButton(true);
}
}
}
} }
private enum SymbolicLink private enum SymbolicLink
{ {
File, File,