Skip to content

Commit 45f90e7

Browse files
committed
refactor(Bootstrap): simplify variant candidate creation and error handling
- Replaced the manual iteration for creating variant candidates with a LINQ expression for improved readability. - Streamlined error handling for mismatched hashes by consolidating the return logic in the TryCreateVariantCandidate method. - Enhanced code maintainability by reducing the number of lines and improving clarity in the variant management process.
1 parent f1141a5 commit 45f90e7

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

Loader/Bootstrap.cs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,9 @@ private static List<VariantCandidate> LoadVariantManifest(string loaderDir, stri
172172
}
173173

174174
var libRootFull = Path.GetFullPath(libRoot);
175-
var variants = new List<VariantCandidate>();
176-
foreach (var entry in manifest.Variants)
177-
{
178-
var candidate = TryCreateVariantCandidate(loaderDir, libRootFull, entry);
179-
if (candidate is not null)
180-
variants.Add(candidate);
181-
}
182175

183-
return variants;
176+
return manifest.Variants.Select(entry => TryCreateVariantCandidate(loaderDir, libRootFull, entry))
177+
.OfType<VariantCandidate>().ToList();
184178
}
185179

186180
private static VariantCandidate? TryCreateVariantCandidate(
@@ -234,13 +228,9 @@ private static List<VariantCandidate> LoadVariantManifest(string loaderDir, stri
234228
return null;
235229
}
236230

237-
if (!MatchesExpectedHash(dllPath, entry.Sha256))
238-
{
239-
Log.Error($"[RitsuLib.Loader] Ignoring variant with mismatched hash: {dllPath}");
240-
return null;
241-
}
242-
243-
return new(compatTarget, version, dllPath);
231+
if (MatchesExpectedHash(dllPath, entry.Sha256)) return new(compatTarget, version, dllPath);
232+
Log.Error($"[RitsuLib.Loader] Ignoring variant with mismatched hash: {dllPath}");
233+
return null;
244234
}
245235

246236
private static bool IsUnderDirectory(string path, string root)
@@ -269,6 +259,7 @@ private sealed class BundleVariantManifest
269259
public List<BundleVariantEntry>? Variants { get; set; }
270260
}
271261

262+
// ReSharper disable once ClassNeverInstantiated.Local
272263
private sealed class BundleVariantEntry
273264
{
274265
public string? CompatTarget { get; set; }

0 commit comments

Comments
 (0)