From a041fe8a2dc03790b8b56a01bb2c1d2c9fd9d690 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Sun, 21 Jun 2020 13:29:35 +0100 Subject: [PATCH 01/34] Add versioning to plugin folders --- .../ApplicationHost.cs | 98 ++++++++++++++++++- .../Updates/InstallationManager.cs | 33 +++++-- 2 files changed, 123 insertions(+), 8 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 23f0571a1d..a3f76470f5 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1008,6 +1008,102 @@ namespace Emby.Server.Implementations protected abstract void RestartInternal(); + /// + /// Converts an string array to a number. + /// Element 0 is the filename. + /// + /// Parts of the filename. + /// Long representing the version of the file. + private long StrToVersion(string[] version) + { + if (version.Length > 4) + { + Logger.LogError("Plugin version number too complex : {0}.", version[0]); + return -1; + } + + // Build version into a string. 1.2.3.4 => 001002003004 (max 999999999999 + string res = string.Empty; + for (int x = 1; x <= version.Length; x++) + { + res += version[1].PadLeft(3 - version[1].Length, '0'); + } + + return long.Parse(res, CultureInfo.InvariantCulture); + } + + /// + /// Only loads the latest version of each assembly based upon the folder name. + /// eg. MyAssembly 11.9.3.6 - will be ignored. + /// MyAssembly 12.2.3.6 - will be loaded. + /// + /// Path to enumerate. + /// Set to true, to try and clean up earlier versions. + /// IEnumerable{string} of filenames. + protected IEnumerable GetLatestDLLVersion(string path, bool cleanup = false) + { + var dllList = new List(); + var versions = new SortedList(); + var directories = Directory.EnumerateDirectories(path, "*.*", SearchOption.TopDirectoryOnly).ToList(); + var folder = string.Empty; + + // Only add the latest version of the folder into the list. + foreach (var dir in directories) + { + string[] parts = dir.Split("."); + + if (parts.Length == 1) + { + dllList.AddRange(Directory.EnumerateFiles(dir, "*.dll", SearchOption.AllDirectories).ToList()); + } + else + { + // Add for version comparison later. + versions.Add(StrToVersion(parts), parts[0]); + } + } + + if (versions.Count > 0) + { + string lastName = string.Empty; + + // Traverse backwards through the list. + // The first item will be the latest version. + for (int x = versions.Count - 1; x > 0; x--) + { + folder = versions.Values[x]; + if (!string.Equals(lastName, folder, StringComparison.OrdinalIgnoreCase)) + { + dllList.AddRange(Directory.EnumerateFiles(path + "\\" + folder, "*.dll", SearchOption.AllDirectories)); + lastName = folder; + continue; + } + + if (!string.IsNullOrEmpty(lastName) && cleanup) + { + // Attempt a cleanup of old folders. + try + { + Logger.LogDebug("Attempting to delete {0}", path + "\\" + folder); + Directory.Delete(path + "\\" + folder); + } + catch + { + // Ignore errors. + } + } + } + + folder = versions.Values[0]; + if (!string.Equals(lastName, folder, StringComparison.OrdinalIgnoreCase)) + { + dllList.AddRange(Directory.EnumerateFiles(path + "\\" + folder, "*.dll", SearchOption.AllDirectories)); + } + } + + return dllList; + } + /// /// Gets the composable part assemblies. /// @@ -1016,7 +1112,7 @@ namespace Emby.Server.Implementations { if (Directory.Exists(ApplicationPaths.PluginsPath)) { - foreach (var file in Directory.EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.AllDirectories)) + foreach (var file in GetLatestDLLVersion(ApplicationPaths.PluginsPath)) { Assembly plugAss; try diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index 80326fddf2..229e0338c0 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -16,6 +16,7 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Net; using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Updates; +using MediaBrowser.Common.System; using MediaBrowser.Controller.Configuration; using MediaBrowser.Model.Events; using MediaBrowser.Model.IO; @@ -23,6 +24,7 @@ using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Updates; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; +using MediaBrowser.Model.System; namespace Emby.Server.Implementations.Updates { @@ -384,9 +386,19 @@ namespace Emby.Server.Implementations.Updates throw new InvalidDataException("The checksum of the received data doesn't match."); } + // Version folder as they cannot be overwritten in Windows. + targetDir += package.Version.ToString(); + if (Directory.Exists(targetDir)) { - Directory.Delete(targetDir, true); + try + { + Directory.Delete(targetDir, true); + } + catch + { + // Ignore any exceptions. + } } stream.Position = 0; @@ -425,15 +437,22 @@ namespace Emby.Server.Implementations.Updates path = file; } - if (isDirectory) + try { - _logger.LogInformation("Deleting plugin directory {0}", path); - Directory.Delete(path, true); + if (isDirectory) + { + _logger.LogInformation("Deleting plugin directory {0}", path); + Directory.Delete(path, true); + } + else + { + _logger.LogInformation("Deleting plugin file {0}", path); + _fileSystem.DeleteFile(path); + } } - else + catch { - _logger.LogInformation("Deleting plugin file {0}", path); - _fileSystem.DeleteFile(path); + // Ignore file errors. } var list = _config.Configuration.UninstalledPlugins.ToList(); From 99410f3c975dbcce44b6cdec2e17e9a8d67db30e Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Sun, 21 Jun 2020 16:15:55 +0100 Subject: [PATCH 02/34] fixes --- .../ApplicationHost.cs | 71 ++++++++++++++----- .../Updates/InstallationManager.cs | 2 +- 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index a3f76470f5..cbd9f7154a 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1013,25 +1013,62 @@ namespace Emby.Server.Implementations /// Element 0 is the filename. /// /// Parts of the filename. + /// Returns the folder name including any periods. eg. vs /// Long representing the version of the file. - private long StrToVersion(string[] version) + private long StrToVersion(string[] version, out string foldername) { - if (version.Length > 4) + if (version.Length > 5) { Logger.LogError("Plugin version number too complex : {0}.", version[0]); - return -1; + foldername = string.Join('.', version); + return 0; } - // Build version into a string. 1.2.3.4 => 001002003004 (max 999999999999 - string res = string.Empty; - for (int x = 1; x <= version.Length; x++) + foldername = string.Empty; + int start = 0; + do { - res += version[1].PadLeft(3 - version[1].Length, '0'); + foldername += "." + version[start]; + start++; + } + while (start < version.Length && !int.TryParse(version[start], out _)); + foldername = foldername.TrimStart('.'); + + if (start == version.Length) + { + // No valid version number. + return 0; + } + + // Build version into a string. 1.2.3.4 => 001002003004 (max 999999999999). + string res = string.Empty; + for (int x = start; x < version.Length; x++) + { + res += version[x].PadLeft(4 - version[x].Length, '0'); } return long.Parse(res, CultureInfo.InvariantCulture); } + private static int VersionCompare(Tuple a, Tuple b) + { + int compare = string.Compare(a.Item2, b.Item2, false, CultureInfo.InvariantCulture); + + if (compare == 0) + { + if (a.Item1 > b.Item1) + { + return 1; + } + + return -1; + + } + + return compare; + + } + /// /// Only loads the latest version of each assembly based upon the folder name. /// eg. MyAssembly 11.9.3.6 - will be ignored. @@ -1043,7 +1080,8 @@ namespace Emby.Server.Implementations protected IEnumerable GetLatestDLLVersion(string path, bool cleanup = false) { var dllList = new List(); - var versions = new SortedList(); + var versions = new List>(); + var directories = Directory.EnumerateDirectories(path, "*.*", SearchOption.TopDirectoryOnly).ToList(); var folder = string.Empty; @@ -1058,23 +1096,24 @@ namespace Emby.Server.Implementations } else { + long id = StrToVersion(parts, out string foldername); // Add for version comparison later. - versions.Add(StrToVersion(parts), parts[0]); + versions.Add(Tuple.Create(id, foldername, dir)); } } if (versions.Count > 0) { string lastName = string.Empty; - + versions.Sort(VersionCompare); // Traverse backwards through the list. // The first item will be the latest version. for (int x = versions.Count - 1; x > 0; x--) { - folder = versions.Values[x]; + folder = versions[x].Item2; if (!string.Equals(lastName, folder, StringComparison.OrdinalIgnoreCase)) { - dllList.AddRange(Directory.EnumerateFiles(path + "\\" + folder, "*.dll", SearchOption.AllDirectories)); + dllList.AddRange(Directory.EnumerateFiles(folder, "*.dll", SearchOption.AllDirectories)); lastName = folder; continue; } @@ -1084,8 +1123,8 @@ namespace Emby.Server.Implementations // Attempt a cleanup of old folders. try { - Logger.LogDebug("Attempting to delete {0}", path + "\\" + folder); - Directory.Delete(path + "\\" + folder); + Logger.LogDebug("Attempting to delete {0}", folder); + Directory.Delete(folder); } catch { @@ -1094,10 +1133,10 @@ namespace Emby.Server.Implementations } } - folder = versions.Values[0]; + folder = versions[0].Item2; if (!string.Equals(lastName, folder, StringComparison.OrdinalIgnoreCase)) { - dllList.AddRange(Directory.EnumerateFiles(path + "\\" + folder, "*.dll", SearchOption.AllDirectories)); + dllList.AddRange(Directory.EnumerateFiles(folder, "*.dll", SearchOption.AllDirectories)); } } diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index 229e0338c0..b6cd5a6336 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -387,7 +387,7 @@ namespace Emby.Server.Implementations.Updates } // Version folder as they cannot be overwritten in Windows. - targetDir += package.Version.ToString(); + targetDir += "." + package.Version.ToString(); if (Directory.Exists(targetDir)) { From d89c46f1a97b436bae0a39816cab71f8d09ad3c3 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Sun, 21 Jun 2020 17:11:21 +0100 Subject: [PATCH 03/34] fixes --- .../ApplicationHost.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index cbd9f7154a..ce907c3cec 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1083,8 +1083,7 @@ namespace Emby.Server.Implementations var versions = new List>(); var directories = Directory.EnumerateDirectories(path, "*.*", SearchOption.TopDirectoryOnly).ToList(); - var folder = string.Empty; - + // Only add the latest version of the folder into the list. foreach (var dir in directories) { @@ -1110,11 +1109,10 @@ namespace Emby.Server.Implementations // The first item will be the latest version. for (int x = versions.Count - 1; x > 0; x--) { - folder = versions[x].Item2; - if (!string.Equals(lastName, folder, StringComparison.OrdinalIgnoreCase)) + if (!string.Equals(lastName, versions[x].Item2, StringComparison.OrdinalIgnoreCase)) { - dllList.AddRange(Directory.EnumerateFiles(folder, "*.dll", SearchOption.AllDirectories)); - lastName = folder; + dllList.AddRange(Directory.EnumerateFiles(versions[x].Item3, "*.dll", SearchOption.AllDirectories)); + lastName = versions[x].Item2; continue; } @@ -1123,8 +1121,8 @@ namespace Emby.Server.Implementations // Attempt a cleanup of old folders. try { - Logger.LogDebug("Attempting to delete {0}", folder); - Directory.Delete(folder); + Logger.LogDebug("Attempting to delete {0}", versions[x].Item3); + Directory.Delete(versions[x].Item3); } catch { @@ -1133,10 +1131,9 @@ namespace Emby.Server.Implementations } } - folder = versions[0].Item2; - if (!string.Equals(lastName, folder, StringComparison.OrdinalIgnoreCase)) + if (!string.Equals(lastName, versions[0].Item2, StringComparison.OrdinalIgnoreCase)) { - dllList.AddRange(Directory.EnumerateFiles(folder, "*.dll", SearchOption.AllDirectories)); + dllList.AddRange(Directory.EnumerateFiles(versions[0].Item3, "*.dll", SearchOption.AllDirectories)); } } From 2255bc98722e57e77e191d08b1485372c1e9a400 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Sun, 21 Jun 2020 18:42:50 +0100 Subject: [PATCH 04/34] Changed padding in version numbers based up how they are stored in the repository. --- Emby.Server.Implementations/ApplicationHost.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index ce907c3cec..22a67b10cf 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1040,11 +1040,16 @@ namespace Emby.Server.Implementations return 0; } - // Build version into a string. 1.2.3.4 => 001002003004 (max 999999999999). + // Build version into a string. 1.2.3.4 => 001002003004, 2.1 -> 200100000000. string res = string.Empty; for (int x = start; x < version.Length; x++) { - res += version[x].PadLeft(4 - version[x].Length, '0'); + res += version[x].PadLeft(3, '0'); + } + + if (res.Length < 12) + { + res = res.PadRight(12, '0'); } return long.Parse(res, CultureInfo.InvariantCulture); @@ -1083,11 +1088,11 @@ namespace Emby.Server.Implementations var versions = new List>(); var directories = Directory.EnumerateDirectories(path, "*.*", SearchOption.TopDirectoryOnly).ToList(); - + // Only add the latest version of the folder into the list. foreach (var dir in directories) { - string[] parts = dir.Split("."); + string[] parts = dir.Replace('_', '.').Split("."); if (parts.Length == 1) { From bf1bbbdd3e72657d0e36a7a2b80c89d03fc40ba8 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Sun, 21 Jun 2020 18:46:48 +0100 Subject: [PATCH 05/34] Changed sorting to case insensitive --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 22a67b10cf..830581d192 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1057,7 +1057,7 @@ namespace Emby.Server.Implementations private static int VersionCompare(Tuple a, Tuple b) { - int compare = string.Compare(a.Item2, b.Item2, false, CultureInfo.InvariantCulture); + int compare = string.Compare(a.Item2, b.Item2, true, CultureInfo.InvariantCulture); if (compare == 0) { From a25a233b75df380d87f1fdca8738b32938095ab4 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Mon, 22 Jun 2020 11:57:46 +0100 Subject: [PATCH 06/34] Using Version class. --- .../ApplicationHost.cs | 130 +++++------------- .../Updates/InstallationManager.cs | 2 +- 2 files changed, 35 insertions(+), 97 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 830581d192..9d452250d8 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1009,136 +1009,74 @@ namespace Emby.Server.Implementations protected abstract void RestartInternal(); /// - /// Converts an string array to a number. - /// Element 0 is the filename. + /// Comparison function used in <. /// - /// Parts of the filename. - /// Returns the folder name including any periods. eg. vs - /// Long representing the version of the file. - private long StrToVersion(string[] version, out string foldername) - { - if (version.Length > 5) - { - Logger.LogError("Plugin version number too complex : {0}.", version[0]); - foldername = string.Join('.', version); - return 0; - } - - foldername = string.Empty; - int start = 0; - do - { - foldername += "." + version[start]; - start++; - } - while (start < version.Length && !int.TryParse(version[start], out _)); - foldername = foldername.TrimStart('.'); - - if (start == version.Length) - { - // No valid version number. - return 0; - } - - // Build version into a string. 1.2.3.4 => 001002003004, 2.1 -> 200100000000. - string res = string.Empty; - for (int x = start; x < version.Length; x++) - { - res += version[x].PadLeft(3, '0'); - } - - if (res.Length < 12) - { - res = res.PadRight(12, '0'); - } - - return long.Parse(res, CultureInfo.InvariantCulture); - } - - private static int VersionCompare(Tuple a, Tuple b) + private static int VersionCompare(Tuple a, Tuple b) { int compare = string.Compare(a.Item2, b.Item2, true, CultureInfo.InvariantCulture); if (compare == 0) { - if (a.Item1 > b.Item1) - { - return 1; - } - - return -1; - + return a.Item1.CompareTo(b.Item1); } return compare; - } /// /// Only loads the latest version of each assembly based upon the folder name. - /// eg. MyAssembly 11.9.3.6 - will be ignored. - /// MyAssembly 12.2.3.6 - will be loaded. + /// eg. MyAssembly_11.9.3.6 - will be ignored. + /// MyAssembly_12.2.3.6 - will be loaded. /// /// Path to enumerate. /// Set to true, to try and clean up earlier versions. /// IEnumerable{string} of filenames. - protected IEnumerable GetLatestDLLVersion(string path, bool cleanup = false) + protected IEnumerable GetLatestDLLVersion(string path, bool cleanup = true) { var dllList = new List(); - var versions = new List>(); + var versions = new List>(); + var directories = Directory.EnumerateDirectories(path, "*.*", SearchOption.TopDirectoryOnly); - var directories = Directory.EnumerateDirectories(path, "*.*", SearchOption.TopDirectoryOnly).ToList(); - - // Only add the latest version of the folder into the list. foreach (var dir in directories) { - string[] parts = dir.Replace('_', '.').Split("."); - - if (parts.Length == 1) + int p = dir.LastIndexOf('_'); + if (p != -1 && Version.TryParse(dir.Substring(p + 1), out Version ver)) { - dllList.AddRange(Directory.EnumerateFiles(dir, "*.dll", SearchOption.AllDirectories).ToList()); + // Versioned folder. + versions.Add(Tuple.Create(ver, dir.Substring(0, p), dir)); } else { - long id = StrToVersion(parts, out string foldername); - // Add for version comparison later. - versions.Add(Tuple.Create(id, foldername, dir)); + // Un-versioned folder. + versions.Add(Tuple.Create(new Version(), dir, dir)); } } - if (versions.Count > 0) + string lastName = string.Empty; + versions.Sort(VersionCompare); + // Traverse backwards through the list. + // The first item will be the latest version. + for (int x = versions.Count - 1; x >= 0; x--) { - string lastName = string.Empty; - versions.Sort(VersionCompare); - // Traverse backwards through the list. - // The first item will be the latest version. - for (int x = versions.Count - 1; x > 0; x--) + if (!string.Equals(lastName, versions[x].Item2, StringComparison.OrdinalIgnoreCase)) { - if (!string.Equals(lastName, versions[x].Item2, StringComparison.OrdinalIgnoreCase)) - { - dllList.AddRange(Directory.EnumerateFiles(versions[x].Item3, "*.dll", SearchOption.AllDirectories)); - lastName = versions[x].Item2; - continue; - } - - if (!string.IsNullOrEmpty(lastName) && cleanup) - { - // Attempt a cleanup of old folders. - try - { - Logger.LogDebug("Attempting to delete {0}", versions[x].Item3); - Directory.Delete(versions[x].Item3); - } - catch - { - // Ignore errors. - } - } + dllList.AddRange(Directory.EnumerateFiles(versions[x].Item3, "*.dll", SearchOption.AllDirectories)); + lastName = versions[x].Item2; + continue; } - if (!string.Equals(lastName, versions[0].Item2, StringComparison.OrdinalIgnoreCase)) + if (!string.IsNullOrEmpty(lastName) && cleanup) { - dllList.AddRange(Directory.EnumerateFiles(versions[0].Item3, "*.dll", SearchOption.AllDirectories)); + // Attempt a cleanup of old folders. + try + { + Logger.LogDebug("Attempting to delete {0}", versions[x].Item3); + Directory.Delete(versions[x].Item3, true); + } + catch + { + // Ignore errors. + } } } diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index b6cd5a6336..1fa71e6739 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -387,7 +387,7 @@ namespace Emby.Server.Implementations.Updates } // Version folder as they cannot be overwritten in Windows. - targetDir += "." + package.Version.ToString(); + targetDir += "_" + package.Version.ToString(); if (Directory.Exists(targetDir)) { From ba3a9f7d466a84040b53399fbc3ae1673b7466ac Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Mon, 22 Jun 2020 12:14:31 +0100 Subject: [PATCH 07/34] removing stray < character from description. --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 9d452250d8..ae6a82e8b9 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1009,7 +1009,7 @@ namespace Emby.Server.Implementations protected abstract void RestartInternal(); /// - /// Comparison function used in <. + /// Comparison function used in . /// private static int VersionCompare(Tuple a, Tuple b) { From e33824d28667df0344420d42032fbb01e9f8f659 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Sat, 5 Sep 2020 20:20:15 +0100 Subject: [PATCH 08/34] Changed to named tuples --- .../ApplicationHost.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index ae6a82e8b9..1e298042c5 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1011,13 +1011,15 @@ namespace Emby.Server.Implementations /// /// Comparison function used in . /// - private static int VersionCompare(Tuple a, Tuple b) + private static int VersionCompare( + (Version PluginVersion, string Name, string Path) a, + (Version PluginVersion, string Name, string Path) b) { - int compare = string.Compare(a.Item2, b.Item2, true, CultureInfo.InvariantCulture); + int compare = string.Compare(a.Name, b.Name, true, CultureInfo.InvariantCulture); if (compare == 0) { - return a.Item1.CompareTo(b.Item1); + return a.PluginVersion.CompareTo(b.PluginVersion); } return compare; @@ -1034,7 +1036,7 @@ namespace Emby.Server.Implementations protected IEnumerable GetLatestDLLVersion(string path, bool cleanup = true) { var dllList = new List(); - var versions = new List>(); + var versions = new List<(Version PluginVersion, string Name, string Path)>(); var directories = Directory.EnumerateDirectories(path, "*.*", SearchOption.TopDirectoryOnly); foreach (var dir in directories) @@ -1043,12 +1045,12 @@ namespace Emby.Server.Implementations if (p != -1 && Version.TryParse(dir.Substring(p + 1), out Version ver)) { // Versioned folder. - versions.Add(Tuple.Create(ver, dir.Substring(0, p), dir)); + versions.Add((ver, dir.Substring(0, p), dir)); } else { // Un-versioned folder. - versions.Add(Tuple.Create(new Version(), dir, dir)); + versions.Add((new Version(), dir, dir)); } } @@ -1058,10 +1060,10 @@ namespace Emby.Server.Implementations // The first item will be the latest version. for (int x = versions.Count - 1; x >= 0; x--) { - if (!string.Equals(lastName, versions[x].Item2, StringComparison.OrdinalIgnoreCase)) + if (!string.Equals(lastName, versions[x].Name, StringComparison.OrdinalIgnoreCase)) { - dllList.AddRange(Directory.EnumerateFiles(versions[x].Item3, "*.dll", SearchOption.AllDirectories)); - lastName = versions[x].Item2; + dllList.AddRange(Directory.EnumerateFiles(versions[x].Path, "*.dll", SearchOption.AllDirectories)); + lastName = versions[x].Name; continue; } @@ -1070,8 +1072,8 @@ namespace Emby.Server.Implementations // Attempt a cleanup of old folders. try { - Logger.LogDebug("Attempting to delete {0}", versions[x].Item3); - Directory.Delete(versions[x].Item3, true); + Logger.LogDebug("Attempting to delete {0}", versions[x].Path); + Directory.Delete(versions[x].Path, true); } catch { From 0f6ea123ea1ead19e6efc915e6af62dc4a198329 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Sat, 5 Sep 2020 20:55:42 +0100 Subject: [PATCH 09/34] Update ApplicationHost.cs --- Emby.Server.Implementations/ApplicationHost.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index d579beb2f2..52c40f4a5e 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Linq; using System.Net; From 2eff0db804dcc46849ad536ad14c3f5faa0695be Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Tue, 8 Sep 2020 17:49:38 +0100 Subject: [PATCH 10/34] Update Emby.Server.Implementations/ApplicationHost.cs Co-authored-by: Cody Robibero --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 52c40f4a5e..8144718037 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1080,7 +1080,7 @@ namespace Emby.Server.Implementations // Attempt a cleanup of old folders. try { - Logger.LogDebug("Attempting to delete {0}", versions[x].Path); + Logger.LogDebug("Deleting {Path}", versions[x].Path); Directory.Delete(versions[x].Path, true); } catch From a9d8b53658930d062c1f2ddc34715c51aec08ce1 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Tue, 8 Sep 2020 17:49:55 +0100 Subject: [PATCH 11/34] Update Emby.Server.Implementations/ApplicationHost.cs Co-authored-by: Cody Robibero --- Emby.Server.Implementations/ApplicationHost.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 8144718037..a6b6505bf9 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1083,9 +1083,9 @@ namespace Emby.Server.Implementations Logger.LogDebug("Deleting {Path}", versions[x].Path); Directory.Delete(versions[x].Path, true); } - catch + catch (Exception e) { - // Ignore errors. + Logger.LogWarning(e, "Unable to delete {Path}", versions[x].Path); } } } From f4eb34a9662a2474cf555e1665db517ee41db68e Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Tue, 8 Sep 2020 17:50:19 +0100 Subject: [PATCH 12/34] Update Emby.Server.Implementations/Updates/InstallationManager.cs Co-authored-by: Cody Robibero --- Emby.Server.Implementations/Updates/InstallationManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index 81cf18f8df..5af2b7e32f 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -375,7 +375,7 @@ namespace Emby.Server.Implementations.Updates } // Version folder as they cannot be overwritten in Windows. - targetDir += "_" + package.Version.ToString(); + targetDir += "_" + package.Version; if (Directory.Exists(targetDir)) { From ddfb13f94550b6df7cbe7d6aeb17ab91d4bb2b54 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Tue, 8 Sep 2020 17:50:37 +0100 Subject: [PATCH 13/34] Update Emby.Server.Implementations/Updates/InstallationManager.cs Co-authored-by: Cody Robibero --- Emby.Server.Implementations/Updates/InstallationManager.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Emby.Server.Implementations/Updates/InstallationManager.cs b/Emby.Server.Implementations/Updates/InstallationManager.cs index 5af2b7e32f..ba0fdfc340 100644 --- a/Emby.Server.Implementations/Updates/InstallationManager.cs +++ b/Emby.Server.Implementations/Updates/InstallationManager.cs @@ -388,7 +388,6 @@ namespace Emby.Server.Implementations.Updates // Ignore any exceptions. } } - stream.Position = 0; _zipClient.ExtractAllFromZip(stream, targetDir, true); From 60e8f47194d0bc7053e5771cd355b1ef628f99a2 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Tue, 8 Sep 2020 17:52:08 +0100 Subject: [PATCH 14/34] Update ApplicationHost.cs --- Emby.Server.Implementations/ApplicationHost.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index a6b6505bf9..1bc436820e 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1049,11 +1049,11 @@ namespace Emby.Server.Implementations foreach (var dir in directories) { - int p = dir.LastIndexOf('_'); - if (p != -1 && Version.TryParse(dir.Substring(p + 1), out Version ver)) + int underscoreIndex = dir.LastIndexOf('_'); + if (underscoreIndex != -1 && Version.TryParse(dir.Substring(underscoreIndex + 1), out Version ver)) { // Versioned folder. - versions.Add((ver, dir.Substring(0, p), dir)); + versions.Add((ver, dir.Substring(0, underscoreIndex), dir)); } else { From 81f655803d50ce75c270d06d409d1f1c190a6d79 Mon Sep 17 00:00:00 2001 From: Jim Cartlidge Date: Sun, 13 Sep 2020 16:30:04 +0100 Subject: [PATCH 15/34] Modified to work with manifests. --- .../ApplicationHost.cs | 43 +++++++++++-------- .../Plugins/PlugInManifest.cs | 32 ++++++++++++++ 2 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 Emby.Server.Implementations/Plugins/PlugInManifest.cs diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 1bc436820e..89752c63c0 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -38,6 +38,7 @@ using Emby.Server.Implementations.LiveTv; using Emby.Server.Implementations.Localization; using Emby.Server.Implementations.Net; using Emby.Server.Implementations.Playlists; +using Emby.Server.Implementations.Plugins; using Emby.Server.Implementations.QuickConnect; using Emby.Server.Implementations.ScheduledTasks; using Emby.Server.Implementations.Security; @@ -1020,7 +1021,7 @@ namespace Emby.Server.Implementations /// Comparison function used in . /// private static int VersionCompare( - (Version PluginVersion, string Name, string Path) a, + (Version PluginVersion, string Name, string Path) a, (Version PluginVersion, string Name, string Path) b) { int compare = string.Compare(a.Name, b.Name, true, CultureInfo.InvariantCulture); @@ -1033,32 +1034,38 @@ namespace Emby.Server.Implementations return compare; } - /// - /// Only loads the latest version of each assembly based upon the folder name. - /// eg. MyAssembly_11.9.3.6 - will be ignored. - /// MyAssembly_12.2.3.6 - will be loaded. - /// - /// Path to enumerate. - /// Set to true, to try and clean up earlier versions. - /// IEnumerable{string} of filenames. - protected IEnumerable GetLatestDLLVersion(string path, bool cleanup = true) + private IEnumerable GetPlugins(string path, bool cleanup = true) { var dllList = new List(); var versions = new List<(Version PluginVersion, string Name, string Path)>(); var directories = Directory.EnumerateDirectories(path, "*.*", SearchOption.TopDirectoryOnly); + var serializer = new JsonSerializer(); foreach (var dir in directories) { - int underscoreIndex = dir.LastIndexOf('_'); - if (underscoreIndex != -1 && Version.TryParse(dir.Substring(underscoreIndex + 1), out Version ver)) + try { - // Versioned folder. - versions.Add((ver, dir.Substring(0, underscoreIndex), dir)); + var manifest = serializer.DeserializeFromFile(dir + "\\meta.json"); + + if (!Version.TryParse(manifest.TargetAbi, out var targetAbi)) + { + targetAbi = new Version("0.0.0.1"); + } + + if (!Version.TryParse(manifest.Version, out var version)) + { + version = new Version("0.0.0.1"); + } + + if (targetAbi <= ApplicationVersion) + { + // Only load Plugins for this version or below. + versions.Add((version, manifest.Name, dir)); + } } - else + catch { - // Un-versioned folder. - versions.Add((new Version(), dir, dir)); + continue; } } @@ -1101,7 +1108,7 @@ namespace Emby.Server.Implementations { if (Directory.Exists(ApplicationPaths.PluginsPath)) { - foreach (var file in GetLatestDLLVersion(ApplicationPaths.PluginsPath)) + foreach (var file in GetPlugins(ApplicationPaths.PluginsPath)) { Assembly plugAss; try diff --git a/Emby.Server.Implementations/Plugins/PlugInManifest.cs b/Emby.Server.Implementations/Plugins/PlugInManifest.cs new file mode 100644 index 0000000000..e334d65e50 --- /dev/null +++ b/Emby.Server.Implementations/Plugins/PlugInManifest.cs @@ -0,0 +1,32 @@ +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member + +using System; + +namespace Emby.Server.Implementations.Plugins +{ + /// + /// Defines a Plugin manifest file. + /// + public class PlugInManifest + { + public string Category { get; set; } + + public string Changelog { get; set; } + + public string Description { get; set; } + + public Guid Guid { get; set; } + + public string Name { get; set; } + + public string Overview { get; set; } + + public string Owner { get; set; } + + public string TargetAbi { get; set; } + + public DateTime Timestamp { get; set; } + + public string Version { get; set; } +} +} From 5f58d2c15183736098ca9e4cb7397ea9fb75d5d1 Mon Sep 17 00:00:00 2001 From: Jim Cartlidge Date: Sun, 13 Sep 2020 16:37:20 +0100 Subject: [PATCH 16/34] With method comments. --- Emby.Server.Implementations/ApplicationHost.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 89752c63c0..7f17419399 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1020,6 +1020,9 @@ namespace Emby.Server.Implementations /// /// Comparison function used in . /// + /// Item to compare. + /// Item to compare with. + /// Boolean result of the operation. private static int VersionCompare( (Version PluginVersion, string Name, string Path) a, (Version PluginVersion, string Name, string Path) b) @@ -1034,6 +1037,12 @@ namespace Emby.Server.Implementations return compare; } + /// + /// Returns a list of plugsin to install. + /// + /// Path to check. + /// True if an attempt should be made to delete old plugs. + /// Enumerable list of dlls to load. private IEnumerable GetPlugins(string path, bool cleanup = true) { var dllList = new List(); From b4edb7c90d82a8a3e1e542e0e5e26cb3a1f70a6a Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Sun, 13 Sep 2020 17:24:02 +0100 Subject: [PATCH 17/34] Update Emby.Server.Implementations/ApplicationHost.cs Co-authored-by: Cody Robibero --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 7f17419399..9aeb0c42a2 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1058,7 +1058,7 @@ namespace Emby.Server.Implementations if (!Version.TryParse(manifest.TargetAbi, out var targetAbi)) { - targetAbi = new Version("0.0.0.1"); + targetAbi = new Version(0, 0, 0, 1); } if (!Version.TryParse(manifest.Version, out var version)) From 008aa51eb731c926df3c584fed8d7ccad1d8c94a Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Sun, 13 Sep 2020 17:24:30 +0100 Subject: [PATCH 18/34] Update Emby.Server.Implementations/ApplicationHost.cs Co-authored-by: Cody Robibero --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 9aeb0c42a2..cf55f392d8 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1063,7 +1063,7 @@ namespace Emby.Server.Implementations if (!Version.TryParse(manifest.Version, out var version)) { - version = new Version("0.0.0.1"); + version = new Version(0, 0, 0, 1); } if (targetAbi <= ApplicationVersion) From 12fb827405473d9f499848ce2098008fc96d0321 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Sun, 13 Sep 2020 17:29:10 +0100 Subject: [PATCH 19/34] Update Emby.Server.Implementations/ApplicationHost.cs Co-authored-by: Cody Robibero --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index cf55f392d8..db70b6203c 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1054,7 +1054,7 @@ namespace Emby.Server.Implementations { try { - var manifest = serializer.DeserializeFromFile(dir + "\\meta.json"); + var manifest = serializer.DeserializeFromFile(Path.Combine(dir, "meta.json"); if (!Version.TryParse(manifest.TargetAbi, out var targetAbi)) { From ea0eb9a6ffc8a667c9d9d455121d3f48d72fa360 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Sun, 13 Sep 2020 17:42:40 +0100 Subject: [PATCH 20/34] Update PlugInManifest.cs Added comments. --- .../Plugins/PlugInManifest.cs | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/Emby.Server.Implementations/Plugins/PlugInManifest.cs b/Emby.Server.Implementations/Plugins/PlugInManifest.cs index e334d65e50..fa48d73c55 100644 --- a/Emby.Server.Implementations/Plugins/PlugInManifest.cs +++ b/Emby.Server.Implementations/Plugins/PlugInManifest.cs @@ -1,5 +1,3 @@ -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - using System; namespace Emby.Server.Implementations.Plugins @@ -9,24 +7,54 @@ namespace Emby.Server.Implementations.Plugins /// public class PlugInManifest { + /// + /// Gets or sets the category of the plugin. + /// public string Category { get; set; } + /// + /// Gets or sets the changelog information. + /// public string Changelog { get; set; } + /// + /// Gets or sets the description of the plugin. + /// public string Description { get; set; } + /// + /// Gets or sets the Global Unique Identifier for the plugin. + /// public Guid Guid { get; set; } + /// + /// Gets or sets the Name of the plugin. + /// public string Name { get; set; } + /// + /// Gets or sets an overview of the plugin. + /// public string Overview { get; set; } + /// + /// Gets or sets the owner of the plugin. + /// public string Owner { get; set; } + /// + /// Gets or sets the compatibility version for the plugin. + /// public string TargetAbi { get; set; } + /// + /// Gets or sets the timestamp of the plugin. + /// public DateTime Timestamp { get; set; } + /// + /// Gets or sets the Version number of the plugin. + /// public string Version { get; set; } -} + } } From 6c2c2cb872b0e98ff27d1cc8d664a185e63e39ac Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Sun, 13 Sep 2020 17:45:17 +0100 Subject: [PATCH 21/34] Update ApplicationHost.cs Global jsonserializer added --- Emby.Server.Implementations/ApplicationHost.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index db70b6203c..ea4c77f3cc 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -121,6 +121,7 @@ namespace Emby.Server.Implementations private readonly IFileSystem _fileSystemManager; private readonly INetworkManager _networkManager; private readonly IXmlSerializer _xmlSerializer; + private readonly IJsonSerializer _jsonSerializer; private readonly IStartupOptions _startupOptions; private IMediaEncoder _mediaEncoder; @@ -251,6 +252,8 @@ namespace Emby.Server.Implementations IServiceCollection serviceCollection) { _xmlSerializer = new MyXmlSerializer(); + _jsonSerializer = new JsonSerializer(); + ServiceCollection = serviceCollection; _networkManager = networkManager; @@ -1049,12 +1052,11 @@ namespace Emby.Server.Implementations var versions = new List<(Version PluginVersion, string Name, string Path)>(); var directories = Directory.EnumerateDirectories(path, "*.*", SearchOption.TopDirectoryOnly); - var serializer = new JsonSerializer(); foreach (var dir in directories) { try { - var manifest = serializer.DeserializeFromFile(Path.Combine(dir, "meta.json"); + var manifest = _jsonSerializer.DeserializeFromFile(Path.Combine(dir, "meta.json"); if (!Version.TryParse(manifest.TargetAbi, out var targetAbi)) { From 107d606a7069e43bafacd0e8254631230219111f Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Sun, 13 Sep 2020 17:51:14 +0100 Subject: [PATCH 22/34] Update ApplicationHost.cs --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index ea4c77f3cc..9540a879af 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1056,7 +1056,7 @@ namespace Emby.Server.Implementations { try { - var manifest = _jsonSerializer.DeserializeFromFile(Path.Combine(dir, "meta.json"); + var manifest = _jsonSerializer.DeserializeFromFile(Path.Combine(dir, "meta.json")); if (!Version.TryParse(manifest.TargetAbi, out var targetAbi)) { From 7b4b101ecacb6026cf2ca4142f0ca0fbb0f637fd Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Sun, 13 Sep 2020 18:06:13 +0100 Subject: [PATCH 23/34] Update ApplicationHost.cs --- Emby.Server.Implementations/ApplicationHost.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 9540a879af..2206fabadf 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1021,7 +1021,7 @@ namespace Emby.Server.Implementations protected abstract void RestartInternal(); /// - /// Comparison function used in . + /// Comparison function used in . /// /// Item to compare. /// Item to compare with. @@ -1068,7 +1068,7 @@ namespace Emby.Server.Implementations version = new Version(0, 0, 0, 1); } - if (targetAbi <= ApplicationVersion) + if (targetAbi >= ApplicationVersion) { // Only load Plugins for this version or below. versions.Add((version, manifest.Name, dir)); From 68d08e94fded259adc2b2cd3d9379d6ab1e8b384 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Mon, 14 Sep 2020 16:18:39 +0100 Subject: [PATCH 24/34] Update Emby.Server.Implementations/ApplicationHost.cs Co-authored-by: Cody Robibero --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 2206fabadf..878ea30fc7 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1041,7 +1041,7 @@ namespace Emby.Server.Implementations } /// - /// Returns a list of plugsin to install. + /// Returns a list of plugins to install. /// /// Path to check. /// True if an attempt should be made to delete old plugs. From f73e744785fc8016e858c9f676ac0b04ee4f564b Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Mon, 14 Sep 2020 17:58:10 +0100 Subject: [PATCH 25/34] Update Emby.Server.Implementations/Plugins/PlugInManifest.cs Co-authored-by: dkanada --- Emby.Server.Implementations/Plugins/PlugInManifest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/Plugins/PlugInManifest.cs b/Emby.Server.Implementations/Plugins/PlugInManifest.cs index fa48d73c55..b874676d84 100644 --- a/Emby.Server.Implementations/Plugins/PlugInManifest.cs +++ b/Emby.Server.Implementations/Plugins/PlugInManifest.cs @@ -5,7 +5,7 @@ namespace Emby.Server.Implementations.Plugins /// /// Defines a Plugin manifest file. /// - public class PlugInManifest + public class PluginManifest { /// /// Gets or sets the category of the plugin. From d27d2a8990afb80ba137688121f85b831599d45a Mon Sep 17 00:00:00 2001 From: Jim Cartlidge Date: Mon, 14 Sep 2020 18:23:50 +0100 Subject: [PATCH 26/34] Renamed file. --- .../ApplicationHost.cs | 37 ++++++++++++------- .../Plugins/PlugInManifest.cs | 20 +++++----- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 878ea30fc7..d1e28cce5c 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1051,27 +1051,38 @@ namespace Emby.Server.Implementations var dllList = new List(); var versions = new List<(Version PluginVersion, string Name, string Path)>(); var directories = Directory.EnumerateDirectories(path, "*.*", SearchOption.TopDirectoryOnly); + string metafile; foreach (var dir in directories) { try { - var manifest = _jsonSerializer.DeserializeFromFile(Path.Combine(dir, "meta.json")); - - if (!Version.TryParse(manifest.TargetAbi, out var targetAbi)) + metafile = Path.Combine(dir, "meta.json"); + if (File.Exists(metafile)) { - targetAbi = new Version(0, 0, 0, 1); + var manifest = _jsonSerializer.DeserializeFromFile(metafile); + + if (!Version.TryParse(manifest.TargetAbi, out var targetAbi)) + { + targetAbi = new Version(0, 0, 0, 1); + } + + if (!Version.TryParse(manifest.Version, out var version)) + { + version = new Version(0, 0, 0, 1); + } + + if (ApplicationVersion <= targetAbi) + { + // Only load Plugins if the plugin is built for this version or below. + versions.Add((version, manifest.Name, dir)); + } } - - if (!Version.TryParse(manifest.Version, out var version)) + else { - version = new Version(0, 0, 0, 1); - } - - if (targetAbi >= ApplicationVersion) - { - // Only load Plugins for this version or below. - versions.Add((version, manifest.Name, dir)); + metafile = dir.Split(new char[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries).Last(); + // Add it under the path name and version 0.0.0.1. + versions.Add((new Version("0.0.0.1"), metafile, dir)); } } catch diff --git a/Emby.Server.Implementations/Plugins/PlugInManifest.cs b/Emby.Server.Implementations/Plugins/PlugInManifest.cs index b874676d84..33762791bc 100644 --- a/Emby.Server.Implementations/Plugins/PlugInManifest.cs +++ b/Emby.Server.Implementations/Plugins/PlugInManifest.cs @@ -9,52 +9,52 @@ namespace Emby.Server.Implementations.Plugins { /// /// Gets or sets the category of the plugin. - /// + /// public string Category { get; set; } /// /// Gets or sets the changelog information. - /// + /// public string Changelog { get; set; } /// /// Gets or sets the description of the plugin. - /// + /// public string Description { get; set; } /// /// Gets or sets the Global Unique Identifier for the plugin. - /// + /// public Guid Guid { get; set; } /// /// Gets or sets the Name of the plugin. - /// + /// public string Name { get; set; } /// /// Gets or sets an overview of the plugin. - /// + /// public string Overview { get; set; } /// /// Gets or sets the owner of the plugin. - /// + /// public string Owner { get; set; } /// /// Gets or sets the compatibility version for the plugin. - /// + /// public string TargetAbi { get; set; } /// /// Gets or sets the timestamp of the plugin. - /// + /// public DateTime Timestamp { get; set; } /// /// Gets or sets the Version number of the plugin. - /// + /// public string Version { get; set; } } } From f80e181eda2d1bb9348bb2b7e050e51d9948cb41 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Mon, 14 Sep 2020 18:44:17 +0100 Subject: [PATCH 27/34] Update Emby.Server.Implementations/ApplicationHost.cs Co-authored-by: Cody Robibero --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index d1e28cce5c..4cb107f804 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1080,7 +1080,7 @@ namespace Emby.Server.Implementations } else { - metafile = dir.Split(new char[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries).Last(); + metafile = dir.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries)[^1]; // Add it under the path name and version 0.0.0.1. versions.Add((new Version("0.0.0.1"), metafile, dir)); } From e88d3ba8c2fd502ee159c0554467e9af064dfd1c Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Mon, 14 Sep 2020 18:44:29 +0100 Subject: [PATCH 28/34] Update Emby.Server.Implementations/ApplicationHost.cs Co-authored-by: Cody Robibero --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 4cb107f804..8eed609d42 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1082,7 +1082,7 @@ namespace Emby.Server.Implementations { metafile = dir.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries)[^1]; // Add it under the path name and version 0.0.0.1. - versions.Add((new Version("0.0.0.1"), metafile, dir)); + versions.Add(new Version(0, 0, 0, 1), metafile, dir)); } } catch From 51c416c83250988a20c2bd1c21a9fa4d528437a3 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Mon, 14 Sep 2020 20:23:35 +0100 Subject: [PATCH 29/34] Update Emby.Server.Implementations/ApplicationHost.cs Co-authored-by: Cody Robibero --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 8eed609d42..b9e2f5b672 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1072,7 +1072,7 @@ namespace Emby.Server.Implementations version = new Version(0, 0, 0, 1); } - if (ApplicationVersion <= targetAbi) + if (ApplicationVersion >= targetAbi) { // Only load Plugins if the plugin is built for this version or below. versions.Add((version, manifest.Name, dir)); From 69c4b44d248367fb45019242ab95d68ef0eff7e3 Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Mon, 14 Sep 2020 20:52:18 +0100 Subject: [PATCH 30/34] Update ApplicationHost.cs --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index b9e2f5b672..3dce001c7d 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1080,7 +1080,7 @@ namespace Emby.Server.Implementations } else { - metafile = dir.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries)[^1]; + metafile = dir.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries)[^1]); // Add it under the path name and version 0.0.0.1. versions.Add(new Version(0, 0, 0, 1), metafile, dir)); } From 02951bb8ce19f5487f2960c3a71fb23f870f9f9a Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Mon, 14 Sep 2020 20:57:00 +0100 Subject: [PATCH 31/34] Update Emby.Server.Implementations/ApplicationHost.cs Co-authored-by: h1dden-da3m0n <33120068+h1dden-da3m0n@users.noreply.github.com> --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 3dce001c7d..c4447770fb 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1082,7 +1082,7 @@ namespace Emby.Server.Implementations { metafile = dir.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries)[^1]); // Add it under the path name and version 0.0.0.1. - versions.Add(new Version(0, 0, 0, 1), metafile, dir)); + versions.Add(new Version(0, 0, 0, 1), metafile, dir); } } catch From 5baf87663f80a2e4f899b596d6f14aaa2f01687b Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Mon, 14 Sep 2020 20:57:49 +0100 Subject: [PATCH 32/34] Update Emby.Server.Implementations/ApplicationHost.cs Co-authored-by: h1dden-da3m0n <33120068+h1dden-da3m0n@users.noreply.github.com> --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index c4447770fb..d4d3a1d3b6 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1080,7 +1080,7 @@ namespace Emby.Server.Implementations } else { - metafile = dir.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries)[^1]); + metafile = dir.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries)[^1]; // Add it under the path name and version 0.0.0.1. versions.Add(new Version(0, 0, 0, 1), metafile, dir); } From a2c50e8005280887ad744739469cd64df13bfabb Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Mon, 14 Sep 2020 21:02:13 +0100 Subject: [PATCH 33/34] Update Emby.Server.Implementations/ApplicationHost.cs Co-authored-by: h1dden-da3m0n <33120068+h1dden-da3m0n@users.noreply.github.com> --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index d4d3a1d3b6..83617111b1 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -1082,7 +1082,7 @@ namespace Emby.Server.Implementations { metafile = dir.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries)[^1]; // Add it under the path name and version 0.0.0.1. - versions.Add(new Version(0, 0, 0, 1), metafile, dir); + versions.Add((new Version(0, 0, 0, 1), metafile, dir)); } } catch From ad00b93be54115674750b1b89421f9e5ea1807cb Mon Sep 17 00:00:00 2001 From: BaronGreenback Date: Wed, 16 Sep 2020 14:14:10 +0100 Subject: [PATCH 34/34] Rename PlugInManifest.cs to PluginManifest.cs --- .../Plugins/{PlugInManifest.cs => PluginManifest.cs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Emby.Server.Implementations/Plugins/{PlugInManifest.cs => PluginManifest.cs} (100%) diff --git a/Emby.Server.Implementations/Plugins/PlugInManifest.cs b/Emby.Server.Implementations/Plugins/PluginManifest.cs similarity index 100% rename from Emby.Server.Implementations/Plugins/PlugInManifest.cs rename to Emby.Server.Implementations/Plugins/PluginManifest.cs