ApplicationUpdater.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. // Use our installer passing it the specific archive
  21. // We need to copy to a temp directory and execute it there
  22. var source = Path.Combine(appPaths.ProgramSystemPath, UpdaterExe);
  23. var tempUpdater = Path.Combine(Path.GetTempPath(), UpdaterExe);
  24. File.Copy(source, tempUpdater, true);
  25. source = Path.Combine(appPaths.ProgramSystemPath, UpdaterDll);
  26. var tempUpdaterDll = Path.Combine(Path.GetTempPath(), UpdaterDll);
  27. File.Copy(source, tempUpdaterDll, true);
  28. var product = app == MBApplication.MBTheater ? "mbt" : "server";
  29. // Our updater needs SS and ionic
  30. source = Path.Combine(appPaths.ProgramSystemPath, "ServiceStack.Text.dll");
  31. File.Copy(source, Path.Combine(Path.GetTempPath(), "ServiceStack.Text.dll"), true);
  32. source = Path.Combine(appPaths.ProgramSystemPath, "Ionic.Zip.dll");
  33. File.Copy(source, Path.Combine(Path.GetTempPath(), "Ionic.Zip.dll"), true);
  34. Process.Start(tempUpdater, string.Format("product={0} archive=\"{1}\" caller={2} pismo=false", product, archive, Process.GetCurrentProcess().Id));
  35. // That's it. The installer will do the work once we exit
  36. }
  37. }
  38. }