Handle multiple entries with the same name but different case

This is done so that entries whose keys have a higher ordinal value (lowercase) will replace entries whose keys have a lower ordinal value. This is based on how I've seen GZDoom handle this sort of situation.
This commit is contained in:
Kevin Caccamo 2020-09-11 22:24:43 -04:00
parent 2f48255ddf
commit 71f86980fd
No known key found for this signature in database
GPG key ID: 483F90E1F56A8723

View file

@ -77,7 +77,7 @@ namespace CodeImp.DoomBuilder.IO
}
if(skipfolder) continue;
entries.Add(e.filepathname, e);
AddOrReplaceEntry(e);
}
}
@ -113,7 +113,7 @@ namespace CodeImp.DoomBuilder.IO
continue;
}
entries.Add(e.filepathname, e);
AddOrReplaceEntry(e);
}
}
@ -121,6 +121,31 @@ namespace CodeImp.DoomBuilder.IO
#region ================== Methods
// This checks whether a file is in the entry dictionary, adds it if it
// isn't, and replaces the existing entry if the new entry is lowercase
private void AddOrReplaceEntry(DirectoryFileEntry e)
{
// If the entry is already in the dictionary, add the one with
// greater ordinal value (prefer lowercase)
if(entries.ContainsKey(e.filepathname))
{
// Get the key for the existing entry. It may have a
// different case, since the dictionary is set up to be
// case insensitive.
string existingEntryPath = entries[e.filepathname].filepathname;
if(e.filepathname.CompareTo(existingEntryPath) == -1)
{
entries.Remove(e.filepathname);
entries.Add(e.filepathname, e);
}
}
else
{
// Just add the entry, since it's not in the dictionary yet.
entries.Add(e.filepathname, e);
}
}
// This checks if a given file exists
// The given file path must not be absolute
public bool FileExists(string filepathname)