diff options
Diffstat (limited to 'MediaBrowser.Server.Startup.Common')
11 files changed, 301 insertions, 387 deletions
diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index ae839e6ee0..1e5c54d93c 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -160,7 +160,6 @@ namespace MediaBrowser.Server.Startup.Common private IHttpServer HttpServer { get; set; } private IDtoService DtoService { get; set; } private IImageProcessor ImageProcessor { get; set; } - private ISeriesOrderManager SeriesOrderManager { get; set; } /// <summary> /// Gets or sets the media encoder. @@ -190,7 +189,6 @@ namespace MediaBrowser.Server.Startup.Common internal IItemRepository ItemRepository { get; set; } private INotificationsRepository NotificationsRepository { get; set; } private IFileOrganizationRepository FileOrganizationRepository { get; set; } - private IProviderRepository ProviderRepository { get; set; } private INotificationManager NotificationManager { get; set; } private ISubtitleManager SubtitleManager { get; set; } @@ -314,7 +312,6 @@ namespace MediaBrowser.Server.Startup.Common /// <summary> /// Runs the startup tasks. /// </summary> - /// <returns>Task.</returns> public override async Task RunStartupTasks() { if (ServerConfigurationManager.Configuration.MigrationVersion < CleanDatabaseScheduledTask.MigrationVersion && @@ -325,23 +322,30 @@ namespace MediaBrowser.Server.Startup.Common await base.RunStartupTasks().ConfigureAwait(false); + await MediaEncoder.Init().ConfigureAwait(false); + Logger.Info("ServerId: {0}", SystemId); Logger.Info("Core startup complete"); HttpServer.GlobalResponse = null; PerformPostInitMigrations(); + Logger.Info("Post-init migrations complete"); - Parallel.ForEach(GetExports<IServerEntryPoint>(), entryPoint => + foreach (var entryPoint in GetExports<IServerEntryPoint>().ToList()) { + var name = entryPoint.GetType().FullName; + Logger.Info("Starting entry point {0}", name); try { entryPoint.Run(); } catch (Exception ex) { - Logger.ErrorException("Error in {0}", ex, entryPoint.GetType().Name); + Logger.ErrorException("Error in {0}", ex, name); } - }); + Logger.Info("Entry point completed: {0}", name); + } + Logger.Info("All entry points have started"); LogManager.RemoveConsoleOutput(); } @@ -360,12 +364,18 @@ namespace MediaBrowser.Server.Startup.Common { var migrations = new List<IVersionMigration> { - new RenameXmlOptions(ServerConfigurationManager) }; foreach (var task in migrations) { - task.Run(); + try + { + task.Run(); + } + catch (Exception ex) + { + Logger.ErrorException("Error running migration", ex); + } } } @@ -375,19 +385,28 @@ namespace MediaBrowser.Server.Startup.Common { new OmdbEpisodeProviderMigration(ServerConfigurationManager), new MovieDbEpisodeProviderMigration(ServerConfigurationManager), - new DbMigration(ServerConfigurationManager, TaskManager) + new DbMigration(ServerConfigurationManager, TaskManager), + new FolderViewSettingMigration(ServerConfigurationManager, UserManager), + new CollectionGroupingMigration(ServerConfigurationManager, UserManager), + new CollectionsViewMigration(ServerConfigurationManager, UserManager) }; foreach (var task in migrations) { - task.Run(); + try + { + task.Run(); + } + catch (Exception ex) + { + Logger.ErrorException("Error running migration", ex); + } } } /// <summary> /// Registers resources that classes will depend on /// </summary> - /// <returns>Task.</returns> protected override async Task RegisterResources(IProgress<double> progress) { await base.RegisterResources(progress).ConfigureAwait(false); @@ -410,18 +429,14 @@ namespace MediaBrowser.Server.Startup.Common UserRepository = await GetUserRepository().ConfigureAwait(false); RegisterSingleInstance(UserRepository); - var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LogManager, JsonSerializer, ApplicationPaths); + var displayPreferencesRepo = new SqliteDisplayPreferencesRepository(LogManager, JsonSerializer, ApplicationPaths, NativeApp.GetDbConnector()); DisplayPreferencesRepository = displayPreferencesRepo; RegisterSingleInstance(DisplayPreferencesRepository); - var itemRepo = new SqliteItemRepository(ServerConfigurationManager, JsonSerializer, LogManager); + var itemRepo = new SqliteItemRepository(ServerConfigurationManager, JsonSerializer, LogManager, NativeApp.GetDbConnector()); ItemRepository = itemRepo; RegisterSingleInstance(ItemRepository); - var providerRepo = new SqliteProviderInfoRepository(LogManager, ApplicationPaths); - ProviderRepository = providerRepo; - RegisterSingleInstance(ProviderRepository); - FileOrganizationRepository = await GetFileOrganizationRepository().ConfigureAwait(false); RegisterSingleInstance(FileOrganizationRepository); @@ -446,9 +461,6 @@ namespace MediaBrowser.Server.Startup.Common ProviderManager = new ProviderManager(HttpClient, ServerConfigurationManager, LibraryMonitor, LogManager, FileSystemManager, ApplicationPaths, () => LibraryManager, JsonSerializer); RegisterSingleInstance(ProviderManager); - SeriesOrderManager = new SeriesOrderManager(); - RegisterSingleInstance(SeriesOrderManager); - RegisterSingleInstance<ISearchEngine>(() => new SearchEngine(LogManager, LibraryManager, UserManager)); HttpServer = ServerFactory.CreateServer(this, LogManager, ServerConfigurationManager, NetworkManager, "Emby", "web/index.html"); @@ -543,8 +555,8 @@ namespace MediaBrowser.Server.Startup.Common RegisterSingleInstance(NativeApp.GetPowerManagement()); - var sharingRepo = new SharingRepository(LogManager, ApplicationPaths); - await sharingRepo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false); + var sharingRepo = new SharingRepository(LogManager, ApplicationPaths, NativeApp.GetDbConnector()); + await sharingRepo.Initialize().ConfigureAwait(false); RegisterSingleInstance<ISharingManager>(new SharingManager(sharingRepo, ServerConfigurationManager, LibraryManager, this)); RegisterSingleInstance<ISsdpHandler>(new SsdpHandler(LogManager.GetLogger("SsdpHandler"), ServerConfigurationManager, this)); @@ -560,11 +572,13 @@ namespace MediaBrowser.Server.Startup.Common SubtitleEncoder = new SubtitleEncoder(LibraryManager, LogManager.GetLogger("SubtitleEncoder"), ApplicationPaths, FileSystemManager, MediaEncoder, JsonSerializer, HttpClient, MediaSourceManager); RegisterSingleInstance(SubtitleEncoder); - - await displayPreferencesRepo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false); - await ConfigureUserDataRepositories().ConfigureAwait(false); - await itemRepo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false); - await providerRepo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false); + + await displayPreferencesRepo.Initialize().ConfigureAwait(false); + + var userDataRepo = new SqliteUserDataRepository(LogManager, ApplicationPaths, NativeApp.GetDbConnector()); + + ((UserDataManager)UserDataManager).Repository = userDataRepo; + await itemRepo.Initialize(userDataRepo).ConfigureAwait(false); ((LibraryManager)LibraryManager).ItemRepository = ItemRepository; await ConfigureNotificationsRepository().ConfigureAwait(false); progress.Report(100); @@ -623,14 +637,21 @@ namespace MediaBrowser.Server.Startup.Common /// <returns>Task.</returns> private async Task RegisterMediaEncoder(IProgress<double> progress) { - var info = await new FFMpegLoader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager, NativeApp.Environment, NativeApp.GetType().Assembly, NativeApp.GetFfmpegInstallInfo()) + string encoderPath = null; + string probePath = null; + + var info = await new FFMpegLoader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager, NativeApp.Environment, NativeApp.GetFfmpegInstallInfo()) .GetFFMpegInfo(NativeApp.Environment, _startupOptions, progress).ConfigureAwait(false); + encoderPath = info.EncoderPath; + probePath = info.ProbePath; + var hasExternalEncoder = string.Equals(info.Version, "external", StringComparison.OrdinalIgnoreCase); + var mediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), JsonSerializer, - info.EncoderPath, - info.ProbePath, - info.Version, + encoderPath, + probePath, + hasExternalEncoder, ServerConfigurationManager, FileSystemManager, LiveTvManager, @@ -643,14 +664,6 @@ namespace MediaBrowser.Server.Startup.Common MediaEncoder = mediaEncoder; RegisterSingleInstance(MediaEncoder); - - Task.Run(() => - { - var result = new FFmpegValidator(Logger, ApplicationPaths, FileSystemManager).Validate(info); - - mediaEncoder.SetAvailableDecoders(result.Item1); - mediaEncoder.SetAvailableEncoders(result.Item2); - }); } /// <summary> @@ -661,9 +674,9 @@ namespace MediaBrowser.Server.Startup.Common { try { - var repo = new SqliteUserRepository(LogManager, ApplicationPaths, JsonSerializer); + var repo = new SqliteUserRepository(LogManager, ApplicationPaths, JsonSerializer, NativeApp.GetDbConnector()); - await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false); + await repo.Initialize().ConfigureAwait(false); return repo; } @@ -680,36 +693,36 @@ namespace MediaBrowser.Server.Startup.Common /// <returns>Task{IUserRepository}.</returns> private async Task<IFileOrganizationRepository> GetFileOrganizationRepository() { - var repo = new SqliteFileOrganizationRepository(LogManager, ServerConfigurationManager.ApplicationPaths); + var repo = new SqliteFileOrganizationRepository(LogManager, ServerConfigurationManager.ApplicationPaths, NativeApp.GetDbConnector()); - await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false); + await repo.Initialize().ConfigureAwait(false); return repo; } private async Task<IAuthenticationRepository> GetAuthenticationRepository() { - var repo = new AuthenticationRepository(LogManager, ServerConfigurationManager.ApplicationPaths); + var repo = new AuthenticationRepository(LogManager, ServerConfigurationManager.ApplicationPaths, NativeApp.GetDbConnector()); - await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false); + await repo.Initialize().ConfigureAwait(false); return repo; } private async Task<IActivityRepository> GetActivityLogRepository() { - var repo = new ActivityRepository(LogManager, ServerConfigurationManager.ApplicationPaths); + var repo = new ActivityRepository(LogManager, ServerConfigurationManager.ApplicationPaths, NativeApp.GetDbConnector()); - await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false); + await repo.Initialize().ConfigureAwait(false); return repo; } private async Task<ISyncRepository> GetSyncRepository() { - var repo = new SyncRepository(LogManager, JsonSerializer, ServerConfigurationManager.ApplicationPaths); + var repo = new SyncRepository(LogManager, JsonSerializer, ServerConfigurationManager.ApplicationPaths, NativeApp.GetDbConnector()); - await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false); + await repo.Initialize().ConfigureAwait(false); return repo; } @@ -717,12 +730,11 @@ namespace MediaBrowser.Server.Startup.Common /// <summary> /// Configures the repositories. /// </summary> - /// <returns>Task.</returns> private async Task ConfigureNotificationsRepository() { - var repo = new SqliteNotificationsRepository(LogManager, ApplicationPaths); + var repo = new SqliteNotificationsRepository(LogManager, ApplicationPaths, NativeApp.GetDbConnector()); - await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false); + await repo.Initialize().ConfigureAwait(false); NotificationsRepository = repo; @@ -730,19 +742,6 @@ namespace MediaBrowser.Server.Startup.Common } /// <summary> - /// Configures the user data repositories. - /// </summary> - /// <returns>Task.</returns> - private async Task ConfigureUserDataRepositories() - { - var repo = new SqliteUserDataRepository(LogManager, ApplicationPaths); - - await repo.Initialize(NativeApp.GetDbConnector()).ConfigureAwait(false); - - ((UserDataManager)UserDataManager).Repository = repo; - } - - /// <summary> /// Dirty hacks /// </summary> private void SetStaticProperties() @@ -797,15 +796,11 @@ namespace MediaBrowser.Server.Startup.Common ProviderManager.AddParts(GetExports<IImageProvider>(), GetExports<IMetadataService>(), - GetExports<IItemIdentityProvider>(), - GetExports<IItemIdentityConverter>(), GetExports<IMetadataProvider>(), GetExports<IMetadataSaver>(), GetExports<IImageSaver>(), GetExports<IExternalId>()); - SeriesOrderManager.AddParts(GetExports<ISeriesOrderProvider>()); - ImageProcessor.AddParts(GetExports<IImageEnhancer>()); LiveTvManager.AddParts(GetExports<ILiveTvService>(), GetExports<ITunerHost>(), GetExports<IListingsProvider>()); @@ -825,19 +820,57 @@ namespace MediaBrowser.Server.Startup.Common private string CertificatePath { get; set; } + private string NormalizeConfiguredLocalAddress(string address) + { + var index = address.Trim('/').IndexOf('/'); + + if (index != -1) + { + address = address.Substring(index + 1); + } + + return address.Trim('/'); + } private IEnumerable<string> GetUrlPrefixes() { - var prefixes = new List<string> - { - "http://+:" + ServerConfigurationManager.Configuration.HttpServerPortNumber + "/" - }; + var hosts = ServerConfigurationManager + .Configuration + .LocalNetworkAddresses + .Select(NormalizeConfiguredLocalAddress) + .ToList(); - if (!string.IsNullOrWhiteSpace(CertificatePath)) + if (hosts.Count == 0) { - prefixes.Add("https://+:" + ServerConfigurationManager.Configuration.HttpsPortNumber + "/"); + hosts.Add("+"); } - return prefixes; + if (!hosts.Contains("+", StringComparer.OrdinalIgnoreCase)) + { + if (!hosts.Contains("localhost", StringComparer.OrdinalIgnoreCase)) + { + hosts.Add("localhost"); + } + + if (!hosts.Contains("127.0.0.1", StringComparer.OrdinalIgnoreCase)) + { + hosts.Add("127.0.0.1"); + } + } + + return hosts.SelectMany(i => + { + var prefixes = new List<string> + { + "http://"+i+":" + ServerConfigurationManager.Configuration.HttpServerPortNumber + "/" + }; + + if (!string.IsNullOrWhiteSpace(CertificatePath)) + { + prefixes.Add("https://" + i + ":" + ServerConfigurationManager.Configuration.HttpsPortNumber + "/"); + } + + return prefixes; + }); } /// <summary> @@ -1056,8 +1089,10 @@ namespace MediaBrowser.Server.Startup.Common /// Gets the system status. /// </summary> /// <returns>SystemInfo.</returns> - public virtual SystemInfo GetSystemInfo() + public async Task<SystemInfo> GetSystemInfo() { + var localAddress = await GetLocalApiUrl().ConfigureAwait(false); + return new SystemInfo { HasPendingRestart = HasPendingRestart, @@ -1088,8 +1123,10 @@ namespace MediaBrowser.Server.Startup.Common IsRunningAsService = IsRunningAsService, SupportsRunningAsService = SupportsRunningAsService, ServerName = FriendlyName, - LocalAddress = LocalApiUrl, - SupportsLibraryMonitor = SupportsLibraryMonitor + LocalAddress = localAddress, + SupportsLibraryMonitor = SupportsLibraryMonitor, + EncoderLocationType = MediaEncoder.EncoderLocationType, + SystemArchitecture = NativeApp.Environment.SystemArchitecture }; } @@ -1106,29 +1143,26 @@ namespace MediaBrowser.Server.Startup.Common get { return !string.IsNullOrWhiteSpace(HttpServer.CertificatePath); } } - public string LocalApiUrl + public async Task<string> GetLocalApiUrl() { - get + try { - try - { - // Return the first matched address, if found, or the first known local address - var address = LocalIpAddresses.FirstOrDefault(i => !IPAddress.IsLoopback(i)); + // Return the first matched address, if found, or the first known local address + var address = (await GetLocalIpAddresses().ConfigureAwait(false)).FirstOrDefault(i => !IPAddress.IsLoopback(i)); - if (address != null) - { - return GetLocalApiUrl(address); - } - - return null; - } - catch (Exception ex) + if (address != null) { - Logger.ErrorException("Error getting local Ip address information", ex); + return GetLocalApiUrl(address); } return null; } + catch (Exception ex) + { + Logger.ErrorException("Error getting local Ip address information", ex); + } + + return null; } public string GetLocalApiUrl(IPAddress ipAddress) @@ -1148,16 +1182,13 @@ namespace MediaBrowser.Server.Startup.Common HttpPort.ToString(CultureInfo.InvariantCulture)); } - public List<IPAddress> LocalIpAddresses + public async Task<List<IPAddress>> GetLocalIpAddresses() { - get - { - var localAddresses = NetworkManager.GetLocalIpAddresses() - .Where(IsIpAddressValid) - .ToList(); + var localAddresses = NetworkManager.GetLocalIpAddresses() + .Where(IsIpAddressValid) + .ToList(); - return localAddresses; - } + return localAddresses; } private readonly ConcurrentDictionary<string, bool> _validAddressResults = new ConcurrentDictionary<string, bool>(StringComparer.OrdinalIgnoreCase); @@ -1343,7 +1374,6 @@ namespace MediaBrowser.Server.Startup.Common /// <param name="package">The package that contains the update</param> /// <param name="cancellationToken">The cancellation token.</param> /// <param name="progress">The progress.</param> - /// <returns>Task.</returns> public override async Task UpdateApplication(PackageVersionInfo package, CancellationToken cancellationToken, IProgress<double> progress) { await InstallationManager.InstallPackage(package, false, progress, cancellationToken).ConfigureAwait(false); diff --git a/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegInstallInfo.cs b/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegInstallInfo.cs index 1ce1b55c24..a2a44f805c 100644 --- a/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegInstallInfo.cs +++ b/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegInstallInfo.cs @@ -8,7 +8,6 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg public string FFProbeFilename { get; set; } public string ArchiveType { get; set; } public string[] DownloadUrls { get; set; } - public bool IsEmbedded { get; set; } public FFMpegInstallInfo() { diff --git a/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegLoader.cs b/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegLoader.cs index ee284fdc56..4c5759b567 100644 --- a/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegLoader.cs +++ b/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegLoader.cs @@ -24,7 +24,6 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg private readonly IZipClient _zipClient; private readonly IFileSystem _fileSystem; private readonly NativeEnvironment _environment; - private readonly Assembly _ownerAssembly; private readonly FFMpegInstallInfo _ffmpegInstallInfo; private readonly string[] _fontUrls = @@ -32,7 +31,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg "https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/ARIALUNI.7z" }; - public FFMpegLoader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IZipClient zipClient, IFileSystem fileSystem, NativeEnvironment environment, Assembly ownerAssembly, FFMpegInstallInfo ffmpegInstallInfo) + public FFMpegLoader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IZipClient zipClient, IFileSystem fileSystem, NativeEnvironment environment, FFMpegInstallInfo ffmpegInstallInfo) { _logger = logger; _appPaths = appPaths; @@ -40,7 +39,6 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg _zipClient = zipClient; _fileSystem = fileSystem; _environment = environment; - _ownerAssembly = ownerAssembly; _ffmpegInstallInfo = ffmpegInstallInfo; } @@ -55,7 +53,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg { ProbePath = customffProbePath, EncoderPath = customffMpegPath, - Version = "custom" + Version = "external" }; } @@ -73,6 +71,11 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg }; } + if (string.Equals(version, "0", StringComparison.OrdinalIgnoreCase)) + { + return new FFMpegInfo(); + } + var rootEncoderPath = Path.Combine(_appPaths.ProgramDataPath, "ffmpeg"); var versionedDirectoryPath = Path.Combine(rootEncoderPath, version); @@ -95,18 +98,16 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg // No older version. Need to download and block until complete if (existingVersion == null) { - await DownloadFFMpeg(downloadInfo, versionedDirectoryPath, progress).ConfigureAwait(false); + var success = await DownloadFFMpeg(downloadInfo, versionedDirectoryPath, progress).ConfigureAwait(false); + if (!success) + { + return new FFMpegInfo(); + } } else { - // Older version found. - // Start with that. Download new version in the background. - var newPath = versionedDirectoryPath; - Task.Run(() => DownloadFFMpegInBackground(downloadInfo, newPath)); - info = existingVersion; versionedDirectoryPath = Path.GetDirectoryName(info.EncoderPath); - excludeFromDeletions.Add(versionedDirectoryPath); } } @@ -183,36 +184,8 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg return null; } - private async void DownloadFFMpegInBackground(FFMpegInstallInfo downloadinfo, string directory) - { - try - { - await DownloadFFMpeg(downloadinfo, directory, new Progress<double>()).ConfigureAwait(false); - } - catch (Exception ex) - { - _logger.ErrorException("Error downloading ffmpeg", ex); - } - } - - private async Task DownloadFFMpeg(FFMpegInstallInfo downloadinfo, string directory, IProgress<double> progress) + private async Task<bool> DownloadFFMpeg(FFMpegInstallInfo downloadinfo, string directory, IProgress<double> progress) { - if (downloadinfo.IsEmbedded) - { - var tempFile = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid().ToString()); - _fileSystem.CreateDirectory(Path.GetDirectoryName(tempFile)); - - using (var stream = _ownerAssembly.GetManifestResourceStream(downloadinfo.DownloadUrls[0])) - { - using (var fs = _fileSystem.GetFileStream(tempFile, FileMode.Create, FileAccess.Write, FileShare.Read, true)) - { - await stream.CopyToAsync(fs).ConfigureAwait(false); - } - } - ExtractFFMpeg(downloadinfo, tempFile, directory); - return; - } - foreach (var url in downloadinfo.DownloadUrls) { progress.Report(0); @@ -228,20 +201,14 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg }).ConfigureAwait(false); ExtractFFMpeg(downloadinfo, tempFile, directory); - return; + return true; } catch (Exception ex) { _logger.ErrorException("Error downloading {0}", ex, url); } } - - if (downloadinfo.DownloadUrls.Length == 0) - { - throw new ApplicationException("ffmpeg unvailable. Please install it and start the server with two command line arguments: -ffmpeg \"{PATH}\" and -ffprobe \"{PATH}\""); - } - - throw new ApplicationException("Unable to download required components. Please try again later."); + return false; } private void ExtractFFMpeg(FFMpegInstallInfo downloadinfo, string tempFile, string targetFolder) diff --git a/MediaBrowser.Server.Startup.Common/FFMpeg/FFmpegValidator.cs b/MediaBrowser.Server.Startup.Common/FFMpeg/FFmpegValidator.cs deleted file mode 100644 index 0ae021407b..0000000000 --- a/MediaBrowser.Server.Startup.Common/FFMpeg/FFmpegValidator.cs +++ /dev/null @@ -1,164 +0,0 @@ -using MediaBrowser.Common.Configuration; -using MediaBrowser.Model.Logging; -using System; -using System.Diagnostics; -using System.IO; -using System.Collections.Generic; -using CommonIO; - -namespace MediaBrowser.Server.Startup.Common.FFMpeg -{ - public class FFmpegValidator - { - private readonly ILogger _logger; - private readonly IApplicationPaths _appPaths; - private readonly IFileSystem _fileSystem; - - public FFmpegValidator(ILogger logger, IApplicationPaths appPaths, IFileSystem fileSystem) - { - _logger = logger; - _appPaths = appPaths; - _fileSystem = fileSystem; - } - - public Tuple<List<string>,List<string>> Validate(FFMpegInfo info) - { - _logger.Info("FFMpeg: {0}", info.EncoderPath); - _logger.Info("FFProbe: {0}", info.ProbePath); - - var decoders = GetDecoders(info.EncoderPath); - var encoders = GetEncoders(info.EncoderPath); - - return new Tuple<List<string>, List<string>>(decoders, encoders); - } - - private List<string> GetDecoders(string ffmpegPath) - { - string output = string.Empty; - try - { - output = GetFFMpegOutput(ffmpegPath, "-decoders"); - } - catch - { - } - //_logger.Debug("ffmpeg decoder query result: {0}", output ?? string.Empty); - - var found = new List<string>(); - var required = new[] - { - "h264_qsv", - "mpeg2_qsv", - "vc1_qsv" - }; - - foreach (var codec in required) - { - var srch = " " + codec + " "; - - if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) == -1) - { - _logger.Warn("ffmpeg is missing decoder " + codec); - } - else - { - found.Add(codec); - } - } - - return found; - } - - private List<string> GetEncoders(string ffmpegPath) - { - string output = null; - try - { - output = GetFFMpegOutput(ffmpegPath, "-encoders"); - } - catch - { - } - //_logger.Debug("ffmpeg encoder query result: {0}", output ?? string.Empty); - - var found = new List<string>(); - var required = new[] - { - "libx264", - "libx265", - "mpeg4", - "msmpeg4", - //"libvpx", - //"libvpx-vp9", - "aac", - "libmp3lame", - "libopus", - //"libvorbis", - "srt" - }; - - foreach (var codec in required) - { - var srch = " " + codec + " "; - - if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) == -1) - { - _logger.Warn("ffmpeg is missing encoder " + codec); - } - else - { - found.Add(codec); - } - } - - return found; - } - - private string GetFFMpegOutput(string path, string arguments) - { - var process = new Process - { - StartInfo = new ProcessStartInfo - { - CreateNoWindow = true, - UseShellExecute = false, - FileName = path, - Arguments = arguments, - WindowStyle = ProcessWindowStyle.Hidden, - ErrorDialog = false, - RedirectStandardOutput = true, - RedirectStandardError = true - } - }; - - using (process) - { - process.Start(); - - try - { - process.BeginErrorReadLine(); - - using (var reader = new StreamReader(process.StandardOutput.BaseStream)) - { - return reader.ReadToEnd(); - } - } - catch - { - // Hate having to do this - try - { - process.Kill(); - } - catch (Exception ex1) - { - _logger.ErrorException("Error killing ffmpeg", ex1); - } - - throw; - } - } - } - } -} diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj index 19ce9ed9e3..808d25fc9c 100644 --- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj +++ b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj @@ -68,14 +68,15 @@ <Compile Include="FFMpeg\FFMpegLoader.cs" /> <Compile Include="FFMpeg\FFMpegInstallInfo.cs" /> <Compile Include="FFMpeg\FFMpegInfo.cs" /> - <Compile Include="FFMpeg\FFmpegValidator.cs" /> <Compile Include="INativeApp.cs" /> <Compile Include="MbLinkShortcutHandler.cs" /> + <Compile Include="Migrations\CollectionGroupingMigration.cs" /> + <Compile Include="Migrations\CollectionsViewMigration.cs" /> + <Compile Include="Migrations\FolderViewSettingMigration.cs" /> <Compile Include="Migrations\IVersionMigration.cs" /> <Compile Include="Migrations\DbMigration.cs" /> <Compile Include="Migrations\MovieDbEpisodeProviderMigration.cs" /> <Compile Include="Migrations\OmdbEpisodeProviderMigration.cs" /> - <Compile Include="Migrations\RenameXmlOptions.cs" /> <Compile Include="NativeEnvironment.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="StartupOptions.cs" /> diff --git a/MediaBrowser.Server.Startup.Common/Migrations/CollectionGroupingMigration.cs b/MediaBrowser.Server.Startup.Common/Migrations/CollectionGroupingMigration.cs new file mode 100644 index 0000000000..b497eeb424 --- /dev/null +++ b/MediaBrowser.Server.Startup.Common/Migrations/CollectionGroupingMigration.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Library; + +namespace MediaBrowser.Server.Startup.Common.Migrations +{ + public class CollectionGroupingMigration : IVersionMigration + { + private readonly IServerConfigurationManager _config; + private readonly IUserManager _userManager; + + public CollectionGroupingMigration(IServerConfigurationManager config, IUserManager userManager) + { + _config = config; + _userManager = userManager; + } + + public void Run() + { + var migrationKey = this.GetType().Name; + var migrationKeyList = _config.Configuration.Migrations.ToList(); + + if (!migrationKeyList.Contains(migrationKey)) + { + if (_config.Configuration.IsStartupWizardCompleted) + { + if (_userManager.Users.Any(i => i.Configuration.GroupMoviesIntoBoxSets)) + { + _config.Configuration.EnableGroupingIntoCollections = true; + } + } + + migrationKeyList.Add(migrationKey); + _config.Configuration.Migrations = migrationKeyList.ToArray(); + _config.SaveConfiguration(); + } + + } + } +} diff --git a/MediaBrowser.Server.Startup.Common/Migrations/CollectionsViewMigration.cs b/MediaBrowser.Server.Startup.Common/Migrations/CollectionsViewMigration.cs new file mode 100644 index 0000000000..c6186ce081 --- /dev/null +++ b/MediaBrowser.Server.Startup.Common/Migrations/CollectionsViewMigration.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Library; + +namespace MediaBrowser.Server.Startup.Common.Migrations +{ + public class CollectionsViewMigration : IVersionMigration + { + private readonly IServerConfigurationManager _config; + private readonly IUserManager _userManager; + + public CollectionsViewMigration(IServerConfigurationManager config, IUserManager userManager) + { + _config = config; + _userManager = userManager; + } + + public void Run() + { + var migrationKey = this.GetType().Name; + var migrationKeyList = _config.Configuration.Migrations.ToList(); + + if (!migrationKeyList.Contains(migrationKey)) + { + if (_config.Configuration.IsStartupWizardCompleted) + { + if (_userManager.Users.Any(i => i.Configuration.DisplayCollectionsView)) + { + _config.Configuration.DisplayCollectionsView = true; + } + } + + migrationKeyList.Add(migrationKey); + _config.Configuration.Migrations = migrationKeyList.ToArray(); + _config.SaveConfiguration(); + } + + } + } +} diff --git a/MediaBrowser.Server.Startup.Common/Migrations/DbMigration.cs b/MediaBrowser.Server.Startup.Common/Migrations/DbMigration.cs index 65517c09c2..f0cb9e84ee 100644 --- a/MediaBrowser.Server.Startup.Common/Migrations/DbMigration.cs +++ b/MediaBrowser.Server.Startup.Common/Migrations/DbMigration.cs @@ -18,6 +18,7 @@ namespace MediaBrowser.Server.Startup.Common.Migrations public void Run() { + // If a forced migration is required, do that now if (_config.Configuration.MigrationVersion < CleanDatabaseScheduledTask.MigrationVersion) { if (!_config.Configuration.IsStartupWizardCompleted) @@ -36,6 +37,25 @@ namespace MediaBrowser.Server.Startup.Common.Migrations _taskManager.Execute<CleanDatabaseScheduledTask>(); }); + + return; + } + + if (_config.Configuration.SchemaVersion < SqliteItemRepository.LatestSchemaVersion) + { + if (!_config.Configuration.IsStartupWizardCompleted) + { + _config.Configuration.SchemaVersion = SqliteItemRepository.LatestSchemaVersion; + _config.SaveConfiguration(); + return; + } + + Task.Run(async () => + { + await Task.Delay(1000).ConfigureAwait(false); + + _taskManager.Execute<CleanDatabaseScheduledTask>(); + }); } } } diff --git a/MediaBrowser.Server.Startup.Common/Migrations/FolderViewSettingMigration.cs b/MediaBrowser.Server.Startup.Common/Migrations/FolderViewSettingMigration.cs new file mode 100644 index 0000000000..12054864b3 --- /dev/null +++ b/MediaBrowser.Server.Startup.Common/Migrations/FolderViewSettingMigration.cs @@ -0,0 +1,40 @@ +using System.Linq; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Library; + +namespace MediaBrowser.Server.Startup.Common.Migrations +{ + public class FolderViewSettingMigration : IVersionMigration + { + private readonly IServerConfigurationManager _config; + private readonly IUserManager _userManager; + + public FolderViewSettingMigration(IServerConfigurationManager config, IUserManager userManager) + { + _config = config; + _userManager = userManager; + } + + public void Run() + { + var migrationKey = this.GetType().Name; + var migrationKeyList = _config.Configuration.Migrations.ToList(); + + if (!migrationKeyList.Contains(migrationKey)) + { + if (_config.Configuration.IsStartupWizardCompleted) + { + if (_userManager.Users.Any(i => i.Configuration.DisplayFoldersView)) + { + _config.Configuration.EnableFolderView = true; + } + } + + migrationKeyList.Add(migrationKey); + _config.Configuration.Migrations = migrationKeyList.ToArray(); + _config.SaveConfiguration(); + } + + } + } +} diff --git a/MediaBrowser.Server.Startup.Common/Migrations/RenameXmlOptions.cs b/MediaBrowser.Server.Startup.Common/Migrations/RenameXmlOptions.cs deleted file mode 100644 index 49114b96f3..0000000000 --- a/MediaBrowser.Server.Startup.Common/Migrations/RenameXmlOptions.cs +++ /dev/null @@ -1,61 +0,0 @@ -using MediaBrowser.Controller.Configuration; -using System; - -namespace MediaBrowser.Server.Startup.Common.Migrations -{ - public class RenameXmlOptions : IVersionMigration - { - private readonly IServerConfigurationManager _config; - - public RenameXmlOptions(IServerConfigurationManager config) - { - _config = config; - } - - public void Run() - { - var changed = false; - - foreach (var option in _config.Configuration.MetadataOptions) - { - if (Migrate(option.DisabledMetadataSavers)) - { - changed = true; - } - if (Migrate(option.LocalMetadataReaderOrder)) - { - changed = true; - } - } - - if (changed) - { - _config.SaveConfiguration(); - } - } - - private bool Migrate(string[] options) - { - var changed = false; - - if (options != null) - { - for (var i = 0; i < options.Length; i++) - { - if (string.Equals(options[i], "Media Browser Legacy Xml", StringComparison.OrdinalIgnoreCase)) - { - options[i] = "Emby Xml"; - changed = true; - } - else if (string.Equals(options[i], "Media Browser Xml", StringComparison.OrdinalIgnoreCase)) - { - options[i] = "Emby Xml"; - changed = true; - } - } - } - - return changed; - } - } -} diff --git a/MediaBrowser.Server.Startup.Common/NativeEnvironment.cs b/MediaBrowser.Server.Startup.Common/NativeEnvironment.cs index 5b45afe731..b30509982e 100644 --- a/MediaBrowser.Server.Startup.Common/NativeEnvironment.cs +++ b/MediaBrowser.Server.Startup.Common/NativeEnvironment.cs @@ -1,4 +1,5 @@ - +using MediaBrowser.Model.System; + namespace MediaBrowser.Server.Startup.Common { public class NativeEnvironment @@ -15,11 +16,4 @@ namespace MediaBrowser.Server.Startup.Common Bsd = 2, Linux = 3 } - - public enum Architecture - { - X86 = 0, - X86_X64 = 1, - Arm = 2 - } } |
