Skip to content

Commit

Permalink
Small performance tweaks for DLL scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 10, 2024
1 parent fda489c commit 082b2db
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ public bool SetDlls(IDictionary<string, string> dlls)
{
EnlistWithTransaction();
InvalidateInstalledCaches();
installed_dlls = new Dictionary<string, string>(unregistered);
installed_dlls = unregistered;
return true;
}
return false;
Expand Down
22 changes: 16 additions & 6 deletions Core/Registry/RegistryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,17 @@ public bool ScanUnmanagedFiles()
log.Info(Properties.Resources.GameInstanceScanning);
using (var tx = CkanTransaction.CreateTransactionScope())
{
var dlls = Enumerable.Repeat(gameInstance.game.PrimaryModDirectoryRelative, 1)
.Concat(gameInstance.game.AlternateModDirectoriesRelative)
.Select(gameInstance.ToAbsoluteGameDir)
var modFolders = Enumerable.Repeat(gameInstance.game.PrimaryModDirectoryRelative, 1)
.Concat(gameInstance.game.AlternateModDirectoriesRelative)
.Select(mf => $"{mf}/")
.ToArray();
var stockFolders = gameInstance.game.StockFolders
// Folders outside GameData won't be scanned
.Where(sf => modFolders.Any(mf => sf.StartsWith(mf)))
// Precalculate the full prefix once for all files
.Select(f => $"{f}/")
.ToArray();
var dlls = modFolders.Select(gameInstance.ToAbsoluteGameDir)
.Where(Directory.Exists)
// EnumerateFiles is *case-sensitive* in its pattern, which causes
// DLL files to be missed under Linux; we have to pick .dll, .DLL, or scanning
Expand All @@ -581,10 +589,12 @@ public bool ScanUnmanagedFiles()
// The least evil is to walk it once, and filter it ourselves.
.SelectMany(absDir => Directory.EnumerateFiles(absDir, "*",
SearchOption.AllDirectories))
.Where(file => file.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase))
.Where(file => file.EndsWith(".dll",
StringComparison.CurrentCultureIgnoreCase))
.Select(gameInstance.ToRelativeGameDir)
.Where(relPath => !gameInstance.game.StockFolders.Any(f => relPath.StartsWith($"{f}/")))
.GroupBy(relPath => gameInstance.DllPathToIdentifier(relPath) ?? "")
.Where(relPath => !stockFolders.Any(f => relPath.StartsWith(f)))
.GroupBy(gameInstance.DllPathToIdentifier)
.OfType<IGrouping<string, string>>()
.ToDictionary(grp => grp.Key,
grp => grp.First());
log.DebugFormat("Registering DLLs: {0}", string.Join(", ", dlls.Values));
Expand Down

0 comments on commit 082b2db

Please sign in to comment.