2
0

ApplicationUpdater.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. // Use our installer passing it the specific archive
  23. // We need to copy to a temp directory and execute it there
  24. var source = Path.Combine(appPaths.ProgramSystemPath, UpdaterExe);
  25. logger.Info("Copying updater to temporary location");
  26. var tempUpdater = Path.Combine(Path.GetTempPath(), UpdaterExe);
  27. File.Copy(source, tempUpdater, true);
  28. source = Path.Combine(appPaths.ProgramSystemPath, UpdaterDll);
  29. var tempUpdaterDll = Path.Combine(Path.GetTempPath(), UpdaterDll);
  30. logger.Info("Copying updater dependencies to temporary location");
  31. File.Copy(source, tempUpdaterDll, true);
  32. const string product = "server";
  33. // Our updater needs SS and ionic
  34. source = Path.Combine(appPaths.ProgramSystemPath, "ServiceStack.Text.dll");
  35. File.Copy(source, Path.Combine(Path.GetTempPath(), "ServiceStack.Text.dll"), true);
  36. source = Path.Combine(appPaths.ProgramSystemPath, "SharpCompress.dll");
  37. File.Copy(source, Path.Combine(Path.GetTempPath(), "SharpCompress.dll"), true);
  38. logger.Info("Starting updater process.");
  39. 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));
  40. // That's it. The installer will do the work once we exit
  41. }
  42. }
  43. }