aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common.Implementations
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-12-29 12:07:29 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-12-29 12:07:29 -0500
commit04d1a53d199bbf5fced102daae77b3ef0d64474d (patch)
tree59a6e7c153187bb2bd163edd55364d06f619838c /MediaBrowser.Common.Implementations
parent30b29f63c470eb0e92c53ad7df67d6bcf8a25914 (diff)
don't persist lazy loaded paths
Diffstat (limited to 'MediaBrowser.Common.Implementations')
-rw-r--r--MediaBrowser.Common.Implementations/BaseApplicationPaths.cs13
-rw-r--r--MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs6
-rw-r--r--MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs40
-rw-r--r--MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs20
4 files changed, 34 insertions, 45 deletions
diff --git a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs
index 213942c9d..668b1395d 100644
--- a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs
+++ b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs
@@ -141,10 +141,6 @@ namespace MediaBrowser.Common.Implementations
}
/// <summary>
- /// The _configuration directory path
- /// </summary>
- private string _configurationDirectoryPath;
- /// <summary>
/// Gets the path to the application configuration root directory
/// </summary>
/// <value>The configuration directory path.</value>
@@ -152,12 +148,7 @@ namespace MediaBrowser.Common.Implementations
{
get
{
- if (_configurationDirectoryPath == null)
- {
- _configurationDirectoryPath = Path.Combine(ProgramDataPath, "config");
- Directory.CreateDirectory(_configurationDirectoryPath);
- }
- return _configurationDirectoryPath;
+ return Path.Combine(ProgramDataPath, "config");
}
}
@@ -218,7 +209,7 @@ namespace MediaBrowser.Common.Implementations
/// <returns>System.String.</returns>
private string GetProgramDataPath()
{
- var programDataPath = _useDebugPath ? ConfigurationManager.AppSettings["DebugProgramDataPath"] : Path.Combine(ConfigurationManager.AppSettings["ReleaseProgramDataPath"], ConfigurationManager.AppSettings["ProgramDataFolderName"]);
+ var programDataPath = _useDebugPath ? ConfigurationManager.AppSettings["DebugProgramDataPath"] : ConfigurationManager.AppSettings["ReleaseProgramDataPath"];
programDataPath = programDataPath.Replace("%ApplicationData%", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
diff --git a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs
index 3c00673ba..8c4840ea7 100644
--- a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs
+++ b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs
@@ -99,9 +99,13 @@ namespace MediaBrowser.Common.Implementations.Configuration
/// </summary>
public void SaveConfiguration()
{
+ var path = CommonApplicationPaths.SystemConfigurationFilePath;
+
+ Directory.CreateDirectory(Path.GetDirectoryName(path));
+
lock (_configurationSaveLock)
{
- XmlSerializer.SerializeToFile(CommonConfiguration, CommonApplicationPaths.SystemConfigurationFilePath);
+ XmlSerializer.SerializeToFile(CommonConfiguration, path);
}
OnConfigurationUpdated();
diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs
index 2406d0470..477dc4aee 100644
--- a/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs
+++ b/MediaBrowser.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs
@@ -121,7 +121,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
{
LazyInitializer.EnsureInitialized(ref _lastExecutionResult, ref _lastExecutionResultinitialized, ref _lastExecutionResultSyncLock, () =>
{
- var path = GetHistoryFilePath(false);
+ var path = GetHistoryFilePath();
try
{
@@ -432,43 +432,28 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
/// <summary>
/// Gets the scheduled tasks configuration directory.
/// </summary>
- /// <param name="create">if set to <c>true</c> [create].</param>
/// <returns>System.String.</returns>
- private string GetScheduledTasksConfigurationDirectory(bool create)
+ private string GetScheduledTasksConfigurationDirectory()
{
- var path = Path.Combine(ApplicationPaths.ConfigurationDirectoryPath, "ScheduledTasks");
-
- if (create)
- {
- Directory.CreateDirectory(path);
- }
-
- return path;
+ return Path.Combine(ApplicationPaths.ConfigurationDirectoryPath, "ScheduledTasks");
}
/// <summary>
/// Gets the scheduled tasks data directory.
/// </summary>
- /// <param name="create">if set to <c>true</c> [create].</param>
/// <returns>System.String.</returns>
- private string GetScheduledTasksDataDirectory(bool create)
+ private string GetScheduledTasksDataDirectory()
{
- var path = Path.Combine(ApplicationPaths.DataPath, "ScheduledTasks");
-
- if (create)
- {
- Directory.CreateDirectory(path);
- }
- return path;
+ return Path.Combine(ApplicationPaths.DataPath, "ScheduledTasks");
}
/// <summary>
/// Gets the history file path.
/// </summary>
/// <value>The history file path.</value>
- private string GetHistoryFilePath(bool createDirectory)
+ private string GetHistoryFilePath()
{
- return Path.Combine(GetScheduledTasksDataDirectory(createDirectory), Id + ".js");
+ return Path.Combine(GetScheduledTasksDataDirectory(), Id + ".js");
}
/// <summary>
@@ -477,7 +462,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
/// <returns>System.String.</returns>
private string GetConfigurationFilePath()
{
- return Path.Combine(GetScheduledTasksConfigurationDirectory(false), Id + ".js");
+ return Path.Combine(GetScheduledTasksConfigurationDirectory(), Id + ".js");
}
/// <summary>
@@ -512,9 +497,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
{
var path = GetConfigurationFilePath();
- var parentPath = Path.GetDirectoryName(path);
-
- Directory.CreateDirectory(parentPath);
+ Directory.CreateDirectory(Path.GetDirectoryName(path));
JsonSerializer.SerializeToFile(triggers.Select(ScheduledTaskHelpers.GetTriggerInfo), path);
}
@@ -545,7 +528,10 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
result.ErrorMessage = ex.Message;
}
- JsonSerializer.SerializeToFile(result, GetHistoryFilePath(true));
+ var path = GetHistoryFilePath();
+ Directory.CreateDirectory(Path.GetDirectoryName(path));
+
+ JsonSerializer.SerializeToFile(result, path);
LastExecutionResult = result;
diff --git a/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs b/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs
index 163a368bf..c5d5f28d6 100644
--- a/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs
+++ b/MediaBrowser.Common.Implementations/Security/MBLicenseFile.cs
@@ -11,7 +11,6 @@ namespace MediaBrowser.Common.Implementations.Security
{
private readonly IApplicationPaths _appPaths;
- private readonly string _filename;
public string RegKey
{
get { return _regKey; }
@@ -26,6 +25,14 @@ namespace MediaBrowser.Common.Implementations.Security
}
}
+ private string Filename
+ {
+ get
+ {
+ return Path.Combine(_appPaths.ConfigurationDirectoryPath, "mb.lic");
+ }
+ }
+
public string LegacyKey { get; set; }
private Dictionary<Guid, DateTime> UpdateRecords { get; set; }
private readonly object _lck = new object();
@@ -35,8 +42,6 @@ namespace MediaBrowser.Common.Implementations.Security
{
_appPaths = appPaths;
- _filename = Path.Combine(_appPaths.ConfigurationDirectoryPath, "mb.lic");
-
UpdateRecords = new Dictionary<Guid, DateTime>();
Load();
}
@@ -64,15 +69,16 @@ namespace MediaBrowser.Common.Implementations.Security
private void Load()
{
string[] contents = null;
+ var licenseFile = Filename;
lock (_lck)
{
try
{
- contents = File.ReadAllLines(_filename);
+ contents = File.ReadAllLines(licenseFile);
}
catch (FileNotFoundException)
{
- (File.Create(_filename)).Close();
+ (File.Create(licenseFile)).Close();
}
}
if (contents != null && contents.Length > 0)
@@ -100,7 +106,9 @@ namespace MediaBrowser.Common.Implementations.Security
lines.Add(pair.Value.Ticks.ToString());
}
- lock(_lck) File.WriteAllLines(_filename, lines);
+ var licenseFile = Filename;
+ Directory.CreateDirectory(Path.GetDirectoryName(licenseFile));
+ lock (_lck) File.WriteAllLines(licenseFile, lines);
}
}
}