ApplicationUpdater.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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.Configuration;
  9. using MediaBrowser.Common.Kernel;
  10. namespace MediaBrowser.Common.Updates
  11. {
  12. public enum MBApplication
  13. {
  14. MBServer,
  15. MBTheater
  16. }
  17. /// <summary>
  18. /// Update the specified application using the specified archive
  19. /// </summary>
  20. public class ApplicationUpdater
  21. {
  22. private const string UpdaterExe = "Mediabrowser.Installer.exe";
  23. public void UpdateApplication(MBApplication app, IApplicationPaths appPaths, string archive)
  24. {
  25. // Use our installer passing it the specific archive
  26. // We need to copy to a temp directory and execute it there
  27. var source = Path.Combine(appPaths.ProgramSystemPath, UpdaterExe);
  28. var target = Path.Combine(Path.GetTempPath(), UpdaterExe);
  29. var product = app == MBApplication.MBTheater ? "mbt" : "server";
  30. File.Copy(source, target, true);
  31. Process.Start(UpdaterExe, string.Format("product={0} archive=\"{1}\" caller={2}", product, archive, Process.GetCurrentProcess().Id));
  32. // That's it. The installer will do the work once we exit
  33. }
  34. }
  35. }