From 1c320505c6d8d261b1f58daa8b16cba96203802d Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sun, 12 Apr 2020 03:26:34 -0500 Subject: [PATCH] Only launch updater copy in elevated mode if required --- DS4Windows/DS4Forms/MainWindow.xaml.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/DS4Windows/DS4Forms/MainWindow.xaml.cs b/DS4Windows/DS4Forms/MainWindow.xaml.cs index 571a57c..80ef377 100644 --- a/DS4Windows/DS4Forms/MainWindow.xaml.cs +++ b/DS4Windows/DS4Forms/MainWindow.xaml.cs @@ -242,9 +242,9 @@ Properties.Resources.DS4Update, MessageBoxButton.YesNo, MessageBoxImage.Question private bool RunUpdaterCheck(bool launch) { - if (!File.Exists(Global.exedirpath + "\\DS4Updater.exe") || - (File.Exists(Global.exedirpath + "\\DS4Updater.exe") - && (FileVersionInfo.GetVersionInfo(Global.exedirpath + "\\DS4Updater.exe").FileVersion.CompareTo(MainWindowsViewModel.UPDATER_VERSION) != 0))) + bool updaterExists = File.Exists(Global.exedirpath + "\\DS4Updater.exe"); + if (!updaterExists || + (FileVersionInfo.GetVersionInfo(Global.exedirpath + "\\DS4Updater.exe").FileVersion.CompareTo(MainWindowsViewModel.UPDATER_VERSION) != 0)) { launch = false; Uri url2 = new Uri($"https://github.com/Ryochan7/DS4Updater/releases/download/v{MainWindowsViewModel.UPDATER_VERSION}/{mainWinVM.updaterExe}"); @@ -259,8 +259,15 @@ Properties.Resources.DS4Update, MessageBoxButton.YesNo, MessageBoxImage.Question if (launch) { - int copyStatus = Util.ElevatedCopyUpdater(filename); - if (copyStatus != 0) launch = false; + if (Global.AdminNeeded()) + { + int copyStatus = Util.ElevatedCopyUpdater(filename); + if (copyStatus != 0) launch = false; + } + else + { + File.Move(filename, Global.exedirpath + "\\DS4Updater.exe"); + } } }