make common project portable

pull/702/head
Luke Pulverenti 8 years ago
parent abc5a2eabd
commit 2af3ec43d5

@ -462,6 +462,10 @@ namespace MediaBrowser.Common.Implementations
assemblyPlugin.SetAttributes(assemblyFilePath, assemblyFileName, assemblyName.Version, assemblyId); assemblyPlugin.SetAttributes(assemblyFilePath, assemblyFileName, assemblyName.Version, assemblyId);
} }
var isFirstRun = !File.Exists(plugin.ConfigurationFilePath);
plugin.SetStartupInfo(isFirstRun, File.GetLastWriteTimeUtc, s => Directory.CreateDirectory(s));
} }
catch (Exception ex) catch (Exception ex)
{ {

@ -13,8 +13,11 @@
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<ProductVersion>10.0.0</ProductVersion> <ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkProfile /> <TargetFrameworkProfile>
</TargetFrameworkProfile>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@ -42,11 +45,6 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\SharedVersion.cs"> <Compile Include="..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link> <Link>Properties\SharedVersion.cs</Link>
@ -83,8 +81,10 @@
<Name>MediaBrowser.Model</Name> <Name>MediaBrowser.Model</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <None Include="project.json" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent /> <PostBuildEvent />
</PropertyGroup> </PropertyGroup>

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

@ -104,5 +104,7 @@ namespace MediaBrowser.Common.Plugins
/// Called when just before the plugin is uninstalled from the server. /// Called when just before the plugin is uninstalled from the server.
/// </summary> /// </summary>
void OnUninstalling(); void OnUninstalling();
void SetStartupInfo(bool isFirstRun, Func<string, DateTime> dateModifiedFn, Action<string> directoryCreateFn);
} }
} }

@ -0,0 +1,16 @@
{
"supports": {
"net46.app": {},
"uwp.10.0.app": {},
"dnxcore50.app": {}
},
"dependencies": {
"Microsoft.NETCore": "5.0.0",
"Microsoft.NETCore.Portable.Compatibility": "1.0.0"
},
"frameworks": {
"dotnet": {
"imports": "portable-net452+win81"
}
}
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save