aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Entities/CollectionFolder.cs
diff options
context:
space:
mode:
authorhatharry <hatharry@hotmail.com>2016-08-28 12:51:32 +0000
committerGitHub <noreply@github.com>2016-08-28 12:51:32 +0000
commitc974641a352685b2e6595dd7b291843c8e6364ac (patch)
tree2e6ca83c4d08c5b676e12edae947e635d290bc3f /MediaBrowser.Controller/Entities/CollectionFolder.cs
parentf21f9923de6291aaf985f32dbbbaddbb26d07fb1 (diff)
parent81765ff29f624fd34e1abe3c7bb8149bbb001aef (diff)
Merge pull request #22 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.Controller/Entities/CollectionFolder.cs')
-rw-r--r--MediaBrowser.Controller/Entities/CollectionFolder.cs74
1 files changed, 73 insertions, 1 deletions
diff --git a/MediaBrowser.Controller/Entities/CollectionFolder.cs b/MediaBrowser.Controller/Entities/CollectionFolder.cs
index 35dfd52e9..597ecf973 100644
--- a/MediaBrowser.Controller/Entities/CollectionFolder.cs
+++ b/MediaBrowser.Controller/Entities/CollectionFolder.cs
@@ -3,11 +3,15 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
+using MediaBrowser.Controller.Configuration;
+using MediaBrowser.Model.Configuration;
+using MediaBrowser.Model.Serialization;
using MoreLinq;
namespace MediaBrowser.Controller.Entities
@@ -18,6 +22,8 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
public class CollectionFolder : Folder, ICollectionFolder
{
+ public static IXmlSerializer XmlSerializer { get; set; }
+
public CollectionFolder()
{
PhysicalLocationsList = new List<string>();
@@ -39,6 +45,72 @@ namespace MediaBrowser.Controller.Entities
public string CollectionType { get; set; }
+ private static readonly Dictionary<string, LibraryOptions> LibraryOptions = new Dictionary<string, LibraryOptions>();
+ public LibraryOptions GetLibraryOptions()
+ {
+ lock (LibraryOptions)
+ {
+ LibraryOptions options;
+ if (!LibraryOptions.TryGetValue(Path, out options))
+ {
+ options = LoadLibraryOptions();
+ LibraryOptions[Path] = options;
+ }
+
+ return options;
+ }
+ }
+
+ private LibraryOptions LoadLibraryOptions()
+ {
+ try
+ {
+ var result = XmlSerializer.DeserializeFromFile(typeof(LibraryOptions), GetLibraryOptionsPath(Path)) as LibraryOptions;
+
+ if (result == null)
+ {
+ return new LibraryOptions();
+ }
+
+ return result;
+ }
+ catch (FileNotFoundException)
+ {
+ return new LibraryOptions();
+ }
+ catch (DirectoryNotFoundException)
+ {
+ return new LibraryOptions();
+ }
+ catch (Exception ex)
+ {
+ Logger.ErrorException("Error loading library options", ex);
+
+ return new LibraryOptions();
+ }
+ }
+
+ private static string GetLibraryOptionsPath(string path)
+ {
+ return System.IO.Path.Combine(path, "options.xml");
+ }
+
+ public void UpdateLibraryOptions(LibraryOptions options)
+ {
+ SaveLibraryOptions(Path, options);
+ }
+
+ public static void SaveLibraryOptions(string path, LibraryOptions options)
+ {
+ lock (LibraryOptions)
+ {
+ LibraryOptions[path] = options;
+
+ options.SchemaVersion = 1;
+ XmlSerializer.SerializeToFile(options, GetLibraryOptionsPath(path));
+ }
+ }
+
/// <summary>
/// Allow different display preferences for each collection folder
/// </summary>
@@ -82,7 +154,7 @@ namespace MediaBrowser.Controller.Entities
{
var locations = PhysicalLocations.ToList();
- var newLocations = CreateResolveArgs(new DirectoryService(BaseItem.FileSystem), false).PhysicalLocations.ToList();
+ var newLocations = CreateResolveArgs(new DirectoryService(Logger, FileSystem), false).PhysicalLocations.ToList();
if (!locations.SequenceEqual(newLocations))
{