WindowsApp.cs 4.8 KB

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