From 0b9b3f40d052d45862852053460b06aab529f9c0 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sun, 12 Apr 2020 10:03:58 -0500 Subject: [PATCH] Download latest updater version number from online repository --- DS4Windows/DS4Forms/MainWindow.xaml.cs | 29 ++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/DS4Windows/DS4Forms/MainWindow.xaml.cs b/DS4Windows/DS4Forms/MainWindow.xaml.cs index 7a57bdb..c647294 100644 --- a/DS4Windows/DS4Forms/MainWindow.xaml.cs +++ b/DS4Windows/DS4Forms/MainWindow.xaml.cs @@ -169,6 +169,30 @@ namespace DS4WinWPF.DS4Forms } } + private string DownloadUpstreamUpdaterVersion() + { + string result = string.Empty; + // Sorry other devs, gonna have to find your own server + Uri url = new Uri("https://raw.githubusercontent.com/Ryochan7/DS4Updater/master/Updater2/newest.txt"); + string filename = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "DS4Updater_version.txt"); + bool readFile = false; + using (var downloadStream = new FileStream(filename, FileMode.Create)) + { + Task temp = App.requestClient.GetAsync(url.ToString(), downloadStream); + temp.Wait(); + + if (temp.Result.IsSuccessStatusCode) readFile = true; + } + + if (readFile) + { + result = File.ReadAllText(filename).Trim(); + File.Delete(filename); + } + + return result; + } + private void Check_Version(bool showstatus = false) { string version = Global.exeversion; @@ -244,11 +268,12 @@ Properties.Resources.DS4Update, MessageBoxButton.YesNo, MessageBoxImage.Question { string destPath = Global.exedirpath + "\\DS4Updater.exe"; bool updaterExists = File.Exists(destPath); + string version = DownloadUpstreamUpdaterVersion(); if (!updaterExists || - (FileVersionInfo.GetVersionInfo(destPath).FileVersion.CompareTo(MainWindowsViewModel.UPDATER_VERSION) != 0)) + (!string.IsNullOrEmpty(version) && FileVersionInfo.GetVersionInfo(destPath).FileVersion.CompareTo(version) != 0)) { launch = false; - Uri url2 = new Uri($"https://github.com/Ryochan7/DS4Updater/releases/download/v{MainWindowsViewModel.UPDATER_VERSION}/{mainWinVM.updaterExe}"); + Uri url2 = new Uri($"https://github.com/Ryochan7/DS4Updater/releases/download/v{version}/{mainWinVM.updaterExe}"); string filename = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "DS4Updater.exe"); using (var downloadStream = new FileStream(filename, FileMode.Create)) {