ApplicationUpdater.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using MediaBrowser.Common.Configuration;
  2. using MediaBrowser.Model.Logging;
  3. using System.Diagnostics;
  4. using System.IO;
  5. namespace MediaBrowser.Common.Implementations.Updates
  6. {
  7. public enum MBApplication
  8. {
  9. MBServer,
  10. MBTheater
  11. }
  12. /// <summary>
  13. /// Update the specified application using the specified archive
  14. /// </summary>
  15. public class ApplicationUpdater
  16. {
  17. private const string UpdaterExe = "Mediabrowser.Updater.exe";
  18. private const string UpdaterDll = "Mediabrowser.InstallUtil.dll";
  19. public void UpdateApplication(MBApplication app, IApplicationPaths appPaths, string archive, ILogger logger, string restartServiceName)
  20. {
  21. // First see if there is a version file and read that in
  22. var version = "Unknown";
  23. if (File.Exists(archive + ".ver"))
  24. {
  25. version = File.ReadAllText(archive + ".ver");
  26. }
  27. // Use our installer passing it the specific archive
  28. // We need to copy to a temp directory and execute it there
  29. var source = Path.Combine(appPaths.ProgramSystemPath, UpdaterExe);
  30. logger.Info("Copying updater to temporary location");
  31. var tempUpdater = Path.Combine(Path.GetTempPath(), UpdaterExe);
  32. File.Copy(source, tempUpdater, true);
  33. source = Path.Combine(appPaths.ProgramSystemPath, UpdaterDll);
  34. var tempUpdaterDll = Path.Combine(Path.GetTempPath(), UpdaterDll);
  35. logger.Info("Copying updater dependencies to temporary location");
  36. File.Copy(source, tempUpdaterDll, true);
  37. var product = app == MBApplication.MBTheater ? "mbt" : "server";
  38. // Our updater needs SS and ionic
  39. source = Path.Combine(appPaths.ProgramSystemPath, "ServiceStack.Text.dll");
  40. File.Copy(source, Path.Combine(Path.GetTempPath(), "ServiceStack.Text.dll"), true);
  41. source = Path.Combine(appPaths.ProgramSystemPath, "SharpCompress.dll");
  42. File.Copy(source, Path.Combine(Path.GetTempPath(), "SharpCompress.dll"), true);
  43. logger.Info("Starting updater process.");
  44. Process.Start(tempUpdater, string.Format("product={0} archive=\"{1}\" caller={2} pismo=false version={3} service={4}", product, archive, Process.GetCurrentProcess().Id, version, restartServiceName ?? string.Empty));
  45. // That's it. The installer will do the work once we exit
  46. }
  47. }
  48. }