ApplicationUpdater.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.IO;
  8. using MediaBrowser.Common.Kernel;
  9. namespace MediaBrowser.Common.Updates
  10. {
  11. public enum MBApplication
  12. {
  13. MBServer,
  14. MBTheater
  15. }
  16. /// <summary>
  17. /// Update the specified application using the specified archive
  18. /// </summary>
  19. public class ApplicationUpdater
  20. {
  21. private const string UpdaterExe = "Mediabrowser.Installer.exe";
  22. public void UpdateApplication(MBApplication app, IApplicationPaths appPaths, string archive)
  23. {
  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(appPaths.ProgramSystemPath, UpdaterExe);
  27. var target = Path.Combine(Path.GetTempPath(), UpdaterExe);
  28. var product = app == MBApplication.MBTheater ? "mbt" : "server";
  29. File.Copy(source, target, true);
  30. Process.Start(UpdaterExe, string.Format("product={0} archive=\"{1}\" caller={2}", product, archive, Process.GetCurrentProcess().Id));
  31. // That's it. The installer will do the work once we exit
  32. }
  33. }
  34. }