don't persist lazy loaded paths

This commit is contained in:
Luke Pulverenti
2013-12-29 12:07:29 -05:00
parent 30b29f63c4
commit 04d1a53d19
12 changed files with 61 additions and 145 deletions

View File

@@ -140,10 +140,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>
@@ -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));

View File

@@ -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();

View File

@@ -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;

View File

@@ -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);
}
}
}