Case insensitive installed file lookup on Windows #3479
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problems
Recently, Windows users have been encountering weird install/uninstall errors relating to Scatterer:
Causes
In its latest release, Scatterer renamed its install folder from
scatterer
toScatterer
(capitalizing the S), but the metadata was unchanged until KSP-CKAN/NetKAN#8862. There was no inflation error because install stanza matching is case insensitive, sofind: scatterer
matched a path in the ZIP ofScatterer
:CKAN/Core/Types/ModuleInstallDescriptor.cs
Lines 230 to 245 in 35927bc
One user who encountered these errors shared a screenshot confirming that the mod was installed into
GameData/scatterer
:But their
registry.json
has it asGameData/Scatterer
in theinstalled_files
hashes:https://1drv.ms/u/s!AlCbO5GR6RGwj7RlQn2vSUdicVFNQA?e=pJQfMM
On Windows, filenames are treated as case insensitive, so if we take a filename with mismatched capitalization from the registry and look for it on disk, it will be found. But
Dictionary<string, whatever>
lookups are case sensitive by default, so if we take a filename with mismatched capitalization from disk and look for it in the registry, it won't be found unless we take extra steps to make that happen.One place this happens is when we look for manually installed DLLs. This is done by iterating over all the DLLs in GameData and checking whether each one is registered to an installed module. If the capitalization is mismatched, then that code does not find the file and adds it to the list of manually installed DLLs. Later the
RelationshipResolver
will trip on Scatterer's self-conflict when it sees it in the manually installed DLL list and emit the above strange errors.Changes
Now on Windows we initialize the
installed_file
dictionaries withStringComparer.OrdinalIgnoreCase
, which makes their key lookup case insensitive. This should allow us to find files properly when going from disk to the registry, so CKAN will no longer think thatScatterer.dll
is manually installed.