Skip to content

Commit

Permalink
Merge #3479 Case insensitive installed file lookup on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Nov 17, 2021
2 parents 35927bc + 6919fdb commit 6d24c67
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ All notable changes to this project will be documented in this file.
- [GUI] French translation bits in label dialog (#3465 by: vinix38; reviewed: HebaruSan)
- [GUI] Suppress filter updates for unchanged semantic search meaning (#3435 by: HebaruSan; reviewed: DasSkelett)
- [GUI] Use CRLF for resx files (#3471 by: HebaruSan; reviewed: DasSkelett)
- [Core] Case insensitive installed file lookup on Windows (#3479 by: HebaruSan; reviewed: DasSkelett)

### Internal

Expand Down
21 changes: 19 additions & 2 deletions Core/Registry/InstalledModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace CKAN
Expand Down Expand Up @@ -128,7 +129,10 @@ public InstalledModule(GameInstance ksp, CkanModule module, IEnumerable<string>
{
install_time = DateTime.Now;
source_module = module;
installed_files = new Dictionary<string, InstalledModuleFile>();
// We need case insensitive path matching on Windows
installed_files = Platform.IsWindows
? new Dictionary<string, InstalledModuleFile>(StringComparer.OrdinalIgnoreCase)
: new Dictionary<string, InstalledModuleFile>();
auto_installed = autoInstalled;

foreach (string file in relative_files)
Expand All @@ -154,14 +158,27 @@ private InstalledModule()

#region Serialisation Fixes

[OnDeserialized]
private void DeSerialisationFixes(StreamingContext context)
{
if (Platform.IsWindows)
{
// We need case insensitive path matching on Windows
installed_files = new Dictionary<string, InstalledModuleFile>(installed_files, StringComparer.OrdinalIgnoreCase);
}
}

/// <summary>
/// Ensures all files for this module have relative paths.
/// Called when upgrading registry versions. Should be a no-op
/// if called on newer registries.
/// </summary>
public void Renormalise(GameInstance ksp)
{
var normalised_installed_files = new Dictionary<string, InstalledModuleFile>();
// We need case insensitive path matching on Windows
var normalised_installed_files = Platform.IsWindows
? new Dictionary<string, InstalledModuleFile>(StringComparer.OrdinalIgnoreCase)
: new Dictionary<string, InstalledModuleFile>();

foreach (KeyValuePair<string, InstalledModuleFile> tuple in installed_files)
{
Expand Down
18 changes: 15 additions & 3 deletions Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Registry : IEnlistmentNotification, IRegistryQuerier
// name => path
[JsonProperty] private Dictionary<string, string> installed_dlls;
[JsonProperty] private Dictionary<string, InstalledModule> installed_modules;
// filename => module
// filename (case insensitive on Windows) => module
[JsonProperty] private Dictionary<string, string> installed_files;

[JsonProperty] public readonly SortedDictionary<string, int> download_counts = new SortedDictionary<string, int>();
Expand Down Expand Up @@ -157,7 +157,10 @@ private void DeSerialisationFixes(StreamingContext context)
{
log.Warn("Older registry format detected, normalising paths...");

var normalised_installed_files = new Dictionary<string, string>();
// We need case insensitive path matching on Windows
var normalised_installed_files = Platform.IsWindows
? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
: new Dictionary<string, string>();

foreach (KeyValuePair<string,string> tuple in installed_files)
{
Expand Down Expand Up @@ -190,6 +193,12 @@ private void DeSerialisationFixes(StreamingContext context)

log.Warn("Registry upgrade complete");
}
else if (Platform.IsWindows)
{
// We need case insensitive path matching on Windows
// (already done when replacing this object in the above block, hence the 'else')
installed_files = new Dictionary<string, string>(installed_files, StringComparer.OrdinalIgnoreCase);
}

// Fix control lock, which previously was indexed with an invalid identifier.
if (registry_version < 2)
Expand Down Expand Up @@ -254,7 +263,10 @@ private void DeSerialisationFixes(StreamingContext context)
/// </summary>
public void ReindexInstalled()
{
installed_files = new Dictionary<string, string>();
// We need case insensitive path matching on Windows
installed_files = Platform.IsWindows
? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
: new Dictionary<string, string>();

foreach (InstalledModule module in installed_modules.Values)
{
Expand Down

0 comments on commit 6d24c67

Please sign in to comment.