mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-07 11:57:55 +02:00
Improve waiting for things to end in (un)installer
This commit is contained in:
parent
e8f5fade43
commit
334c069207
3 changed files with 71 additions and 6 deletions
|
@ -80,6 +80,20 @@ namespace MediaBrowser.Installer
|
||||||
PackageClass = (PackageVersionClass) Enum.Parse(typeof (PackageVersionClass), ConfigurationManager.AppSettings["class"] ?? "Release");
|
PackageClass = (PackageVersionClass) Enum.Parse(typeof (PackageVersionClass), ConfigurationManager.AppSettings["class"] ?? "Release");
|
||||||
var cmdArgs = Environment.GetCommandLineArgs();
|
var cmdArgs = Environment.GetCommandLineArgs();
|
||||||
Archive = cmdArgs.Length > 1 ? cmdArgs[1] : null;
|
Archive = cmdArgs.Length > 1 ? cmdArgs[1] : null;
|
||||||
|
var callerId = cmdArgs.Length > 2 ? cmdArgs[2] : null;
|
||||||
|
if (callerId != null)
|
||||||
|
{
|
||||||
|
// Wait for our caller to exit
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var process = Process.GetProcessById(Convert.ToInt32(callerId));
|
||||||
|
process.WaitForExit();
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
// wasn't running
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (product.ToLower())
|
switch (product.ToLower())
|
||||||
{
|
{
|
||||||
|
@ -108,13 +122,15 @@ namespace MediaBrowser.Installer
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
protected async Task DoInstall(string archive)
|
protected async Task DoInstall(string archive)
|
||||||
{
|
{
|
||||||
lblStatus.Text = string.Format("Downloading {0}...", FriendlyName);
|
lblStatus.Text = string.Format("Installing {0}...", FriendlyName);
|
||||||
|
|
||||||
// Determine Package version
|
// Determine Package version
|
||||||
var version = await GetPackageVersion();
|
var version = await GetPackageVersion();
|
||||||
|
|
||||||
// Now try and shut down the server if that is what we are installing and it is running
|
// Now try and shut down the server if that is what we are installing and it is running
|
||||||
if (PackageName == "MBServer" && Process.GetProcessesByName("mediabrowser.serverapplication").Length != 0)
|
var procs = Process.GetProcessesByName("mediabrowser.serverapplication");
|
||||||
|
var server = procs.Length > 0 ? procs[0] : null;
|
||||||
|
if (PackageName == "MBServer" && server != null)
|
||||||
{
|
{
|
||||||
lblStatus.Text = "Shutting Down Media Browser Server...";
|
lblStatus.Text = "Shutting Down Media Browser Server...";
|
||||||
using (var client = new WebClient())
|
using (var client = new WebClient())
|
||||||
|
@ -122,6 +138,14 @@ namespace MediaBrowser.Installer
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
client.UploadString("http://localhost:8096/mediabrowser/System/Shutdown", "");
|
client.UploadString("http://localhost:8096/mediabrowser/System/Shutdown", "");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
server.WaitForExit();
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
// already gone
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (WebException e)
|
catch (WebException e)
|
||||||
{
|
{
|
||||||
|
@ -278,7 +302,17 @@ namespace MediaBrowser.Installer
|
||||||
{
|
{
|
||||||
// Delete old content of system
|
// Delete old content of system
|
||||||
var systemDir = Path.Combine(RootPath, "system");
|
var systemDir = Path.Combine(RootPath, "system");
|
||||||
if (Directory.Exists(systemDir)) Directory.Delete(systemDir, true);
|
if (Directory.Exists(systemDir))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.Delete(systemDir, true);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// we tried...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// And extract
|
// And extract
|
||||||
using (var fileStream = File.OpenRead(archive))
|
using (var fileStream = File.OpenRead(archive))
|
||||||
|
|
|
@ -18,10 +18,28 @@ namespace MediaBrowser.Uninstaller.Execute
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
Thread.Sleep(800); // be sure our caller is shut down
|
|
||||||
|
|
||||||
var args = Environment.GetCommandLineArgs();
|
var args = Environment.GetCommandLineArgs();
|
||||||
var product = args.Length > 1 ? args[1] : "server";
|
var product = args.Length > 1 ? args[1] : "server";
|
||||||
|
var callerId = args.Length > 2 ? args[2] : null;
|
||||||
|
if (callerId != null)
|
||||||
|
{
|
||||||
|
// Wait for our caller to exit
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var process = Process.GetProcessById(Convert.ToInt32(callerId));
|
||||||
|
process.WaitForExit();
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
// wasn't running
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Thread.Sleep(1000); // crude method
|
||||||
|
}
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,7 +97,9 @@ namespace MediaBrowser.Uninstaller.Execute
|
||||||
if (Product == "Server")
|
if (Product == "Server")
|
||||||
{
|
{
|
||||||
RemoveShortcut(Path.Combine(startMenu, "MB Dashboard.lnk"));
|
RemoveShortcut(Path.Combine(startMenu, "MB Dashboard.lnk"));
|
||||||
if (Process.GetProcessesByName("mediabrowser.serverapplication").Length != 0)
|
var procs = Process.GetProcessesByName("mediabrowser.serverapplication");
|
||||||
|
var server = procs.Length > 0 ? procs[0] : null;
|
||||||
|
if (server != null)
|
||||||
{
|
{
|
||||||
using (var client = new WebClient())
|
using (var client = new WebClient())
|
||||||
{
|
{
|
||||||
|
@ -87,6 +107,14 @@ namespace MediaBrowser.Uninstaller.Execute
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
client.UploadString("http://localhost:8096/mediabrowser/system/shutdown", "");
|
client.UploadString("http://localhost:8096/mediabrowser/system/shutdown", "");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
server.WaitForExit();
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
// already gone
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (WebException ex)
|
catch (WebException ex)
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,8 +24,11 @@ namespace MediaBrowser.Uninstaller
|
||||||
var sourceDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "";
|
var sourceDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "";
|
||||||
File.WriteAllBytes(tempExe, File.ReadAllBytes(Path.Combine(sourceDir, "MediaBrowser.Uninstaller.Execute.exe")));
|
File.WriteAllBytes(tempExe, File.ReadAllBytes(Path.Combine(sourceDir, "MediaBrowser.Uninstaller.Execute.exe")));
|
||||||
File.Copy(Path.Combine(sourceDir, "MediaBrowser.Uninstaller.Execute.exe.config"), tempConfig, true);
|
File.Copy(Path.Combine(sourceDir, "MediaBrowser.Uninstaller.Execute.exe.config"), tempConfig, true);
|
||||||
|
|
||||||
|
//get our pid to pass to the uninstaller so it can wait for us to exit
|
||||||
|
var pid = Process.GetCurrentProcess().Id;
|
||||||
//kick off the copy
|
//kick off the copy
|
||||||
Process.Start(tempExe, product);
|
Process.Start(tempExe, product + " " + pid);
|
||||||
//and shut down
|
//and shut down
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue