Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle duplicative dll paths #13

Conversation

HebaruSan
Copy link

Motivation

KSP-CKAN/NetKAN#1455 (comment)

If a copy of miniavc.dll exists in both the GameData base folder and any subfolder then all dialogs surfaced by the mod are surfaced twice and that is annoying AF if you have a couple hundred mods installed.

This pull request aims to fix that.

Cause

The scenario described above can be generalized to any situation in which two copies of MiniAVC.dll are located in directories which are in an ancestor/descendant relationship. E.g.:

  • GameData/MiniAVC.dll
  • GameData/Astrogator/MiniAVC.dll

Or even something like:

  • GameData/HeavilyBundledMod/MiniAVC.dll
  • GameData/HeavilyBundledMod/AnotherMod/Plugins/MiniAVC.dll

In those cases, this code will find version files in the nested subfolder multiple times and add them to the list of addons to check:

var threadAddons = new List<Addon>();
var threadSettings = new List<AddonSettings>();
foreach (var rootPath in AssemblyLoader.loadedAssemblies.Where(a => a.name == "MiniAVC").Select(a => Path.GetDirectoryName(a.path)))
{
var settings = AddonSettings.Load(rootPath);
threadSettings.Add(settings);
threadAddons.AddRange(Directory.GetFiles(rootPath, "*.version", SearchOption.AllDirectories).Select(p => new Addon(p, settings)).ToList());
}
addons = threadAddons;
Settings = threadSettings;
Populated = true;

Later this results in multiple popups if there are incompatibilities or updates.

Changes

Now we build a temporary Dictionary that tracks version files and their associated settings. If we find the same version file more than once, we don't add it multiple times; instead we compare the associated settings files and choose the one that is closest to that version file. Once we've checked all the files, we collapse the Dictionary to a list of Addons, as before.

This is what I was trying to compile on the mod adoption tutorial thread. I have not been able to get the build working, so there may be syntax errors here; just let me know and I'll fix them.

@linuxgurugamer linuxgurugamer changed the base branch from master to DuplicateElimiation August 10, 2018 15:31
@linuxgurugamer linuxgurugamer merged commit a5f9591 into linuxgurugamer:DuplicateElimiation Aug 10, 2018
@linuxgurugamer
Copy link
Owner

Merged into a branch, will test first

@linuxgurugamer
Copy link
Owner

Did you consider, instead of adding all this, to modify it to only look a .version files in the same directory it is in? That is the original intention of it

@HebaruSan
Copy link
Author

I assume that would break existing usages. E.g.:

  • MyMod/MiniAVC.dll
  • MyMod/MyMod.version
  • MyMod/BundledMod1/BundledMod1.version

@HebaruSan
Copy link
Author

HebaruSan commented Aug 10, 2018

And it doesn't look like that's the original intention:

This plugin checks inside its current directory and all contained directories for version files.

  • If your add-on contains multiple version files, place it at the lowest directory level which will cover all the version files, but do not place it in GameData.

The changelog doesn't mention this being added later; looks like "all contained directories" was part of the intention all along.

@linuxgurugamer
Copy link
Owner

I see, you are correct.

@linuxgurugamer
Copy link
Owner

I've been testing this.
This works for the DLL, but it still shows multiple entries if there are multiple copies of the .version file.
Still a great improvement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants