make common project portable

This commit is contained in:
Luke Pulverenti
2016-10-23 19:49:13 -04:00
parent abc5a2eabd
commit 2af3ec43d5
6 changed files with 18548 additions and 64 deletions

View File

@@ -61,8 +61,17 @@ namespace MediaBrowser.Common.Plugins
AssemblyFileName = assemblyFileName;
Version = assemblyVersion;
Id = assemblyId;
}
IsFirstRun = !File.Exists(ConfigurationFilePath);
private Func<string, DateTime> _dateModifiedFn;
private Action<string> _directoryCreateFn;
public void SetStartupInfo(bool isFirstRun, Func<string, DateTime> dateModifiedFn, Action<string> directoryCreateFn)
{
IsFirstRun = isFirstRun;
// hack alert, until the .net core transition is complete
_dateModifiedFn = dateModifiedFn;
_directoryCreateFn = directoryCreateFn;
}
/// <summary>
@@ -94,7 +103,7 @@ namespace MediaBrowser.Common.Plugins
// Ensure it's been lazy loaded
var config = Configuration;
return File.GetLastWriteTimeUtc(ConfigurationFilePath);
return _dateModifiedFn(ConfigurationFilePath);
}
}
@@ -147,14 +156,6 @@ namespace MediaBrowser.Common.Plugins
{
return (TConfigurationType)XmlSerializer.DeserializeFromFile(typeof(TConfigurationType), path);
}
catch (DirectoryNotFoundException)
{
return (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType));
}
catch (FileNotFoundException)
{
return (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType));
}
catch
{
return (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType));
@@ -182,10 +183,6 @@ namespace MediaBrowser.Common.Plugins
}
}
/// <summary>
/// The _data folder path
/// </summary>
private string _dataFolderPath;
/// <summary>
/// Gets the full path to the data folder, where the plugin can store any miscellaneous files needed
/// </summary>
@@ -194,16 +191,9 @@ namespace MediaBrowser.Common.Plugins
{
get
{
if (_dataFolderPath == null)
{
// Give the folder name the same name as the config file name
// We can always make this configurable if/when needed
_dataFolderPath = Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(ConfigurationFileName));
Directory.CreateDirectory(_dataFolderPath);
}
return _dataFolderPath;
// Give the folder name the same name as the config file name
// We can always make this configurable if/when needed
return Path.Combine(ApplicationPaths.PluginsPath, Path.GetFileNameWithoutExtension(ConfigurationFileName));
}
}
@@ -230,7 +220,7 @@ namespace MediaBrowser.Common.Plugins
{
lock (_configurationSaveLock)
{
Directory.CreateDirectory(Path.GetDirectoryName(ConfigurationFilePath));
_directoryCreateFn(Path.GetDirectoryName(ConfigurationFilePath));
XmlSerializer.SerializeToFile(Configuration, ConfigurationFilePath);
}