Case-sensitivity checks on Windows

Should prevent "TigerThresher" from happening again.
This commit is contained in:
juanjp600
2016-11-10 21:45:59 -03:00
parent b4515367f2
commit 0e9c20c666
5 changed files with 53 additions and 1 deletions
@@ -184,6 +184,7 @@ namespace Barotrauma
spritePath = spritePath.Replace("[GENDER]", (this.gender == Gender.Female) ? "f" : "");
spritePath = spritePath.Replace("[HEADID]", HeadSpriteId.ToString());
ToolBox.IsProperFilenameCase(spritePath);
string fileName = Path.GetFileNameWithoutExtension(spritePath);
//go through the files in the directory to find a matching sprite
+2
View File
@@ -748,6 +748,8 @@ namespace Barotrauma
DebugConsole.ThrowError("TutorialSub.sub not found!");
}
break;
case "testasd":
break;
default:
NewMessage("Command not found", Color.Red);
+5 -1
View File
@@ -14,7 +14,11 @@ namespace Barotrauma
componentStyles = new Dictionary<string, GUIComponentStyle>();
XDocument doc;
try { doc = XDocument.Load(file); }
try
{
ToolBox.IsProperFilenameCase(file);
doc = XDocument.Load(file);
}
catch (Exception e)
{
DebugConsole.ThrowError("Loading style \"" + file + "\" failed", e);
+1
View File
@@ -973,6 +973,7 @@ namespace Barotrauma
{
try
{
ToolBox.IsProperFilenameCase(file);
doc = XDocument.Load(file);
}
+44
View File
@@ -27,11 +27,55 @@ namespace Barotrauma
public static class ToolBox
{
public static bool IsProperFilenameCase(string filename)
{
char[] delimiters = { '/','\\' };
string[] subDirs = filename.Split(delimiters);
string originalFilename = filename;
filename = "";
for (int i=0;i<subDirs.Length-1;i++)
{
filename += subDirs[i] + "/";
if (i == subDirs.Length - 2)
{
string[] filePaths = Directory.GetFiles(filename);
if (filePaths.Any(s => s.Equals(filename + subDirs[i + 1], StringComparison.Ordinal)))
{
return true;
}
else if (filePaths.Any(s => s.Equals(filename + subDirs[i + 1], StringComparison.OrdinalIgnoreCase)))
{
DebugConsole.ThrowError(originalFilename + " has incorrect case!");
return false;
}
}
string[] dirPaths = Directory.GetDirectories(filename);
if (!dirPaths.Any(s => s.Equals(filename+subDirs[i+1],StringComparison.Ordinal)))
{
if (dirPaths.Any(s => s.Equals(filename + subDirs[i + 1], StringComparison.OrdinalIgnoreCase)))
{
DebugConsole.ThrowError(originalFilename + " has incorrect case!");
}
else
{
DebugConsole.ThrowError(originalFilename + " doesn't exist!");
}
return false;
}
}
return true;
}
public static XDocument TryLoadXml(string filePath)
{
XDocument doc;
try
{
IsProperFilenameCase(filePath);
doc = XDocument.Load(filePath);
}
catch (Exception e)