From d3305aa27c50865f70298abaef16a3649a7f279e Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Tue, 25 May 2021 13:14:20 +0200 Subject: [PATCH] changed endpoints for version,data and listing, its now implemented into the EZPPanel --- EZPPClient Installer/DownloadUtil.cs | 50 ++++++++++----- EZPPClient Installer/MainWindow.xaml.cs | 81 ++++++++++++++++++------- 2 files changed, 96 insertions(+), 35 deletions(-) diff --git a/EZPPClient Installer/DownloadUtil.cs b/EZPPClient Installer/DownloadUtil.cs index c511ab4..f9d8f06 100644 --- a/EZPPClient Installer/DownloadUtil.cs +++ b/EZPPClient Installer/DownloadUtil.cs @@ -24,7 +24,7 @@ namespace EZPPClient_Installer using (WebClient wc = new WebClient()) { - var data = wc.DownloadString("https://ez-pp.farm/static/client/client.data"); + var data = wc.DownloadString("https://new.ez-pp.farm/ezppclient?list"); string[] dataList = data.Split('\n'); foreach (string datastring in dataList) { @@ -32,12 +32,13 @@ namespace EZPPClient_Installer continue; string[] se = datastring.Split('#'); - string md5 = se[0].Replace("\r\n", "").Replace("\r", "").Replace("\n", ""); - string name = se[1].Replace("\r\n", "").Replace("\r", "").Replace("\n", ""); + string md5 = StripHTML(se[0]); + string name = StripHTML(se[1]); md5Files.Add(new MD5File(name, md5)); } } - }catch(WebException error) + } + catch (WebException error) { new ContentDialog() { @@ -54,12 +55,7 @@ namespace EZPPClient_Installer } else { - /*string[] files = Directory.GetFiles(pathToEZPP, "*"); - foreach (var file in files) - { - - }*/ - foreach(MD5File md5file in md5Files) + foreach (MD5File md5file in md5Files) { string file = pathToEZPP + @"\" + md5file.getName(); bool doesExistOnPC = File.Exists(file); @@ -71,7 +67,7 @@ namespace EZPPClient_Installer { string onlineHash = md5file.getMD5(); string pcHash = MD5Util.CalculateMD5(file); - if(!string.Equals(onlineHash, pcHash)) + if (!string.Equals(onlineHash, pcHash)) { downloadList.Add(md5file.getName()); } @@ -79,15 +75,41 @@ namespace EZPPClient_Installer } } +#if DEBUG MessageBox.Show(downloadList.Count + "/" + md5Files.Count + " Files need for update"); - +#endif return downloadList; } - public async Task CheckForUpdate() + public static async Task DownloadFiles(List files, string path) { - return false; + if (!Directory.Exists(path)) + Directory.CreateDirectory(path); + + foreach(string filename in files) + { + await DownloadFile(filename, path); + + } } + private static async Task DownloadFile(string filename, string path) + { + try + { + using (WebClient wc = new WebClient()) + { + wc.DownloadProgressChanged += (sender, value) => MainWindow.updateProgress(filename + " - " + value.ProgressPercentage + "% - " + Math.Round((value.BytesReceived / 1024000D), 2) + "MB/" + Math.Round((value.TotalBytesToReceive / 1024000D), 2) + "MB", value.ProgressPercentage); + await wc.DownloadFileTaskAsync(@"https://new.ez-pp.farm/ezppclient?file=" + filename, path + @"\" + filename); + } + }catch(WebException) + { + } + } + + private static string StripHTML(string input) + { + return input.Replace("\r\n", "").Replace("\r", "").Replace("\n", ""); + } } } \ No newline at end of file diff --git a/EZPPClient Installer/MainWindow.xaml.cs b/EZPPClient Installer/MainWindow.xaml.cs index d5db305..d4c3631 100644 --- a/EZPPClient Installer/MainWindow.xaml.cs +++ b/EZPPClient Installer/MainWindow.xaml.cs @@ -29,6 +29,8 @@ namespace EZPPClient_Installer public partial class MainWindow : Window { + public static MainWindow Instance { get; private set; } + [DllImport("kernel32.dll")] private static extern bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, SymbolicLink dwFlags); @@ -36,8 +38,8 @@ namespace EZPPClient_Installer public MainWindow() { + Instance = this; InitializeComponent(); - DownloadUtil.FilesToDownload("yeet"); Init(); } @@ -61,13 +63,13 @@ namespace EZPPClient_Installer string versionString = "v" + VERSION; InstallerWindow.Title = "EZPPClient Installer " + versionString.Replace(",", "."); - string osuPath = ""; + string osuPath = Util.osuInstallDir(); bool isValidFolder = await isValidOsuFolder(osuPath); UpdateInstallButton(!string.IsNullOrEmpty(osuPath)); if(!string.IsNullOrEmpty(osuPath) && isValidFolder) { - bool foundInstall = await isEZPPClientInstallationFound(osuPath); + bool foundInstall = isEZPPClientInstallationFound(osuPath); if (foundInstall) { Uninstall_Button.Visibility = Visibility.Visible; @@ -96,7 +98,7 @@ namespace EZPPClient_Installer { using (WebClient client = new WebClient()) { - string newVersionString = client.DownloadString("https://ez-pp.farm/static/client/installer.ver"); + string newVersionString = client.DownloadString("https://new.ez-pp.farm/ezppclient?version"); double ver = 0; try { @@ -169,8 +171,50 @@ namespace EZPPClient_Installer }.ShowAsync(); return; } - - + + string EZPPFolder = osuFolder + @"\EZPPClient"; + + List filesToDownload = DownloadUtil.FilesToDownload(EZPPFolder); + + Visibility prevInstallBtnVis = InstallButton.Visibility; + Visibility prevUninstallBtnVis = Uninstall_Button.Visibility; + Visibility prevLinkFCVis = linkFoldersCheckbox.Visibility; + + InstallButton.Visibility = Visibility.Hidden; + Uninstall_Button.Visibility = Visibility.Hidden; + linkFoldersCheckbox.Visibility = Visibility.Hidden; + + Download_Text.Visibility = Visibility.Visible; + Download_Progressbar.Visibility = Visibility.Visible; + + await DownloadUtil.DownloadFiles(filesToDownload, EZPPFolder); + + InstallButton.Visibility = prevInstallBtnVis; + Uninstall_Button.Visibility = prevUninstallBtnVis; + linkFoldersCheckbox.Visibility = prevLinkFCVis; + + Download_Text.Visibility = Visibility.Hidden; + Download_Progressbar.Visibility = Visibility.Hidden; + + await new ContentDialog() + { + Title = "Success!", + Content = "The EZPPClient was successfully installed!", + PrimaryButtonText = "Yaaay :3" + }.ShowAsync(); + + Uninstall_Button.Visibility = Visibility.Visible; + UpdateInstallButton(false); + + string osuEZPPPath = folderTextbox.Text + @"\EZPPClient"; + List outdatedFiles = DownloadUtil.FilesToDownload(osuEZPPPath); + + if (!IsEmpty(outdatedFiles)) + { + InstallButton.Content = "Update"; + UpdateInstallButton(true); + } + } private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) @@ -200,7 +244,7 @@ namespace EZPPClient_Installer } else { - bool foundInstall = await isEZPPClientInstallationFound(fbd.SelectedPath); + bool foundInstall = isEZPPClientInstallationFound(fbd.SelectedPath); folderTextbox.Text = fbd.SelectedPath; if (foundInstall) @@ -224,21 +268,9 @@ namespace EZPPClient_Installer } } - private async Task isEZPPClientInstallationFound(string folder) + private 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; + return Directory.Exists(folder + @"\EZPPClient"); } private async Task isValidOsuFolder(string folder) @@ -289,5 +321,12 @@ namespace EZPPClient_Installer Directory } + public static void updateProgress(string file, double progress) + { + Instance.Download_Progressbar.IsIndeterminate = (progress == 100); + Instance.Download_Progressbar.Value = progress; + Instance.Download_Text.Content = "Downloading: " + file; + } + } }