Add case insensitive pathing for proper cross-platform kotor support of File IO #7
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.
This PR creates the
PathHelperandPathValidatorclasses which have all the necessary methods to read a case-insensitive path and somewhat determine a case-sensitive path based on it. Methods are available to find case-insensitive duplicates, find the closest case-sensitive match, and validate a directory/file path. There are discrepancies in some NET versions that are accounted for here to provide some better unified support across most Unix/windows platforms. We also have a method that will find a case-sensitive path on case-insensitive systems.The problem:
KOTOR assumes a case-insensitive filesystem, but on case-sensitive filesystems there's the potential for files/directories to duplicate which KOTOR either randomly picks one or picks a specific duplicate that matches the file/directory exactly.
The solution:
This PR provides the following methods in the
PathHelperandPathValidatorclasses:List<FileSystemInfo> FindCaseInsensitiveDuplicates(DirectoryInfo directory): If you want to initially scan the KOTOR directory to find case-insensitive duplicates on case-sensitive systems, this method will return a List on all duplicates found (e.g. nwScripT.NSS and nwscript.nss found in the same directory).string FixPathFormatting( string path ): fixes common problems in path strings (backslash vs forwardslash, multiple slashes, and trailing slashes are resolved)(FileSystemInfo?, List<string>) GetClosestMatchingEntry( string path ): Takes the argument of a case-insensitive path to a file/directory on disk, and will find out if that file is duplicated on disk in the same folder. If it is, it will return a tuple containing the closest matching entry (the closest valid case-sensitive path to the file/directory if one is found), and all other case-sensitive files/directories that duplicate in a case insensitive environment. This method matches more or less what KOTOR does internally.List<string> EnumerateFilesWithWildcards(IEnumerable<string> filesAndFolders, bool topLevelOnly = false): Will handle common wildcards such as * (anything here) and ? (any character here) in path strings. Takes a collection of path strings as an argument, and an optional bool for whether to recurse into subfolders.string? GetCaseSensitivePath(string path): Takes a case-insensitive path and returns a case-sensitive path. Even works on Windows somewhat, but some refactoring must be done to have it work correctly everytime on windows as windows was never meant to support something like that.bool IsValidPath( string path?): Some versions of NET will exception if the path string sent to the DirectoryInfo or FileInfo constructors are too malformed, this method will safely determine whether the file/directory path string will always be valid in both unix/windows filesystems. It enforces windows restrictions in unix and vice versa.