From 02fedead11f738c09e503c3bdc74e2dd98e21cc8 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 3 Jun 2013 22:02:49 -0400 Subject: re-factored some file system access --- MediaBrowser.Common/IO/FileSystemRepository.cs | 65 ++++---------------------- 1 file changed, 10 insertions(+), 55 deletions(-) (limited to 'MediaBrowser.Common/IO/FileSystemRepository.cs') diff --git a/MediaBrowser.Common/IO/FileSystemRepository.cs b/MediaBrowser.Common/IO/FileSystemRepository.cs index f2fa8ce54..07328d72d 100644 --- a/MediaBrowser.Common/IO/FileSystemRepository.cs +++ b/MediaBrowser.Common/IO/FileSystemRepository.cs @@ -1,6 +1,5 @@ using MediaBrowser.Common.Extensions; using System; -using System.Collections.Concurrent; using System.IO; namespace MediaBrowser.Common.IO @@ -11,12 +10,6 @@ namespace MediaBrowser.Common.IO /// public class FileSystemRepository { - /// - /// Contains the list of subfolders under the main directory - /// The directory entry is created when the item is first added to the dictionary - /// - private readonly ConcurrentDictionary _subFolderPaths = new ConcurrentDictionary(); - /// /// Gets or sets the path. /// @@ -36,18 +29,6 @@ namespace MediaBrowser.Common.IO } Path = path; - Initialize(); - } - - /// - /// Initializes this instance. - /// - protected void Initialize() - { - if (!Directory.Exists(Path)) - { - Directory.CreateDirectory(Path); - } } /// @@ -56,17 +37,18 @@ namespace MediaBrowser.Common.IO /// Name of the unique. /// The file extension. /// System.String. - /// + /// + /// public string GetResourcePath(string uniqueName, string fileExtension) { if (string.IsNullOrEmpty(uniqueName)) { - throw new ArgumentNullException(); + throw new ArgumentNullException("uniqueName"); } if (string.IsNullOrEmpty(fileExtension)) { - throw new ArgumentNullException(); + throw new ArgumentNullException("fileExtension"); } var filename = uniqueName.GetMD5() + fileExtension; @@ -75,7 +57,7 @@ namespace MediaBrowser.Common.IO } /// - /// Gets the full path of where a file should be stored within the repository + /// Gets the resource path. /// /// The filename. /// System.String. @@ -84,41 +66,14 @@ namespace MediaBrowser.Common.IO { if (string.IsNullOrEmpty(filename)) { - throw new ArgumentNullException(); + throw new ArgumentNullException("filename"); } - return GetInternalResourcePath(filename); - } - - /// - /// Takes a filename and returns the full path of where it should be stored - /// - /// The filename. - /// System.String. - private string GetInternalResourcePath(string filename) - { var prefix = filename.Substring(0, 1); - var folder = _subFolderPaths.GetOrAdd(prefix, GetCachePath); - - return System.IO.Path.Combine(folder, filename); - } - - /// - /// Creates a subfolder under the image cache directory and returns the full path - /// - /// The prefix. - /// System.String. - private string GetCachePath(string prefix) - { var path = System.IO.Path.Combine(Path, prefix); - - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } - - return path; + + return System.IO.Path.Combine(path, filename); } /// @@ -144,8 +99,8 @@ namespace MediaBrowser.Common.IO { throw new ArgumentNullException(); } - - return ContainsFilePath(GetInternalResourcePath(filename)); + + return ContainsFilePath(GetResourcePath(filename)); } /// -- cgit v1.2.3