axx0/Civ2-clone

Make File.Exists case insensitive for linux (gtk)

Closed this issue · 4 comments

axx0 commented

(for .txt files like Game/game, Labels/labels, etc.)
See here:

public static string GetFilePath(string filename, IEnumerable<string> searchPaths = null, params string[] extensions)
{
if (searchPaths != null)
{
foreach (var path in searchPaths)
{
var searchPath = path + Path.DirectorySeparatorChar + filename;
if (extensions.Length > 0)
{
foreach (var extension in extensions)
{
var filePath = searchPath + "." + extension;
if (File.Exists(filePath))
{
return filePath;
}
}
}
else if (File.Exists(searchPath))
{
return searchPath;
}
}
}
var rootPath = Settings.Civ2Path + filename;
if (File.Exists(rootPath))
{
return rootPath;
}
Console.WriteLine(filename + " not found!");
return null;
}

Windows (WinForms) doesn't have this problem.

If you are in-charge of extracting assets, maybe a one-time upon boot change to the files to be consistently lowercase or uppercase would avoid the need to worry about this during the game?

axx0 commented

You mean scanning all the files and changing their case? I'll have to think about it, I'm more in favour of programmatically ignoring the case instead of changing the actual names of files. (or did I misinterpret what you wrote?)

I was suggesting a one-time action of scanning files when extracting (so you'd already be scanning them), but converting their saved paths to be lowercase (or uppercase, consistent casing is the core of this).

axx0 commented

I did some adjustments so that it can read files on Linux, even when files are upper/lower case.