ApplicationUpdater.cs 2.1 KB

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