WindowsApp.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using MediaBrowser.Common.Net;
  2. using MediaBrowser.Model.Logging;
  3. using MediaBrowser.Server.Startup.Common;
  4. using MediaBrowser.ServerApplication.Networking;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Reflection;
  8. using System.Windows.Forms;
  9. using CommonIO;
  10. using MediaBrowser.Controller.Power;
  11. using MediaBrowser.Server.Startup.Common.FFMpeg;
  12. namespace MediaBrowser.ServerApplication.Native
  13. {
  14. public class WindowsApp : INativeApp
  15. {
  16. private readonly IFileSystem _fileSystem;
  17. private readonly ILogger _logger;
  18. public WindowsApp(IFileSystem fileSystem, ILogger logger)
  19. {
  20. _fileSystem = fileSystem;
  21. _logger = logger;
  22. }
  23. public List<Assembly> GetAssembliesWithParts()
  24. {
  25. var list = new List<Assembly>();
  26. if (!System.Environment.Is64BitProcess)
  27. {
  28. //list.Add(typeof(PismoIsoManager).Assembly);
  29. }
  30. list.Add(GetType().Assembly);
  31. return list;
  32. }
  33. public void AuthorizeServer(int udpPort, int httpServerPort, int httpsPort, string applicationPath, string tempDirectory)
  34. {
  35. ServerAuthorization.AuthorizeServer(udpPort, httpServerPort, httpsPort, applicationPath, tempDirectory);
  36. }
  37. public NativeEnvironment Environment
  38. {
  39. get
  40. {
  41. return new NativeEnvironment
  42. {
  43. OperatingSystem = OperatingSystem.Windows,
  44. SystemArchitecture = System.Environment.Is64BitOperatingSystem ? Architecture.X86_X64 : Architecture.X86,
  45. OperatingSystemVersionString = System.Environment.OSVersion.VersionString
  46. };
  47. }
  48. }
  49. public bool SupportsLibraryMonitor
  50. {
  51. get { return true; }
  52. }
  53. public bool SupportsRunningAsService
  54. {
  55. get
  56. {
  57. return true;
  58. }
  59. }
  60. public bool IsRunningAsService
  61. {
  62. get;
  63. set;
  64. }
  65. public bool CanSelfRestart
  66. {
  67. get
  68. {
  69. return MainStartup.CanSelfRestart;
  70. }
  71. }
  72. public bool SupportsAutoRunAtStartup
  73. {
  74. get
  75. {
  76. return true;
  77. }
  78. }
  79. public bool CanSelfUpdate
  80. {
  81. get
  82. {
  83. return MainStartup.CanSelfUpdate;
  84. }
  85. }
  86. public void Shutdown()
  87. {
  88. MainStartup.Shutdown();
  89. }
  90. public void Restart(StartupOptions startupOptions)
  91. {
  92. MainStartup.Restart();
  93. }
  94. public void ConfigureAutoRun(bool autorun)
  95. {
  96. var shortcutPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk");
  97. var startupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
  98. if (autorun)
  99. {
  100. //Copy our shortut into the startup folder for this user
  101. var targetPath = Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk");
  102. _fileSystem.CreateDirectory(Path.GetDirectoryName(targetPath));
  103. File.Copy(shortcutPath, targetPath, true);
  104. }
  105. else
  106. {
  107. //Remove our shortcut from the startup folder for this user
  108. _fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"));
  109. }
  110. }
  111. public INetworkManager CreateNetworkManager(ILogger logger)
  112. {
  113. return new NetworkManager(logger);
  114. }
  115. public void PreventSystemStandby()
  116. {
  117. MainStartup.Invoke(Standby.PreventSleep);
  118. }
  119. public void AllowSystemStandby()
  120. {
  121. MainStartup.Invoke(Standby.AllowSleep);
  122. }
  123. public IPowerManagement GetPowerManagement()
  124. {
  125. return new WindowsPowerManagement(_logger);
  126. }
  127. public FFMpegInstallInfo GetFfmpegInstallInfo()
  128. {
  129. var info = new FFMpegInstallInfo();
  130. info.FFMpegFilename = "ffmpeg.exe";
  131. info.FFProbeFilename = "ffprobe.exe";
  132. info.Version = "20160401";
  133. info.ArchiveType = "7z";
  134. info.IsEmbedded = true;
  135. info.DownloadUrls = GetDownloadUrls();
  136. return info;
  137. }
  138. private string[] GetDownloadUrls()
  139. {
  140. switch (Environment.SystemArchitecture)
  141. {
  142. case Architecture.X86_X64:
  143. return new[] { "MediaBrowser.ServerApplication.ffmpeg.ffmpegx64.7z" };
  144. case Architecture.X86:
  145. return new[] { "MediaBrowser.ServerApplication.ffmpeg.ffmpegx86.7z" };
  146. }
  147. return new string[] { };
  148. }
  149. }
  150. }