Skip to content

Commit

Permalink
Fix logic error
Browse files Browse the repository at this point in the history
  • Loading branch information
Emik03 committed Apr 13, 2024
1 parent c6472c8 commit c1350f1
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions wawa.IO/Source/PathFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,23 +249,25 @@ static string FindLibrary(
}

var directory = root.Join(Library).Join(platform).Join(architecture);
Directory.CreateDirectory(directory);
var source = Directory.GetFiles(directory, $"{file}*");

if (Directory.GetFiles(directory, $"{file}*") is var source && source.Length is 0 || File.Exists(source[0]))
switch (source.Length)
{
AssemblyLog(@$"Couldn't find the library ""{file}"" in the directory ""{directory}"".", LogType.Error);
return null;
}

case 0:
AssemblyLog(@$"Couldn't find the library ""{file}"" in the directory ""{directory}"".", LogType.Error);
return null;
case > 1:
#pragma warning disable CI0003
if (source.Length > 1 && string.Join(@""", """, source.Skip(1).ToArray()) is var others)
var others = string.Join(@""", """, source.Skip(1).ToArray());
#pragma warning restore CI0003
AssemblyLog(
@$"Multiple binaries were found, assuming ""{source[0]}"", but could have also used ""{others}"".",
LogType.Error
);
AssemblyLog(
@$"Multiple binaries were found, assuming ""{source[0]}"", but could have also used ""{others}"".",
LogType.Warning
);

return source[0];
return source[0];
default: return source[0];
}
}

// Boxing required; Avoids creating closures with the 'Mod' type.
Expand Down Expand Up @@ -350,7 +352,7 @@ [NotNull] in string name
)
where T : Delegate
{
if (typeof(T).GetMethod(nameof(Action<T>.Invoke)) is not { } invoke)
if (typeof(T).GetMethod(nameof(Action.Invoke)) is not { } invoke)
return null;

var assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(new(name), AssemblyBuilderAccess.Run);
Expand Down

0 comments on commit c1350f1

Please sign in to comment.