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;
|
|
|
|
|
|
2013-03-07 05:34:00 +00:00
|
|
|
|
namespace MediaBrowser.Common.Implementations.Updates
|
2013-03-02 19:48:25 +00:00
|
|
|
|
{
|
|
|
|
|
public enum MBApplication
|
|
|
|
|
{
|
|
|
|
|
MBServer,
|
|
|
|
|
MBTheater
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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";
|
2013-10-06 18:47:39 +00:00
|
|
|
|
public void UpdateApplication(MBApplication app, 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");
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
var source = Path.Combine(appPaths.ProgramSystemPath, UpdaterExe);
|
2013-10-06 18:47:39 +00:00
|
|
|
|
|
|
|
|
|
logger.Info("Copying updater to temporary location");
|
2013-03-13 21:52:56 +00:00
|
|
|
|
var tempUpdater = Path.Combine(Path.GetTempPath(), UpdaterExe);
|
|
|
|
|
File.Copy(source, tempUpdater, true);
|
2013-04-15 21:27:24 +00:00
|
|
|
|
source = Path.Combine(appPaths.ProgramSystemPath, UpdaterDll);
|
|
|
|
|
var tempUpdaterDll = Path.Combine(Path.GetTempPath(), 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);
|
|
|
|
|
var product = app == MBApplication.MBTheater ? "mbt" : "server";
|
2013-03-13 21:52:56 +00:00
|
|
|
|
// Our updater needs SS and ionic
|
|
|
|
|
source = Path.Combine(appPaths.ProgramSystemPath, "ServiceStack.Text.dll");
|
|
|
|
|
File.Copy(source, Path.Combine(Path.GetTempPath(), "ServiceStack.Text.dll"), true);
|
2013-09-25 20:36:11 +00:00
|
|
|
|
source = Path.Combine(appPaths.ProgramSystemPath, "SharpCompress.dll");
|
|
|
|
|
File.Copy(source, Path.Combine(Path.GetTempPath(), "SharpCompress.dll"), true);
|
2013-10-06 18:47:39 +00:00
|
|
|
|
|
|
|
|
|
logger.Info("Starting updater process.");
|
2014-02-28 16:50:52 +00:00
|
|
|
|
Process.Start(tempUpdater, string.Format("product={0} archive=\"{1}\" caller={2} pismo=false version={3} service={4} installpath=\"{5}\"", product, archive, Process.GetCurrentProcess().Id, version, restartServiceName ?? string.Empty, appPaths.ProgramDataPath));
|
2013-03-02 19:48:25 +00:00
|
|
|
|
|
|
|
|
|
// That's it. The installer will do the work once we exit
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|