added optional launch args for the auto updater

pull/771/head
Jamie.Rees 8 years ago
parent defc5a7a91
commit 9165f3f31e

@ -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);

@ -11,7 +11,7 @@
<label class="control-label">Current Version: </label>
<label class="control-label">@Model.Status.CurrentVersion</label>
</div>
@if (Model.Status.UpdateAvailable)
{
<div class="form-group">
@ -50,6 +50,8 @@
{
<label class="control-label"><a href="@Model.Status.UpdateUri" target="_blank"><i class="fa fa-check"></i></a></label>
<br />
<input id="args" class="form-control form-control-custom " placeholder="optional launch arguments e.g. /etc/mono /opt/PlexRequests.exe">
<br/>
<button id="autoUpdate" class="btn btn-success-outline">Automatic Update (beta) <i class="fa fa-download"></i></button>
}
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(

@ -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);
}
}
}
}

@ -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);
}
}

Loading…
Cancel
Save