[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove code for pre-installed plugins & properly check if file exists #740

Merged
merged 2 commits into from
Jan 27, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Remove code for pre-installed plugins
  • Loading branch information
Bond-009 committed Jan 27, 2019
commit 1a3543e5a5984d4ec5284f43b7df63a9d19c8a9c
75 changes: 1 addition & 74 deletions Emby.Server.Implementations/ApplicationHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ public void Restart()
/// <returns>IEnumerable{Assembly}.</returns>
protected List<Tuple<Assembly, string>> GetComposablePartAssemblies()
{
var list = GetPluginAssemblies();
var list = GetPluginAssemblies(ApplicationPaths.PluginsPath);

// Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that
// This will prevent the .dll file from getting locked, and allow us to replace it when needed
Expand Down Expand Up @@ -1615,79 +1615,6 @@ protected List<Tuple<Assembly, string>> GetComposablePartAssemblies()

protected abstract IEnumerable<Assembly> GetAssembliesWithPartsInternal();

/// <summary>
/// Gets the plugin assemblies.
/// </summary>
/// <returns>IEnumerable{Assembly}.</returns>
private List<Tuple<Assembly, string>> GetPluginAssemblies()
{
// Copy pre-installed plugins
var sourcePath = Path.Combine(ApplicationPaths.ApplicationResourcesPath, "plugins");
CopyPlugins(sourcePath, ApplicationPaths.PluginsPath);

return GetPluginAssemblies(ApplicationPaths.PluginsPath);
}

private void CopyPlugins(string source, string target)
{
List<string> files;

try
{
files = Directory.EnumerateFiles(source, "*.dll", SearchOption.TopDirectoryOnly)
.ToList();

}
catch (DirectoryNotFoundException)
{
return;
}

if (files.Count == 0)
{
return;
}

foreach (var sourceFile in files)
{
var filename = Path.GetFileName(sourceFile);
var targetFile = Path.Combine(target, filename);

var targetFileExists = File.Exists(targetFile);

if (!targetFileExists && ServerConfigurationManager.Configuration.UninstalledPlugins.Contains(filename, StringComparer.OrdinalIgnoreCase))
{
continue;
}

if (targetFileExists && GetDllVersion(targetFile) >= GetDllVersion(sourceFile))
{
continue;
}

Directory.CreateDirectory(target);
File.Copy(sourceFile, targetFile, true);
}
}

private Version GetDllVersion(string path)
{
try
{
var result = Version.Parse(FileVersionInfo.GetVersionInfo(path).FileVersion);

Logger.LogInformation("File {Path} has version {Version}", path, result);

return result;
}
catch (Exception ex)
{
Logger.LogError(ex, "Error getting version number from {Path}", path);

return new Version(1, 0);
}
}

private List<Tuple<Assembly, string>> GetPluginAssemblies(string path)
{
try
Expand Down