From 0e9c20c6666a34a3a304075a68cea14ff385fe1b Mon Sep 17 00:00:00 2001 From: juanjp600 Date: Thu, 10 Nov 2016 21:45:59 -0300 Subject: [PATCH] Case-sensitivity checks on Windows Should prevent "TigerThresher" from happening again. --- Subsurface/Source/Characters/CharacterInfo.cs | 1 + Subsurface/Source/DebugConsole.cs | 2 + Subsurface/Source/GUI/GUIStyle.cs | 6 ++- Subsurface/Source/Map/Submarine.cs | 1 + Subsurface/Source/Utils/ToolBox.cs | 44 +++++++++++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/Subsurface/Source/Characters/CharacterInfo.cs b/Subsurface/Source/Characters/CharacterInfo.cs index 39cdcdf3b..a789df893 100644 --- a/Subsurface/Source/Characters/CharacterInfo.cs +++ b/Subsurface/Source/Characters/CharacterInfo.cs @@ -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 diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index 16083a694..42554ccd6 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -748,6 +748,8 @@ namespace Barotrauma DebugConsole.ThrowError("TutorialSub.sub not found!"); } + break; + case "testasd": break; default: NewMessage("Command not found", Color.Red); diff --git a/Subsurface/Source/GUI/GUIStyle.cs b/Subsurface/Source/GUI/GUIStyle.cs index ea137a4ab..5fdc59c7d 100644 --- a/Subsurface/Source/GUI/GUIStyle.cs +++ b/Subsurface/Source/GUI/GUIStyle.cs @@ -14,7 +14,11 @@ namespace Barotrauma componentStyles = new Dictionary(); 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); diff --git a/Subsurface/Source/Map/Submarine.cs b/Subsurface/Source/Map/Submarine.cs index de045b928..bf2ba494f 100644 --- a/Subsurface/Source/Map/Submarine.cs +++ b/Subsurface/Source/Map/Submarine.cs @@ -973,6 +973,7 @@ namespace Barotrauma { try { + ToolBox.IsProperFilenameCase(file); doc = XDocument.Load(file); } diff --git a/Subsurface/Source/Utils/ToolBox.cs b/Subsurface/Source/Utils/ToolBox.cs index 30cffdc35..101f2dd00 100644 --- a/Subsurface/Source/Utils/ToolBox.cs +++ b/Subsurface/Source/Utils/ToolBox.cs @@ -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 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)