Added Uninstall feature, made everything async c:
This commit is contained in:
parent
b39ca245c3
commit
6892bc2a47
|
@ -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,11 +144,25 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
|
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
|
||||||
|
@ -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,48 +179,80 @@ 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, "*");
|
|
||||||
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 (!isValid)
|
||||||
{
|
{
|
||||||
if (dir.Contains("Songs") && !hasSongsFolder)
|
await new ContentDialog()
|
||||||
hasSongsFolder = true;
|
|
||||||
if (dir.Contains("Skins") && !hasSkinsFolder)
|
|
||||||
hasSkinsFolder = true;
|
|
||||||
|
|
||||||
if (hasSkinsFolder && hasSongsFolder)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasSongsFolder || !hasSkinsFolder || !hasOsuExecutable)
|
|
||||||
{
|
|
||||||
new ContentDialog()
|
|
||||||
{
|
{
|
||||||
Title = "Hmmm..",
|
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"
|
PrimaryButtonText = "Okay qwq"
|
||||||
}.ShowAsync();
|
}.ShowAsync();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
bool foundInstall = await isEZPPClientInstallationFound(fbd.SelectedPath);
|
||||||
folderTextbox.Text = fbd.SelectedPath;
|
folderTextbox.Text = fbd.SelectedPath;
|
||||||
|
|
||||||
|
if(foundInstall)
|
||||||
|
InstallButton.Content = "Uninstall";
|
||||||
|
|
||||||
UpdateInstallButton(true);
|
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
|
private enum SymbolicLink
|
||||||
{
|
{
|
||||||
File,
|
File,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user