Skip to content

Commit

Permalink
feat: Update NuGet plugin loading
Browse files Browse the repository at this point in the history
- Added a special case condition to skip files with .NET 5.0+ runtime monikers that have major versions exceeding the current runtime major version.
- Updated the declaration of TargetMonikerRegexes from IEnumerable<Regex> to Regex[] in NugetUtilities class.
  • Loading branch information
SakuraIsayeki committed Jul 16, 2023
1 parent 844863c commit f270e0e
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/YumeChan.Core/Services/Plugins/NugetPluginsFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,29 @@ private static void FlattenDownloadedPackageToDirectoryStructure(DirectoryInfo d
List<FileInfo> files = new();

// Sort all directories by matched moniker, then by last version, and pull all .dll files to "files" list.
foreach (Regex regex in TargetMonikerRegexes)
for (int i = 0; i < TargetMonikerRegexes.Length; i++)
{
Regex regex = TargetMonikerRegexes[i];

foreach (DirectoryInfo dir in directories
.Where(d =>
regex.Matches(d.FullName).Count is 1
|| regex.Matches(d.FullName).Count is 2
&& string.Equals(regex.Matches(d.FullName)[1].Value, RuntimeInformation.RuntimeIdentifier, StringComparison.OrdinalIgnoreCase))
.OrderByDescending(d => d.Name, StringComparer.OrdinalIgnoreCase))
.Where(d =>
regex.Matches(d.FullName).Count is 1
|| regex.Matches(d.FullName).Count is 2
&& string.Equals(regex.Matches(d.FullName)[1].Value, RuntimeInformation.RuntimeIdentifier, StringComparison.OrdinalIgnoreCase)
).OrderByDescending(d => d.Name, StringComparer.OrdinalIgnoreCase))
{
// Special case for .NET 5.0+ runtime monikers, we must make sure the major version does not exceed the current runtime major version.
if (i is 1 && regex.Matches(dir.FullName) is [{ Value: var moniker }, ..]
&& int.TryParse(moniker["net".Length..moniker.IndexOf('.')], out int majorVersion)
&& majorVersion > Environment.Version.Major)
{
continue;
}

files.AddRange(dir.GetFiles("*.dll", SearchOption.AllDirectories));
}
}

// Move all selected files to the target folder (if not present already).
foreach (FileInfo file in files.AsParallel())
{
Expand Down Expand Up @@ -322,7 +332,7 @@ private static void DeletePluginPackage(string pluginsDirectory, string packageN

public static class NugetUtilities
{
public static IEnumerable<Regex> TargetMonikerRegexes { get; } = new List<Regex>
public static Regex[] TargetMonikerRegexes { get; } =
{
// net x.x (5.0+) moniker
new(@"(net\d+\.\d+)-(\D+)"),
Expand Down

0 comments on commit f270e0e

Please sign in to comment.