diff options
| author | Michalis Adamidis <gsnerf@gsnerf.de> | 2014-09-14 18:00:44 +0200 |
|---|---|---|
| committer | Michalis Adamidis <gsnerf@gsnerf.de> | 2014-09-14 18:00:44 +0200 |
| commit | 411a0531e0a71b2d458b5b3a8a9951ca763ca09a (patch) | |
| tree | 871614a2cab9da0aa95d1d1f9f350d80fcf56271 /MediaBrowser.ServerApplication | |
| parent | 4f3ea6c6c3cdde7f4b8d21dc97c711635d73b4e0 (diff) | |
| parent | 6a177d21478774b3ea1a5adc606935bb3aff65bf (diff) | |
Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
Diffstat (limited to 'MediaBrowser.ServerApplication')
5 files changed, 98 insertions, 14 deletions
diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index b5db94776..25d410bfc 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -219,6 +219,8 @@ namespace MediaBrowser.ServerApplication private ISyncRepository SyncRepository { get; set; } private ITVSeriesManager TVSeriesManager { get; set; } + private StartupOptions _startupOptions; + /// <summary> /// Initializes a new instance of the <see cref="ApplicationHost" /> class. /// </summary> @@ -226,9 +228,15 @@ namespace MediaBrowser.ServerApplication /// <param name="logManager">The log manager.</param> /// <param name="supportsRunningAsService">if set to <c>true</c> [supports running as service].</param> /// <param name="isRunningAsService">if set to <c>true</c> [is running as service].</param> - public ApplicationHost(ServerApplicationPaths applicationPaths, ILogManager logManager, bool supportsRunningAsService, bool isRunningAsService) + /// <param name="options">The options.</param> + public ApplicationHost(ServerApplicationPaths applicationPaths, + ILogManager logManager, + bool supportsRunningAsService, + bool isRunningAsService, + StartupOptions options) : base(applicationPaths, logManager) { + _startupOptions = options; _isRunningAsService = isRunningAsService; SupportsRunningAsService = supportsRunningAsService; } @@ -447,7 +455,7 @@ namespace MediaBrowser.ServerApplication var encryptionManager = new EncryptionManager(); RegisterSingleInstance<IEncryptionManager>(encryptionManager); - ConnectManager = new ConnectManager(LogManager.GetLogger("Connect"), ApplicationPaths, JsonSerializer, encryptionManager, HttpClient, this, ServerConfigurationManager); + ConnectManager = new ConnectManager(LogManager.GetLogger("Connect"), ApplicationPaths, JsonSerializer, encryptionManager, HttpClient, this, ServerConfigurationManager, UserManager); RegisterSingleInstance(ConnectManager); SessionManager = new SessionManager(UserDataManager, ServerConfigurationManager, Logger, UserRepository, LibraryManager, UserManager, musicManager, DtoService, ImageProcessor, ItemRepository, JsonSerializer, this, HttpClient, AuthenticationRepository); @@ -548,7 +556,7 @@ namespace MediaBrowser.ServerApplication /// <returns>Task.</returns> private async Task RegisterMediaEncoder(IProgress<double> progress) { - var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager).GetFFMpegInfo(progress).ConfigureAwait(false); + var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager).GetFFMpegInfo(_startupOptions, progress).ConfigureAwait(false); MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), JsonSerializer, info.EncoderPath, info.ProbePath, info.Version); RegisterSingleInstance(MediaEncoder); diff --git a/MediaBrowser.ServerApplication/FFMpeg/FFMpegDownloader.cs b/MediaBrowser.ServerApplication/FFMpeg/FFMpegDownloader.cs index 4f94ebd67..a026f9a49 100644 --- a/MediaBrowser.ServerApplication/FFMpeg/FFMpegDownloader.cs +++ b/MediaBrowser.ServerApplication/FFMpeg/FFMpegDownloader.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Configuration; +using System.Collections.Generic; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.IO; using MediaBrowser.Common.Net; using MediaBrowser.Model.IO; @@ -13,6 +14,7 @@ using System.Threading.Tasks; #if __MonoCS__ using Mono.Unix.Native; #endif +using MediaBrowser.ServerApplication.IO; namespace MediaBrowser.ServerApplication.FFMpeg { @@ -38,8 +40,21 @@ namespace MediaBrowser.ServerApplication.FFMpeg _fileSystem = fileSystem; } - public async Task<FFMpegInfo> GetFFMpegInfo(IProgress<double> progress) + public async Task<FFMpegInfo> GetFFMpegInfo(StartupOptions options, IProgress<double> progress) { + var customffMpegPath = options.GetOption("-ffmpeg"); + var customffProbePath = options.GetOption("-ffprobe"); + + if (!string.IsNullOrWhiteSpace(customffMpegPath) && !string.IsNullOrWhiteSpace(customffProbePath)) + { + return new FFMpegInfo + { + ProbePath = customffProbePath, + EncoderPath = customffMpegPath, + Version = "custom" + }; + } + var rootEncoderPath = Path.Combine(_appPaths.ProgramDataPath, "ffmpeg"); var versionedDirectoryPath = Path.Combine(rootEncoderPath, FFMpegDownloadInfo.Version); @@ -52,6 +67,8 @@ namespace MediaBrowser.ServerApplication.FFMpeg Directory.CreateDirectory(versionedDirectoryPath); + var excludeFromDeletions = new List<string> { versionedDirectoryPath }; + if (!File.Exists(info.ProbePath) || !File.Exists(info.EncoderPath)) { // ffmpeg not present. See if there's an older version we can start with @@ -71,14 +88,42 @@ namespace MediaBrowser.ServerApplication.FFMpeg info = existingVersion; versionedDirectoryPath = Path.GetDirectoryName(info.EncoderPath); + + excludeFromDeletions.Add(versionedDirectoryPath); } } await DownloadFonts(versionedDirectoryPath).ConfigureAwait(false); + DeleteOlderFolders(Path.GetDirectoryName(versionedDirectoryPath), excludeFromDeletions); + return info; } + private void DeleteOlderFolders(string path, IEnumerable<string> excludeFolders ) + { + var folders = Directory.GetDirectories(path) + .Where(i => !excludeFolders.Contains(i, StringComparer.OrdinalIgnoreCase)) + .ToList(); + + foreach (var folder in folders) + { + DeleteFolder(folder); + } + } + + private void DeleteFolder(string path) + { + try + { + Directory.Delete(path, true); + } + catch (Exception ex) + { + _logger.ErrorException("Error deleting {0}", ex, path); + } + } + private FFMpegInfo GetExistingVersion(FFMpegInfo info, string rootEncoderPath) { var encoderFilename = Path.GetFileName(info.EncoderPath); diff --git a/MediaBrowser.ServerApplication/IO/StartupOptions.cs b/MediaBrowser.ServerApplication/IO/StartupOptions.cs new file mode 100644 index 000000000..e74151e4c --- /dev/null +++ b/MediaBrowser.ServerApplication/IO/StartupOptions.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MediaBrowser.ServerApplication.IO +{ + public class StartupOptions + { + private readonly List<string> _options = Environment.GetCommandLineArgs().ToList(); + + public bool ContainsOption(string option) + { + return _options.Contains(option, StringComparer.OrdinalIgnoreCase); + } + + public string GetOption(string name) + { + var index = _options.IndexOf(name); + + if (index != -1) + { + return _options.ElementAtOrDefault(index + 1); + } + + return null; + } + } +} diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index 685e60c8a..33529a31a 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -2,6 +2,7 @@ using MediaBrowser.Common.Implementations.Logging; using MediaBrowser.Model.Logging; using MediaBrowser.Server.Implementations; +using MediaBrowser.ServerApplication.IO; using MediaBrowser.ServerApplication.Native; using MediaBrowser.ServerApplication.Splash; using MediaBrowser.ServerApplication.Updates; @@ -32,8 +33,8 @@ namespace MediaBrowser.ServerApplication /// </summary> public static void Main() { - var startFlag = Environment.GetCommandLineArgs().ElementAtOrDefault(1); - _isRunningAsService = string.Equals(startFlag, "-service", StringComparison.OrdinalIgnoreCase); + var options = new StartupOptions(); + _isRunningAsService = options.ContainsOption("-service"); var applicationPath = Process.GetCurrentProcess().MainModule.FileName; @@ -48,7 +49,7 @@ namespace MediaBrowser.ServerApplication BeginLog(logger, appPaths); // Install directly - if (string.Equals(startFlag, "-installservice", StringComparison.OrdinalIgnoreCase)) + if (options.ContainsOption("-installservice")) { logger.Info("Performing service installation"); InstallService(applicationPath, logger); @@ -56,7 +57,7 @@ namespace MediaBrowser.ServerApplication } // Restart with admin rights, then install - if (string.Equals(startFlag, "-installserviceasadmin", StringComparison.OrdinalIgnoreCase)) + if (options.ContainsOption("-installserviceasadmin")) { logger.Info("Performing service installation"); RunServiceInstallation(applicationPath); @@ -64,7 +65,7 @@ namespace MediaBrowser.ServerApplication } // Uninstall directly - if (string.Equals(startFlag, "-uninstallservice", StringComparison.OrdinalIgnoreCase)) + if (options.ContainsOption("-uninstallservice")) { logger.Info("Performing service uninstallation"); UninstallService(applicationPath, logger); @@ -72,7 +73,7 @@ namespace MediaBrowser.ServerApplication } // Restart with admin rights, then uninstall - if (string.Equals(startFlag, "-uninstallserviceasadmin", StringComparison.OrdinalIgnoreCase)) + if (options.ContainsOption("-uninstallserviceasadmin")) { logger.Info("Performing service uninstallation"); RunServiceUninstallation(applicationPath); @@ -99,7 +100,7 @@ namespace MediaBrowser.ServerApplication try { - RunApplication(appPaths, logManager, _isRunningAsService); + RunApplication(appPaths, logManager, _isRunningAsService, options); } finally { @@ -205,9 +206,10 @@ namespace MediaBrowser.ServerApplication /// <param name="appPaths">The app paths.</param> /// <param name="logManager">The log manager.</param> /// <param name="runService">if set to <c>true</c> [run service].</param> - private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService) + /// <param name="options">The options.</param> + private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService, StartupOptions options) { - _appHost = new ApplicationHost(appPaths, logManager, true, runService); + _appHost = new ApplicationHost(appPaths, logManager, true, runService, options); var initProgress = new Progress<double>(); diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index 6c255f2a8..33bdea0f6 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -105,6 +105,7 @@ <Compile Include="FFMpeg\FFMpegInfo.cs" /> <Compile Include="IO\FileSystemFactory.cs" /> <Compile Include="IO\NativeFileSystem.cs" /> + <Compile Include="IO\StartupOptions.cs" /> <Compile Include="Logging\LogForm.cs"> <SubType>Form</SubType> </Compile> |
