From 51edd5d067c919800f504bfa9fe1708279faaa3f Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sun, 27 Jan 2019 10:20:05 +0100 Subject: Reworked LocalizationManager to load data async --- Jellyfin.Server/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Jellyfin.Server/Program.cs') diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index f64f50cd7..c8861c65c 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -98,7 +98,7 @@ namespace Jellyfin.Server new NullImageEncoder(), new NetworkManager(_loggerFactory, environmentInfo))) { - appHost.Init(); + await appHost.Init(); appHost.ImageProcessor.ImageEncoder = GetImageEncoder(fileSystem, appPaths, appHost.LocalizationManager); -- cgit v1.2.3 From 85a58fd655240fd0ddd10bdaaad4a9bb8cd7051d Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Sun, 27 Jan 2019 15:40:37 +0100 Subject: Start startup tasks async --- Emby.Dlna/DlnaManager.cs | 9 +++--- Emby.Dlna/Main/DlnaEntryPoint.cs | 4 +-- Emby.Notifications/Notifications.cs | 4 ++- .../Activity/ActivityLogEntryPoint.cs | 5 +++- Emby.Server.Implementations/ApplicationHost.cs | 35 +++++++++------------- .../Collections/CollectionManager.cs | 2 +- .../Devices/DeviceManager.cs | 2 +- .../EntryPoints/AutomaticRestartEntryPoint.cs | 4 ++- .../EntryPoints/ExternalPortForwarding.cs | 8 +++-- .../EntryPoints/LibraryChangedNotifier.cs | 5 +++- .../EntryPoints/RecordingNotifier.cs | 5 +++- .../EntryPoints/ServerEventNotifier.cs | 5 +++- .../EntryPoints/StartupWizard.cs | 7 +++-- .../EntryPoints/UdpServerEntryPoint.cs | 5 +++- .../EntryPoints/UserDataChangeNotifier.cs | 4 ++- Emby.Server.Implementations/IO/LibraryMonitor.cs | 3 +- Emby.Server.Implementations/Library/UserManager.cs | 4 ++- .../LiveTv/EmbyTV/EmbyTV.cs | 2 +- .../LiveTv/EmbyTV/EntryPoint.cs | 5 ++-- Jellyfin.Server/Program.cs | 4 --- MediaBrowser.Api/ApiEntryPoint.cs | 7 +++-- .../Plugins/IServerEntryPoint.cs | 3 +- MediaBrowser.WebDashboard/Api/DashboardService.cs | 6 ++-- MediaBrowser.WebDashboard/ServerEntryPoint.cs | 5 +++- MediaBrowser.XbmcMetadata/EntryPoint.cs | 5 +++- 25 files changed, 87 insertions(+), 61 deletions(-) (limited to 'Jellyfin.Server/Program.cs') diff --git a/Emby.Dlna/DlnaManager.cs b/Emby.Dlna/DlnaManager.cs index f795b58cb..3be596865 100644 --- a/Emby.Dlna/DlnaManager.cs +++ b/Emby.Dlna/DlnaManager.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; +using System.Threading.Tasks; using Emby.Dlna.Profiles; using Emby.Dlna.Server; using MediaBrowser.Common.Configuration; @@ -48,11 +49,11 @@ namespace Emby.Dlna _assemblyInfo = assemblyInfo; } - public void InitProfiles() + public async Task InitProfilesAsync() { try { - ExtractSystemProfiles(); + await ExtractSystemProfilesAsync(); LoadProfiles(); } catch (Exception ex) @@ -359,7 +360,7 @@ namespace Emby.Dlna }; } - private void ExtractSystemProfiles() + private async Task ExtractSystemProfilesAsync() { var namespaceName = GetType().Namespace + ".Profiles.Xml."; @@ -383,7 +384,7 @@ namespace Emby.Dlna using (var fileStream = _fileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read)) { - stream.CopyTo(fileStream); + await stream.CopyToAsync(fileStream); } } } diff --git a/Emby.Dlna/Main/DlnaEntryPoint.cs b/Emby.Dlna/Main/DlnaEntryPoint.cs index 1ab6014eb..89cba4c47 100644 --- a/Emby.Dlna/Main/DlnaEntryPoint.cs +++ b/Emby.Dlna/Main/DlnaEntryPoint.cs @@ -125,9 +125,9 @@ namespace Emby.Dlna.Main Current = this; } - public void Run() + public async Task RunAsync() { - ((DlnaManager)_dlnaManager).InitProfiles(); + await ((DlnaManager)_dlnaManager).InitProfilesAsync().ConfigureAwait(false); ReloadComponents(); diff --git a/Emby.Notifications/Notifications.cs b/Emby.Notifications/Notifications.cs index fbdc39f94..045aa6f16 100644 --- a/Emby.Notifications/Notifications.cs +++ b/Emby.Notifications/Notifications.cs @@ -71,12 +71,14 @@ namespace Emby.Notifications _coreNotificationTypes = new CoreNotificationTypes(localization, appHost).GetNotificationTypes().Select(i => i.Type).ToArray(); } - public void Run() + public Task RunAsync() { _libraryManager.ItemAdded += _libraryManager_ItemAdded; _appHost.HasPendingRestartChanged += _appHost_HasPendingRestartChanged; _appHost.HasUpdateAvailableChanged += _appHost_HasUpdateAvailableChanged; _activityManager.EntryCreated += _activityManager_EntryCreated; + + return Task.CompletedTask; } private async void _appHost_HasPendingRestartChanged(object sender, EventArgs e) diff --git a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs index a8e8f815a..9cdb3b1b5 100644 --- a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs +++ b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading.Tasks; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Updates; @@ -58,7 +59,7 @@ namespace Emby.Server.Implementations.Activity _deviceManager = deviceManager; } - public void Run() + public Task RunAsync() { _taskManager.TaskCompleted += _taskManager_TaskCompleted; @@ -90,6 +91,8 @@ namespace Emby.Server.Implementations.Activity _deviceManager.CameraImageUploaded += _deviceManager_CameraImageUploaded; _appHost.ApplicationUpdated += _appHost_ApplicationUpdated; + + return Task.CompletedTask; } void _deviceManager_CameraImageUploaded(object sender, GenericEventArgs e) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index f0a914922..c71b917b8 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -647,8 +647,10 @@ namespace Emby.Server.Implementations /// /// Runs the startup tasks. /// - public Task RunStartupTasks() + public async Task RunStartupTasks() { + Logger.LogInformation("Running startup tasks"); + Resolve().AddTasks(GetExports(false)); ConfigurationManager.ConfigurationUpdated += OnConfigurationUpdated; @@ -667,20 +669,20 @@ namespace Emby.Server.Implementations Logger.LogInformation("ServerId: {0}", SystemId); var entryPoints = GetExports(); - RunEntryPoints(entryPoints, true); + + var now = DateTime.UtcNow; + await Task.WhenAll(StartEntryPoints(entryPoints, true)); + Logger.LogInformation("Executed all pre-startup entry points in {Elapsed:fff} ms", DateTime.Now - now); Logger.LogInformation("Core startup complete"); HttpServer.GlobalResponse = null; - Logger.LogInformation("Post-init migrations complete"); - - RunEntryPoints(entryPoints, false); - Logger.LogInformation("All entry points have started"); - - return Task.CompletedTask; + now = DateTime.UtcNow; + await Task.WhenAll(StartEntryPoints(entryPoints, false)); + Logger.LogInformation("Executed all post-startup entry points in {Elapsed:fff} ms", DateTime.Now - now); } - private void RunEntryPoints(IEnumerable entryPoints, bool isBeforeStartup) + private IEnumerable StartEntryPoints(IEnumerable entryPoints, bool isBeforeStartup) { foreach (var entryPoint in entryPoints) { @@ -689,18 +691,9 @@ namespace Emby.Server.Implementations continue; } - var name = entryPoint.GetType().FullName; - Logger.LogInformation("Starting entry point {Name}", name); - var now = DateTime.UtcNow; - try - { - entryPoint.Run(); - } - catch (Exception ex) - { - Logger.LogError(ex, "Error while running entrypoint {Name}", name); - } - Logger.LogInformation("Entry point completed: {Name}. Duration: {Duration} seconds", name, (DateTime.UtcNow - now).TotalSeconds.ToString(CultureInfo.InvariantCulture), "ImageInfos"); + Logger.LogDebug("Starting entry point {Type}", entryPoint.GetType()); + + yield return entryPoint.RunAsync(); } } diff --git a/Emby.Server.Implementations/Collections/CollectionManager.cs b/Emby.Server.Implementations/Collections/CollectionManager.cs index 0166bbc5a..7268811f8 100644 --- a/Emby.Server.Implementations/Collections/CollectionManager.cs +++ b/Emby.Server.Implementations/Collections/CollectionManager.cs @@ -353,7 +353,7 @@ namespace Emby.Server.Implementations.Collections _logger = logger; } - public async void Run() + public async Task RunAsync() { if (!_config.Configuration.CollectionsUpgraded && _config.Configuration.IsStartupWizardCompleted) { diff --git a/Emby.Server.Implementations/Devices/DeviceManager.cs b/Emby.Server.Implementations/Devices/DeviceManager.cs index 60d57519e..46d36f9f6 100644 --- a/Emby.Server.Implementations/Devices/DeviceManager.cs +++ b/Emby.Server.Implementations/Devices/DeviceManager.cs @@ -425,7 +425,7 @@ namespace Emby.Server.Implementations.Devices _logger = logger; } - public async void Run() + public async Task RunAsync() { if (!_config.Configuration.CameraUploadUpgraded && _config.Configuration.IsStartupWizardCompleted) { diff --git a/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs b/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs index 0fc4c3858..361656ff2 100644 --- a/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs +++ b/Emby.Server.Implementations/EntryPoints/AutomaticRestartEntryPoint.cs @@ -37,12 +37,14 @@ namespace Emby.Server.Implementations.EntryPoints _timerFactory = timerFactory; } - public void Run() + public Task RunAsync() { if (_appHost.CanSelfRestart) { _appHost.HasPendingRestartChanged += _appHost_HasPendingRestartChanged; } + + return Task.CompletedTask; } void _appHost_HasPendingRestartChanged(object sender, EventArgs e) diff --git a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs index 8755ee3a7..56c730c80 100644 --- a/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs +++ b/Emby.Server.Implementations/EntryPoints/ExternalPortForwarding.cs @@ -61,17 +61,17 @@ namespace Emby.Server.Implementations.EntryPoints return string.Join("|", values.ToArray()); } - void _config_ConfigurationUpdated(object sender, EventArgs e) + private async void _config_ConfigurationUpdated(object sender, EventArgs e) { if (!string.Equals(_lastConfigIdentifier, GetConfigIdentifier(), StringComparison.OrdinalIgnoreCase)) { DisposeNat(); - Run(); + await RunAsync(); } } - public void Run() + public Task RunAsync() { if (_config.Configuration.EnableUPnP && _config.Configuration.EnableRemoteAccess) { @@ -80,6 +80,8 @@ namespace Emby.Server.Implementations.EntryPoints _config.ConfigurationUpdated -= _config_ConfigurationUpdated; _config.ConfigurationUpdated += _config_ConfigurationUpdated; + + return Task.CompletedTask; } private void Start() diff --git a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs index 7a8b09cf7..98c08e6ba 100644 --- a/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs +++ b/Emby.Server.Implementations/EntryPoints/LibraryChangedNotifier.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading; +using System.Threading.Tasks; using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; @@ -65,7 +66,7 @@ namespace Emby.Server.Implementations.EntryPoints _providerManager = providerManager; } - public void Run() + public Task RunAsync() { _libraryManager.ItemAdded += libraryManager_ItemAdded; _libraryManager.ItemUpdated += libraryManager_ItemUpdated; @@ -74,6 +75,8 @@ namespace Emby.Server.Implementations.EntryPoints _providerManager.RefreshCompleted += _providerManager_RefreshCompleted; _providerManager.RefreshStarted += _providerManager_RefreshStarted; _providerManager.RefreshProgress += _providerManager_RefreshProgress; + + return Task.CompletedTask; } private Dictionary _lastProgressMessageTimes = new Dictionary(); diff --git a/Emby.Server.Implementations/EntryPoints/RecordingNotifier.cs b/Emby.Server.Implementations/EntryPoints/RecordingNotifier.cs index e37ea96a1..0186da9e1 100644 --- a/Emby.Server.Implementations/EntryPoints/RecordingNotifier.cs +++ b/Emby.Server.Implementations/EntryPoints/RecordingNotifier.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Threading; +using System.Threading.Tasks; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.Plugins; @@ -24,12 +25,14 @@ namespace Emby.Server.Implementations.EntryPoints _liveTvManager = liveTvManager; } - public void Run() + public Task RunAsync() { _liveTvManager.TimerCancelled += _liveTvManager_TimerCancelled; _liveTvManager.SeriesTimerCancelled += _liveTvManager_SeriesTimerCancelled; _liveTvManager.TimerCreated += _liveTvManager_TimerCreated; _liveTvManager.SeriesTimerCreated += _liveTvManager_SeriesTimerCreated; + + return Task.CompletedTask; } private void _liveTvManager_SeriesTimerCreated(object sender, MediaBrowser.Model.Events.GenericEventArgs e) diff --git a/Emby.Server.Implementations/EntryPoints/ServerEventNotifier.cs b/Emby.Server.Implementations/EntryPoints/ServerEventNotifier.cs index 92ea3a8f4..091dd6a45 100644 --- a/Emby.Server.Implementations/EntryPoints/ServerEventNotifier.cs +++ b/Emby.Server.Implementations/EntryPoints/ServerEventNotifier.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading; +using System.Threading.Tasks; using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Updates; using MediaBrowser.Controller; @@ -49,7 +50,7 @@ namespace Emby.Server.Implementations.EntryPoints _sessionManager = sessionManager; } - public void Run() + public Task RunAsync() { _userManager.UserDeleted += userManager_UserDeleted; _userManager.UserUpdated += userManager_UserUpdated; @@ -65,6 +66,8 @@ namespace Emby.Server.Implementations.EntryPoints _installationManager.PackageInstallationFailed += _installationManager_PackageInstallationFailed; _taskManager.TaskCompleted += _taskManager_TaskCompleted; + + return Task.CompletedTask; } void _installationManager_PackageInstalling(object sender, InstallationEventArgs e) diff --git a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs index 05c8b07ab..1d44bffbb 100644 --- a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs +++ b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs @@ -1,3 +1,4 @@ +using System.Threading.Tasks; using Emby.Server.Implementations.Browser; using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; @@ -32,11 +33,11 @@ namespace Emby.Server.Implementations.EntryPoints /// /// Runs this instance. /// - public void Run() + public Task RunAsync() { if (!_appHost.CanLaunchWebBrowser) { - return; + return Task.CompletedTask; } if (!_config.Configuration.IsStartupWizardCompleted) @@ -52,6 +53,8 @@ namespace Emby.Server.Implementations.EntryPoints BrowserLauncher.OpenWebApp(_appHost); } } + + return Task.CompletedTask; } /// diff --git a/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs b/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs index 2c8246d13..5b90dc1fb 100644 --- a/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs +++ b/Emby.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Emby.Server.Implementations.Udp; using MediaBrowser.Controller; using MediaBrowser.Controller.Plugins; @@ -43,7 +44,7 @@ namespace Emby.Server.Implementations.EntryPoints /// /// Runs this instance. /// - public void Run() + public Task RunAsync() { var udpServer = new UdpServer(_logger, _appHost, _json, _socketFactory); @@ -57,6 +58,8 @@ namespace Emby.Server.Implementations.EntryPoints { _logger.LogError(ex, "Failed to start UDP Server"); } + + return Task.CompletedTask; } /// diff --git a/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs b/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs index 9e71ffceb..d1d05eeb0 100644 --- a/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs +++ b/Emby.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs @@ -38,9 +38,11 @@ namespace Emby.Server.Implementations.EntryPoints _timerFactory = timerFactory; } - public void Run() + public Task RunAsync() { _userDataManager.UserDataSaved += _userDataManager_UserDataSaved; + + return Task.CompletedTask; } void _userDataManager_UserDataSaved(object sender, UserDataSaveEventArgs e) diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.cs index 204f9d949..e432b31da 100644 --- a/Emby.Server.Implementations/IO/LibraryMonitor.cs +++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs @@ -627,9 +627,10 @@ namespace Emby.Server.Implementations.IO _monitor = monitor; } - public void Run() + public Task RunAsync() { _monitor.Start(); + return Task.CompletedTask; } public void Dispose() diff --git a/Emby.Server.Implementations/Library/UserManager.cs b/Emby.Server.Implementations/Library/UserManager.cs index 6139659b7..6e4450bb1 100644 --- a/Emby.Server.Implementations/Library/UserManager.cs +++ b/Emby.Server.Implementations/Library/UserManager.cs @@ -1204,9 +1204,11 @@ namespace Emby.Server.Implementations.Library _sessionManager = sessionManager; } - public void Run() + public Task RunAsync() { _userManager.UserPolicyUpdated += _userManager_UserPolicyUpdated; + + return Task.CompletedTask; } private void _userManager_UserPolicyUpdated(object sender, GenericEventArgs e) diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 4805e54dd..4e131c941 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -124,7 +124,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV } } - public async void Start() + public async Task Start() { _timerProvider.RestartTimers(); diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EntryPoint.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EntryPoint.cs index 982a54b68..9c9ba09f5 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EntryPoint.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EntryPoint.cs @@ -1,12 +1,13 @@ +using System.Threading.Tasks; using MediaBrowser.Controller.Plugins; namespace Emby.Server.Implementations.LiveTv.EmbyTV { public class EntryPoint : IServerEntryPoint { - public void Run() + public Task RunAsync() { - EmbyTV.Current.Start(); + return EmbyTV.Current.Start(); } public void Dispose() diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index 66586d4e4..4dfe83441 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -103,8 +103,6 @@ namespace Jellyfin.Server appHost.ImageProcessor.ImageEncoder = GetImageEncoder(fileSystem, appPaths, appHost.LocalizationManager); - _logger.LogInformation("Running startup tasks"); - await appHost.RunStartupTasks(); // TODO: read input for a stop command @@ -118,8 +116,6 @@ namespace Jellyfin.Server { // Don't throw on cancellation } - - _logger.LogInformation("Disposing app host"); } if (_restartOnShutdown) diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index 8ae0ad942..cfd37667a 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -130,7 +130,7 @@ namespace MediaBrowser.Api /// /// Runs this instance. /// - public void Run() + public Task RunAsync() { try { @@ -148,6 +148,8 @@ namespace MediaBrowser.Api { Logger.LogError(ex, "Error deleting encoded media cache"); } + + return Task.CompletedTask; } public EncodingOptions GetEncodingOptions() @@ -162,8 +164,7 @@ namespace MediaBrowser.Api { var path = _config.ApplicationPaths.TranscodingTempPath; - foreach (var file in _fileSystem.GetFilePaths(path, true) - .ToList()) + foreach (var file in _fileSystem.GetFilePaths(path, true)) { _fileSystem.DeleteFile(file); } diff --git a/MediaBrowser.Controller/Plugins/IServerEntryPoint.cs b/MediaBrowser.Controller/Plugins/IServerEntryPoint.cs index 7b7a591aa..e57929989 100644 --- a/MediaBrowser.Controller/Plugins/IServerEntryPoint.cs +++ b/MediaBrowser.Controller/Plugins/IServerEntryPoint.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; namespace MediaBrowser.Controller.Plugins { @@ -10,7 +11,7 @@ namespace MediaBrowser.Controller.Plugins /// /// Runs this instance. /// - void Run(); + Task RunAsync(); } public interface IRunBeforeStartup diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index db0011114..5405934ce 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -425,11 +425,9 @@ namespace MediaBrowser.WebDashboard.Api private async Task DumpFile(PackageCreator packageCreator, string resourceVirtualPath, string destinationFilePath, string mode, string appVersion) { using (var stream = await packageCreator.GetResource(resourceVirtualPath, mode, null, appVersion).ConfigureAwait(false)) + using (var fs = _fileSystem.GetFileStream(destinationFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read)) { - using (var fs = _fileSystem.GetFileStream(destinationFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read)) - { - stream.CopyTo(fs); - } + await stream.CopyToAsync(fs); } } diff --git a/MediaBrowser.WebDashboard/ServerEntryPoint.cs b/MediaBrowser.WebDashboard/ServerEntryPoint.cs index 221fa62c7..18ed54a78 100644 --- a/MediaBrowser.WebDashboard/ServerEntryPoint.cs +++ b/MediaBrowser.WebDashboard/ServerEntryPoint.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using MediaBrowser.Common; using MediaBrowser.Controller.Plugins; @@ -23,9 +24,11 @@ namespace MediaBrowser.WebDashboard Instance = this; } - public void Run() + public Task RunAsync() { PluginConfigurationPages = _appHost.GetExports().ToList(); + + return Task.CompletedTask; } public void Dispose() diff --git a/MediaBrowser.XbmcMetadata/EntryPoint.cs b/MediaBrowser.XbmcMetadata/EntryPoint.cs index 37a1d4c35..992991a7e 100644 --- a/MediaBrowser.XbmcMetadata/EntryPoint.cs +++ b/MediaBrowser.XbmcMetadata/EntryPoint.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; @@ -28,9 +29,11 @@ namespace MediaBrowser.XbmcMetadata _config = config; } - public void Run() + public Task RunAsync() { _userDataManager.UserDataSaved += _userDataManager_UserDataSaved; + + return Task.CompletedTask; } void _userDataManager_UserDataSaved(object sender, UserDataSaveEventArgs e) -- cgit v1.2.3 From fd361421b120b103b2abaf1e3b36c6715887afe4 Mon Sep 17 00:00:00 2001 From: PloughPuff Date: Mon, 28 Jan 2019 13:41:37 +0000 Subject: Use CommandLineParser package for handling CLI args --- Emby.Server.Implementations/ApplicationHost.cs | 4 +- .../Emby.Server.Implementations.csproj | 1 + .../EntryPoints/StartupWizard.cs | 2 +- Emby.Server.Implementations/FFMpeg/FFMpegLoader.cs | 4 +- Emby.Server.Implementations/StartupOptions.cs | 53 ++++++++++++++-------- Jellyfin.Server/CoreAppHost.cs | 2 +- Jellyfin.Server/Program.cs | 42 +++++++++-------- 7 files changed, 64 insertions(+), 44 deletions(-) (limited to 'Jellyfin.Server/Program.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 31dad48be..2306fb370 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -141,7 +141,7 @@ namespace Emby.Server.Implementations return false; } - if (StartupOptions.ContainsOption("-service")) + if (StartupOptions.Service) { return false; } @@ -1747,7 +1747,7 @@ namespace Emby.Server.Implementations EncoderLocationType = MediaEncoder.EncoderLocationType, SystemArchitecture = EnvironmentInfo.SystemArchitecture, SystemUpdateLevel = SystemUpdateLevel, - PackageName = StartupOptions.GetOption("-package") + PackageName = StartupOptions.PackageName }; } diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj index 3aa617b02..bf0546f2e 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -22,6 +22,7 @@ + diff --git a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs index 05c8b07ab..bb96120f4 100644 --- a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs +++ b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs @@ -47,7 +47,7 @@ namespace Emby.Server.Implementations.EntryPoints { var options = ((ApplicationHost)_appHost).StartupOptions; - if (!options.ContainsOption("-noautorunwebapp")) + if (!options.NoAutoRunWebApp) { BrowserLauncher.OpenWebApp(_appHost); } diff --git a/Emby.Server.Implementations/FFMpeg/FFMpegLoader.cs b/Emby.Server.Implementations/FFMpeg/FFMpegLoader.cs index 79a42f294..4c926b91a 100644 --- a/Emby.Server.Implementations/FFMpeg/FFMpegLoader.cs +++ b/Emby.Server.Implementations/FFMpeg/FFMpegLoader.cs @@ -30,8 +30,8 @@ namespace Emby.Server.Implementations.FFMpeg public FFMpegInfo GetFFMpegInfo(StartupOptions options) { - var customffMpegPath = options.GetOption("-ffmpeg"); - var customffProbePath = options.GetOption("-ffprobe"); + var customffMpegPath = options.FFmpeg; + var customffProbePath = options.FFprobe; if (!string.IsNullOrWhiteSpace(customffMpegPath) && !string.IsNullOrWhiteSpace(customffProbePath)) { diff --git a/Emby.Server.Implementations/StartupOptions.cs b/Emby.Server.Implementations/StartupOptions.cs index 221263634..fca60afb8 100644 --- a/Emby.Server.Implementations/StartupOptions.cs +++ b/Emby.Server.Implementations/StartupOptions.cs @@ -1,30 +1,43 @@ -using System; -using System.Linq; - namespace Emby.Server.Implementations { + using CommandLine; + + /// + /// Class used by CommandLine package when parsing the command line arguments. + /// public class StartupOptions { - private readonly string[] _options; + [Option('d', "programdata", Required = false, HelpText = "Path to use for program data (databases files etc.).")] + public string PathProgramData { get; set; } + + [Option('c', "configdir", Required = false, HelpText = "Path to use for config data (user policies and puctures).")] + public string PathConfig { get; set; } + + [Option('l', "logdir", Required = false, HelpText = "Path to use for writing log files.")] + public string PathLog { get; set; } + + + [Option("ffmpeg", Required = false, HelpText = "Path to external FFmpeg exe to use in place of built-in.")] + public string FFmpeg { get; set; } + + [Option("ffprobe", Required = false, HelpText = "ffmpeg and ffprobe switches must be supplied together.")] + public string FFprobe { get; set; } + + + [Option("service", Required = false, HelpText = "Run as headless service.")] + public bool Service { get; set; } - public StartupOptions(string[] commandLineArgs) - { - _options = commandLineArgs; - } + [Option("noautorunwebapp", Required = false, HelpText = "Run headless if startup wizard is complete.")] + public bool NoAutoRunWebApp { get; set; } - public bool ContainsOption(string option) - => _options.Contains(option, StringComparer.OrdinalIgnoreCase); + [Option("package-name", Required = false, HelpText = "Used when packaging Jellyfin (example, synology).")] + public string PackageName { get; set; } - public string GetOption(string name) - { - int index = Array.IndexOf(_options, name); - if (index == -1) - { - return null; - } + [Option("restartpath", Required = false, HelpText = "Path to reset script.")] + public string RestartPath { get; set; } - return _options.ElementAtOrDefault(index + 1); - } + [Option("restartargs", Required = false, HelpText = "Arguments for restart script.")] + public string RestartArgs { get; set; } } -} + } diff --git a/Jellyfin.Server/CoreAppHost.cs b/Jellyfin.Server/CoreAppHost.cs index b580f45ca..5182ab4d7 100644 --- a/Jellyfin.Server/CoreAppHost.cs +++ b/Jellyfin.Server/CoreAppHost.cs @@ -16,7 +16,7 @@ namespace Jellyfin.Server { } - public override bool CanSelfRestart => StartupOptions.ContainsOption("-restartpath"); + public override bool CanSelfRestart => StartupOptions.RestartPath != null; protected override void RestartInternal() => Program.Restart(); diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index 66586d4e4..dbfd59ebf 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -26,6 +26,8 @@ using ILogger = Microsoft.Extensions.Logging.ILogger; namespace Jellyfin.Server { + using CommandLine; + public static class Program { private static readonly CancellationTokenSource _tokenSource = new CancellationTokenSource(); @@ -35,14 +37,18 @@ namespace Jellyfin.Server public static async Task Main(string[] args) { - StartupOptions options = new StartupOptions(args); - Version version = Assembly.GetEntryAssembly().GetName().Version; - - if (options.ContainsOption("-v") || options.ContainsOption("--version")) - { - Console.WriteLine(version.ToString()); - } + // For CommandLine package, change default behaviour to output errors to stdout (instead of stderr) + var parser = new Parser(config => config.HelpWriter = Console.Out); + + // Parse the command line arguments and either start the app or exit indicating error + await parser.ParseArguments(args) + .MapResult( + options => StartApp(options), + errs => Task.FromResult(0)).ConfigureAwait(false); + } + private static async Task StartApp(StartupOptions options) + { ServerApplicationPaths appPaths = CreateApplicationPaths(options); // $JELLYFIN_LOG_DIR needs to be set for the logger configuration manager @@ -78,7 +84,7 @@ namespace Jellyfin.Server Shutdown(); }; - _logger.LogInformation("Jellyfin version: {Version}", version); + _logger.LogInformation("Jellyfin version: {Version}", Assembly.GetEntryAssembly().GetName().Version); EnvironmentInfo environmentInfo = new EnvironmentInfo(getOperatingSystem()); ApplicationHost.LogEnvironmentInfo(_logger, appPaths, environmentInfo); @@ -133,9 +139,9 @@ namespace Jellyfin.Server string programDataPath = Environment.GetEnvironmentVariable("JELLYFIN_DATA_PATH"); if (string.IsNullOrEmpty(programDataPath)) { - if (options.ContainsOption("-programdata")) + if (options.PathProgramData != null) { - programDataPath = options.GetOption("-programdata"); + programDataPath = options.PathProgramData; } else { @@ -171,9 +177,9 @@ namespace Jellyfin.Server string configDir = Environment.GetEnvironmentVariable("JELLYFIN_CONFIG_DIR"); if (string.IsNullOrEmpty(configDir)) { - if (options.ContainsOption("-configdir")) + if (options.PathConfig != null) { - configDir = options.GetOption("-configdir"); + configDir = options.PathConfig; } else { @@ -190,9 +196,9 @@ namespace Jellyfin.Server string logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR"); if (string.IsNullOrEmpty(logDir)) { - if (options.ContainsOption("-logdir")) + if (options.PathLog != null) { - logDir = options.GetOption("-logdir"); + logDir = options.PathLog; } else { @@ -315,11 +321,11 @@ namespace Jellyfin.Server Shutdown(); } - private static void StartNewInstance(StartupOptions startupOptions) + private static void StartNewInstance(StartupOptions options) { _logger.LogInformation("Starting new instance"); - string module = startupOptions.GetOption("-restartpath"); + string module = options.RestartPath; if (string.IsNullOrWhiteSpace(module)) { @@ -328,9 +334,9 @@ namespace Jellyfin.Server string commandLineArgsString; - if (startupOptions.ContainsOption("-restartargs")) + if (options.RestartArgs != null) { - commandLineArgsString = startupOptions.GetOption("-restartargs") ?? string.Empty; + commandLineArgsString = options.RestartArgs ?? string.Empty; } else { -- cgit v1.2.3 From ebd2a3008791ac4043a775d48f0971a554bd9ff4 Mon Sep 17 00:00:00 2001 From: PloughPuff Date: Mon, 28 Jan 2019 14:51:31 +0000 Subject: Accept single-hyphen usage and rename -programdatadir to -datadir For backwards compatibility, modify the args[] strings to replace single-hyphens with double-hyphens before parsing. Also rename -programdatadir to -datadir. --- Emby.Server.Implementations/StartupOptions.cs | 4 ++-- Jellyfin.Server/Program.cs | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'Jellyfin.Server/Program.cs') diff --git a/Emby.Server.Implementations/StartupOptions.cs b/Emby.Server.Implementations/StartupOptions.cs index fca60afb8..f4bb94f74 100644 --- a/Emby.Server.Implementations/StartupOptions.cs +++ b/Emby.Server.Implementations/StartupOptions.cs @@ -7,8 +7,8 @@ namespace Emby.Server.Implementations /// public class StartupOptions { - [Option('d', "programdata", Required = false, HelpText = "Path to use for program data (databases files etc.).")] - public string PathProgramData { get; set; } + [Option('d', "datadir", Required = false, HelpText = "Path to use for the data folder (databases files etc.).")] + public string PathData { get; set; } [Option('c', "configdir", Required = false, HelpText = "Path to use for config data (user policies and puctures).")] public string PathConfig { get; set; } diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index dbfd59ebf..2f7edee65 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -27,6 +27,7 @@ using ILogger = Microsoft.Extensions.Logging.ILogger; namespace Jellyfin.Server { using CommandLine; + using System.Text.RegularExpressions; public static class Program { @@ -37,6 +38,18 @@ namespace Jellyfin.Server public static async Task Main(string[] args) { + // For backwards compatibility. + // Modify any input arguments now which start with single-hyphen to POSIX standard + // double-hyphen to allow parsing by CommandLineParser package. + var pattern = @"^(-[^-\s]{2})"; // Match -xx, not -x, not --xx, not xx + var substitution = @"-$1"; // Prepend with additional single-hyphen + var regex = new Regex(pattern); + + for (var i = 0; i < args.Length; i++) + { + args[i] = regex.Replace(args[i], substitution); + } + // For CommandLine package, change default behaviour to output errors to stdout (instead of stderr) var parser = new Parser(config => config.HelpWriter = Console.Out); @@ -139,9 +152,9 @@ namespace Jellyfin.Server string programDataPath = Environment.GetEnvironmentVariable("JELLYFIN_DATA_PATH"); if (string.IsNullOrEmpty(programDataPath)) { - if (options.PathProgramData != null) + if (options.PathData != null) { - programDataPath = options.PathProgramData; + programDataPath = options.PathData; } else { -- cgit v1.2.3 From e18b89ca275feceee21b540878017a2373e7de6c Mon Sep 17 00:00:00 2001 From: PloughPuff Date: Mon, 28 Jan 2019 20:58:47 +0000 Subject: Move Options to Jellyfin.Server and create interface file Changes following review comments. --- Emby.Server.Implementations/ApplicationHost.cs | 7 +-- .../Emby.Server.Implementations.csproj | 3 +- .../EntryPoints/StartupWizard.cs | 2 +- Emby.Server.Implementations/FFMpeg/FFMpegLoader.cs | 7 +-- Emby.Server.Implementations/IStartupOptions.cs | 55 ++++++++++++++++++++++ Emby.Server.Implementations/StartupOptions.cs | 43 ----------------- Jellyfin.Server/Jellyfin.Server.csproj | 1 + Jellyfin.Server/Program.cs | 21 ++++----- Jellyfin.Server/StartupOptions.cs | 47 ++++++++++++++++++ 9 files changed, 123 insertions(+), 63 deletions(-) create mode 100644 Emby.Server.Implementations/IStartupOptions.cs delete mode 100644 Emby.Server.Implementations/StartupOptions.cs create mode 100644 Jellyfin.Server/StartupOptions.cs (limited to 'Jellyfin.Server/Program.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 2306fb370..3af9e487e 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -43,6 +43,7 @@ using Emby.Server.Implementations.ScheduledTasks; using Emby.Server.Implementations.Security; using Emby.Server.Implementations.Serialization; using Emby.Server.Implementations.Session; +using Emby.Server.Implementations.ParsedStartupOptions; using Emby.Server.Implementations.Threading; using Emby.Server.Implementations.TV; using Emby.Server.Implementations.Updates; @@ -141,7 +142,7 @@ namespace Emby.Server.Implementations return false; } - if (StartupOptions.Service) + if (StartupOptions.IsService) { return false; } @@ -343,7 +344,7 @@ namespace Emby.Server.Implementations protected IHttpResultFactory HttpResultFactory { get; private set; } protected IAuthService AuthService { get; private set; } - public StartupOptions StartupOptions { get; private set; } + public IStartupOptions StartupOptions { get; private set; } internal IImageEncoder ImageEncoder { get; private set; } @@ -364,7 +365,7 @@ namespace Emby.Server.Implementations /// public ApplicationHost(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory, - StartupOptions options, + IStartupOptions options, IFileSystem fileSystem, IEnvironmentInfo environmentInfo, IImageEncoder imageEncoder, diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj index bf0546f2e..92e3172f1 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -1,4 +1,4 @@ - + @@ -22,7 +22,6 @@ - diff --git a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs index bb96120f4..43d18e135 100644 --- a/Emby.Server.Implementations/EntryPoints/StartupWizard.cs +++ b/Emby.Server.Implementations/EntryPoints/StartupWizard.cs @@ -47,7 +47,7 @@ namespace Emby.Server.Implementations.EntryPoints { var options = ((ApplicationHost)_appHost).StartupOptions; - if (!options.NoAutoRunWebApp) + if (options.AutoRunWebApp) { BrowserLauncher.OpenWebApp(_appHost); } diff --git a/Emby.Server.Implementations/FFMpeg/FFMpegLoader.cs b/Emby.Server.Implementations/FFMpeg/FFMpegLoader.cs index 4c926b91a..b422b8862 100644 --- a/Emby.Server.Implementations/FFMpeg/FFMpegLoader.cs +++ b/Emby.Server.Implementations/FFMpeg/FFMpegLoader.cs @@ -6,6 +6,7 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Net; using MediaBrowser.Model.IO; using Microsoft.Extensions.Logging; +using Emby.Server.Implementations.ParsedStartupOptions; namespace Emby.Server.Implementations.FFMpeg { @@ -28,10 +29,10 @@ namespace Emby.Server.Implementations.FFMpeg _ffmpegInstallInfo = ffmpegInstallInfo; } - public FFMpegInfo GetFFMpegInfo(StartupOptions options) + public FFMpegInfo GetFFMpegInfo(IStartupOptions options) { - var customffMpegPath = options.FFmpeg; - var customffProbePath = options.FFprobe; + var customffMpegPath = options.FFmpegPath; + var customffProbePath = options.FFprobePath; if (!string.IsNullOrWhiteSpace(customffMpegPath) && !string.IsNullOrWhiteSpace(customffProbePath)) { diff --git a/Emby.Server.Implementations/IStartupOptions.cs b/Emby.Server.Implementations/IStartupOptions.cs new file mode 100644 index 000000000..878bb6640 --- /dev/null +++ b/Emby.Server.Implementations/IStartupOptions.cs @@ -0,0 +1,55 @@ +namespace Emby.Server.Implementations.ParsedStartupOptions +{ + public interface IStartupOptions + { + /// + /// --datadir + /// + string DataDir { get; } + + /// + /// --configdir + /// + string ConfigDir { get; } + + /// + /// --logdir + /// + string LogDir { get; } + + /// + /// --ffmpeg + /// + string FFmpegPath { get; } + + /// + /// --ffprobe + /// + string FFprobePath { get; } + + /// + /// --service + /// + bool IsService { get; } + + /// + /// --noautorunwebapp + /// + bool AutoRunWebApp { get; } + + /// + /// --package-name + /// + string PackageName { get; } + + /// + /// --restartpath + /// + string RestartPath { get; } + + /// + /// --restartargs + /// + string RestartArgs { get; } + } +} diff --git a/Emby.Server.Implementations/StartupOptions.cs b/Emby.Server.Implementations/StartupOptions.cs deleted file mode 100644 index f4bb94f74..000000000 --- a/Emby.Server.Implementations/StartupOptions.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace Emby.Server.Implementations -{ - using CommandLine; - - /// - /// Class used by CommandLine package when parsing the command line arguments. - /// - public class StartupOptions - { - [Option('d', "datadir", Required = false, HelpText = "Path to use for the data folder (databases files etc.).")] - public string PathData { get; set; } - - [Option('c', "configdir", Required = false, HelpText = "Path to use for config data (user policies and puctures).")] - public string PathConfig { get; set; } - - [Option('l', "logdir", Required = false, HelpText = "Path to use for writing log files.")] - public string PathLog { get; set; } - - - [Option("ffmpeg", Required = false, HelpText = "Path to external FFmpeg exe to use in place of built-in.")] - public string FFmpeg { get; set; } - - [Option("ffprobe", Required = false, HelpText = "ffmpeg and ffprobe switches must be supplied together.")] - public string FFprobe { get; set; } - - - [Option("service", Required = false, HelpText = "Run as headless service.")] - public bool Service { get; set; } - - [Option("noautorunwebapp", Required = false, HelpText = "Run headless if startup wizard is complete.")] - public bool NoAutoRunWebApp { get; set; } - - [Option("package-name", Required = false, HelpText = "Used when packaging Jellyfin (example, synology).")] - public string PackageName { get; set; } - - - [Option("restartpath", Required = false, HelpText = "Path to reset script.")] - public string RestartPath { get; set; } - - [Option("restartargs", Required = false, HelpText = "Arguments for restart script.")] - public string RestartArgs { get; set; } - } - } diff --git a/Jellyfin.Server/Jellyfin.Server.csproj b/Jellyfin.Server/Jellyfin.Server.csproj index 5a4bf5149..1f72de86d 100644 --- a/Jellyfin.Server/Jellyfin.Server.csproj +++ b/Jellyfin.Server/Jellyfin.Server.csproj @@ -32,6 +32,7 @@ + diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index 2f7edee65..905cf3aa0 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -6,8 +6,10 @@ using System.Net; using System.Net.Security; using System.Reflection; using System.Runtime.InteropServices; +using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; +using CommandLine; using Emby.Drawing; using Emby.Server.Implementations; using Emby.Server.Implementations.EnvironmentInfo; @@ -26,9 +28,6 @@ using ILogger = Microsoft.Extensions.Logging.ILogger; namespace Jellyfin.Server { - using CommandLine; - using System.Text.RegularExpressions; - public static class Program { private static readonly CancellationTokenSource _tokenSource = new CancellationTokenSource(); @@ -41,8 +40,8 @@ namespace Jellyfin.Server // For backwards compatibility. // Modify any input arguments now which start with single-hyphen to POSIX standard // double-hyphen to allow parsing by CommandLineParser package. - var pattern = @"^(-[^-\s]{2})"; // Match -xx, not -x, not --xx, not xx - var substitution = @"-$1"; // Prepend with additional single-hyphen + const string pattern = @"^(-[^-\s]{2})"; // Match -xx, not -x, not --xx, not xx + const string substitution = @"-$1"; // Prepend with additional single-hyphen var regex = new Regex(pattern); for (var i = 0; i < args.Length; i++) @@ -152,9 +151,9 @@ namespace Jellyfin.Server string programDataPath = Environment.GetEnvironmentVariable("JELLYFIN_DATA_PATH"); if (string.IsNullOrEmpty(programDataPath)) { - if (options.PathData != null) + if (options.DataDir != null) { - programDataPath = options.PathData; + programDataPath = options.DataDir; } else { @@ -190,9 +189,9 @@ namespace Jellyfin.Server string configDir = Environment.GetEnvironmentVariable("JELLYFIN_CONFIG_DIR"); if (string.IsNullOrEmpty(configDir)) { - if (options.PathConfig != null) + if (options.ConfigDir != null) { - configDir = options.PathConfig; + configDir = options.ConfigDir; } else { @@ -209,9 +208,9 @@ namespace Jellyfin.Server string logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR"); if (string.IsNullOrEmpty(logDir)) { - if (options.PathLog != null) + if (options.LogDir != null) { - logDir = options.PathLog; + logDir = options.LogDir; } else { diff --git a/Jellyfin.Server/StartupOptions.cs b/Jellyfin.Server/StartupOptions.cs new file mode 100644 index 000000000..97fcb633a --- /dev/null +++ b/Jellyfin.Server/StartupOptions.cs @@ -0,0 +1,47 @@ +using CommandLine; +using Emby.Server.Implementations.ParsedStartupOptions; + +namespace Jellyfin.Server +{ + /// + /// Class used by CommandLine package when parsing the command line arguments. + /// + public class StartupOptions : IStartupOptions + { + [Option('d', "datadir", Required = false, HelpText = "Path to use for the data folder (databases files etc.).")] + public string DataDir { get; set; } + + [Option('c', "configdir", Required = false, HelpText = "Path to use for config data (user policies and puctures).")] + public string ConfigDir { get; set; } + + [Option('l', "logdir", Required = false, HelpText = "Path to use for writing log files.")] + public string LogDir { get; set; } + + [Option("ffmpeg", Required = false, HelpText = "Path to external FFmpeg exe to use in place of built-in.")] + public string FFmpegPath { get; set; } + + [Option("ffprobe", Required = false, HelpText = "ffmpeg and ffprobe switches must be supplied together.")] + public string FFprobePath { get; set; } + + [Option("service", Required = false, HelpText = "Run as headless service.")] + public bool IsService { get; set; } + + [Option("noautorunwebapp", Required = false, HelpText = "Run headless if startup wizard is complete.")] + public bool AutoRunWebApp { get => !NoautoRunWebApp; set => NoautoRunWebApp = value; } + + [Option("package-name", Required = false, HelpText = "Used when packaging Jellyfin (example, synology).")] + public string PackageName { get; set; } + + [Option("restartpath", Required = false, HelpText = "Path to reset script.")] + public string RestartPath { get; set; } + + [Option("restartargs", Required = false, HelpText = "Arguments for restart script.")] + public string RestartArgs { get; set; } + + /// + /// Gets or sets a value indicating whether to run not run the web app. + /// Command line switch is --noautorunwebapp, which we store privately here, but provide inverse (AutoRunWebApp) for users. + /// + private bool NoautoRunWebApp { get; set; } + } +} -- cgit v1.2.3 From b5e8cce4cfb5356ca3f46d2cde66b5d0d4084f4d Mon Sep 17 00:00:00 2001 From: PloughPuff Date: Tue, 29 Jan 2019 13:34:59 +0000 Subject: Improved help text and output errors to stderr Addressed review comments from JustAMan. --- Jellyfin.Server/Program.cs | 5 +---- Jellyfin.Server/StartupOptions.cs | 10 +++++----- 2 files changed, 6 insertions(+), 9 deletions(-) (limited to 'Jellyfin.Server/Program.cs') diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index 905cf3aa0..2f1828336 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -49,11 +49,8 @@ namespace Jellyfin.Server args[i] = regex.Replace(args[i], substitution); } - // For CommandLine package, change default behaviour to output errors to stdout (instead of stderr) - var parser = new Parser(config => config.HelpWriter = Console.Out); - // Parse the command line arguments and either start the app or exit indicating error - await parser.ParseArguments(args) + await Parser.Default.ParseArguments(args) .MapResult( options => StartApp(options), errs => Task.FromResult(0)).ConfigureAwait(false); diff --git a/Jellyfin.Server/StartupOptions.cs b/Jellyfin.Server/StartupOptions.cs index a1bdb756e..6e6b61725 100644 --- a/Jellyfin.Server/StartupOptions.cs +++ b/Jellyfin.Server/StartupOptions.cs @@ -8,19 +8,19 @@ namespace Jellyfin.Server /// public class StartupOptions : IStartupOptions { - [Option('d', "datadir", Required = false, HelpText = "Path to use for the data folder (databases files etc.).")] + [Option('d', "datadir", Required = false, HelpText = "Path to use for the data folder (database files, etc.).")] public string DataDir { get; set; } - [Option('c', "configdir", Required = false, HelpText = "Path to use for config data (user policies and puctures).")] + [Option('c', "configdir", Required = false, HelpText = "Path to use for configuration data (user settings and pictures).")] public string ConfigDir { get; set; } [Option('l', "logdir", Required = false, HelpText = "Path to use for writing log files.")] public string LogDir { get; set; } - [Option("ffmpeg", Required = false, HelpText = "Path to external FFmpeg exe to use in place of built-in.")] + [Option("ffmpeg", Required = false, HelpText = "Path to external FFmpeg executable to use in place of default found in PATH. Must be specified along with --ffprobe.")] public string FFmpegPath { get; set; } - [Option("ffprobe", Required = false, HelpText = "ffmpeg and ffprobe switches must be supplied together.")] + [Option("ffprobe", Required = false, HelpText = "Path to external FFprobe executable to use in place of default found in PATH. Must be specified along with --ffmpeg.")] public string FFprobePath { get; set; } [Option("service", Required = false, HelpText = "Run as headless service.")] @@ -32,7 +32,7 @@ namespace Jellyfin.Server [Option("package-name", Required = false, HelpText = "Used when packaging Jellyfin (example, synology).")] public string PackageName { get; set; } - [Option("restartpath", Required = false, HelpText = "Path to reset script.")] + [Option("restartpath", Required = false, HelpText = "Path to restart script.")] public string RestartPath { get; set; } [Option("restartargs", Required = false, HelpText = "Arguments for restart script.")] -- cgit v1.2.3 From 8af1e93cd4c9187ec46e2a6c7002791190be13fc Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Mon, 28 Jan 2019 17:52:56 +0100 Subject: Make cache dir configurable --- .../AppBase/BaseApplicationPaths.cs | 4 +++- .../ServerApplicationPaths.cs | 9 ++++++-- Jellyfin.Server/Program.cs | 27 +++++++++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) (limited to 'Jellyfin.Server/Program.cs') diff --git a/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs b/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs index e4a2cd9df..701c04f9e 100644 --- a/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs +++ b/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs @@ -16,12 +16,14 @@ namespace Emby.Server.Implementations.AppBase string programDataPath, string appFolderPath, string logDirectoryPath = null, - string configurationDirectoryPath = null) + string configurationDirectoryPath = null, + string cacheDirectoryPath = null) { ProgramDataPath = programDataPath; ProgramSystemPath = appFolderPath; LogDirectoryPath = logDirectoryPath; ConfigurationDirectoryPath = configurationDirectoryPath; + CachePath = cacheDirectoryPath; } public string ProgramDataPath { get; private set; } diff --git a/Emby.Server.Implementations/ServerApplicationPaths.cs b/Emby.Server.Implementations/ServerApplicationPaths.cs index 67389536b..36975df50 100644 --- a/Emby.Server.Implementations/ServerApplicationPaths.cs +++ b/Emby.Server.Implementations/ServerApplicationPaths.cs @@ -18,8 +18,13 @@ namespace Emby.Server.Implementations string appFolderPath, string applicationResourcesPath, string logDirectoryPath = null, - string configurationDirectoryPath = null) - : base(programDataPath, appFolderPath, logDirectoryPath, configurationDirectoryPath) + string configurationDirectoryPath = null, + string cacheDirectoryPath = null) + : base(programDataPath, + appFolderPath, + logDirectoryPath, + configurationDirectoryPath, + cacheDirectoryPath) { ApplicationResourcesPath = applicationResourcesPath; } diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index 2f1828336..e0d5ed623 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -202,6 +202,31 @@ namespace Jellyfin.Server Directory.CreateDirectory(configDir); } + string cacheDir = Environment.GetEnvironmentVariable("JELLYFIN_CACHE_DIR"); + if (string.IsNullOrEmpty(cacheDir)) + { + if (options.ContainsOption("-cachedir")) + { + cacheDir = options.GetOption("-cachedir"); + } + else if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + // $XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored. + cacheDir = Environment.GetEnvironmentVariable("XDG_CACHE_HOME"); + // If $XDG_CACHE_HOME is either not set or empty, $HOME/.cache should be used. + if (string.IsNullOrEmpty(cacheDir)) + { + cacheDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".cache"); + } + cacheDir = Path.Combine(cacheDir, "jellyfin"); + } + } + + if (cacheDir != null) + { + Directory.CreateDirectory(cacheDir); + } + string logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR"); if (string.IsNullOrEmpty(logDir)) { @@ -223,7 +248,7 @@ namespace Jellyfin.Server string appPath = AppContext.BaseDirectory; - return new ServerApplicationPaths(programDataPath, appPath, appPath, logDir, configDir); + return new ServerApplicationPaths(programDataPath, appPath, appPath, logDir, configDir, cacheDir); } private static async Task createLogger(IApplicationPaths appPaths) -- cgit v1.2.3 From 660f6174b32268edf7b9bdb4441eef83b187daaf Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Fri, 1 Feb 2019 18:15:35 +0100 Subject: Rebase on master --- Jellyfin.Server/Program.cs | 4 ++-- Jellyfin.Server/StartupOptions.cs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'Jellyfin.Server/Program.cs') diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index e0d5ed623..5c8608a92 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -205,9 +205,9 @@ namespace Jellyfin.Server string cacheDir = Environment.GetEnvironmentVariable("JELLYFIN_CACHE_DIR"); if (string.IsNullOrEmpty(cacheDir)) { - if (options.ContainsOption("-cachedir")) + if (options.CacheDir != null) { - cacheDir = options.GetOption("-cachedir"); + cacheDir = options.CacheDir; } else if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { diff --git a/Jellyfin.Server/StartupOptions.cs b/Jellyfin.Server/StartupOptions.cs index 6e6b61725..4908d86ed 100644 --- a/Jellyfin.Server/StartupOptions.cs +++ b/Jellyfin.Server/StartupOptions.cs @@ -11,6 +11,9 @@ namespace Jellyfin.Server [Option('d', "datadir", Required = false, HelpText = "Path to use for the data folder (database files, etc.).")] public string DataDir { get; set; } + [Option('C', "configdir", Required = false, HelpText = "Path to use for caching.")] + public string CacheDir { get; set; } + [Option('c', "configdir", Required = false, HelpText = "Path to use for configuration data (user settings and pictures).")] public string ConfigDir { get; set; } -- cgit v1.2.3 From 5ac6d0ae59731cdf9de0a5565d0cd894695bdc12 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Fri, 1 Feb 2019 21:56:50 +0100 Subject: Fix more warnings --- Emby.Server.Implementations/IO/LibraryMonitor.cs | 14 ++++++++++---- Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs | 16 ++++++++-------- .../LiveTv/TunerHosts/SharedHttpStream.cs | 2 +- .../Updates/InstallationManager.cs | 4 ++-- Jellyfin.Server/Program.cs | 8 ++++---- MediaBrowser.Api/PackageService.cs | 2 +- MediaBrowser.Api/UserLibrary/PlaystateService.cs | 10 +++++----- 7 files changed, 31 insertions(+), 25 deletions(-) (limited to 'Jellyfin.Server/Program.cs') diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.cs index dad81c195..ed5fddb52 100644 --- a/Emby.Server.Implementations/IO/LibraryMonitor.cs +++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs @@ -601,20 +601,26 @@ namespace Emby.Server.Implementations.IO /// public void Dispose() { - _disposed = true; Dispose(true); } /// /// Releases unmanaged and - optionally - managed resources. /// - /// true to release both managed and unmanaged resources; false to release only unmanaged resources. - protected virtual void Dispose(bool dispose) + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool disposing) { - if (dispose) + if (_disposed) + { + return; + } + + if (disposing) { Stop(); } + + _disposed = true; } } diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 4e68bb545..bce9c240d 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -35,7 +35,6 @@ using MediaBrowser.Model.Providers; using MediaBrowser.Model.Querying; using MediaBrowser.Model.Reflection; using MediaBrowser.Model.Serialization; -using MediaBrowser.Model.System; using MediaBrowser.Model.Threading; using Microsoft.Extensions.Logging; @@ -275,7 +274,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV foreach (var timer in seriesTimers) { - await UpdateTimersForSeriesTimer(timer, false, true).ConfigureAwait(false); + UpdateTimersForSeriesTimer(timer, false, true); } } @@ -763,12 +762,12 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV _timerProvider.AddOrUpdate(timer, false); } - await UpdateTimersForSeriesTimer(info, true, false).ConfigureAwait(false); + UpdateTimersForSeriesTimer(info, true, false); return info.Id; } - public async Task UpdateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken cancellationToken) + public Task UpdateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken cancellationToken) { var instance = _seriesTimerProvider.GetAll().FirstOrDefault(i => string.Equals(i.Id, info.Id, StringComparison.OrdinalIgnoreCase)); @@ -792,8 +791,10 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV _seriesTimerProvider.Update(instance); - await UpdateTimersForSeriesTimer(instance, true, true).ConfigureAwait(false); + UpdateTimersForSeriesTimer(instance, true, true); } + + return Task.CompletedTask; } public Task UpdateTimerAsync(TimerInfo updatedTimer, CancellationToken cancellationToken) @@ -2346,10 +2347,9 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV } } - private async Task UpdateTimersForSeriesTimer(SeriesTimerInfo seriesTimer, bool updateTimerSettings, bool deleteInvalidTimers) + private void UpdateTimersForSeriesTimer(SeriesTimerInfo seriesTimer, bool updateTimerSettings, bool deleteInvalidTimers) { - var allTimers = GetTimersForSeries(seriesTimer) - .ToList(); + var allTimers = GetTimersForSeries(seriesTimer).ToList(); var enabledTimersForSeries = new List(); diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs index 716417ccb..4eff9252e 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/SharedHttpStream.cs @@ -94,7 +94,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts var now = DateTime.UtcNow; - StartStreaming(response, taskCompletionSource, LiveStreamCancellationTokenSource.Token); + var _ = StartStreaming(response, taskCompletionSource, LiveStreamCancellationTokenSource.Token); //OpenedMediaSource.Protocol = MediaProtocol.File; //OpenedMediaSource.Path = tempFile; diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index 552155635..9a49b97c7 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -164,7 +164,7 @@ namespace Emby.Server.Implementations.Updates /// Gets all available packages. /// /// Task{List{PackageInfo}}. - public async Task> GetAvailablePackages(CancellationToken cancellationToken, + public Task> GetAvailablePackages(CancellationToken cancellationToken, bool withRegistration = true, string packageType = null, Version applicationVersion = null) @@ -172,7 +172,7 @@ namespace Emby.Server.Implementations.Updates // TODO cvium: when plugins get back this would need to be fixed // var packages = await GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false); - return new List(); //FilterPackages(packages, packageType, applicationVersion); + return Task.FromResult(new List()); //FilterPackages(packages, packageType, applicationVersion); } /// diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index 2f1828336..88b10cdbe 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -62,7 +62,7 @@ namespace Jellyfin.Server // $JELLYFIN_LOG_DIR needs to be set for the logger configuration manager Environment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", appPaths.LogDirectoryPath); - await createLogger(appPaths); + await CreateLogger(appPaths); _logger = _loggerFactory.CreateLogger("Main"); AppDomain.CurrentDomain.UnhandledException += (sender, e) @@ -95,7 +95,7 @@ namespace Jellyfin.Server _logger.LogInformation("Jellyfin version: {Version}", Assembly.GetEntryAssembly().GetName().Version); - EnvironmentInfo environmentInfo = new EnvironmentInfo(getOperatingSystem()); + EnvironmentInfo environmentInfo = new EnvironmentInfo(GetOperatingSystem()); ApplicationHost.LogEnvironmentInfo(_logger, appPaths, environmentInfo); SQLitePCL.Batteries_V2.Init(); @@ -226,7 +226,7 @@ namespace Jellyfin.Server return new ServerApplicationPaths(programDataPath, appPath, appPath, logDir, configDir); } - private static async Task createLogger(IApplicationPaths appPaths) + private static async Task CreateLogger(IApplicationPaths appPaths) { try { @@ -286,7 +286,7 @@ namespace Jellyfin.Server return new NullImageEncoder(); } - private static MediaBrowser.Model.System.OperatingSystem getOperatingSystem() + private static MediaBrowser.Model.System.OperatingSystem GetOperatingSystem() { switch (Environment.OSVersion.Platform) { diff --git a/MediaBrowser.Api/PackageService.cs b/MediaBrowser.Api/PackageService.cs index 16819ee37..fbb876dea 100644 --- a/MediaBrowser.Api/PackageService.cs +++ b/MediaBrowser.Api/PackageService.cs @@ -197,7 +197,7 @@ namespace MediaBrowser.Api throw new ResourceNotFoundException(string.Format("Package not found: {0}", request.Name)); } - Task.Run(() => _installationManager.InstallPackage(package, true, new SimpleProgress(), CancellationToken.None)); + await _installationManager.InstallPackage(package, true, new SimpleProgress(), CancellationToken.None); } /// diff --git a/MediaBrowser.Api/UserLibrary/PlaystateService.cs b/MediaBrowser.Api/UserLibrary/PlaystateService.cs index 72a943092..a133bc8e9 100644 --- a/MediaBrowser.Api/UserLibrary/PlaystateService.cs +++ b/MediaBrowser.Api/UserLibrary/PlaystateService.cs @@ -247,14 +247,14 @@ namespace MediaBrowser.Api.UserLibrary /// Posts the specified request. /// /// The request. - public async Task Post(MarkPlayedItem request) + public object Post(MarkPlayedItem request) { - var result = await MarkPlayed(request).ConfigureAwait(false); + var result = MarkPlayed(request); return ToOptimizedResult(result); } - private async Task MarkPlayed(MarkPlayedItem request) + private UserItemDataDto MarkPlayed(MarkPlayedItem request) { var user = _userManager.GetUserById(request.UserId); @@ -403,10 +403,10 @@ namespace MediaBrowser.Api.UserLibrary { var task = MarkUnplayed(request); - return ToOptimizedResult(task.Result); + return ToOptimizedResult(task); } - private async Task MarkUnplayed(MarkUnplayedItem request) + private UserItemDataDto MarkUnplayed(MarkUnplayedItem request) { var user = _userManager.GetUserById(request.UserId); -- cgit v1.2.3