v0.12.0.2

This commit is contained in:
Joonas Rikkonen
2021-02-10 17:08:21 +02:00
parent 5c80a59bdd
commit 694cdfee7b
353 changed files with 12897 additions and 5028 deletions
@@ -12,13 +12,13 @@ namespace Barotrauma
private int maxId;
private List<Point> srcRanges;
private int destOffset;
private readonly List<Point> srcRanges;
private readonly int destOffset;
public IdRemap(XElement parentElement, int offset)
{
destOffset = offset;
if (parentElement != null)
if (parentElement != null && parentElement.HasElements)
{
srcRanges = new List<Point>();
foreach (XElement subElement in parentElement.Elements())
@@ -26,7 +26,7 @@ namespace Barotrauma
int id = subElement.GetAttributeInt("ID", -1);
if (id > 0) { InsertId(id); }
}
maxId = GetOffsetId(srcRanges.Last().Y + 1);
maxId = GetOffsetId(srcRanges.Last().Y) + 1;
}
else
{
@@ -42,7 +42,7 @@ namespace Barotrauma
private void InsertId(int id)
{
for (int i=0;i<srcRanges.Count;i++)
for (int i = 0; i < srcRanges.Count; i++)
{
if (srcRanges[i].X > id)
{
@@ -66,10 +66,10 @@ namespace Barotrauma
if (srcRanges[i].Y == (id - 1))
{
srcRanges[i] = new Point(srcRanges[i].X, id);
if (i < (srcRanges.Count-1) && srcRanges[i].Y == srcRanges[i + 1].X)
if (i < (srcRanges.Count - 1) && srcRanges[i].Y == srcRanges[i + 1].X)
{
srcRanges[i] = new Point(srcRanges[i].X, srcRanges[i + 1].Y);
srcRanges.RemoveAt(i+1);
srcRanges.RemoveAt(i + 1);
}
return;
}
@@ -90,9 +90,9 @@ namespace Barotrauma
if (srcRanges == null) { return (ushort)(id + destOffset); }
int currOffset = destOffset;
for (int i=0;i<srcRanges.Count;i++)
for (int i = 0; i < srcRanges.Count; i++)
{
if (id >= srcRanges[i].X && (id <= srcRanges[i].Y || (i == srcRanges.Count-1)))
if (id >= srcRanges[i].X && id <= srcRanges[i].Y)
{
return (ushort)(id - srcRanges[i].X + 1 + currOffset);
}
@@ -33,7 +33,7 @@ namespace Barotrauma
int prevIndex = 0;
int currIndex = 0;
for (int i=0;i<segments.Length;i++)
for (int i = 0; i < segments.Length; i++)
{
if (i % 2 == 0)
{
@@ -44,7 +44,7 @@ namespace Barotrauma
else
{
string[] attributes = segments[i].Split(attributeSeparator);
for (int j=0;j<attributes.Length;j++)
for (int j = 0; j < attributes.Length; j++)
{
if (attributes[j].Contains(endDefinition))
{
@@ -482,6 +482,13 @@ namespace Barotrauma
}
}
}
public static void DeleteDownloadedSubs()
{
if (Directory.Exists(SubmarineDownloadFolder))
{
ClearFolder(SubmarineDownloadFolder);
}
}
public static void CleanUnnecessarySaveFiles()
{
@@ -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; }
}