diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index 0eb92d5a7e9..a9b43090a26 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -1,5 +1,6 @@ using MediaBrowser.Api.Playback; using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.IO; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Session; @@ -39,6 +40,7 @@ namespace MediaBrowser.Api private readonly IServerConfigurationManager _config; private readonly ISessionManager _sessionManager; + private readonly IFileSystem _fileSystem; public readonly SemaphoreSlim TranscodingStartLock = new SemaphoreSlim(1, 1); @@ -48,11 +50,12 @@ namespace MediaBrowser.Api /// The logger. /// The session manager. /// The configuration. - public ApiEntryPoint(ILogger logger, ISessionManager sessionManager, IServerConfigurationManager config) + public ApiEntryPoint(ILogger logger, ISessionManager sessionManager, IServerConfigurationManager config, IFileSystem fileSystem) { Logger = logger; _sessionManager = sessionManager; _config = config; + _fileSystem = fileSystem; Instance = this; } @@ -91,7 +94,7 @@ namespace MediaBrowser.Api foreach (var file in Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories) .ToList()) { - File.Delete(file); + _fileSystem.DeleteFile(file); } } @@ -462,7 +465,7 @@ namespace MediaBrowser.Api /// The output file path. private void DeleteProgressivePartialStreamFiles(string outputFilePath) { - File.Delete(outputFilePath); + _fileSystem.DeleteFile(outputFilePath); } /// @@ -479,13 +482,13 @@ namespace MediaBrowser.Api .ToList(); Exception e = null; - + foreach (var file in filesToDelete) { try { Logger.Info("Deleting HLS file {0}", file); - File.Delete(file); + _fileSystem.DeleteFile(file); } catch (DirectoryNotFoundException) { diff --git a/MediaBrowser.Api/ConnectService.cs b/MediaBrowser.Api/ConnectService.cs index 102e2d45ea2..a5ddcb6f1de 100644 --- a/MediaBrowser.Api/ConnectService.cs +++ b/MediaBrowser.Api/ConnectService.cs @@ -42,8 +42,8 @@ namespace MediaBrowser.Api [ApiMember(Name = "ExcludeLibraries", Description = "ExcludeLibraries", IsRequired = true, DataType = "string", ParameterType = "body", Verb = "POST")] public string ExcludedLibraries { get; set; } - [ApiMember(Name = "ExcludedChannels", Description = "ExcludedChannels", IsRequired = true, DataType = "string", ParameterType = "body", Verb = "POST")] - public string ExcludedChannels { get; set; } + [ApiMember(Name = "EnabledChannels", Description = "EnabledChannels", IsRequired = true, DataType = "string", ParameterType = "body", Verb = "POST")] + public string EnabledChannels { get; set; } [ApiMember(Name = "EnableLiveTv", Description = "EnableLiveTv", IsRequired = true, DataType = "string", ParameterType = "body", Verb = "POST")] public bool EnableLiveTv { get; set; } @@ -96,7 +96,7 @@ namespace MediaBrowser.Api .Where(i => !string.IsNullOrWhiteSpace(i)) .ToArray(); - var excludedChannels = (request.ExcludedChannels ?? string.Empty) + var enabledChannels = (request.EnabledChannels ?? string.Empty) .Split(',') .Where(i => !string.IsNullOrWhiteSpace(i)) .ToArray(); @@ -106,7 +106,7 @@ namespace MediaBrowser.Api ConnectUserName = request.ConnectUsername, SendingUserId = request.SendingUserId, ExcludedLibraries = excludeLibraries, - ExcludedChannels = excludedChannels, + EnabledChannels = enabledChannels, EnableLiveTv = request.EnableLiveTv }); } diff --git a/MediaBrowser.Api/Library/LibraryHelpers.cs b/MediaBrowser.Api/Library/LibraryHelpers.cs index e21dc4a73bb..0ee28d6fefb 100644 --- a/MediaBrowser.Api/Library/LibraryHelpers.cs +++ b/MediaBrowser.Api/Library/LibraryHelpers.cs @@ -42,7 +42,7 @@ namespace MediaBrowser.Api.Library if (!string.IsNullOrEmpty(shortcut)) { - File.Delete(shortcut); + fileSystem.DeleteFile(shortcut); } } diff --git a/MediaBrowser.Api/Library/LibraryStructureService.cs b/MediaBrowser.Api/Library/LibraryStructureService.cs index ee80d4b7349..23f4e4e5c14 100644 --- a/MediaBrowser.Api/Library/LibraryStructureService.cs +++ b/MediaBrowser.Api/Library/LibraryStructureService.cs @@ -348,7 +348,7 @@ namespace MediaBrowser.Api.Library try { - Directory.Delete(path, true); + _fileSystem.DeleteDirectory(path, true); // Need to add a delay here or directory watchers may still pick up the changes var delayTask = Task.Delay(1000); diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index 86866bdf5e6..53229f03102 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -210,10 +210,10 @@ namespace MediaBrowser.Api.Playback.Hls { return; } - + try { - File.Delete(file.FullName); + FileSystem.DeleteFile(file.FullName); } catch (IOException ex) { diff --git a/MediaBrowser.Api/Playback/Hls/MpegDashService.cs b/MediaBrowser.Api/Playback/Hls/MpegDashService.cs index 87e2eedcf5f..514597c3e12 100644 --- a/MediaBrowser.Api/Playback/Hls/MpegDashService.cs +++ b/MediaBrowser.Api/Playback/Hls/MpegDashService.cs @@ -489,7 +489,7 @@ namespace MediaBrowser.Api.Playback.Hls { try { - File.Delete(file.FullName); + FileSystem.DeleteFile(file.FullName); } catch (IOException ex) { diff --git a/MediaBrowser.Api/Session/SessionsService.cs b/MediaBrowser.Api/Session/SessionsService.cs index 59b8e85c227..e5fe69b6222 100644 --- a/MediaBrowser.Api/Session/SessionsService.cs +++ b/MediaBrowser.Api/Session/SessionsService.cs @@ -245,6 +245,11 @@ namespace MediaBrowser.Api.Session [ApiMember(Name = "SupportsUniqueIdentifier", Description = "Determines whether the device supports a unique identifier.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")] public bool SupportsUniqueIdentifier { get; set; } + + public PostCapabilities() + { + SupportsUniqueIdentifier = true; + } } [Route("/Sessions/Capabilities/Full", "POST", Summary = "Updates capabilities for a device")] diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 4443b2a2bc3..97401bbf844 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -62,6 +62,8 @@ namespace MediaBrowser.Api { _config.Configuration.IsStartupWizardCompleted = true; _config.Configuration.EnableLocalizedGuids = true; + _config.Configuration.StoreArtistsInMetadata = true; + _config.Configuration.EnableLibraryMetadataSubFolder = true; _config.SaveConfiguration(); } diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index c98a6bd6ccf..0f89bd1a6fc 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -475,7 +475,7 @@ namespace MediaBrowser.Common.Implementations SecurityManager = new PluginSecurityManager(this, HttpClient, JsonSerializer, ApplicationPaths, LogManager); RegisterSingleInstance(SecurityManager); - InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, ConfigurationManager); + InstallationManager = new InstallationManager(Logger, this, ApplicationPaths, HttpClient, JsonSerializer, SecurityManager, ConfigurationManager, FileSystemManager); RegisterSingleInstance(InstallationManager); ZipClient = new ZipClient(); diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index 1f82c5eb0c6..b925649fce8 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -690,7 +690,7 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager { try { - File.Delete(file); + _fileSystem.DeleteFile(file); } catch (IOException) { diff --git a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs index 68df0e52ac7..c54b053fdab 100644 --- a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs +++ b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs @@ -270,8 +270,8 @@ namespace MediaBrowser.Common.Implementations.IO File.Copy(temp1, file2, true); File.Copy(temp2, file1, true); - File.Delete(temp1); - File.Delete(temp2); + DeleteFile(temp1); + DeleteFile(temp2); } /// @@ -409,5 +409,25 @@ namespace MediaBrowser.Common.Implementations.IO //return Path.IsPathRooted(path); } + + public void DeleteFile(string path, bool sendToRecycleBin) + { + File.Delete(path); + } + + public void DeleteDirectory(string path, bool recursive, bool sendToRecycleBin) + { + Directory.Delete(path, recursive); + } + + public void DeleteFile(string path) + { + DeleteFile(path, false); + } + + public void DeleteDirectory(string path, bool recursive) + { + DeleteDirectory(path, recursive, false); + } } } diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs index fcb7b159b85..779f992d326 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs @@ -125,7 +125,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks { try { - File.Delete(path); + _fileSystem.DeleteFile(path); } catch (IOException ex) { diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs index 3b0c02dc6bc..6b9bcbfc1ae 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteLogFileTask.cs @@ -76,7 +76,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks cancellationToken.ThrowIfCancellationRequested(); - File.Delete(file.FullName); + _fileSystem.DeleteFile(file.FullName); index++; } diff --git a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs index 47215aacf1b..264e63b47f4 100644 --- a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs +++ b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs @@ -1,6 +1,7 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Events; using MediaBrowser.Common.Implementations.Security; +using MediaBrowser.Common.IO; using MediaBrowser.Common.Net; using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Progress; @@ -106,6 +107,7 @@ namespace MediaBrowser.Common.Implementations.Updates private readonly IJsonSerializer _jsonSerializer; private readonly ISecurityManager _securityManager; private readonly IConfigurationManager _config; + private readonly IFileSystem _fileSystem; /// /// Gets the application host. @@ -113,7 +115,7 @@ namespace MediaBrowser.Common.Implementations.Updates /// The application host. private readonly IApplicationHost _applicationHost; - public InstallationManager(ILogger logger, IApplicationHost appHost, IApplicationPaths appPaths, IHttpClient httpClient, IJsonSerializer jsonSerializer, ISecurityManager securityManager, IConfigurationManager config) + public InstallationManager(ILogger logger, IApplicationHost appHost, IApplicationPaths appPaths, IHttpClient httpClient, IJsonSerializer jsonSerializer, ISecurityManager securityManager, IConfigurationManager config, IFileSystem fileSystem) { if (logger == null) { @@ -129,6 +131,7 @@ namespace MediaBrowser.Common.Implementations.Updates _jsonSerializer = jsonSerializer; _securityManager = securityManager; _config = config; + _fileSystem = fileSystem; _logger = logger; } @@ -570,7 +573,7 @@ namespace MediaBrowser.Common.Implementations.Updates try { - File.Delete(tempFile); + _fileSystem.DeleteFile(tempFile); } catch (IOException e) { @@ -591,7 +594,7 @@ namespace MediaBrowser.Common.Implementations.Updates // Remove it the quick way for now _applicationHost.RemovePlugin(plugin); - File.Delete(plugin.AssemblyFilePath); + _fileSystem.DeleteFile(plugin.AssemblyFilePath); OnPluginUninstalled(plugin); diff --git a/MediaBrowser.Common/IO/IFileSystem.cs b/MediaBrowser.Common/IO/IFileSystem.cs index 3bcec98ce63..5ce84f43609 100644 --- a/MediaBrowser.Common/IO/IFileSystem.cs +++ b/MediaBrowser.Common/IO/IFileSystem.cs @@ -133,5 +133,33 @@ namespace MediaBrowser.Common.IO /// The path. /// true if [is path file] [the specified path]; otherwise, false. bool IsPathFile(string path); + + /// + /// Deletes the file. + /// + /// The path. + /// if set to true [send to recycle bin]. + void DeleteFile(string path, bool sendToRecycleBin); + + /// + /// Deletes the directory. + /// + /// The path. + /// if set to true [recursive]. + /// if set to true [send to recycle bin]. + void DeleteDirectory(string path, bool recursive, bool sendToRecycleBin); + + /// + /// Deletes the file. + /// + /// The path. + void DeleteFile(string path); + + /// + /// Deletes the directory. + /// + /// The path. + /// if set to true [recursive]. + void DeleteDirectory(string path, bool recursive); } } diff --git a/MediaBrowser.Controller/Channels/Channel.cs b/MediaBrowser.Controller/Channels/Channel.cs index 5a9fc332270..6ee6fe00626 100644 --- a/MediaBrowser.Controller/Channels/Channel.cs +++ b/MediaBrowser.Controller/Channels/Channel.cs @@ -14,7 +14,7 @@ namespace MediaBrowser.Controller.Channels public override bool IsVisible(User user) { - if (user.Policy.BlockedChannels.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase)) + if (!user.Policy.EnableAllChannels && !user.Policy.EnabledChannels.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase)) { return false; } diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index ee562d8b494..6a30df7fe8b 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -379,7 +379,14 @@ namespace MediaBrowser.Controller.Entities public string GetInternalMetadataPath() { - return GetInternalMetadataPath(ConfigurationManager.ApplicationPaths.InternalMetadataPath); + var basePath = ConfigurationManager.ApplicationPaths.InternalMetadataPath; + + if (ConfigurationManager.Configuration.EnableLibraryMetadataSubFolder) + { + basePath = System.IO.Path.Combine(basePath, "library"); + } + + return GetInternalMetadataPath(basePath); } protected virtual string GetInternalMetadataPath(string basePath) @@ -1458,7 +1465,7 @@ namespace MediaBrowser.Controller.Entities currentFile.Attributes &= ~FileAttributes.Hidden; } - currentFile.Delete(); + FileSystem.DeleteFile(currentFile.FullName); } return UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None); diff --git a/MediaBrowser.Controller/Entities/User.cs b/MediaBrowser.Controller/Entities/User.cs index 626afcfdfe2..869c30ba88d 100644 --- a/MediaBrowser.Controller/Entities/User.cs +++ b/MediaBrowser.Controller/Entities/User.cs @@ -177,7 +177,7 @@ namespace MediaBrowser.Controller.Entities // Exceptions will be thrown if these paths already exist if (Directory.Exists(newConfigDirectory)) { - Directory.Delete(newConfigDirectory, true); + FileSystem.DeleteDirectory(newConfigDirectory, true); } if (Directory.Exists(oldConfigurationDirectory)) diff --git a/MediaBrowser.Controller/IServerApplicationPaths.cs b/MediaBrowser.Controller/IServerApplicationPaths.cs index e3438c3d251..c07934d0b14 100644 --- a/MediaBrowser.Controller/IServerApplicationPaths.cs +++ b/MediaBrowser.Controller/IServerApplicationPaths.cs @@ -59,12 +59,6 @@ namespace MediaBrowser.Controller /// The game genre path. string GameGenrePath { get; } - /// - /// Gets the artists path. - /// - /// The artists path. - string ArtistsPath { get; } - /// /// Gets the path to the Studio directory /// diff --git a/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs b/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs index b95d67ad821..f29204689f3 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs @@ -1,8 +1,8 @@ using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; -using System.Linq; using MediaBrowser.Model.Users; +using System.Linq; namespace MediaBrowser.Controller.LiveTv { @@ -83,5 +83,10 @@ namespace MediaBrowser.Controller.LiveTv { return config.BlockUnratedItems.Contains(UnratedItem.LiveTvProgram); } + + protected override string GetInternalMetadataPath(string basePath) + { + return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N")); + } } } diff --git a/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs b/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs index de72accff82..459ead16cb0 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs @@ -145,5 +145,10 @@ namespace MediaBrowser.Controller.LiveTv return list; } + + protected override string GetInternalMetadataPath(string basePath) + { + return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N"), "metadata"); + } } } diff --git a/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs b/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs index 29b23a551e7..74cf950d429 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs @@ -204,5 +204,10 @@ namespace MediaBrowser.Controller.LiveTv { return config.BlockUnratedItems.Contains(UnratedItem.LiveTvProgram); } + + protected override string GetInternalMetadataPath(string basePath) + { + return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N")); + } } } diff --git a/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs b/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs index 6fc985643aa..91edc06c112 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs @@ -83,5 +83,10 @@ namespace MediaBrowser.Controller.LiveTv { return config.BlockUnratedItems.Contains(UnratedItem.LiveTvProgram); } + + protected override string GetInternalMetadataPath(string basePath) + { + return System.IO.Path.Combine(basePath, "livetv", Id.ToString("N")); + } } } diff --git a/MediaBrowser.Controller/MediaEncoding/MediaStreamSelector.cs b/MediaBrowser.Controller/MediaEncoding/MediaStreamSelector.cs index 4a807df7acb..b18651a68ff 100644 --- a/MediaBrowser.Controller/MediaEncoding/MediaStreamSelector.cs +++ b/MediaBrowser.Controller/MediaEncoding/MediaStreamSelector.cs @@ -38,7 +38,8 @@ namespace MediaBrowser.Controller.MediaEncoding SubtitlePlaybackMode mode, string audioTrackLanguage) { - streams = GetSortedStreams(streams, MediaStreamType.Subtitle, preferredLanguages).ToList(); + streams = GetSortedStreams(streams, MediaStreamType.Subtitle, preferredLanguages) + .ToList(); var full = streams.Where(s => !s.IsForced); @@ -81,11 +82,9 @@ namespace MediaBrowser.Controller.MediaEncoding private static IEnumerable GetSortedStreams(IEnumerable streams, MediaStreamType type, List languagePreferences) { - var orderStreams = streams - .Where(i => i.Type == type); - // Give some preferance to external text subs for better performance - return orderStreams.OrderBy(i => + return streams.Where(i => i.Type == type) + .OrderBy(i => { var index = languagePreferences.FindIndex(l => string.Equals(i.Language, l, StringComparison.OrdinalIgnoreCase)); @@ -94,8 +93,7 @@ namespace MediaBrowser.Controller.MediaEncoding .ThenBy(i => i.IsDefault) .ThenBy(i => i.IsTextSubtitleStream) .ThenBy(i => i.IsExternal) - .ThenBy(i => i.Index) - .ToList(); + .ThenBy(i => i.Index); } } } diff --git a/MediaBrowser.Controller/Session/ISessionController.cs b/MediaBrowser.Controller/Session/ISessionController.cs index d6dd7698e6f..a4badee473e 100644 --- a/MediaBrowser.Controller/Session/ISessionController.cs +++ b/MediaBrowser.Controller/Session/ISessionController.cs @@ -105,5 +105,15 @@ namespace MediaBrowser.Controller.Session /// The cancellation token. /// Task. Task SendServerRestartNotification(CancellationToken cancellationToken); + + /// + /// Sends the message. + /// + /// + /// The name. + /// The data. + /// The cancellation token. + /// Task. + Task SendMessage(string name, T data, CancellationToken cancellationToken); } } diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs index f0272b3350e..1f273a3ee09 100644 --- a/MediaBrowser.Controller/Session/ISessionManager.cs +++ b/MediaBrowser.Controller/Session/ISessionManager.cs @@ -170,6 +170,17 @@ namespace MediaBrowser.Controller.Session /// Task. Task SendPlaystateCommand(string controllingSessionId, string sessionId, PlaystateRequest command, CancellationToken cancellationToken); + /// + /// Sends the message to user sessions. + /// + /// + /// The user identifier. + /// The name. + /// The data. + /// The cancellation token. + /// Task. + Task SendMessageToUserSessions(string userId, string name, T data, CancellationToken cancellationToken); + /// /// Sends the restart required message. /// diff --git a/MediaBrowser.Controller/Session/SessionInfo.cs b/MediaBrowser.Controller/Session/SessionInfo.cs index d8a2464d64e..078d4d70ff4 100644 --- a/MediaBrowser.Controller/Session/SessionInfo.cs +++ b/MediaBrowser.Controller/Session/SessionInfo.cs @@ -160,6 +160,11 @@ namespace MediaBrowser.Controller.Session } } + public bool ContainsUser(string userId) + { + return ContainsUser(new Guid(userId)); + } + public bool ContainsUser(Guid userId) { return (UserId ?? Guid.Empty) == userId || AdditionalUsers.Any(i => userId == new Guid(i.UserId)); diff --git a/MediaBrowser.Dlna/DlnaManager.cs b/MediaBrowser.Dlna/DlnaManager.cs index 7517cea50dd..31f1e0a883d 100644 --- a/MediaBrowser.Dlna/DlnaManager.cs +++ b/MediaBrowser.Dlna/DlnaManager.cs @@ -393,7 +393,7 @@ namespace MediaBrowser.Dlna throw new ArgumentException("System profiles cannot be deleted."); } - File.Delete(info.Path); + _fileSystem.DeleteFile(info.Path); } public void CreateProfile(DeviceProfile profile) @@ -432,9 +432,9 @@ namespace MediaBrowser.Dlna if (!string.Equals(path, current.Path, StringComparison.Ordinal) && current.Info.Type != DeviceProfileType.System) { - File.Delete(current.Path); + _fileSystem.DeleteFile(current.Path); } - + _xmlSerializer.SerializeToFile(profile, path); } diff --git a/MediaBrowser.Dlna/PlayTo/PlayToController.cs b/MediaBrowser.Dlna/PlayTo/PlayToController.cs index 1989c437aa4..202121f68b3 100644 --- a/MediaBrowser.Dlna/PlayTo/PlayToController.cs +++ b/MediaBrowser.Dlna/PlayTo/PlayToController.cs @@ -899,5 +899,11 @@ namespace MediaBrowser.Dlna.PlayTo return request; } } + + public Task SendMessage(string name, T data, CancellationToken cancellationToken) + { + // Not supported or needed right now + return Task.FromResult(true); + } } } diff --git a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs index ecf5d72d5a9..4db4cd42772 100644 --- a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs @@ -248,7 +248,7 @@ namespace MediaBrowser.MediaEncoding.Encoder protected virtual void DeleteFiles(EncodingJob job) { - File.Delete(job.OutputFilePath); + FileSystem.DeleteFile(job.OutputFilePath); } private void OnTranscodeBeginning(EncodingJob job) diff --git a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs index 24b818f5a6d..10d8112ff06 100644 --- a/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs +++ b/MediaBrowser.MediaEncoding/Subtitles/SubtitleEncoder.cs @@ -459,7 +459,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles try { _logger.Info("Deleting converted subtitle due to failure: ", outputPath); - File.Delete(outputPath); + _fileSystem.DeleteFile(outputPath); } catch (IOException ex) { @@ -608,7 +608,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles try { _logger.Info("Deleting extracted subtitle due to failure: {0}", outputPath); - File.Delete(outputPath); + _fileSystem.DeleteFile(outputPath); } catch (FileNotFoundException) { diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index e30cf1789d3..c4a9c5eeaf3 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -73,6 +73,12 @@ namespace MediaBrowser.Model.Configuration /// /// true if [enable localized guids]; otherwise, false. public bool EnableLocalizedGuids { get; set; } + + /// + /// Gets or sets a value indicating whether [enable library metadata sub folder]. + /// + /// true if [enable library metadata sub folder]; otherwise, false. + public bool EnableLibraryMetadataSubFolder { get; set; } /// /// Gets or sets the preferred metadata language. @@ -150,6 +156,8 @@ namespace MediaBrowser.Model.Configuration public bool EnableTvDbUpdates { get; set; } public bool EnableTmdbUpdates { get; set; } + public bool StoreArtistsInMetadata { get; set; } + public bool EnableFanArtUpdates { get; set; } public string FanartApiKey { get; set; } diff --git a/MediaBrowser.Model/Configuration/UserConfiguration.cs b/MediaBrowser.Model/Configuration/UserConfiguration.cs index 9e33c1c36f9..aa49ee50d5a 100644 --- a/MediaBrowser.Model/Configuration/UserConfiguration.cs +++ b/MediaBrowser.Model/Configuration/UserConfiguration.cs @@ -6,12 +6,6 @@ namespace MediaBrowser.Model.Configuration /// public class UserConfiguration { - /// - /// Gets or sets the max parental rating. - /// - /// The max parental rating. - public int? MaxParentalRating { get; set; } - /// /// Gets or sets a value indicating whether this instance is administrator. /// @@ -36,22 +30,8 @@ namespace MediaBrowser.Model.Configuration /// The subtitle language preference. public string SubtitleLanguagePreference { get; set; } - /// - /// Gets or sets a value indicating whether this instance is hidden. - /// - /// true if this instance is hidden; otherwise, false. - public bool IsHidden { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is disabled. - /// - /// true if this instance is disabled; otherwise, false. - public bool IsDisabled { get; set; } - public bool DisplayMissingEpisodes { get; set; } public bool DisplayUnairedEpisodes { get; set; } - public bool EnableRemoteControlOfOtherUsers { get; set; } - public bool EnableSharedDeviceControl { get; set; } public bool EnableLiveTvManagement { get; set; } public bool EnableLiveTvAccess { get; set; } @@ -61,9 +41,6 @@ namespace MediaBrowser.Model.Configuration public bool GroupMoviesIntoBoxSets { get; set; } - public string[] BlockedMediaFolders { get; set; } - public string[] BlockedChannels { get; set; } - public string[] DisplayChannelsWithinViews { get; set; } public string[] ExcludeFoldersFromGrouping { get; set; } @@ -82,12 +59,7 @@ namespace MediaBrowser.Model.Configuration public bool EnableCinemaMode { get; set; } - public AccessSchedule[] AccessSchedules { get; set; } - - public bool EnableUserPreferenceAccess { get; set; } - public string[] LatestItemsExcludes { get; set; } - public string[] BlockedTags { get; set; } public bool HasMigratedToPolicy { get; set; } @@ -100,14 +72,10 @@ namespace MediaBrowser.Model.Configuration EnableLiveTvManagement = true; EnableMediaPlayback = true; EnableLiveTvAccess = true; - EnableSharedDeviceControl = true; LatestItemsExcludes = new string[] { }; OrderedViews = new string[] { }; - BlockedMediaFolders = new string[] { }; DisplayChannelsWithinViews = new string[] { }; - BlockedTags = new string[] { }; - BlockedChannels = new string[] { }; BlockUnratedItems = new UnratedItem[] { }; ExcludeFoldersFromGrouping = new string[] { }; @@ -115,9 +83,6 @@ namespace MediaBrowser.Model.Configuration IncludeTrailersInSuggestions = true; EnableCinemaMode = true; - EnableUserPreferenceAccess = true; - - AccessSchedules = new AccessSchedule[] { }; } } } diff --git a/MediaBrowser.Model/Connect/ConnectAuthorization.cs b/MediaBrowser.Model/Connect/ConnectAuthorization.cs index 0c545f4bac2..9e4537d65a9 100644 --- a/MediaBrowser.Model/Connect/ConnectAuthorization.cs +++ b/MediaBrowser.Model/Connect/ConnectAuthorization.cs @@ -9,12 +9,12 @@ namespace MediaBrowser.Model.Connect public string Id { get; set; } public string[] ExcludedLibraries { get; set; } public bool EnableLiveTv { get; set; } - public string[] ExcludedChannels { get; set; } + public string[] EnabledChannels { get; set; } public ConnectAuthorization() { ExcludedLibraries = new string[] { }; - ExcludedChannels = new string[] { }; + EnabledChannels = new string[] { }; } } } diff --git a/MediaBrowser.Model/Connect/ConnectAuthorizationRequest.cs b/MediaBrowser.Model/Connect/ConnectAuthorizationRequest.cs index d40d353f01d..77c574f8bd3 100644 --- a/MediaBrowser.Model/Connect/ConnectAuthorizationRequest.cs +++ b/MediaBrowser.Model/Connect/ConnectAuthorizationRequest.cs @@ -7,12 +7,12 @@ namespace MediaBrowser.Model.Connect public string ConnectUserName { get; set; } public string[] ExcludedLibraries { get; set; } public bool EnableLiveTv { get; set; } - public string[] ExcludedChannels { get; set; } + public string[] EnabledChannels { get; set; } public ConnectAuthorizationRequest() { ExcludedLibraries = new string[] { }; - ExcludedChannels = new string[] { }; + EnabledChannels = new string[] { }; } } } diff --git a/MediaBrowser.Model/Users/UserPolicy.cs b/MediaBrowser.Model/Users/UserPolicy.cs index 0a6a37696bf..12b8c40715e 100644 --- a/MediaBrowser.Model/Users/UserPolicy.cs +++ b/MediaBrowser.Model/Users/UserPolicy.cs @@ -52,6 +52,9 @@ namespace MediaBrowser.Model.Users public string[] EnabledDevices { get; set; } public bool EnableAllDevices { get; set; } + public string[] EnabledChannels { get; set; } + public bool EnableAllChannels { get; set; } + public UserPolicy() { EnableLiveTvManagement = true; @@ -61,7 +64,6 @@ namespace MediaBrowser.Model.Users BlockedMediaFolders = new string[] { }; BlockedTags = new string[] { }; - BlockedChannels = new string[] { }; BlockUnratedItems = new UnratedItem[] { }; EnableUserPreferenceAccess = true; diff --git a/MediaBrowser.Providers/Manager/ImageSaver.cs b/MediaBrowser.Providers/Manager/ImageSaver.cs index 700bca0fab3..6175587a723 100644 --- a/MediaBrowser.Providers/Manager/ImageSaver.cs +++ b/MediaBrowser.Providers/Manager/ImageSaver.cs @@ -183,7 +183,7 @@ namespace MediaBrowser.Providers.Manager currentFile.Attributes &= ~FileAttributes.Hidden; } - currentFile.Delete(); + _fileSystem.DeleteFile(currentFile.FullName); } } finally diff --git a/MediaBrowser.Providers/Manager/ItemImageProvider.cs b/MediaBrowser.Providers/Manager/ItemImageProvider.cs index 0d318c37739..66b0f925976 100644 --- a/MediaBrowser.Providers/Manager/ItemImageProvider.cs +++ b/MediaBrowser.Providers/Manager/ItemImageProvider.cs @@ -349,7 +349,7 @@ namespace MediaBrowser.Providers.Manager currentFile.Attributes &= ~FileAttributes.Hidden; } - currentFile.Delete(); + _fileSystem.DeleteFile(currentFile.FullName); deleted = true; } } diff --git a/MediaBrowser.Providers/Subtitles/SubtitleManager.cs b/MediaBrowser.Providers/Subtitles/SubtitleManager.cs index 9a16ae24d9b..187f8814bcd 100644 --- a/MediaBrowser.Providers/Subtitles/SubtitleManager.cs +++ b/MediaBrowser.Providers/Subtitles/SubtitleManager.cs @@ -245,7 +245,7 @@ namespace MediaBrowser.Providers.Subtitles try { - File.Delete(path); + _fileSystem.DeleteFile(path); } finally { diff --git a/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs b/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs index 20dc6c48597..fa49afbe974 100644 --- a/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs +++ b/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs @@ -1108,7 +1108,7 @@ namespace MediaBrowser.Providers.TV .EnumerateFiles("*.xml", SearchOption.AllDirectories) .ToList()) { - file.Delete(); + _fileSystem.DeleteFile(file.FullName); } } catch (DirectoryNotFoundException) diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelDownloadScheduledTask.cs b/MediaBrowser.Server.Implementations/Channels/ChannelDownloadScheduledTask.cs index 7179395b4da..0e0e4fbcb69 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelDownloadScheduledTask.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelDownloadScheduledTask.cs @@ -96,7 +96,7 @@ namespace MediaBrowser.Server.Implementations.Channels public static string GetUserDistinctValue(User user) { - var channels = user.Policy.BlockedChannels + var channels = user.Policy.EnabledChannels .OrderBy(i => i) .ToList(); @@ -374,7 +374,7 @@ namespace MediaBrowser.Server.Implementations.Channels { try { - File.Delete(path); + _fileSystem.DeleteFile(path); } catch (IOException ex) { diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index c12a1161ba0..1130a510c57 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -1492,7 +1492,7 @@ namespace MediaBrowser.Server.Implementations.Channels } else { - File.Delete(response.TempFilePath); + _fileSystem.DeleteFile(response.TempFilePath); throw new ApplicationException("Unexpected response type encountered: " + response.ContentType); } @@ -1501,7 +1501,7 @@ namespace MediaBrowser.Server.Implementations.Channels try { - File.Delete(response.TempFilePath); + _fileSystem.DeleteFile(response.TempFilePath); } catch { diff --git a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs index 9fee27db9bc..05efcaa1c93 100644 --- a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs +++ b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs @@ -258,7 +258,7 @@ namespace MediaBrowser.Server.Implementations.Collections { foreach (var file in shortcutFilesToDelete) { - File.Delete(file); + _fileSystem.DeleteFile(file); } foreach (var child in list) diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs index 67d84454385..b703b204ee3 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs @@ -548,7 +548,7 @@ namespace MediaBrowser.Server.Implementations.Connect ImageUrl = response.UserImageUrl, UserName = response.UserName, ExcludedLibraries = request.ExcludedLibraries, - ExcludedChannels = request.ExcludedChannels, + EnabledChannels = request.EnabledChannels, EnableLiveTv = request.EnableLiveTv, AccessToken = accessToken }); @@ -810,7 +810,8 @@ namespace MediaBrowser.Server.Implementations.Connect { user.Policy.EnableLiveTvAccess = currentPendingEntry.EnableLiveTv; user.Policy.BlockedMediaFolders = currentPendingEntry.ExcludedLibraries; - user.Policy.BlockedChannels = currentPendingEntry.ExcludedChannels; + user.Policy.EnabledChannels = currentPendingEntry.EnabledChannels; + user.Policy.EnableAllChannels = false; } await _userManager.UpdateConfiguration(user.Id.ToString("N"), user.Configuration); @@ -937,7 +938,7 @@ namespace MediaBrowser.Server.Implementations.Connect { ConnectUserId = i.ConnectUserId, EnableLiveTv = i.EnableLiveTv, - ExcludedChannels = i.ExcludedChannels, + EnabledChannels = i.EnabledChannels, ExcludedLibraries = i.ExcludedLibraries, Id = i.Id, ImageUrl = i.ImageUrl, diff --git a/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs b/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs index d587e5af739..70a04d2494b 100644 --- a/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs +++ b/MediaBrowser.Server.Implementations/Devices/DeviceRepository.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.IO; using MediaBrowser.Controller.Devices; using MediaBrowser.Model.Devices; using MediaBrowser.Model.Logging; @@ -21,14 +22,16 @@ namespace MediaBrowser.Server.Implementations.Devices private readonly IApplicationPaths _appPaths; private readonly IJsonSerializer _json; private readonly ILogger _logger; + private readonly IFileSystem _fileSystem; private ConcurrentBag _devices; - public DeviceRepository(IApplicationPaths appPaths, IJsonSerializer json, ILogger logger) + public DeviceRepository(IApplicationPaths appPaths, IJsonSerializer json, ILogger logger, IFileSystem fileSystem) { _appPaths = appPaths; _json = json; _logger = logger; + _fileSystem = fileSystem; } private string GetDevicesPath() @@ -129,12 +132,12 @@ namespace MediaBrowser.Server.Implementations.Devices { try { - Directory.Delete(path, true); + _fileSystem.DeleteDirectory(path, true); } catch (DirectoryNotFoundException) { } - + _devices = null; } diff --git a/MediaBrowser.Server.Implementations/EntryPoints/ServerEventNotifier.cs b/MediaBrowser.Server.Implementations/EntryPoints/ServerEventNotifier.cs index 1eb4a665528..bc10253058d 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/ServerEventNotifier.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/ServerEventNotifier.cs @@ -2,7 +2,6 @@ using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Common.Updates; using MediaBrowser.Controller; -using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Net; @@ -44,28 +43,15 @@ namespace MediaBrowser.Server.Implementations.EntryPoints /// private readonly ITaskManager _taskManager; - private readonly IDtoService _dtoService; - private readonly ISessionManager _sessionManager; - /// - /// Initializes a new instance of the class. - /// - /// The server manager. - /// The application host. - /// The user manager. - /// The installation manager. - /// The task manager. - /// The dto service. - /// The session manager. - public ServerEventNotifier(IServerManager serverManager, IServerApplicationHost appHost, IUserManager userManager, IInstallationManager installationManager, ITaskManager taskManager, IDtoService dtoService, ISessionManager sessionManager) + public ServerEventNotifier(IServerManager serverManager, IServerApplicationHost appHost, IUserManager userManager, IInstallationManager installationManager, ITaskManager taskManager, ISessionManager sessionManager) { _serverManager = serverManager; _userManager = userManager; _installationManager = installationManager; _appHost = appHost; _taskManager = taskManager; - _dtoService = dtoService; _sessionManager = sessionManager; } @@ -86,13 +72,6 @@ namespace MediaBrowser.Server.Implementations.EntryPoints _taskManager.TaskCompleted += _taskManager_TaskCompleted; } - void _userManager_UserConfigurationUpdated(object sender, GenericEventArgs e) - { - var dto = _userManager.GetUserDto(e.Argument); - - _serverManager.SendWebSocketMessage("UserConfigurationUpdated", dto); - } - void _installationManager_PackageInstalling(object sender, InstallationEventArgs e) { _serverManager.SendWebSocketMessage("PackageInstalling", e.InstallationInfo); @@ -146,8 +125,8 @@ namespace MediaBrowser.Server.Implementations.EntryPoints void userManager_UserUpdated(object sender, GenericEventArgs e) { var dto = _userManager.GetUserDto(e.Argument); - - _serverManager.SendWebSocketMessage("UserUpdated", dto); + + SendMessageToUserSession(e.Argument, "UserUpdated", dto); } /// @@ -157,7 +136,19 @@ namespace MediaBrowser.Server.Implementations.EntryPoints /// The e. void userManager_UserDeleted(object sender, GenericEventArgs e) { - _serverManager.SendWebSocketMessage("UserDeleted", e.Argument.Id.ToString("N")); + SendMessageToUserSession(e.Argument, "UserDeleted", e.Argument.Id.ToString("N")); + } + + void _userManager_UserConfigurationUpdated(object sender, GenericEventArgs e) + { + var dto = _userManager.GetUserDto(e.Argument); + + SendMessageToUserSession(e.Argument, "UserConfigurationUpdated", dto); + } + + private async void SendMessageToUserSession(User user, string name, T data) + { + await _sessionManager.SendMessageToUserSessions(user.Id.ToString("N"), name, data, CancellationToken.None); } /// diff --git a/MediaBrowser.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs b/MediaBrowser.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs index c31f4621508..ccd427a47e9 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs @@ -108,7 +108,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints { var userId = pair.Key; var userSessions = _sessionManager.Sessions - .Where(u => u.UserId.HasValue && u.UserId.Value == userId && u.SessionController != null && u.IsActive) + .Where(u => u.ContainsUser(userId) && u.SessionController != null && u.IsActive) .ToList(); if (userSessions.Count > 0) diff --git a/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs b/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs index 611f887eedf..cfc3e2b234e 100644 --- a/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs +++ b/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs @@ -209,7 +209,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization try { - File.Delete(path); + _fileSystem.DeleteFile(path); } catch (IOException ex) { @@ -315,7 +315,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization { try { - File.Delete(result.OriginalPath); + _fileSystem.DeleteFile(result.OriginalPath); } catch (Exception ex) { diff --git a/MediaBrowser.Server.Implementations/FileOrganization/FileOrganizationService.cs b/MediaBrowser.Server.Implementations/FileOrganization/FileOrganizationService.cs index 7c526967872..a6116ab0965 100644 --- a/MediaBrowser.Server.Implementations/FileOrganization/FileOrganizationService.cs +++ b/MediaBrowser.Server.Implementations/FileOrganization/FileOrganizationService.cs @@ -85,7 +85,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization _logger.Info("Requested to delete {0}", result.OriginalPath); try { - File.Delete(result.OriginalPath); + _fileSystem.DeleteFile(result.OriginalPath); } catch (Exception ex) { diff --git a/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs b/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs index cf120f1476e..e3c8e6d2573 100644 --- a/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs +++ b/MediaBrowser.Server.Implementations/FileOrganization/TvFolderOrganizer.cs @@ -166,7 +166,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization { try { - File.Delete(file.FullName); + _fileSystem.DeleteFile(file.FullName); } catch (Exception ex) { diff --git a/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/RequestMono.cs b/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/RequestMono.cs index 226d97b3cd7..2c8413f5e36 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/RequestMono.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/SocketSharp/RequestMono.cs @@ -556,31 +556,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp return (stream); } } - - public void SaveAs(string filename) - { - byte[] buffer = new byte[16 * 1024]; - long old_post = stream.Position; - - try - { - File.Delete(filename); - using (FileStream fs = File.Create(filename)) - { - stream.Position = 0; - int n; - - while ((n = stream.Read(buffer, 0, 16 * 1024)) != 0) - { - fs.Write(buffer, 0, n); - } - } - } - finally - { - stream.Position = old_post; - } - } } class Helpers diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 597dcd9af8d..cceccceacf7 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -401,11 +401,11 @@ namespace MediaBrowser.Server.Implementations.Library try { - Directory.Delete(metadataPath, true); + _fileSystem.DeleteDirectory(metadataPath, true); } catch (DirectoryNotFoundException) { - + } catch (Exception ex) { @@ -420,12 +420,12 @@ namespace MediaBrowser.Server.Implementations.Library if (Directory.Exists(path)) { _logger.Debug("Deleting path {0}", path); - Directory.Delete(path, true); + _fileSystem.DeleteDirectory(path, true); } else if (File.Exists(path)) { _logger.Debug("Deleting path {0}", path); - File.Delete(path); + _fileSystem.DeleteFile(path); } } @@ -840,6 +840,23 @@ namespace MediaBrowser.Server.Implementations.Library return GetItemByName(ConfigurationManager.ApplicationPaths.YearPath, value.ToString(UsCulture)); } + /// + /// Gets the artists path. + /// + /// The artists path. + public string ArtistsPath + { + get + { + if (ConfigurationManager.Configuration.StoreArtistsInMetadata) + { + return Path.Combine(ConfigurationManager.ApplicationPaths.InternalMetadataPath, "artists"); + } + + return Path.Combine(ConfigurationManager.ApplicationPaths.ItemsByNamePath, "artists"); + } + } + /// /// Gets a Genre /// @@ -847,7 +864,7 @@ namespace MediaBrowser.Server.Implementations.Library /// Task{Genre}. public MusicArtist GetArtist(string name) { - return GetItemByName(ConfigurationManager.ApplicationPaths.ArtistsPath, name); + return GetItemByName(ArtistsPath, name); } private T GetItemByName(string path, string name) @@ -976,7 +993,7 @@ namespace MediaBrowser.Server.Implementations.Library public Task ValidateArtists(CancellationToken cancellationToken, IProgress progress) { // Ensure the location is unavailable. - Directory.CreateDirectory(ConfigurationManager.ApplicationPaths.ArtistsPath); + Directory.CreateDirectory(ArtistsPath); return new ArtistsValidator(this, _userManager, _logger).Run(progress, cancellationToken); } diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs index 3b6de5998fc..b51a9ee7cd3 100644 --- a/MediaBrowser.Server.Implementations/Library/UserManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs @@ -1,7 +1,9 @@ using MediaBrowser.Common.Events; using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.IO; using MediaBrowser.Common.Net; using MediaBrowser.Controller; +using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Connect; using MediaBrowser.Controller.Drawing; @@ -11,6 +13,7 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Channels; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Connect; using MediaBrowser.Model.Dto; @@ -69,9 +72,11 @@ namespace MediaBrowser.Server.Implementations.Library private readonly Func _imageProcessorFactory; private readonly Func _dtoServiceFactory; private readonly Func _connectFactory; + private readonly Func _channelManager; private readonly IServerApplicationHost _appHost; + private readonly IFileSystem _fileSystem; - public UserManager(ILogger logger, IServerConfigurationManager configurationManager, IUserRepository userRepository, IXmlSerializer xmlSerializer, INetworkManager networkManager, Func imageProcessorFactory, Func dtoServiceFactory, Func connectFactory, IServerApplicationHost appHost, IJsonSerializer jsonSerializer) + public UserManager(ILogger logger, IServerConfigurationManager configurationManager, IUserRepository userRepository, IXmlSerializer xmlSerializer, INetworkManager networkManager, Func imageProcessorFactory, Func dtoServiceFactory, Func connectFactory, IServerApplicationHost appHost, IJsonSerializer jsonSerializer, IFileSystem fileSystem, Func channelManager) { _logger = logger; UserRepository = userRepository; @@ -82,6 +87,8 @@ namespace MediaBrowser.Server.Implementations.Library _connectFactory = connectFactory; _appHost = appHost; _jsonSerializer = jsonSerializer; + _fileSystem = fileSystem; + _channelManager = channelManager; ConfigurationManager = configurationManager; Users = new List(); @@ -165,6 +172,7 @@ namespace MediaBrowser.Server.Implementations.Library foreach (var user in users) { await DoPolicyMigration(user).ConfigureAwait(false); + await DoChannelMigration(user).ConfigureAwait(false); } // If there are no local users with admin rights, make them all admins @@ -204,7 +212,7 @@ namespace MediaBrowser.Server.Implementations.Library { return username; } - + // Usernames can contain letters (a-z), numbers (0-9), dashes (-), underscores (_), apostrophes ('), and periods (.) var builder = new StringBuilder(); @@ -329,22 +337,12 @@ namespace MediaBrowser.Server.Implementations.Library { if (!user.Configuration.HasMigratedToPolicy) { - user.Policy.AccessSchedules = user.Configuration.AccessSchedules; - user.Policy.BlockedChannels = user.Configuration.BlockedChannels; - user.Policy.BlockedMediaFolders = user.Configuration.BlockedMediaFolders; - user.Policy.BlockedTags = user.Configuration.BlockedTags; user.Policy.BlockUnratedItems = user.Configuration.BlockUnratedItems; user.Policy.EnableContentDeletion = user.Configuration.EnableContentDeletion; user.Policy.EnableLiveTvAccess = user.Configuration.EnableLiveTvAccess; user.Policy.EnableLiveTvManagement = user.Configuration.EnableLiveTvManagement; user.Policy.EnableMediaPlayback = user.Configuration.EnableMediaPlayback; - user.Policy.EnableRemoteControlOfOtherUsers = user.Configuration.EnableRemoteControlOfOtherUsers; - user.Policy.EnableSharedDeviceControl = user.Configuration.EnableSharedDeviceControl; - user.Policy.EnableUserPreferenceAccess = user.Configuration.EnableUserPreferenceAccess; user.Policy.IsAdministrator = user.Configuration.IsAdministrator; - user.Policy.IsDisabled = user.Configuration.IsDisabled; - user.Policy.IsHidden = user.Configuration.IsHidden; - user.Policy.MaxParentalRating = user.Configuration.MaxParentalRating; await UpdateUserPolicy(user, user.Policy, false); @@ -353,6 +351,44 @@ namespace MediaBrowser.Server.Implementations.Library } } + private async Task DoChannelMigration(User user) + { + if (user.Policy.BlockedChannels != null) + { + if (user.Policy.BlockedChannels.Length > 0) + { + user.Policy.EnableAllChannels = false; + + try + { + var channelResult = await _channelManager().GetChannelsInternal(new ChannelQuery + { + UserId = user.Id.ToString("N") + + }, CancellationToken.None).ConfigureAwait(false); + + user.Policy.EnabledChannels = channelResult.Items + .Select(i => i.Id.ToString("N")) + .Except(user.Policy.BlockedChannels) + .ToArray(); + } + catch + { + user.Policy.EnabledChannels = new string[] { }; + } + } + else + { + user.Policy.EnableAllChannels = true; + user.Policy.EnabledChannels = new string[] { }; + } + + user.Policy.BlockedChannels = null; + + await UpdateUserPolicy(user, user.Policy, false); + } + } + public UserDto GetUserDto(User user, string remoteEndPoint = null) { if (user == null) @@ -591,7 +627,7 @@ namespace MediaBrowser.Server.Implementations.Library try { - File.Delete(configPath); + _fileSystem.DeleteFile(configPath); } catch (IOException ex) { @@ -817,7 +853,7 @@ namespace MediaBrowser.Server.Implementations.Library { try { - File.Delete(PasswordResetFile); + _fileSystem.DeleteFile(PasswordResetFile); } catch { @@ -881,7 +917,7 @@ namespace MediaBrowser.Server.Implementations.Library var json = _jsonSerializer.SerializeToString(userPolicy); userPolicy = _jsonSerializer.DeserializeFromString(json); } - + var path = GetPolifyFilePath(user); Directory.CreateDirectory(Path.GetDirectoryName(path)); @@ -909,7 +945,7 @@ namespace MediaBrowser.Server.Implementations.Library { lock (_policySyncLock) { - File.Delete(path); + _fileSystem.DeleteFile(path); } } catch (IOException) @@ -971,14 +1007,14 @@ namespace MediaBrowser.Server.Implementations.Library var path = GetConfigurationFilePath(user); // The xml serializer will output differently if the type is not exact - if (config.GetType() != typeof (UserConfiguration)) + if (config.GetType() != typeof(UserConfiguration)) { var json = _jsonSerializer.SerializeToString(config); config = _jsonSerializer.DeserializeFromString(json); } Directory.CreateDirectory(Path.GetDirectoryName(path)); - + lock (_configSyncLock) { _xmlSerializer.SerializeToFile(config, path); diff --git a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json index 943daff5ef4..8acce7b725d 100644 --- a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json +++ b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json @@ -42,6 +42,7 @@ "LabelFailed": "(failed)", "ButtonHelp": "Help", "ButtonSave": "Save", + "HeaderDevices": "Devices", "HeaderSupporterBenefit": "A supporter membership provides additional benefits such as access to premium plugins, internet channel content, and more. {0}Learn more{1}.", "HeaderWelcomeToMediaBrowserServerDashboard": "Welcome to the Media Browser Dashboard", "HeaderWelcomeToMediaBrowserWebClient": "Welcome to the Media Browser Web Client", diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.json index e3add2f19b9..7bd42507d29 100644 --- a/MediaBrowser.Server.Implementations/Localization/Server/server.json +++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json @@ -86,6 +86,7 @@ "TabCollectionTitles": "Titles", "HeaderDeviceAccess": "Device Access", "OptionEnableAccessFromAllDevices": "Enable access from all devices", + "OptionEnableAccessToAllChannels": "Enable access to all channels", "DeviceAccessHelp": "This only applies to devices that can be uniquely identified and will not prevent browser access. Filtering user device access will prevent them from using new devices until they've been approved here.", "LabelDisplayMissingEpisodesWithinSeasons": "Display missing episodes within seasons", "LabelUnairedMissingEpisodesWithinSeasons": "Display unaired episodes within seasons", diff --git a/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs b/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs index a0b60464533..56557d6e1dc 100644 --- a/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs +++ b/MediaBrowser.Server.Implementations/MediaEncoder/EncodingManager.cs @@ -215,7 +215,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder try { - File.Delete(image); + _fileSystem.DeleteFile(image); } catch (IOException ex) { diff --git a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs index d9973afe781..8a04f29a2c3 100644 --- a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs +++ b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs @@ -197,19 +197,6 @@ namespace MediaBrowser.Server.Implementations } } - /// - /// Gets the artists path. - /// - /// The artists path. - public string ArtistsPath - { - get - { - return Path.Combine(ItemsByNamePath, "artists"); - } - } - - /// /// Gets the game genre path. /// diff --git a/MediaBrowser.Server.Implementations/Session/HttpSessionController.cs b/MediaBrowser.Server.Implementations/Session/HttpSessionController.cs index 4a64d37532b..4d5c4085353 100644 --- a/MediaBrowser.Server.Implementations/Session/HttpSessionController.cs +++ b/MediaBrowser.Server.Implementations/Session/HttpSessionController.cs @@ -209,6 +209,12 @@ namespace MediaBrowser.Server.Implementations.Session return SendMessage(command.Name, command.Arguments, cancellationToken); } + public Task SendMessage(string name, T data, CancellationToken cancellationToken) + { + // Not supported or needed right now + return Task.FromResult(true); + } + private string ToQueryString(Dictionary nvc) { var array = (from item in nvc diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index d9ec9b7e4d7..8bf39fd6b9b 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -1632,5 +1632,26 @@ namespace MediaBrowser.Server.Implementations.Session return Sessions.FirstOrDefault(i => string.Equals(i.DeviceId, deviceId) && string.Equals(i.Client, client)); } + + public Task SendMessageToUserSessions(string userId, string name, T data, + CancellationToken cancellationToken) + { + var sessions = Sessions.Where(i => i.IsActive && i.SessionController != null && i.ContainsUser(userId)).ToList(); + + var tasks = sessions.Select(session => Task.Run(async () => + { + try + { + await session.SessionController.SendMessage(name, data, cancellationToken).ConfigureAwait(false); + } + catch (Exception ex) + { + _logger.ErrorException("Error in SendPlaybackStoppedNotification.", ex); + } + + }, cancellationToken)); + + return Task.WhenAll(tasks); + } } } \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs index 7d1057397e8..19aaaf8a558 100644 --- a/MediaBrowser.Server.Implementations/Session/WebSocketController.cs +++ b/MediaBrowser.Server.Implementations/Session/WebSocketController.cs @@ -90,7 +90,7 @@ namespace MediaBrowser.Server.Implementations.Session public Task SendPlayCommand(PlayRequest command, CancellationToken cancellationToken) { - return SendMessage(new WebSocketMessage + return SendMessageInternal(new WebSocketMessage { MessageType = "Play", Data = command @@ -100,7 +100,7 @@ namespace MediaBrowser.Server.Implementations.Session public Task SendPlaystateCommand(PlaystateRequest command, CancellationToken cancellationToken) { - return SendMessage(new WebSocketMessage + return SendMessageInternal(new WebSocketMessage { MessageType = "Playstate", Data = command @@ -110,7 +110,7 @@ namespace MediaBrowser.Server.Implementations.Session public Task SendLibraryUpdateInfo(LibraryUpdateInfo info, CancellationToken cancellationToken) { - return SendMessages(new WebSocketMessage + return SendMessagesInternal(new WebSocketMessage { MessageType = "LibraryChanged", Data = info @@ -126,7 +126,7 @@ namespace MediaBrowser.Server.Implementations.Session /// Task. public Task SendRestartRequiredNotification(SystemInfo info, CancellationToken cancellationToken) { - return SendMessages(new WebSocketMessage + return SendMessagesInternal(new WebSocketMessage { MessageType = "RestartRequired", Data = info @@ -143,7 +143,7 @@ namespace MediaBrowser.Server.Implementations.Session /// Task. public Task SendUserDataChangeInfo(UserDataChangeInfo info, CancellationToken cancellationToken) { - return SendMessages(new WebSocketMessage + return SendMessagesInternal(new WebSocketMessage { MessageType = "UserDataChanged", Data = info @@ -158,7 +158,7 @@ namespace MediaBrowser.Server.Implementations.Session /// Task. public Task SendServerShutdownNotification(CancellationToken cancellationToken) { - return SendMessages(new WebSocketMessage + return SendMessagesInternal(new WebSocketMessage { MessageType = "ServerShuttingDown", Data = string.Empty @@ -173,7 +173,7 @@ namespace MediaBrowser.Server.Implementations.Session /// Task. public Task SendServerRestartNotification(CancellationToken cancellationToken) { - return SendMessages(new WebSocketMessage + return SendMessagesInternal(new WebSocketMessage { MessageType = "ServerRestarting", Data = string.Empty @@ -183,7 +183,7 @@ namespace MediaBrowser.Server.Implementations.Session public Task SendGeneralCommand(GeneralCommand command, CancellationToken cancellationToken) { - return SendMessage(new WebSocketMessage + return SendMessageInternal(new WebSocketMessage { MessageType = "GeneralCommand", Data = command @@ -193,7 +193,7 @@ namespace MediaBrowser.Server.Implementations.Session public Task SendSessionEndedNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken) { - return SendMessages(new WebSocketMessage + return SendMessagesInternal(new WebSocketMessage { MessageType = "SessionEnded", Data = sessionInfo @@ -203,7 +203,7 @@ namespace MediaBrowser.Server.Implementations.Session public Task SendPlaybackStartNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken) { - return SendMessages(new WebSocketMessage + return SendMessagesInternal(new WebSocketMessage { MessageType = "PlaybackStart", Data = sessionInfo @@ -213,7 +213,7 @@ namespace MediaBrowser.Server.Implementations.Session public Task SendPlaybackStoppedNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken) { - return SendMessages(new WebSocketMessage + return SendMessagesInternal(new WebSocketMessage { MessageType = "PlaybackStopped", Data = sessionInfo @@ -221,7 +221,17 @@ namespace MediaBrowser.Server.Implementations.Session }, cancellationToken); } - private Task SendMessage(WebSocketMessage message, CancellationToken cancellationToken) + public Task SendMessage(string name, T data, CancellationToken cancellationToken) + { + return SendMessagesInternal(new WebSocketMessage + { + Data = data, + MessageType = name + + }, cancellationToken); + } + + private Task SendMessageInternal(WebSocketMessage message, CancellationToken cancellationToken) { if (SkipSending()) return Task.FromResult(true); @@ -230,7 +240,7 @@ namespace MediaBrowser.Server.Implementations.Session return socket.SendAsync(message, cancellationToken); } - private Task SendMessages(WebSocketMessage message, CancellationToken cancellationToken) + private Task SendMessagesInternal(WebSocketMessage message, CancellationToken cancellationToken) { if (SkipSending()) return Task.FromResult(true); diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs index b8f199e6bc0..33db54ee1b1 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common; using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.IO; using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Dto; @@ -37,10 +38,11 @@ namespace MediaBrowser.Server.Implementations.Sync private readonly IApplicationHost _appHost; private readonly ITVSeriesManager _tvSeriesManager; private readonly Func _mediaEncoder; + private readonly IFileSystem _fileSystem; private ISyncProvider[] _providers = { }; - public SyncManager(ILibraryManager libraryManager, ISyncRepository repo, IImageProcessor imageProcessor, ILogger logger, IUserManager userManager, Func dtoService, IApplicationHost appHost, ITVSeriesManager tvSeriesManager, Func mediaEncoder) + public SyncManager(ILibraryManager libraryManager, ISyncRepository repo, IImageProcessor imageProcessor, ILogger logger, IUserManager userManager, Func dtoService, IApplicationHost appHost, ITVSeriesManager tvSeriesManager, Func mediaEncoder, IFileSystem fileSystem) { _libraryManager = libraryManager; _repo = repo; @@ -51,6 +53,7 @@ namespace MediaBrowser.Server.Implementations.Sync _appHost = appHost; _tvSeriesManager = tvSeriesManager; _mediaEncoder = mediaEncoder; + _fileSystem = fileSystem; } public void AddParts(IEnumerable providers) @@ -396,7 +399,7 @@ namespace MediaBrowser.Server.Implementations.Sync { try { - File.Delete(jobItem.OutputPath); + _fileSystem.DeleteFile(jobItem.OutputPath); } catch (Exception ex) { diff --git a/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs b/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs index c2925551b71..068261ffd3c 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncScheduledTask.cs @@ -67,7 +67,7 @@ namespace MediaBrowser.Server.Implementations.Sync public bool IsHidden { - get { return true; } + get { return false; } } public bool IsEnabled diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index 013e9205ab7..65453987026 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -365,11 +365,11 @@ namespace MediaBrowser.Server.Startup.Common { var migrations = new List { - new MigrateUserFolders(ApplicationPaths), + new MigrateUserFolders(ApplicationPaths, FileSystemManager), new RenameXbmcOptions(ServerConfigurationManager), new RenameXmlOptions(ServerConfigurationManager), - new DeprecatePlugins(ApplicationPaths), - new DeleteDlnaProfiles(ApplicationPaths) + new DeprecatePlugins(ApplicationPaths, FileSystemManager), + new DeleteDlnaProfiles(ApplicationPaths, FileSystemManager) }; foreach (var task in migrations) @@ -435,7 +435,7 @@ namespace MediaBrowser.Server.Startup.Common SyncRepository = await GetSyncRepository().ConfigureAwait(false); RegisterSingleInstance(SyncRepository); - UserManager = new UserManager(LogManager.GetLogger("UserManager"), ServerConfigurationManager, UserRepository, XmlSerializer, NetworkManager, () => ImageProcessor, () => DtoService, () => ConnectManager, this, JsonSerializer); + UserManager = new UserManager(LogManager.GetLogger("UserManager"), ServerConfigurationManager, UserRepository, XmlSerializer, NetworkManager, () => ImageProcessor, () => DtoService, () => ConnectManager, this, JsonSerializer, FileSystemManager, () => ChannelManager); RegisterSingleInstance(UserManager); LibraryManager = new LibraryManager(Logger, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, () => ProviderManager); @@ -483,7 +483,7 @@ namespace MediaBrowser.Server.Startup.Common TVSeriesManager = new TVSeriesManager(UserManager, UserDataManager, LibraryManager); RegisterSingleInstance(TVSeriesManager); - SyncManager = new SyncManager(LibraryManager, SyncRepository, ImageProcessor, LogManager.GetLogger("SyncManager"), UserManager, () => DtoService, this, TVSeriesManager, () => MediaEncoder); + SyncManager = new SyncManager(LibraryManager, SyncRepository, ImageProcessor, LogManager.GetLogger("SyncManager"), UserManager, () => DtoService, this, TVSeriesManager, () => MediaEncoder, FileSystemManager); RegisterSingleInstance(SyncManager); DtoService = new DtoService(Logger, LibraryManager, UserDataManager, ItemRepository, ImageProcessor, ServerConfigurationManager, FileSystemManager, ProviderManager, () => ChannelManager, SyncManager, this); @@ -495,7 +495,7 @@ namespace MediaBrowser.Server.Startup.Common ConnectManager = new ConnectManager(LogManager.GetLogger("Connect"), ApplicationPaths, JsonSerializer, encryptionManager, HttpClient, this, ServerConfigurationManager, UserManager, ProviderManager); RegisterSingleInstance(ConnectManager); - DeviceManager = new DeviceManager(new DeviceRepository(ApplicationPaths, JsonSerializer, Logger), UserManager, FileSystemManager, LibraryMonitor, ConfigurationManager, LogManager.GetLogger("DeviceManager")); + DeviceManager = new DeviceManager(new DeviceRepository(ApplicationPaths, JsonSerializer, Logger, FileSystemManager), UserManager, FileSystemManager, LibraryMonitor, ConfigurationManager, LogManager.GetLogger("DeviceManager")); RegisterSingleInstance(DeviceManager); SessionManager = new SessionManager(UserDataManager, Logger, UserRepository, LibraryManager, UserManager, musicManager, DtoService, ImageProcessor, ItemRepository, JsonSerializer, this, HttpClient, AuthenticationRepository, DeviceManager); diff --git a/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloader.cs b/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloader.cs index 229fee18d8a..58e8e2da8e5 100644 --- a/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloader.cs +++ b/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloader.cs @@ -129,7 +129,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg { try { - Directory.Delete(path, true); + _fileSystem.DeleteDirectory(path, true); } catch (Exception ex) { @@ -272,7 +272,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg { try { - File.Delete(path); + _fileSystem.DeleteFile(path); } catch (IOException ex) { @@ -380,10 +380,10 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg } Extract7zArchive(tempFile, fontsDirectory); - + try { - File.Delete(tempFile); + _fileSystem.DeleteFile(tempFile); } catch (IOException ex) { diff --git a/MediaBrowser.Server.Startup.Common/Migrations/DeleteDlnaProfiles.cs b/MediaBrowser.Server.Startup.Common/Migrations/DeleteDlnaProfiles.cs index 8fe841ffce0..166c2627f13 100644 --- a/MediaBrowser.Server.Startup.Common/Migrations/DeleteDlnaProfiles.cs +++ b/MediaBrowser.Server.Startup.Common/Migrations/DeleteDlnaProfiles.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller; +using MediaBrowser.Common.IO; +using MediaBrowser.Controller; using System.IO; namespace MediaBrowser.Server.Startup.Common.Migrations @@ -6,10 +7,12 @@ namespace MediaBrowser.Server.Startup.Common.Migrations public class DeleteDlnaProfiles : IVersionMigration { private readonly IServerApplicationPaths _appPaths; + private readonly IFileSystem _fileSystem; - public DeleteDlnaProfiles(IServerApplicationPaths appPaths) + public DeleteDlnaProfiles(IServerApplicationPaths appPaths, IFileSystem fileSystem) { _appPaths = appPaths; + _fileSystem = fileSystem; } public void Run() @@ -23,7 +26,7 @@ namespace MediaBrowser.Server.Startup.Common.Migrations { try { - File.Delete(Path.Combine(_appPaths.ConfigurationDirectoryPath, "dlna", "system", filename + ".xml")); + _fileSystem.DeleteFile(Path.Combine(_appPaths.ConfigurationDirectoryPath, "dlna", "system", filename + ".xml")); } catch { @@ -31,7 +34,7 @@ namespace MediaBrowser.Server.Startup.Common.Migrations } try { - File.Delete(Path.Combine(_appPaths.ConfigurationDirectoryPath, "dlna", "user", filename + ".xml")); + _fileSystem.DeleteFile(Path.Combine(_appPaths.ConfigurationDirectoryPath, "dlna", "user", filename + ".xml")); } catch { diff --git a/MediaBrowser.Server.Startup.Common/Migrations/DeprecatePlugins.cs b/MediaBrowser.Server.Startup.Common/Migrations/DeprecatePlugins.cs index ce4665b26ca..afdd4e623fb 100644 --- a/MediaBrowser.Server.Startup.Common/Migrations/DeprecatePlugins.cs +++ b/MediaBrowser.Server.Startup.Common/Migrations/DeprecatePlugins.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller; +using MediaBrowser.Common.IO; +using MediaBrowser.Controller; using System.IO; namespace MediaBrowser.Server.Startup.Common.Migrations @@ -6,10 +7,12 @@ namespace MediaBrowser.Server.Startup.Common.Migrations public class DeprecatePlugins : IVersionMigration { private readonly IServerApplicationPaths _appPaths; + private readonly IFileSystem _fileSystem; - public DeprecatePlugins(IServerApplicationPaths appPaths) + public DeprecatePlugins(IServerApplicationPaths appPaths, IFileSystem fileSystem) { _appPaths = appPaths; + _fileSystem = fileSystem; } public void Run() @@ -21,7 +24,7 @@ namespace MediaBrowser.Server.Startup.Common.Migrations { try { - File.Delete(Path.Combine(_appPaths.PluginsPath, filename)); + _fileSystem.DeleteFile(Path.Combine(_appPaths.PluginsPath, filename)); } catch { diff --git a/MediaBrowser.Server.Startup.Common/Migrations/MigrateUserFolders.cs b/MediaBrowser.Server.Startup.Common/Migrations/MigrateUserFolders.cs index 5e3df5701e7..cb566d6cf89 100644 --- a/MediaBrowser.Server.Startup.Common/Migrations/MigrateUserFolders.cs +++ b/MediaBrowser.Server.Startup.Common/Migrations/MigrateUserFolders.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Controller; +using MediaBrowser.Common.IO; +using MediaBrowser.Controller; using System; using System.IO; using System.Linq; @@ -8,10 +9,12 @@ namespace MediaBrowser.Server.Startup.Common.Migrations public class MigrateUserFolders : IVersionMigration { private readonly IServerApplicationPaths _appPaths; + private readonly IFileSystem _fileSystem; - public MigrateUserFolders(IServerApplicationPaths appPaths) + public MigrateUserFolders(IServerApplicationPaths appPaths, IFileSystem fileSystem) { _appPaths = appPaths; + _fileSystem = fileSystem; } public void Run() @@ -25,7 +28,7 @@ namespace MediaBrowser.Server.Startup.Common.Migrations foreach (var folder in folders) { - Directory.Delete(folder.FullName, true); + _fileSystem.DeleteDirectory(folder.FullName, true); } } catch (IOException) diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index adc8eecb1d1..7532a2edd37 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -203,7 +203,7 @@ namespace MediaBrowser.ServerApplication { var fileSystem = new NativeFileSystem(logManager.GetLogger("FileSystem"), false); - var nativeApp = new WindowsApp + var nativeApp = new WindowsApp(fileSystem) { IsRunningAsService = runService }; diff --git a/MediaBrowser.ServerApplication/Native/Autorun.cs b/MediaBrowser.ServerApplication/Native/Autorun.cs index 0262f711e7a..593bb7955cb 100644 --- a/MediaBrowser.ServerApplication/Native/Autorun.cs +++ b/MediaBrowser.ServerApplication/Native/Autorun.cs @@ -1,4 +1,5 @@ -using System; +using MediaBrowser.Common.IO; +using System; using System.IO; namespace MediaBrowser.ServerApplication.Native @@ -12,7 +13,8 @@ namespace MediaBrowser.ServerApplication.Native /// Configures the specified autorun. /// /// if set to true [autorun]. - public static void Configure(bool autorun) + /// The file system. + public static void Configure(bool autorun, IFileSystem fileSystem) { var shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser 3", "Media Browser Server.lnk"); @@ -26,7 +28,7 @@ namespace MediaBrowser.ServerApplication.Native else { //Remove our shortcut from the startup folder for this user - File.Delete(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "MBstartup.lnk")); + fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "MBstartup.lnk")); } } } diff --git a/MediaBrowser.ServerApplication/Native/WindowsApp.cs b/MediaBrowser.ServerApplication/Native/WindowsApp.cs index 45070e6ecea..476fb58b9d9 100644 --- a/MediaBrowser.ServerApplication/Native/WindowsApp.cs +++ b/MediaBrowser.ServerApplication/Native/WindowsApp.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Net; +using MediaBrowser.Common.IO; +using MediaBrowser.Common.Net; using MediaBrowser.IsoMounter; using MediaBrowser.Model.Logging; using MediaBrowser.Server.Startup.Common; @@ -10,6 +11,13 @@ namespace MediaBrowser.ServerApplication.Native { public class WindowsApp : INativeApp { + private readonly IFileSystem _fileSystem; + + public WindowsApp(IFileSystem fileSystem) + { + _fileSystem = fileSystem; + } + public List GetAssembliesWithParts() { var list = new List(); @@ -89,7 +97,7 @@ namespace MediaBrowser.ServerApplication.Native public void ConfigureAutoRun(bool autorun) { - Autorun.Configure(autorun); + Autorun.Configure(autorun, _fileSystem); } public INetworkManager CreateNetworkManager(ILogger logger) diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index 6e343907976..74496ef9c6f 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -275,11 +275,11 @@ namespace MediaBrowser.WebDashboard.Api try { - Directory.Delete(path, true); + _fileSystem.DeleteDirectory(path, true); } catch (IOException) { - + } var creator = GetPackageCreator(); diff --git a/SharedVersion.cs b/SharedVersion.cs index 238d57f0ce3..5af3efc1c8c 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,4 +1,4 @@ using System.Reflection; -//[assembly: AssemblyVersion("3.0.*")] -[assembly: AssemblyVersion("3.0.5490.2")] +[assembly: AssemblyVersion("3.0.*")] +//[assembly: AssemblyVersion("3.0.5490.2")]