diff options
Diffstat (limited to 'Emby.Server.Implementations/Devices')
4 files changed, 185 insertions, 2 deletions
diff --git a/Emby.Server.Implementations/Devices/CameraUploadsDynamicFolder.cs b/Emby.Server.Implementations/Devices/CameraUploadsDynamicFolder.cs index 52979f085..bb9ef157c 100644 --- a/Emby.Server.Implementations/Devices/CameraUploadsDynamicFolder.cs +++ b/Emby.Server.Implementations/Devices/CameraUploadsDynamicFolder.cs @@ -10,7 +10,6 @@ using MediaBrowser.Controller.IO; using MediaBrowser.Model.IO; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Serialization; -using MediaBrowser.Server.Implementations.Devices; namespace Emby.Server.Implementations.Devices { diff --git a/Emby.Server.Implementations/Devices/CameraUploadsFolder.cs b/Emby.Server.Implementations/Devices/CameraUploadsFolder.cs new file mode 100644 index 000000000..55063872c --- /dev/null +++ b/Emby.Server.Implementations/Devices/CameraUploadsFolder.cs @@ -0,0 +1,71 @@ +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Serialization; + +namespace Emby.Server.Implementations.Devices +{ + public class CameraUploadsFolder : BasePluginFolder, ISupportsUserSpecificView + { + public CameraUploadsFolder() + { + Name = "Camera Uploads"; + } + + public override bool IsVisible(User user) + { + if (!user.Policy.EnableAllFolders && !user.Policy.EnabledFolders.Contains(Id.ToString("N"), StringComparer.OrdinalIgnoreCase)) + { + return false; + } + + return base.IsVisible(user) && HasChildren(); + } + + [IgnoreDataMember] + public override string CollectionType + { + get { return MediaBrowser.Model.Entities.CollectionType.Photos; } + } + + [IgnoreDataMember] + public override bool SupportsInheritedParentImages + { + get + { + return false; + } + } + + public override string GetClientTypeName() + { + return typeof(CollectionFolder).Name; + } + + private bool? _hasChildren; + private bool HasChildren() + { + if (!_hasChildren.HasValue) + { + _hasChildren = LibraryManager.GetItemIds(new InternalItemsQuery { Parent = this }).Count > 0; + } + + return _hasChildren.Value; + } + + protected override Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService) + { + _hasChildren = null; + return base.ValidateChildrenInternal(progress, cancellationToken, recursive, refreshChildMetadata, refreshOptions, directoryService); + } + + [IgnoreDataMember] + public bool EnableUserSpecificView + { + get { return true; } + } + } +} diff --git a/Emby.Server.Implementations/Devices/DeviceId.cs b/Emby.Server.Implementations/Devices/DeviceId.cs new file mode 100644 index 000000000..5e0323ddb --- /dev/null +++ b/Emby.Server.Implementations/Devices/DeviceId.cs @@ -0,0 +1,109 @@ +using System; +using System.IO; +using System.Text; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.Logging; + +namespace Emby.Server.Implementations.Devices +{ + public class DeviceId + { + private readonly IApplicationPaths _appPaths; + private readonly ILogger _logger; + private readonly IFileSystem _fileSystem; + + private readonly object _syncLock = new object(); + + private string CachePath + { + get { return Path.Combine(_appPaths.DataPath, "device.txt"); } + } + + private string GetCachedId() + { + try + { + lock (_syncLock) + { + var value = File.ReadAllText(CachePath, Encoding.UTF8); + + Guid guid; + if (Guid.TryParse(value, out guid)) + { + return value; + } + + _logger.Error("Invalid value found in device id file"); + } + } + catch (DirectoryNotFoundException) + { + } + catch (FileNotFoundException) + { + } + catch (Exception ex) + { + _logger.ErrorException("Error reading file", ex); + } + + return null; + } + + private void SaveId(string id) + { + try + { + var path = CachePath; + + _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path)); + + lock (_syncLock) + { + _fileSystem.WriteAllText(path, id, Encoding.UTF8); + } + } + catch (Exception ex) + { + _logger.ErrorException("Error writing to file", ex); + } + } + + private string GetNewId() + { + return Guid.NewGuid().ToString("N"); + } + + private string GetDeviceId() + { + var id = GetCachedId(); + + if (string.IsNullOrWhiteSpace(id)) + { + id = GetNewId(); + SaveId(id); + } + + return id; + } + + private string _id; + + public DeviceId(IApplicationPaths appPaths, ILogger logger, IFileSystem fileSystem) + { + if (fileSystem == null) { + throw new ArgumentNullException ("fileSystem"); + } + + _appPaths = appPaths; + _logger = logger; + _fileSystem = fileSystem; + } + + public string Value + { + get { return _id ?? (_id = GetDeviceId()); } + } + } +} diff --git a/Emby.Server.Implementations/Devices/DeviceRepository.cs b/Emby.Server.Implementations/Devices/DeviceRepository.cs index de0dfda2e..b286a3bb0 100644 --- a/Emby.Server.Implementations/Devices/DeviceRepository.cs +++ b/Emby.Server.Implementations/Devices/DeviceRepository.cs @@ -11,6 +11,7 @@ using MediaBrowser.Model.IO; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Session; +using MediaBrowser.Model.Extensions; namespace Emby.Server.Implementations.Devices { @@ -199,7 +200,10 @@ namespace Emby.Server.Implementations.Devices } history.DeviceId = deviceId; - history.FilesUploaded.Add(file); + + var list = history.FilesUploaded.ToList(); + list.Add(file); + history.FilesUploaded = list.ToArray(list.Count); _json.SerializeToFile(history, path); } |
