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))
{