diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/Devices')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs | 36 | ||||
| -rw-r--r-- | MediaBrowser.Server.Implementations/Devices/DeviceManager.cs | 98 |
2 files changed, 111 insertions, 23 deletions
diff --git a/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs b/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs index 6d7265972..d1e66abce 100644 --- a/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs +++ b/MediaBrowser.Server.Implementations/Devices/CameraUploadsFolder.cs @@ -3,8 +3,11 @@ using MediaBrowser.Controller.Entities; using System; using System.IO; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using CommonIO; using MediaBrowser.Common.IO; +using MediaBrowser.Controller.Providers; namespace MediaBrowser.Server.Implementations.Devices { @@ -21,32 +24,35 @@ namespace MediaBrowser.Server.Implementations.Devices { return false; } - - return GetChildren(user, true).Any() && - base.IsVisible(user); + + return base.IsVisible(user) && HasChildren(); } - public override bool IsHidden + public override string CollectionType { - get - { - return base.IsHidden || !Children.Any(); - } + get { return Model.Entities.CollectionType.Photos; } } - public override bool IsHiddenFromUser(User user) + public override string GetClientTypeName() { - return false; + return typeof(CollectionFolder).Name; } - public override string CollectionType + private bool? _hasChildren; + private bool HasChildren() { - get { return Model.Entities.CollectionType.Photos; } + if (!_hasChildren.HasValue) + { + _hasChildren = LibraryManager.GetItemIds(new InternalItemsQuery { ParentId = Id }).Count > 0; + } + + return _hasChildren.Value; } - public override string GetClientTypeName() + protected override Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService) { - return typeof(CollectionFolder).Name; + _hasChildren = null; + return base.ValidateChildrenInternal(progress, cancellationToken, recursive, refreshChildMetadata, refreshOptions, directoryService); } } @@ -65,7 +71,7 @@ namespace MediaBrowser.Server.Implementations.Devices { var path = Path.Combine(_appPaths.DataPath, "camerauploads"); - _fileSystem.CreateDirectory(path); + _fileSystem.CreateDirectory(path); return new CameraUploadsFolder { diff --git a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs index 0b2c082a8..e0713bfd5 100644 --- a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs +++ b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs @@ -18,6 +18,9 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using CommonIO; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Plugins; +using MediaBrowser.Model.Entities; namespace MediaBrowser.Server.Implementations.Devices { @@ -27,7 +30,7 @@ namespace MediaBrowser.Server.Implementations.Devices private readonly IUserManager _userManager; private readonly IFileSystem _fileSystem; private readonly ILibraryMonitor _libraryMonitor; - private readonly IConfigurationManager _config; + private readonly IServerConfigurationManager _config; private readonly ILogger _logger; private readonly INetworkManager _network; @@ -38,7 +41,7 @@ namespace MediaBrowser.Server.Implementations.Devices /// </summary> public event EventHandler<GenericEventArgs<DeviceInfo>> DeviceOptionsUpdated; - public DeviceManager(IDeviceRepository repo, IUserManager userManager, IFileSystem fileSystem, ILibraryMonitor libraryMonitor, IConfigurationManager config, ILogger logger, INetworkManager network) + public DeviceManager(IDeviceRepository repo, IUserManager userManager, IFileSystem fileSystem, ILibraryMonitor libraryMonitor, IServerConfigurationManager config, ILogger logger, INetworkManager network) { _repo = repo; _userManager = userManager; @@ -187,11 +190,6 @@ namespace MediaBrowser.Server.Implementations.Devices } } - private string GetUploadPath(string deviceId) - { - return GetUploadPath(GetDevice(deviceId)); - } - private string GetUploadPath(DeviceInfo device) { if (!string.IsNullOrWhiteSpace(device.CameraUploadPath)) @@ -205,16 +203,81 @@ namespace MediaBrowser.Server.Implementations.Devices return config.CameraUploadPath; } - var path = Path.Combine(_config.CommonApplicationPaths.DataPath, "camerauploads"); + var path = DefaultCameraUploadsPath; if (config.EnableCameraUploadSubfolders) { path = Path.Combine(path, _fileSystem.GetValidFilename(device.Name)); } + EnsureMediaLibrarySetup(); + return path; } + private string DefaultCameraUploadsPath + { + get { return Path.Combine(_config.CommonApplicationPaths.DataPath, "camerauploads"); } + } + + internal void EnsureMediaLibrarySetup() + { + //EnsureMediaLibrarySetup(DefaultCameraUploadsPath, false); + } + + private void EnsureMediaLibrarySetup(string libraryPath, bool force) + { + var requiresSetup = false; + + var path = Path.Combine(_config.ApplicationPaths.DefaultUserViewsPath, "Camera Uploads"); + + var collectionMarkerFile = Path.Combine(path, CollectionType.Photos + ".collection"); + if (!_fileSystem.FileExists(collectionMarkerFile)) + { + requiresSetup = true; + } + + var shortcutFile = Path.Combine(path, "camerauploads.mblink"); + try + { + if (!string.Equals(_fileSystem.ReadAllText(shortcutFile), libraryPath)) + { + requiresSetup = true; + } + } + catch + { + requiresSetup = true; + } + + if (requiresSetup) + { + if (!force) + { + var extensions = new[] { ".jpg", ".png" }; + var hasPhotos = _fileSystem.GetFiles(libraryPath, true).Any(i => extensions.Contains(i.Extension, StringComparer.OrdinalIgnoreCase)); + + // Nothing to do + if (!hasPhotos) + { + return; + } + } + } + + if (requiresSetup) + { + Directory.CreateDirectory(path); + + using (File.Create(collectionMarkerFile)) + { + + } + + _fileSystem.CreateShortcut(shortcutFile, libraryPath); + } + } + public async Task UpdateDeviceInfo(string id, DeviceOptions options) { var device = GetDevice(id); @@ -274,6 +337,25 @@ namespace MediaBrowser.Server.Implementations.Devices } } + public class DeviceManagerEntryPoint : IServerEntryPoint + { + private readonly IDeviceManager _deviceManager; + + public DeviceManagerEntryPoint(IDeviceManager deviceManager) + { + _deviceManager = deviceManager; + } + + public void Run() + { + ((DeviceManager)_deviceManager).EnsureMediaLibrarySetup(); + } + + public void Dispose() + { + } + } + public class DevicesConfigStore : IConfigurationFactory { public IEnumerable<ConfigurationStore> GetConfigurations() |
