Only launch updater copy in elevated mode if required

This commit is contained in:
Travis Nickles 2020-04-12 03:26:34 -05:00
parent 339846f701
commit 1c320505c6

View File

@ -242,9 +242,9 @@ Properties.Resources.DS4Update, MessageBoxButton.YesNo, MessageBoxImage.Question
private bool RunUpdaterCheck(bool launch) private bool RunUpdaterCheck(bool launch)
{ {
if (!File.Exists(Global.exedirpath + "\\DS4Updater.exe") || bool updaterExists = File.Exists(Global.exedirpath + "\\DS4Updater.exe");
(File.Exists(Global.exedirpath + "\\DS4Updater.exe") if (!updaterExists ||
&& (FileVersionInfo.GetVersionInfo(Global.exedirpath + "\\DS4Updater.exe").FileVersion.CompareTo(MainWindowsViewModel.UPDATER_VERSION) != 0))) (FileVersionInfo.GetVersionInfo(Global.exedirpath + "\\DS4Updater.exe").FileVersion.CompareTo(MainWindowsViewModel.UPDATER_VERSION) != 0))
{ {
launch = false; 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{MainWindowsViewModel.UPDATER_VERSION}/{mainWinVM.updaterExe}");
@ -259,8 +259,15 @@ Properties.Resources.DS4Update, MessageBoxButton.YesNo, MessageBoxImage.Question
if (launch) if (launch)
{ {
int copyStatus = Util.ElevatedCopyUpdater(filename); if (Global.AdminNeeded())
if (copyStatus != 0) launch = false; {
int copyStatus = Util.ElevatedCopyUpdater(filename);
if (copyStatus != 0) launch = false;
}
else
{
File.Move(filename, Global.exedirpath + "\\DS4Updater.exe");
}
} }
} }