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
1 changed files with 85 additions and 33 deletions

View File

@ -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<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 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,