|
@@ -9,6 +9,7 @@ using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
+using System.Reflection;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
@@ -73,7 +74,15 @@ namespace PRS.Shared
|
|
|
return form.ShowDialog();
|
|
|
}
|
|
|
|
|
|
- public static void CheckForUpdates(
|
|
|
+ private static string GenerateInstallerScript(string installerFile)
|
|
|
+ {
|
|
|
+ var commands = new List<string>();
|
|
|
+ commands.Add($"\"{installerFile}\" /SILENT /SUPPRESSMSGBOXES /FORCECLOSEAPPLICATIONS /RESTARTAPPLICATIONS");
|
|
|
+ commands.Add($"\"{Path.ChangeExtension(Assembly.GetEntryAssembly().Location, ".exe")}\"");
|
|
|
+ return string.Join('\n', commands);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static bool CheckForUpdates(
|
|
|
Func<string> getUpdateLocation,
|
|
|
Func<string, string> getLatestVersion,
|
|
|
Func<string, string> getReleaseNotes,
|
|
@@ -107,7 +116,7 @@ namespace PRS.Shared
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- if (display.IsNullOrWhiteSpace()) return;
|
|
|
+ if (display.IsNullOrWhiteSpace()) return false;
|
|
|
|
|
|
if (ShowReleaseNotes(display, latestVersion, currentVersion) == true)
|
|
|
{
|
|
@@ -115,28 +124,43 @@ namespace PRS.Shared
|
|
|
var tempinstall = Path.Combine(CoreUtils.GetPath(), tempName);
|
|
|
Progress.ShowModal("Retrieving Update", progress =>
|
|
|
{
|
|
|
- var installer = getInstaller(location);
|
|
|
- if (installer?.Any() == true)
|
|
|
+ try
|
|
|
{
|
|
|
- File.WriteAllBytes(tempinstall, installer);
|
|
|
- bOK = true;
|
|
|
- }
|
|
|
+ var installer = getInstaller(location);
|
|
|
+ if (installer?.Any() == true)
|
|
|
+ {
|
|
|
+ File.WriteAllBytes(tempinstall, installer);
|
|
|
|
|
|
- beforeUpdate?.Invoke();
|
|
|
- progress.Report("Launching Installer");
|
|
|
- if (bOK)
|
|
|
+ var scriptFile = Path.Combine(CoreUtils.GetPath(), "install.bat");
|
|
|
+ File.WriteAllText(scriptFile, GenerateInstallerScript(tempinstall));
|
|
|
+
|
|
|
+ bOK = true;
|
|
|
+
|
|
|
+ beforeUpdate?.Invoke();
|
|
|
+ progress.Report("Launching Installer");
|
|
|
+ /*var startInfo = new ProcessStartInfo(tempinstall,
|
|
|
+ " /SILENT /SUPPRESSMSGBOXES /FORCECLOSEAPPLICATIONS /RESTARTAPPLICATIONS");*/
|
|
|
+ var startInfo = new ProcessStartInfo(scriptFile);
|
|
|
+ startInfo.Verb = elevated ? "runas" : "open";
|
|
|
+ startInfo.UseShellExecute = true;
|
|
|
+ startInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
|
|
+ var p = Process.Start(startInfo);
|
|
|
+ p.WaitForExit();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
{
|
|
|
- var startInfo = new ProcessStartInfo(tempinstall,
|
|
|
- " /SILENT /SUPPRESSMSGBOXES /FORCECLOSEAPPLICATIONS /RESTARTAPPLICATIONS");
|
|
|
- startInfo.Verb = elevated ? "runas" : "open";
|
|
|
- startInfo.UseShellExecute = true;
|
|
|
- var p = Process.Start(startInfo);
|
|
|
- p.WaitForExit();
|
|
|
+ Logger.Send(LogType.Error, "", CoreUtils.FormatException(e));
|
|
|
+ MessageBox.Show("Error during installation!");
|
|
|
}
|
|
|
});
|
|
|
- if (!bOK)
|
|
|
- MessageBox.Show("Unable to retrieve installer!");
|
|
|
+ if (bOK)
|
|
|
+ return true;
|
|
|
+
|
|
|
+ MessageBox.Show("Unable to retrieve installer!");
|
|
|
+ return false;
|
|
|
}
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
}
|