diff --git a/PlexRequests.UI/Modules/Admin/SystemStatusModule.cs b/PlexRequests.UI/Modules/Admin/SystemStatusModule.cs index 3f5b33947..32bc92abe 100644 --- a/PlexRequests.UI/Modules/Admin/SystemStatusModule.cs +++ b/PlexRequests.UI/Modules/Admin/SystemStatusModule.cs @@ -28,6 +28,8 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; +using System.Reflection; using System.Threading.Tasks; using MarkdownSharp; using Nancy; @@ -118,10 +120,23 @@ namespace PlexRequests.UI.Modules.Admin Analytics.TrackEventAsync(Category.Admin, PlexRequests.Helpers.Analytics.Action.Update, "AutoUpdate", Username, CookieHelper.GetAnalyticClientId(Cookies)); var url = Request.Form["url"]; + var args = (string)Request.Form["args"].ToString(); + var lowered = args.ToLower(); + var appPath = Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(typeof(SystemStatusModule)).Location ?? string.Empty) ?? string.Empty, "PlexRequests.Updater.exe"); + + if (!string.IsNullOrEmpty(lowered)) + { + if (lowered.Contains("plexrequests.exe")) + { + lowered = lowered.Replace("plexrequests.exe", ""); + } + } + + var startArgs = string.IsNullOrEmpty(lowered) ? appPath : $"{lowered} Plexrequests.Updater.exe"; var startInfo = Type.GetType("Mono.Runtime") != null - ? new ProcessStartInfo("mono PlexRequests.Updater.exe") { Arguments = url } - : new ProcessStartInfo("PlexRequests.Updater.exe") { Arguments = url }; + ? new ProcessStartInfo(startArgs) { Arguments = $"{url} {lowered}", } + : new ProcessStartInfo(startArgs) { Arguments = $"{url} {lowered}" }; Process.Start(startInfo); diff --git a/PlexRequests.UI/Views/SystemStatus/Status.cshtml b/PlexRequests.UI/Views/SystemStatus/Status.cshtml index 6b1c65403..9dd06986a 100644 --- a/PlexRequests.UI/Views/SystemStatus/Status.cshtml +++ b/PlexRequests.UI/Views/SystemStatus/Status.cshtml @@ -11,7 +11,7 @@ - + @if (Model.Status.UpdateAvailable) {
@@ -50,6 +50,8 @@ {
+ +
} else @@ -92,7 +94,10 @@ $.ajax({ type: "Post", url: "autoupdate", - data: { url: "@Model.Status.DownloadUri" }, + data: { + url: "@Model.Status.DownloadUri", + args: $('#args').val() + }, dataType: "json", error: function () { setTimeout( diff --git a/PlexRequests.Updater/Program.cs b/PlexRequests.Updater/Program.cs index 98692c11d..122f84966 100644 --- a/PlexRequests.Updater/Program.cs +++ b/PlexRequests.Updater/Program.cs @@ -8,7 +8,14 @@ namespace PlexRequests.Updater { Console.WriteLine ("Starting PlexRequests .Net updater"); var s = new Updater(); - s.Start(args[0]); + if (args.Length >= 2) + { + s.Start(args[0], args[1]); + } + else + { + s.Start(args[0], string.Empty); + } } } } diff --git a/PlexRequests.Updater/Updater.cs b/PlexRequests.Updater/Updater.cs index 2b32317b0..2b04776eb 100644 --- a/PlexRequests.Updater/Updater.cs +++ b/PlexRequests.Updater/Updater.cs @@ -29,6 +29,7 @@ using System.Diagnostics; using System.IO; using System.IO.Compression; using System.Net; +using System.Reflection; using System.Windows.Forms; namespace PlexRequests.Updater @@ -67,7 +68,7 @@ namespace PlexRequests.Updater } } - public void Start(string downloadPath) + public void Start(string downloadPath, string launchOptions) { try { @@ -79,6 +80,10 @@ namespace PlexRequests.Updater Console.WriteLine("Downloading new version"); using (var client = new WebClient()) { + client.DownloadProgressChanged += (s, e) => + { + Console.WriteLine($"{e.ProgressPercentage}%"); + }; client.DownloadFile(downloadPath, TempPath); } Console.WriteLine("Downloaded!"); @@ -130,7 +135,7 @@ namespace PlexRequests.Updater RestoreBackup(); } - FinishUpdate(); + FinishUpdate(launchOptions); } } @@ -139,8 +144,9 @@ namespace PlexRequests.Updater Console.WriteLine("Backing up the current version"); try { - var dir = Directory.CreateDirectory("BackupSystem"); - var applicationPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath)); + var applicationPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Updater)).Location ?? string.Empty) ?? string.Empty; + + var dir = Directory.CreateDirectory(Path.Combine(applicationPath, "BackupSystem")); var allfiles = Directory.GetFiles(applicationPath, "*.*", SearchOption.AllDirectories); BackupPath = Path.Combine(dir.FullName, "PlexRequestsBackup.zip"); @@ -179,7 +185,9 @@ namespace PlexRequests.Updater { try { - return Directory.CreateDirectory("UpdateTemp"); + var location = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Updater)).Location ?? string.Empty); + var path = Path.Combine(location, "UpdateTemp"); + return Directory.CreateDirectory(path); } catch (Exception e) { @@ -190,15 +198,13 @@ namespace PlexRequests.Updater } } - private void FinishUpdate() + private void FinishUpdate(string launchOptions) { - ProcessStartInfo startInfo; - startInfo = Type.GetType("Mono.Runtime") != null - ? new ProcessStartInfo("mono PlexRequests.exe") { Arguments = Error ? "-u 2" : "-u 1" } - : new ProcessStartInfo("PlexRequests.exe") { Arguments = Error ? "-u 2" : "-u 1" }; + var args = Error ? "-u 2" : "-u 1"; + var startInfo = new ProcessStartInfo($"{launchOptions}PlexRequests.exe") { Arguments = args, UseShellExecute = true }; Process.Start(startInfo); - + Environment.Exit(0); } }