ApplicationUpdater.cs 2.7 KB

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