2021-05-25 06:44:50 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
using System.Windows.Navigation;
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using MessageBox = System.Windows.MessageBox;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using ModernWpf.Controls;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace EZPPClient_Installer
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll")]
|
|
|
|
|
private static extern bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, SymbolicLink dwFlags);
|
|
|
|
|
|
|
|
|
|
private static double VERSION = 1.6;
|
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2021-05-25 09:04:08 +00:00
|
|
|
|
DownloadUtil.FilesToDownload("yeet");
|
2021-05-25 06:44:50 +00:00
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void Init()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
UpdateInstallButton(false);
|
|
|
|
|
|
2021-05-25 09:04:08 +00:00
|
|
|
|
UpdateState status = await CheckForInstallerUpdates();
|
2021-05-25 06:44:50 +00:00
|
|
|
|
|
|
|
|
|
switch (status)
|
|
|
|
|
{
|
2021-05-25 09:04:08 +00:00
|
|
|
|
case UpdateState.UpdateFound:
|
|
|
|
|
ShowInstallerUpdateDialog();
|
2021-05-25 06:44:50 +00:00
|
|
|
|
return;
|
2021-05-25 09:04:08 +00:00
|
|
|
|
case UpdateState.Error:
|
2021-05-25 06:44:50 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string versionString = "v" + VERSION;
|
|
|
|
|
InstallerWindow.Title = "EZPPClient Installer " + versionString.Replace(",", ".");
|
|
|
|
|
|
|
|
|
|
string osuPath = "";
|
2021-05-25 08:13:53 +00:00
|
|
|
|
bool isValidFolder = await isValidOsuFolder(osuPath);
|
2021-05-25 06:44:50 +00:00
|
|
|
|
UpdateInstallButton(!string.IsNullOrEmpty(osuPath));
|
2021-05-25 08:13:53 +00:00
|
|
|
|
|
|
|
|
|
if(!string.IsNullOrEmpty(osuPath) && isValidFolder)
|
|
|
|
|
{
|
|
|
|
|
bool foundInstall = await isEZPPClientInstallationFound(osuPath);
|
2021-05-25 09:04:08 +00:00
|
|
|
|
if (foundInstall)
|
|
|
|
|
{
|
|
|
|
|
Uninstall_Button.Visibility = Visibility.Visible;
|
|
|
|
|
UpdateInstallButton(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2021-05-25 08:13:53 +00:00
|
|
|
|
|
2021-05-25 06:44:50 +00:00
|
|
|
|
folderTextbox.Text = osuPath;
|
2021-05-25 08:13:53 +00:00
|
|
|
|
}
|
2021-05-25 06:44:50 +00:00
|
|
|
|
else
|
|
|
|
|
await new ContentDialog()
|
|
|
|
|
{
|
|
|
|
|
Title = "Hmmm..",
|
|
|
|
|
Content = "We failed to locate your osu! Installation path, please define it manually qwq",
|
|
|
|
|
PrimaryButtonText = "Okay qwq"
|
|
|
|
|
}.ShowAsync();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-25 09:04:08 +00:00
|
|
|
|
private async Task<UpdateState> CheckForInstallerUpdates()
|
2021-05-25 06:44:50 +00:00
|
|
|
|
{
|
|
|
|
|
#if !DEBUG
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (WebClient client = new WebClient())
|
|
|
|
|
{
|
|
|
|
|
string newVersionString = client.DownloadString("https://ez-pp.farm/static/client/installer.ver");
|
|
|
|
|
double ver = 0;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ver = double.Parse(newVersionString, CultureInfo.InvariantCulture);
|
|
|
|
|
}
|
|
|
|
|
catch (FormatException)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ver > VERSION)
|
2021-05-25 09:04:08 +00:00
|
|
|
|
return UpdateState.UpdateFound;
|
2021-05-25 06:44:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (WebException e)
|
|
|
|
|
{
|
|
|
|
|
ShowErrorDialog(e.Message);
|
2021-05-25 09:04:08 +00:00
|
|
|
|
return UpdateState.Error;
|
2021-05-25 06:44:50 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2021-05-25 09:04:08 +00:00
|
|
|
|
return UpdateState.UpToDate;
|
2021-05-25 06:44:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void ShowErrorDialog(string error)
|
|
|
|
|
{
|
|
|
|
|
var dialog = new ContentDialog()
|
|
|
|
|
{
|
|
|
|
|
Title = "Oops...",
|
|
|
|
|
Content = "Failed to connect to the EZPPFarm Website.\n" + error,
|
|
|
|
|
PrimaryButtonText = "Exit"
|
|
|
|
|
};
|
|
|
|
|
await dialog.ShowAsync();
|
|
|
|
|
this.Close();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-25 09:04:08 +00:00
|
|
|
|
private async void ShowInstallerUpdateDialog()
|
2021-05-25 06:44:50 +00:00
|
|
|
|
{
|
2021-05-25 09:04:08 +00:00
|
|
|
|
UpdateInstallButton(false);
|
2021-05-25 06:44:50 +00:00
|
|
|
|
var dialog = new ContentDialog()
|
|
|
|
|
{
|
|
|
|
|
Title = "New version available.",
|
|
|
|
|
Content = "Please download the latest version.",
|
|
|
|
|
PrimaryButtonText = "Download"
|
|
|
|
|
};
|
|
|
|
|
var result = await dialog.ShowAsync();
|
|
|
|
|
|
|
|
|
|
if (result == ContentDialogResult.Primary)
|
|
|
|
|
{
|
|
|
|
|
System.Diagnostics.Process.Start("https://ez-pp.farm/download");
|
2021-05-25 09:04:08 +00:00
|
|
|
|
ShowInstallerUpdateDialog();
|
2021-05-25 06:44:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateInstallButton(bool enable)
|
|
|
|
|
{
|
|
|
|
|
InstallButton.IsEnabled = enable;
|
2021-05-25 08:13:53 +00:00
|
|
|
|
linkFoldersCheckbox.IsEnabled = enable;
|
2021-05-25 06:44:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-25 08:13:53 +00:00
|
|
|
|
private async void Install_Click(object sender, RoutedEventArgs e)
|
2021-05-25 06:44:50 +00:00
|
|
|
|
{
|
2021-05-25 08:13:53 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-05-25 06:44:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
System.Diagnostics.Process.Start("https://ez-pp.farm/");
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-25 08:13:53 +00:00
|
|
|
|
private async void Browse_Click(object sender, RoutedEventArgs e)
|
2021-05-25 06:44:50 +00:00
|
|
|
|
{
|
|
|
|
|
using (var fbd = new FolderBrowserDialog())
|
|
|
|
|
{
|
|
|
|
|
DialogResult result = fbd.ShowDialog();
|
|
|
|
|
|
|
|
|
|
if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
|
|
|
|
|
{
|
2021-05-25 08:13:53 +00:00
|
|
|
|
bool isValid = await isValidOsuFolder(fbd.SelectedPath);
|
2021-05-25 06:44:50 +00:00
|
|
|
|
|
2021-05-25 08:13:53 +00:00
|
|
|
|
if (!isValid)
|
2021-05-25 06:44:50 +00:00
|
|
|
|
{
|
2021-05-25 08:13:53 +00:00
|
|
|
|
await new ContentDialog()
|
2021-05-25 06:44:50 +00:00
|
|
|
|
{
|
|
|
|
|
Title = "Hmmm..",
|
2021-05-25 09:33:06 +00:00
|
|
|
|
Content = "It seems like this location is not an osu! installation.",
|
2021-05-25 06:44:50 +00:00
|
|
|
|
PrimaryButtonText = "Okay qwq"
|
|
|
|
|
}.ShowAsync();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-05-25 08:13:53 +00:00
|
|
|
|
bool foundInstall = await isEZPPClientInstallationFound(fbd.SelectedPath);
|
2021-05-25 06:44:50 +00:00
|
|
|
|
folderTextbox.Text = fbd.SelectedPath;
|
2021-05-25 09:04:08 +00:00
|
|
|
|
|
|
|
|
|
if (foundInstall)
|
|
|
|
|
{
|
|
|
|
|
Uninstall_Button.Visibility = Visibility.Visible;
|
|
|
|
|
UpdateInstallButton(false);
|
|
|
|
|
|
|
|
|
|
string osuEZPPPath = folderTextbox.Text + @"\EZPPClient";
|
2021-05-25 09:33:06 +00:00
|
|
|
|
List<string> outdatedFiles = DownloadUtil.FilesToDownload(osuEZPPPath);
|
2021-05-25 09:04:08 +00:00
|
|
|
|
|
2021-05-25 09:33:06 +00:00
|
|
|
|
if (!IsEmpty(outdatedFiles))
|
|
|
|
|
{
|
|
|
|
|
InstallButton.Content = "Update";
|
|
|
|
|
UpdateInstallButton(true);
|
|
|
|
|
}
|
2021-05-25 09:04:08 +00:00
|
|
|
|
|
|
|
|
|
}else
|
2021-05-25 06:44:50 +00:00
|
|
|
|
UpdateInstallButton(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-25 08:13:53 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2021-05-25 09:33:06 +00:00
|
|
|
|
|
|
|
|
|
public static bool IsEmpty<T>(List<T> list)
|
|
|
|
|
{
|
|
|
|
|
if (list == null)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return !list.Any();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-25 06:44:50 +00:00
|
|
|
|
private enum SymbolicLink
|
|
|
|
|
{
|
|
|
|
|
File,
|
|
|
|
|
Directory
|
|
|
|
|
}
|
2021-05-25 09:04:08 +00:00
|
|
|
|
|
2021-05-25 06:44:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|