| | 1 | | using System; |
| | 2 | | using System.Linq; |
| | 3 | | using System.Threading.Tasks; |
| | 4 | | using Jellyfin.Server.Implementations.StorageHelpers; |
| | 5 | | using MediaBrowser.Common.Configuration; |
| | 6 | | using MediaBrowser.Common.Updates; |
| | 7 | | using MediaBrowser.Controller; |
| | 8 | | using MediaBrowser.Controller.Configuration; |
| | 9 | | using MediaBrowser.Controller.Library; |
| | 10 | | using MediaBrowser.Model.System; |
| | 11 | | using Microsoft.AspNetCore.Http; |
| | 12 | | using Microsoft.Extensions.Hosting; |
| | 13 | |
|
| | 14 | | namespace Emby.Server.Implementations; |
| | 15 | |
|
| | 16 | | /// <inheritdoc /> |
| | 17 | | public class SystemManager : ISystemManager |
| | 18 | | { |
| | 19 | | private readonly IHostApplicationLifetime _applicationLifetime; |
| | 20 | | private readonly IServerApplicationHost _applicationHost; |
| | 21 | | private readonly IServerApplicationPaths _applicationPaths; |
| | 22 | | private readonly IServerConfigurationManager _configurationManager; |
| | 23 | | private readonly IStartupOptions _startupOptions; |
| | 24 | | private readonly IInstallationManager _installationManager; |
| | 25 | | private readonly ILibraryManager _libraryManager; |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// Initializes a new instance of the <see cref="SystemManager"/> class. |
| | 29 | | /// </summary> |
| | 30 | | /// <param name="applicationLifetime">Instance of <see cref="IHostApplicationLifetime"/>.</param> |
| | 31 | | /// <param name="applicationHost">Instance of <see cref="IServerApplicationHost"/>.</param> |
| | 32 | | /// <param name="applicationPaths">Instance of <see cref="IServerApplicationPaths"/>.</param> |
| | 33 | | /// <param name="configurationManager">Instance of <see cref="IServerConfigurationManager"/>.</param> |
| | 34 | | /// <param name="startupOptions">Instance of <see cref="IStartupOptions"/>.</param> |
| | 35 | | /// <param name="installationManager">Instance of <see cref="IInstallationManager"/>.</param> |
| | 36 | | /// <param name="libraryManager">Instance of <see cref="ILibraryManager"/>.</param> |
| | 37 | | public SystemManager( |
| | 38 | | IHostApplicationLifetime applicationLifetime, |
| | 39 | | IServerApplicationHost applicationHost, |
| | 40 | | IServerApplicationPaths applicationPaths, |
| | 41 | | IServerConfigurationManager configurationManager, |
| | 42 | | IStartupOptions startupOptions, |
| | 43 | | IInstallationManager installationManager, |
| | 44 | | ILibraryManager libraryManager) |
| | 45 | | { |
| 0 | 46 | | _applicationLifetime = applicationLifetime; |
| 0 | 47 | | _applicationHost = applicationHost; |
| 0 | 48 | | _applicationPaths = applicationPaths; |
| 0 | 49 | | _configurationManager = configurationManager; |
| 0 | 50 | | _startupOptions = startupOptions; |
| 0 | 51 | | _installationManager = installationManager; |
| 0 | 52 | | _libraryManager = libraryManager; |
| 0 | 53 | | } |
| | 54 | |
|
| | 55 | | /// <inheritdoc /> |
| | 56 | | public SystemInfo GetSystemInfo(HttpRequest request) |
| | 57 | | { |
| 0 | 58 | | return new SystemInfo |
| 0 | 59 | | { |
| 0 | 60 | | HasPendingRestart = _applicationHost.HasPendingRestart, |
| 0 | 61 | | IsShuttingDown = _applicationLifetime.ApplicationStopping.IsCancellationRequested, |
| 0 | 62 | | Version = _applicationHost.ApplicationVersionString, |
| 0 | 63 | | ProductName = _applicationHost.Name, |
| 0 | 64 | | WebSocketPortNumber = _applicationHost.HttpPort, |
| 0 | 65 | | CompletedInstallations = _installationManager.CompletedInstallations.ToArray(), |
| 0 | 66 | | Id = _applicationHost.SystemId, |
| 0 | 67 | | #pragma warning disable CS0618 // Type or member is obsolete |
| 0 | 68 | | ProgramDataPath = _applicationPaths.ProgramDataPath, |
| 0 | 69 | | WebPath = _applicationPaths.WebPath, |
| 0 | 70 | | LogPath = _applicationPaths.LogDirectoryPath, |
| 0 | 71 | | ItemsByNamePath = _applicationPaths.InternalMetadataPath, |
| 0 | 72 | | InternalMetadataPath = _applicationPaths.InternalMetadataPath, |
| 0 | 73 | | CachePath = _applicationPaths.CachePath, |
| 0 | 74 | | TranscodingTempPath = _configurationManager.GetTranscodePath(), |
| 0 | 75 | | #pragma warning restore CS0618 // Type or member is obsolete |
| 0 | 76 | | ServerName = _applicationHost.FriendlyName, |
| 0 | 77 | | LocalAddress = _applicationHost.GetSmartApiUrl(request), |
| 0 | 78 | | StartupWizardCompleted = _configurationManager.CommonConfiguration.IsStartupWizardCompleted, |
| 0 | 79 | | SupportsLibraryMonitor = true, |
| 0 | 80 | | PackageName = _startupOptions.PackageName, |
| 0 | 81 | | CastReceiverApplications = _configurationManager.Configuration.CastReceiverApplications |
| 0 | 82 | | }; |
| | 83 | | } |
| | 84 | |
|
| | 85 | | /// <inheritdoc/> |
| | 86 | | public SystemStorageInfo GetSystemStorageInfo() |
| | 87 | | { |
| 0 | 88 | | var virtualFolderInfos = _libraryManager.GetVirtualFolders().Select(e => new LibraryStorageInfo() |
| 0 | 89 | | { |
| 0 | 90 | | Id = Guid.Parse(e.ItemId), |
| 0 | 91 | | Name = e.Name, |
| 0 | 92 | | Folders = e.Locations.Select(f => StorageHelper.GetFreeSpaceOf(f)).ToArray() |
| 0 | 93 | | }); |
| | 94 | |
|
| 0 | 95 | | return new SystemStorageInfo() |
| 0 | 96 | | { |
| 0 | 97 | | ProgramDataFolder = StorageHelper.GetFreeSpaceOf(_applicationPaths.ProgramDataPath), |
| 0 | 98 | | WebFolder = StorageHelper.GetFreeSpaceOf(_applicationPaths.WebPath), |
| 0 | 99 | | LogFolder = StorageHelper.GetFreeSpaceOf(_applicationPaths.LogDirectoryPath), |
| 0 | 100 | | ImageCacheFolder = StorageHelper.GetFreeSpaceOf(_applicationPaths.ImageCachePath), |
| 0 | 101 | | InternalMetadataFolder = StorageHelper.GetFreeSpaceOf(_applicationPaths.InternalMetadataPath), |
| 0 | 102 | | CacheFolder = StorageHelper.GetFreeSpaceOf(_applicationPaths.CachePath), |
| 0 | 103 | | TranscodingTempFolder = StorageHelper.GetFreeSpaceOf(_configurationManager.GetTranscodePath()), |
| 0 | 104 | | Libraries = virtualFolderInfos.ToArray() |
| 0 | 105 | | }; |
| | 106 | | } |
| | 107 | |
|
| | 108 | | /// <inheritdoc /> |
| | 109 | | public PublicSystemInfo GetPublicSystemInfo(HttpRequest request) |
| | 110 | | { |
| 0 | 111 | | return new PublicSystemInfo |
| 0 | 112 | | { |
| 0 | 113 | | Version = _applicationHost.ApplicationVersionString, |
| 0 | 114 | | ProductName = _applicationHost.Name, |
| 0 | 115 | | Id = _applicationHost.SystemId, |
| 0 | 116 | | ServerName = _applicationHost.FriendlyName, |
| 0 | 117 | | LocalAddress = _applicationHost.GetSmartApiUrl(request), |
| 0 | 118 | | StartupWizardCompleted = _configurationManager.CommonConfiguration.IsStartupWizardCompleted |
| 0 | 119 | | }; |
| | 120 | | } |
| | 121 | |
|
| | 122 | | /// <inheritdoc /> |
| 0 | 123 | | public void Restart() => ShutdownInternal(true); |
| | 124 | |
|
| | 125 | | /// <inheritdoc /> |
| 0 | 126 | | public void Shutdown() => ShutdownInternal(false); |
| | 127 | |
|
| | 128 | | private void ShutdownInternal(bool restart) |
| | 129 | | { |
| 0 | 130 | | Task.Run(async () => |
| 0 | 131 | | { |
| 0 | 132 | | await Task.Delay(100).ConfigureAwait(false); |
| 0 | 133 | | _applicationHost.ShouldRestart = restart; |
| 0 | 134 | | _applicationLifetime.StopApplication(); |
| 0 | 135 | | }); |
| 0 | 136 | | } |
| | 137 | | } |