v0.12.0.2
This commit is contained in:
@@ -97,7 +97,7 @@ namespace Barotrauma
|
||||
return !corrected;
|
||||
}
|
||||
|
||||
public static string CorrectFilenameCase(string filename, out bool corrected)
|
||||
public static string CorrectFilenameCase(string filename, out bool corrected, string directory = "")
|
||||
{
|
||||
char[] delimiters = { '/', '\\' };
|
||||
string[] subDirs = filename.Split(delimiters);
|
||||
@@ -117,21 +117,32 @@ namespace Barotrauma
|
||||
return originalFilename; //assume that rooted paths have correct case since these are generated by the game
|
||||
}
|
||||
|
||||
string startPath = directory ?? "";
|
||||
|
||||
for (int i = 0; i < subDirs.Length; i++)
|
||||
{
|
||||
if (i == subDirs.Length - 1 && string.IsNullOrEmpty(subDirs[i]))
|
||||
{
|
||||
break;
|
||||
}
|
||||
string enumPath = string.IsNullOrEmpty(filename) ? "./" : filename;
|
||||
List<string> filePaths = Directory.GetFileSystemEntries(enumPath).Select(s => Path.GetFileName(s)).ToList();
|
||||
if (filePaths.Any(s => s.Equals(subDirs[i], StringComparison.Ordinal)))
|
||||
|
||||
string subDir = subDirs[i].TrimEnd();
|
||||
string enumPath = Path.Combine(startPath, filename);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(filename))
|
||||
{
|
||||
filename += subDirs[i];
|
||||
enumPath = string.IsNullOrWhiteSpace(startPath) ? "./" : startPath;
|
||||
}
|
||||
|
||||
List<string> filePaths = Directory.GetFileSystemEntries(enumPath).Select(Path.GetFileName).ToList();
|
||||
|
||||
if (filePaths.Any(s => s.Equals(subDir, StringComparison.Ordinal)))
|
||||
{
|
||||
filename += subDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
IEnumerable<string> correctedPaths = filePaths.Where(s => s.Equals(subDirs[i], StringComparison.OrdinalIgnoreCase));
|
||||
List<string> correctedPaths = filePaths.Where(s => s.Equals(subDir, StringComparison.OrdinalIgnoreCase)).ToList();
|
||||
if (correctedPaths.Any())
|
||||
{
|
||||
corrected = true;
|
||||
@@ -152,7 +163,7 @@ namespace Barotrauma
|
||||
|
||||
public static string RemoveInvalidFileNameChars(string fileName)
|
||||
{
|
||||
var invalidChars = Path.GetInvalidFileNameChars().Concat(new char[] {':', ';'});
|
||||
var invalidChars = Path.GetInvalidFileNameChars().Concat(new char[] {':', ';', '<', '>', '"', '/', '\\', '|', '?', '*'});
|
||||
foreach (char invalidChar in invalidChars)
|
||||
{
|
||||
fileName = fileName.Replace(invalidChar.ToString(), "");
|
||||
@@ -572,7 +583,7 @@ namespace Barotrauma
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
|
||||
public static string CleanUpPathCrossPlatform(this string path, bool correctFilenameCase = true)
|
||||
public static string CleanUpPathCrossPlatform(this string path, bool correctFilenameCase = true, string directory = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(path)) { return ""; }
|
||||
|
||||
@@ -584,7 +595,7 @@ namespace Barotrauma
|
||||
|
||||
if (correctFilenameCase)
|
||||
{
|
||||
string correctedPath = CorrectFilenameCase(path, out _);
|
||||
string correctedPath = CorrectFilenameCase(path, out _, directory);
|
||||
if (!string.IsNullOrEmpty(correctedPath)) { path = correctedPath; }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user