Tweak update checker routine

Simplify a bit. Result feels more responsive
This commit is contained in:
Travis Nickles 2019-10-28 20:28:42 -05:00
parent 541112e188
commit 8c12fe742c

View File

@ -962,9 +962,14 @@ namespace DS4Windows.Forms
bool launchUpdate = false; bool launchUpdate = false;
if (!string.IsNullOrWhiteSpace(newversion) && version.Replace(',', '.').CompareTo(newversion) != 0) if (!string.IsNullOrWhiteSpace(newversion) && version.Replace(',', '.').CompareTo(newversion) != 0)
{ {
if ((DialogResult)this.Invoke(new Func<DialogResult>(() => { DialogResult result = DialogResult.No;
return MessageBox.Show(Properties.Resources.DownloadVersion.Replace("*number*", newversion), this.Invoke((System.Action)(() =>
Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question); })) == DialogResult.Yes) {
MessageBox.Show(Properties.Resources.DownloadVersion.Replace("*number*", newversion),
Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
}));
if (result == DialogResult.Yes)
{ {
launchUpdate = true; launchUpdate = true;
if (!File.Exists(exepath + "\\DS4Updater.exe") || (File.Exists(exepath + "\\DS4Updater.exe") if (!File.Exists(exepath + "\\DS4Updater.exe") || (File.Exists(exepath + "\\DS4Updater.exe")
@ -986,14 +991,21 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
if (launchUpdate) if (launchUpdate)
{ {
Process p = new Process(); using (Process p = new Process())
{
p.StartInfo.FileName = exepath + "\\DS4Updater.exe"; p.StartInfo.FileName = exepath + "\\DS4Updater.exe";
p.StartInfo.Arguments = "-autolaunch"; p.StartInfo.Arguments = "-autolaunch";
if (AdminNeeded()) if (AdminNeeded())
p.StartInfo.Verb = "runas"; p.StartInfo.Verb = "runas";
try { p.Start(); Close(); } try { p.Start(); }
catch { } catch (Exception) { launchUpdate = false; }
}
}
if (launchUpdate)
{
Close();
} }
} }
else else
@ -2356,14 +2368,19 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
string version2 = fvi.FileVersion; string version2 = fvi.FileVersion;
string newversion2 = File.ReadAllText(appdatapath + "\\version.txt").Trim(); string newversion2 = File.ReadAllText(appdatapath + "\\version.txt").Trim();
bool launchUpdate = false;
if (!string.IsNullOrWhiteSpace(newversion2) && version2.Replace(',', '.').CompareTo(newversion2) != 0) if (!string.IsNullOrWhiteSpace(newversion2) && version2.Replace(',', '.').CompareTo(newversion2) != 0)
{ {
if ((DialogResult)this.Invoke(new Func<DialogResult>(() => DialogResult result = DialogResult.No;
this.Invoke((System.Action)(() =>
{ {
return MessageBox.Show(Properties.Resources.DownloadVersion.Replace("*number*", newversion2), MessageBox.Show(Properties.Resources.DownloadVersion.Replace("*number*", newversion2),
Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question); Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
})) == DialogResult.Yes) }));
if (result == DialogResult.Yes)
{ {
launchUpdate = true;
if (!File.Exists(exepath + "\\DS4Updater.exe") || (File.Exists(exepath + "\\DS4Updater.exe") if (!File.Exists(exepath + "\\DS4Updater.exe") || (File.Exists(exepath + "\\DS4Updater.exe")
&& (FileVersionInfo.GetVersionInfo(exepath + "\\DS4Updater.exe").FileVersion.CompareTo(UPDATER_VERSION) != 0))) && (FileVersionInfo.GetVersionInfo(exepath + "\\DS4Updater.exe").FileVersion.CompareTo(UPDATER_VERSION) != 0)))
{ {
@ -2375,17 +2392,28 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
{ {
this.BeginInvoke((System.Action)(() => MessageBox.Show(Properties.Resources.PleaseDownloadUpdater))); this.BeginInvoke((System.Action)(() => MessageBox.Show(Properties.Resources.PleaseDownloadUpdater)));
Process.Start($"https://github.com/Ryochan7/DS4Updater/releases/download/v{UPDATER_VERSION}/{updaterExe}"); Process.Start($"https://github.com/Ryochan7/DS4Updater/releases/download/v{UPDATER_VERSION}/{updaterExe}");
launchUpdate = false;
} }
} }
Process p = new Process(); if (launchUpdate)
{
using (Process p = new Process())
{
p.StartInfo.FileName = exepath + "\\DS4Updater.exe"; p.StartInfo.FileName = exepath + "\\DS4Updater.exe";
p.StartInfo.Arguments = "-autolaunch"; p.StartInfo.Arguments = "-autolaunch";
if (AdminNeeded()) if (AdminNeeded())
p.StartInfo.Verb = "runas"; p.StartInfo.Verb = "runas";
try { p.Start(); Close(); } try { p.Start(); }
catch { } catch (Exception) { launchUpdate = false; }
}
}
if (launchUpdate)
{
Close();
}
} }
else else
File.Delete(appdatapath + "\\version.txt"); File.Delete(appdatapath + "\\version.txt");