jellyfin/MediaBrowser.ServerApplication/Updates/ApplicationUpdater.cs

61 lines
2.7 KiB
C#
Raw Normal View History

2013-03-07 05:34:00 +00:00
using MediaBrowser.Common.Configuration;
2013-10-06 18:47:39 +00:00
using MediaBrowser.Model.Logging;
2013-03-02 19:48:25 +00:00
using System.Diagnostics;
using System.IO;
namespace MediaBrowser.ServerApplication.Updates
2013-03-02 19:48:25 +00:00
{
/// <summary>
/// Update the specified application using the specified archive
/// </summary>
public class ApplicationUpdater
{
2013-04-15 21:27:24 +00:00
private const string UpdaterExe = "Mediabrowser.Updater.exe";
private const string UpdaterDll = "Mediabrowser.InstallUtil.dll";
public void UpdateApplication(IApplicationPaths appPaths, string archive, ILogger logger, string restartServiceName)
2013-03-02 19:48:25 +00:00
{
2013-05-14 01:47:10 +00:00
// First see if there is a version file and read that in
var version = "Unknown";
if (File.Exists(archive + ".ver"))
{
version = File.ReadAllText(archive + ".ver");
}
2015-05-28 05:51:48 +00:00
var systemPath = appPaths.ProgramSystemPath;
var tempPath = Path.GetTempPath();
2013-03-02 19:48:25 +00:00
// Use our installer passing it the specific archive
// We need to copy to a temp directory and execute it there
2015-05-28 05:51:48 +00:00
var source = Path.Combine(systemPath, UpdaterExe);
2013-10-06 18:47:39 +00:00
logger.Info("Copying updater to temporary location");
2015-05-28 05:51:48 +00:00
var tempUpdater = Path.Combine(tempPath, UpdaterExe);
2013-03-13 21:52:56 +00:00
File.Copy(source, tempUpdater, true);
2015-05-28 05:51:48 +00:00
source = Path.Combine(systemPath, UpdaterDll);
var tempUpdaterDll = Path.Combine(tempPath, UpdaterDll);
2013-10-06 18:47:39 +00:00
logger.Info("Copying updater dependencies to temporary location");
2013-04-15 21:27:24 +00:00
File.Copy(source, tempUpdaterDll, true);
2015-05-28 05:51:48 +00:00
var product = "server";
2013-03-13 21:52:56 +00:00
// Our updater needs SS and ionic
2015-05-28 05:51:48 +00:00
source = Path.Combine(systemPath, "ServiceStack.Text.dll");
File.Copy(source, Path.Combine(tempPath, "ServiceStack.Text.dll"), true);
source = Path.Combine(systemPath, "SharpCompress.dll");
File.Copy(source, Path.Combine(tempPath, "SharpCompress.dll"), true);
2013-10-06 18:47:39 +00:00
logger.Info("Starting updater process.");
2015-05-28 05:51:48 +00:00
// installpath = program data folder
// startpath = executable to launch
// systempath = folder containing installation
var args = string.Format("product={0} archive=\"{1}\" caller={2} pismo=false version={3} service={4} installpath=\"{5}\" startpath=\"{6}\" systempath=\"{7}\"",
product, archive, Process.GetCurrentProcess().Id, version, restartServiceName ?? string.Empty, appPaths.ProgramDataPath, appPaths.ApplicationPath, systemPath);
logger.Info("Args: {0}", args);
Process.Start(tempUpdater, args);
2013-03-02 19:48:25 +00:00
// That's it. The installer will do the work once we exit
}
}
}