aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Devices
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2017-08-18 02:04:21 -0400
committerGitHub <noreply@github.com>2017-08-18 02:04:21 -0400
commitc58db90c950c766321615eca236557d87b8d1b74 (patch)
tree80f1823f901bdadad6af4fce8d36d9b73f79c0fb /Emby.Server.Implementations/Devices
parentd5a9db3af77b06a355558165a984328e35555279 (diff)
parent883399caeba54da4c9f3e15e639f8fd72f5b559e (diff)
Merge pull request #2827 from MediaBrowser/dev
Dev
Diffstat (limited to 'Emby.Server.Implementations/Devices')
-rw-r--r--Emby.Server.Implementations/Devices/CameraUploadsDynamicFolder.cs1
-rw-r--r--Emby.Server.Implementations/Devices/CameraUploadsFolder.cs71
-rw-r--r--Emby.Server.Implementations/Devices/DeviceId.cs109
3 files changed, 180 insertions, 1 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()); }
+ }
+ }
+}