aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common.Implementations
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common.Implementations')
-rw-r--r--MediaBrowser.Common.Implementations/BaseApplicationPaths.cs33
-rw-r--r--MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs39
-rw-r--r--MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs2
3 files changed, 47 insertions, 27 deletions
diff --git a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs
index 6acaac5c9..eba8f5698 100644
--- a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs
+++ b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs
@@ -2,7 +2,6 @@
using System;
using System.Configuration;
using System.IO;
-using System.Reflection;
namespace MediaBrowser.Common.Implementations
{
@@ -82,10 +81,6 @@ namespace MediaBrowser.Common.Implementations
}
/// <summary>
- /// The _image cache path
- /// </summary>
- private string _imageCachePath;
- /// <summary>
/// Gets the image cache path.
/// </summary>
/// <value>The image cache path.</value>
@@ -93,14 +88,7 @@ namespace MediaBrowser.Common.Implementations
{
get
{
- if (_imageCachePath == null)
- {
- _imageCachePath = Path.Combine(CachePath, "images");
-
- Directory.CreateDirectory(_imageCachePath);
- }
-
- return _imageCachePath;
+ return Path.Combine(CachePath, "images");
}
}
@@ -233,7 +221,7 @@ namespace MediaBrowser.Common.Implementations
{
get
{
- if (_cachePath == null)
+ if (string.IsNullOrEmpty(_cachePath))
{
_cachePath = Path.Combine(ProgramDataPath, "cache");
@@ -242,13 +230,13 @@ namespace MediaBrowser.Common.Implementations
return _cachePath;
}
+ set
+ {
+ _cachePath = value;
+ }
}
/// <summary>
- /// The _temp directory
- /// </summary>
- private string _tempDirectory;
- /// <summary>
/// Gets the folder path to the temp directory within the cache folder
/// </summary>
/// <value>The temp directory.</value>
@@ -256,14 +244,7 @@ namespace MediaBrowser.Common.Implementations
{
get
{
- if (_tempDirectory == null)
- {
- _tempDirectory = Path.Combine(CachePath, "temp");
-
- Directory.CreateDirectory(_tempDirectory);
- }
-
- return _tempDirectory;
+ return Path.Combine(CachePath, "temp");
}
}
diff --git a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs
index 317a288ff..3c00673ba 100644
--- a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs
+++ b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Common.Configuration;
+using System.IO;
+using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Events;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Logging;
@@ -84,6 +85,8 @@ namespace MediaBrowser.Common.Implementations.Configuration
CommonApplicationPaths = applicationPaths;
XmlSerializer = xmlSerializer;
Logger = logManager.GetLogger(GetType().Name);
+
+ UpdateCachePath();
}
/// <summary>
@@ -109,6 +112,8 @@ namespace MediaBrowser.Common.Implementations.Configuration
/// </summary>
protected virtual void OnConfigurationUpdated()
{
+ UpdateCachePath();
+
EventHelper.QueueEventIfNotNull(ConfigurationUpdated, this, EventArgs.Empty, Logger);
}
@@ -124,8 +129,40 @@ namespace MediaBrowser.Common.Implementations.Configuration
throw new ArgumentNullException("newConfiguration");
}
+ ValidateCachePath(newConfiguration);
+
CommonConfiguration = newConfiguration;
SaveConfiguration();
}
+
+ /// <summary>
+ /// Updates the items by name path.
+ /// </summary>
+ private void UpdateCachePath()
+ {
+ ((BaseApplicationPaths)CommonApplicationPaths).CachePath = string.IsNullOrEmpty(CommonConfiguration.CachePath) ?
+ null :
+ CommonConfiguration.CachePath;
+ }
+
+ /// <summary>
+ /// Replaces the cache path.
+ /// </summary>
+ /// <param name="newConfig">The new configuration.</param>
+ /// <exception cref="System.IO.DirectoryNotFoundException"></exception>
+ private void ValidateCachePath(BaseApplicationConfiguration newConfig)
+ {
+ var newPath = newConfig.CachePath;
+
+ if (!string.IsNullOrWhiteSpace(newPath)
+ && !string.Equals(CommonConfiguration.CachePath ?? string.Empty, newPath))
+ {
+ // Validate
+ if (!Directory.Exists(newPath))
+ {
+ throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath));
+ }
+ }
+ }
}
}
diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
index 19091885d..b5317319f 100644
--- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
+++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs
@@ -445,6 +445,8 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager
{
ValidateParams(options.Url, options.CancellationToken);
+ Directory.CreateDirectory(_appPaths.TempDirectory);
+
var tempFile = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".tmp");
if (options.Progress == null)