(5a377a8ee) Unstable v0.9.1000.0
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
public class RichTextData
|
||||
{
|
||||
public int StartIndex, EndIndex;
|
||||
public Color? Color;
|
||||
public string Metadata;
|
||||
|
||||
private const char definitionIndicator = '‖';
|
||||
private const char attributeSeparator = ';';
|
||||
private const char keyValueSeparator = ':';
|
||||
//private const char lineChangeIndicator = '\n';
|
||||
|
||||
private const string colorDefinition = "color";
|
||||
private const string metadataDefinition = "metadata";
|
||||
private const string endDefinition = "end";
|
||||
|
||||
public static List<RichTextData> GetRichTextData(string text, out string sanitizedText)
|
||||
{
|
||||
List<RichTextData> textColors = null;
|
||||
sanitizedText = text;
|
||||
if (!string.IsNullOrEmpty(text) && text.Contains(definitionIndicator))
|
||||
{
|
||||
string[] segments = text.Split(definitionIndicator);
|
||||
|
||||
sanitizedText = string.Empty;
|
||||
|
||||
textColors = new List<RichTextData>();
|
||||
RichTextData tempData = null;
|
||||
|
||||
int prevIndex = 0;
|
||||
int currIndex = 0;
|
||||
for (int i=0;i<segments.Length;i++)
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
sanitizedText += segments[i];
|
||||
prevIndex = currIndex;
|
||||
currIndex += segments[i].Replace("\n", "").Replace("\r", "").Length;
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] attributes = segments[i].Split(attributeSeparator);
|
||||
for (int j=0;j<attributes.Length;j++)
|
||||
{
|
||||
if (attributes[j].Contains(endDefinition))
|
||||
{
|
||||
if (tempData != null)
|
||||
{
|
||||
tempData.StartIndex = prevIndex;
|
||||
tempData.EndIndex = currIndex - 1;
|
||||
textColors.Add(tempData);
|
||||
}
|
||||
tempData = null;
|
||||
}
|
||||
else if (attributes[j].StartsWith(colorDefinition))
|
||||
{
|
||||
if (tempData == null) { tempData = new RichTextData(); }
|
||||
string valueStr = attributes[j].Substring(attributes[j].IndexOf(keyValueSeparator) + 1);
|
||||
if (valueStr.Equals("null", System.StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
tempData.Color = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
tempData.Color = XMLExtensions.ParseColor(valueStr);
|
||||
}
|
||||
}
|
||||
else if (attributes[j].StartsWith(metadataDefinition))
|
||||
{
|
||||
if (tempData == null) { tempData = new RichTextData(); }
|
||||
tempData.Metadata = attributes[j].Substring(attributes[j].IndexOf(keyValueSeparator) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return textColors;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,546 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Barotrauma.IO
|
||||
{
|
||||
static class Validation
|
||||
{
|
||||
static readonly string[] unwritableDirs = new string[] { "Content", "Data/ContentPackages" };
|
||||
|
||||
public static bool CanWrite(string path, bool canWarn = true)
|
||||
{
|
||||
path = System.IO.Path.GetFullPath(path).CleanUpPath();
|
||||
|
||||
foreach (string unwritableDir in unwritableDirs)
|
||||
{
|
||||
string dir = System.IO.Path.GetFullPath(unwritableDir).CleanUpPath();
|
||||
|
||||
if (path.StartsWith(dir, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
#if DEBUG
|
||||
if (canWarn)
|
||||
{
|
||||
DebugConsole.NewMessage($"WARNING: writing to \"{path}\" is disallowed in Release builds!\n{Environment.StackTrace}", Color.Orange);
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SafeXML
|
||||
{
|
||||
public static void SaveSafe(this System.Xml.Linq.XDocument doc, string path)
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot save XML document to \"{path}\": failed validation");
|
||||
return;
|
||||
}
|
||||
doc.Save(path);
|
||||
}
|
||||
|
||||
public static void SaveSafe(this System.Xml.Linq.XDocument doc, XmlWriter writer)
|
||||
{
|
||||
doc.WriteTo(writer);
|
||||
}
|
||||
|
||||
public static void WriteTo(this System.Xml.Linq.XDocument doc, XmlWriter writer)
|
||||
{
|
||||
writer.Write(doc);
|
||||
}
|
||||
}
|
||||
|
||||
public class XmlWriter : IDisposable
|
||||
{
|
||||
public readonly System.Xml.XmlWriter Writer;
|
||||
|
||||
public XmlWriter(string path, System.Xml.XmlWriterSettings settings)
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot write XML document to \"{path}\": failed validation");
|
||||
Writer = null;
|
||||
return;
|
||||
}
|
||||
Writer = System.Xml.XmlWriter.Create(path, settings);
|
||||
}
|
||||
|
||||
public static XmlWriter Create(string path, System.Xml.XmlWriterSettings settings)
|
||||
{
|
||||
return new XmlWriter(path, settings);
|
||||
}
|
||||
|
||||
public void Write(System.Xml.Linq.XDocument doc)
|
||||
{
|
||||
if (Writer == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Cannot write to invalid XmlWriter");
|
||||
return;
|
||||
}
|
||||
doc.WriteTo(Writer);
|
||||
}
|
||||
|
||||
public void Flush()
|
||||
{
|
||||
if (Writer == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Cannot flush invalid XmlWriter");
|
||||
return;
|
||||
}
|
||||
Writer.Flush();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Writer == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Cannot dispose invalid XmlWriter");
|
||||
return;
|
||||
}
|
||||
Writer.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Path
|
||||
{
|
||||
public static readonly char DirectorySeparatorChar = System.IO.Path.DirectorySeparatorChar;
|
||||
public static readonly char AltDirectorySeparatorChar = System.IO.Path.AltDirectorySeparatorChar;
|
||||
|
||||
public static string GetExtension(string path)
|
||||
{
|
||||
return System.IO.Path.GetExtension(path);
|
||||
}
|
||||
|
||||
public static string GetFileNameWithoutExtension(string path)
|
||||
{
|
||||
return System.IO.Path.GetFileNameWithoutExtension(path);
|
||||
}
|
||||
|
||||
public static string GetPathRoot(string path)
|
||||
{
|
||||
return System.IO.Path.GetPathRoot(path);
|
||||
}
|
||||
|
||||
public static string GetDirectoryName(string path)
|
||||
{
|
||||
return System.IO.Path.GetDirectoryName(path);
|
||||
}
|
||||
|
||||
public static string GetFileName(string path)
|
||||
{
|
||||
return System.IO.Path.GetFileName(path);
|
||||
}
|
||||
|
||||
public static string GetFullPath(string path)
|
||||
{
|
||||
return System.IO.Path.GetFullPath(path);
|
||||
}
|
||||
|
||||
public static string Combine(params string[] s)
|
||||
{
|
||||
return System.IO.Path.Combine(s);
|
||||
}
|
||||
|
||||
public static string GetTempFileName()
|
||||
{
|
||||
return System.IO.Path.GetTempFileName();
|
||||
}
|
||||
|
||||
public static bool IsPathRooted(string path)
|
||||
{
|
||||
return System.IO.Path.IsPathRooted(path);
|
||||
}
|
||||
public static IEnumerable<char> GetInvalidFileNameChars()
|
||||
{
|
||||
return System.IO.Path.GetInvalidFileNameChars();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Directory
|
||||
{
|
||||
public static string GetCurrentDirectory()
|
||||
{
|
||||
return System.IO.Directory.GetCurrentDirectory();
|
||||
}
|
||||
|
||||
public static void SetCurrentDirectory(string path)
|
||||
{
|
||||
System.IO.Directory.SetCurrentDirectory(path);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> GetFiles(string path)
|
||||
{
|
||||
return System.IO.Directory.GetFiles(path);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> GetFiles(string path, string pattern, System.IO.SearchOption option = System.IO.SearchOption.AllDirectories)
|
||||
{
|
||||
return System.IO.Directory.GetFiles(path, pattern, option);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> GetDirectories(string path)
|
||||
{
|
||||
return System.IO.Directory.GetDirectories(path);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> GetFileSystemEntries(string path)
|
||||
{
|
||||
return System.IO.Directory.GetFileSystemEntries(path);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> EnumerateDirectories(string path, string pattern)
|
||||
{
|
||||
return System.IO.Directory.EnumerateDirectories(path, pattern);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> EnumerateFiles(string path, string pattern)
|
||||
{
|
||||
return System.IO.Directory.EnumerateFiles(path, pattern);
|
||||
}
|
||||
|
||||
public static bool Exists(string path)
|
||||
{
|
||||
return System.IO.Directory.Exists(path);
|
||||
}
|
||||
|
||||
public static System.IO.DirectoryInfo CreateDirectory(string path)
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot create directory \"{path}\": failed validation");
|
||||
return null;
|
||||
}
|
||||
return System.IO.Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
public static void Delete(string path, bool recursive=true)
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot delete directory \"{path}\": failed validation");
|
||||
return;
|
||||
}
|
||||
//TODO: validate recursion?
|
||||
System.IO.Directory.Delete(path, recursive);
|
||||
}
|
||||
}
|
||||
|
||||
public static class File
|
||||
{
|
||||
public static bool Exists(string path)
|
||||
{
|
||||
return System.IO.File.Exists(path);
|
||||
}
|
||||
|
||||
public static void Copy(string src, string dest, bool overwrite=false)
|
||||
{
|
||||
if (!Validation.CanWrite(dest))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot copy \"{src}\" to \"{dest}\": failed validation");
|
||||
return;
|
||||
}
|
||||
System.IO.File.Copy(src, dest, overwrite);
|
||||
}
|
||||
|
||||
public static void Move(string src, string dest)
|
||||
{
|
||||
if (!Validation.CanWrite(src))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot move \"{src}\" to \"{dest}\": src failed validation");
|
||||
return;
|
||||
}
|
||||
if (!Validation.CanWrite(dest))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot move \"{src}\" to \"{dest}\": dest failed validation");
|
||||
return;
|
||||
}
|
||||
System.IO.File.Move(src, dest);
|
||||
}
|
||||
|
||||
public static void Delete(string path)
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot delete file \"{path}\": failed validation");
|
||||
return;
|
||||
}
|
||||
System.IO.File.Delete(path);
|
||||
}
|
||||
|
||||
public static DateTime GetLastWriteTime(string path)
|
||||
{
|
||||
return System.IO.File.GetLastWriteTime(path);
|
||||
}
|
||||
|
||||
public static FileStream Open(string path, System.IO.FileMode mode, System.IO.FileAccess access = System.IO.FileAccess.ReadWrite)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case System.IO.FileMode.Create:
|
||||
case System.IO.FileMode.CreateNew:
|
||||
case System.IO.FileMode.OpenOrCreate:
|
||||
case System.IO.FileMode.Append:
|
||||
case System.IO.FileMode.Truncate:
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot open \"{path}\" in {mode} mode: failed validation");
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return new FileStream(path, System.IO.File.Open(path, mode,
|
||||
!Validation.CanWrite(path, false) ?
|
||||
System.IO.FileAccess.Read :
|
||||
access));
|
||||
}
|
||||
|
||||
public static FileStream OpenRead(string path)
|
||||
{
|
||||
return Open(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
|
||||
}
|
||||
|
||||
public static FileStream OpenWrite(string path)
|
||||
{
|
||||
return Open(path, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
|
||||
}
|
||||
|
||||
public static FileStream Create(string path)
|
||||
{
|
||||
return Open(path, System.IO.FileMode.Create, System.IO.FileAccess.Write);
|
||||
}
|
||||
|
||||
public static void WriteAllBytes(string path, byte[] contents)
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot write all bytes to \"{path}\": failed validation");
|
||||
return;
|
||||
}
|
||||
System.IO.File.WriteAllBytes(path, contents);
|
||||
}
|
||||
|
||||
public static void WriteAllText(string path, string contents, System.Text.Encoding? encoding = null)
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot write all text to \"{path}\": failed validation");
|
||||
return;
|
||||
}
|
||||
System.IO.File.WriteAllText(path, contents, encoding ?? System.Text.Encoding.UTF8);
|
||||
}
|
||||
|
||||
public static void WriteAllLines(string path, IEnumerable<string> contents, System.Text.Encoding? encoding = null)
|
||||
{
|
||||
if (!Validation.CanWrite(path))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot write all lines to \"{path}\": failed validation");
|
||||
return;
|
||||
}
|
||||
System.IO.File.WriteAllLines(path, contents, encoding ?? System.Text.Encoding.UTF8);
|
||||
}
|
||||
|
||||
public static byte[] ReadAllBytes(string path)
|
||||
{
|
||||
return System.IO.File.ReadAllBytes(path);
|
||||
}
|
||||
|
||||
public static string ReadAllText(string path, System.Text.Encoding? encoding = null)
|
||||
{
|
||||
return System.IO.File.ReadAllText(path, encoding ?? System.Text.Encoding.UTF8);
|
||||
}
|
||||
|
||||
public static string[] ReadAllLines(string path, System.Text.Encoding? encoding = null)
|
||||
{
|
||||
return System.IO.File.ReadAllLines(path, encoding ?? System.Text.Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
|
||||
public class FileStream : System.IO.Stream
|
||||
{
|
||||
private System.IO.FileStream innerStream;
|
||||
private string fileName;
|
||||
|
||||
public FileStream(string fn, System.IO.FileStream stream)
|
||||
{
|
||||
innerStream = stream;
|
||||
fileName = fn;
|
||||
}
|
||||
|
||||
public override bool CanRead => innerStream.CanRead;
|
||||
public override bool CanSeek => innerStream.CanSeek;
|
||||
public override bool CanTimeout => innerStream.CanTimeout;
|
||||
public override bool CanWrite
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Validation.CanWrite(fileName)) { return false; }
|
||||
return innerStream.CanWrite;
|
||||
}
|
||||
}
|
||||
|
||||
public override long Length => innerStream.Length;
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return innerStream.Position;
|
||||
}
|
||||
set
|
||||
{
|
||||
innerStream.Position = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
return innerStream.Read(buffer, offset, count);
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (Validation.CanWrite(fileName))
|
||||
{
|
||||
innerStream.Write(buffer, offset, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot write to file \"{fileName}\": failed validation");
|
||||
}
|
||||
}
|
||||
|
||||
public override long Seek(long offset, System.IO.SeekOrigin origin)
|
||||
{
|
||||
return innerStream.Seek(offset, origin);
|
||||
}
|
||||
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
innerStream.SetLength(value);
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
innerStream.Flush();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
innerStream.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public class DirectoryInfo
|
||||
{
|
||||
private System.IO.DirectoryInfo innerInfo;
|
||||
|
||||
public DirectoryInfo(string path)
|
||||
{
|
||||
innerInfo = new System.IO.DirectoryInfo(path);
|
||||
}
|
||||
|
||||
private DirectoryInfo(System.IO.DirectoryInfo info)
|
||||
{
|
||||
innerInfo = info;
|
||||
}
|
||||
|
||||
public bool Exists => innerInfo.Exists;
|
||||
public string Name => innerInfo.Name;
|
||||
public string FullName => innerInfo.FullName;
|
||||
|
||||
public System.IO.FileAttributes Attributes => innerInfo.Attributes;
|
||||
|
||||
public IEnumerable<DirectoryInfo> GetDirectories()
|
||||
{
|
||||
var dirs = innerInfo.GetDirectories();
|
||||
foreach (var dir in dirs)
|
||||
{
|
||||
yield return new DirectoryInfo(dir);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<FileInfo> GetFiles()
|
||||
{
|
||||
var files = innerInfo.GetFiles();
|
||||
foreach (var file in files)
|
||||
{
|
||||
yield return new FileInfo(file);
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
if (!Validation.CanWrite(innerInfo.FullName))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot delete directory \"{Name}\": failed validation");
|
||||
return;
|
||||
}
|
||||
innerInfo.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
public class FileInfo
|
||||
{
|
||||
private System.IO.FileInfo innerInfo;
|
||||
|
||||
public FileInfo(string path)
|
||||
{
|
||||
innerInfo = new System.IO.FileInfo(path);
|
||||
}
|
||||
|
||||
public FileInfo(System.IO.FileInfo info)
|
||||
{
|
||||
innerInfo = info;
|
||||
}
|
||||
|
||||
public bool Exists => innerInfo.Exists;
|
||||
public string Name => innerInfo.Name;
|
||||
public string FullName => innerInfo.FullName;
|
||||
public long Length => innerInfo.Length;
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return innerInfo.IsReadOnly;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!Validation.CanWrite(innerInfo.FullName))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot set read-only to {value} for \"{Name}\": failed validation");
|
||||
return;
|
||||
}
|
||||
innerInfo.IsReadOnly = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void CopyTo(string dest, bool overwriteExisting = false)
|
||||
{
|
||||
if (!Validation.CanWrite(dest))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot copy \"{Name}\" to \"{dest}\": failed validation");
|
||||
return;
|
||||
}
|
||||
innerInfo.CopyTo(dest, overwriteExisting);
|
||||
}
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
if (!Validation.CanWrite(innerInfo.FullName))
|
||||
{
|
||||
DebugConsole.ThrowError($"Cannot delete file \"{Name}\": failed validation");
|
||||
return;
|
||||
}
|
||||
innerInfo.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -245,7 +245,7 @@ namespace Barotrauma
|
||||
// B.
|
||||
// Read file into byte array buffer.
|
||||
byte[] b;
|
||||
using (FileStream f = new FileStream(temp, FileMode.Open))
|
||||
using (FileStream f = File.Open(temp, System.IO.FileMode.Open))
|
||||
{
|
||||
b = new byte[f.Length];
|
||||
f.Read(b, 0, (int)f.Length);
|
||||
@@ -253,7 +253,7 @@ namespace Barotrauma
|
||||
|
||||
// C.
|
||||
// Use GZipStream to write compressed bytes to target file.
|
||||
using (FileStream f2 = new FileStream(fileName, FileMode.Create))
|
||||
using (FileStream f2 = File.Open(fileName, System.IO.FileMode.Create))
|
||||
using (GZipStream gz = new GZipStream(f2, CompressionMode.Compress, false))
|
||||
{
|
||||
gz.Write(b, 0, b.Length);
|
||||
@@ -276,10 +276,10 @@ namespace Barotrauma
|
||||
|
||||
public static void CompressDirectory(string sInDir, string sOutFile, ProgressDelegate progress)
|
||||
{
|
||||
string[] sFiles = Directory.GetFiles(sInDir, "*.*", SearchOption.AllDirectories);
|
||||
IEnumerable<string> sFiles = Directory.GetFiles(sInDir, "*.*", System.IO.SearchOption.AllDirectories);
|
||||
int iDirLen = sInDir[sInDir.Length - 1] == Path.DirectorySeparatorChar ? sInDir.Length : sInDir.Length + 1;
|
||||
|
||||
using (FileStream outFile = new FileStream(sOutFile, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
using (FileStream outFile = File.Open(sOutFile, System.IO.FileMode.Create, System.IO.FileAccess.Write))
|
||||
using (GZipStream str = new GZipStream(outFile, CompressionMode.Compress))
|
||||
foreach (string sFilePath in sFiles)
|
||||
{
|
||||
@@ -290,11 +290,11 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
|
||||
public static Stream DecompressFiletoStream(string fileName)
|
||||
public static System.IO.Stream DecompressFiletoStream(string fileName)
|
||||
{
|
||||
using (FileStream originalFileStream = new FileStream(fileName, FileMode.Open))
|
||||
using (FileStream originalFileStream = File.Open(fileName, System.IO.FileMode.Open))
|
||||
{
|
||||
MemoryStream decompressedFileStream = new MemoryStream();
|
||||
System.IO.MemoryStream decompressedFileStream = new System.IO.MemoryStream();
|
||||
|
||||
using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress))
|
||||
{
|
||||
@@ -347,13 +347,13 @@ namespace Barotrauma
|
||||
{
|
||||
try
|
||||
{
|
||||
using (FileStream outFile = new FileStream(sFilePath, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
using (FileStream outFile = File.Open(sFilePath, System.IO.FileMode.Create, System.IO.FileAccess.Write))
|
||||
{
|
||||
outFile.Write(bytes, 0, iFileLen);
|
||||
}
|
||||
break;
|
||||
}
|
||||
catch (IOException e)
|
||||
catch (System.IO.IOException e)
|
||||
{
|
||||
if (i >= maxRetries || !File.Exists(sFilePath)) { throw; }
|
||||
DebugConsole.NewMessage("Failed decompress file \"" + sFilePath + "\" {" + e.Message + "}, retrying in 250 ms...", Color.Red);
|
||||
@@ -371,13 +371,13 @@ namespace Barotrauma
|
||||
{
|
||||
try
|
||||
{
|
||||
using (FileStream inFile = new FileStream(sCompressedFile, FileMode.Open, FileAccess.Read, FileShare.None))
|
||||
using (FileStream inFile = File.Open(sCompressedFile, System.IO.FileMode.Open, System.IO.FileAccess.Read))
|
||||
using (GZipStream zipStream = new GZipStream(inFile, CompressionMode.Decompress, true))
|
||||
while (DecompressFile(sDir, zipStream, progress)) { };
|
||||
|
||||
break;
|
||||
}
|
||||
catch (IOException e)
|
||||
catch (System.IO.IOException e)
|
||||
{
|
||||
if (i >= maxRetries || !File.Exists(sCompressedFile)) { throw; }
|
||||
DebugConsole.NewMessage("Failed decompress file \"" + sCompressedFile + "\" {" + e.Message + "}, retrying in 250 ms...", Color.Red);
|
||||
@@ -393,12 +393,12 @@ namespace Barotrauma
|
||||
|
||||
if (!dir.Exists)
|
||||
{
|
||||
throw new DirectoryNotFoundException(
|
||||
throw new System.IO.DirectoryNotFoundException(
|
||||
"Source directory does not exist or could not be found: "
|
||||
+ sourceDirName);
|
||||
}
|
||||
|
||||
DirectoryInfo[] dirs = dir.GetDirectories();
|
||||
IEnumerable<DirectoryInfo> dirs = dir.GetDirectories();
|
||||
// If the destination directory doesn't exist, create it.
|
||||
if (!Directory.Exists(destDirName))
|
||||
{
|
||||
@@ -406,11 +406,12 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
// Get the files in the directory and copy them to the new location.
|
||||
FileInfo[] files = dir.GetFiles();
|
||||
IEnumerable<FileInfo> files = dir.GetFiles();
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
string tempPath = Path.Combine(destDirName, file.Name);
|
||||
file.CopyTo(tempPath, overwriteExisting);
|
||||
if (!overwriteExisting && File.Exists(tempPath)) { continue; }
|
||||
file.CopyTo(tempPath, true);
|
||||
}
|
||||
|
||||
// If copying subdirectories, copy them and their contents to new location.
|
||||
@@ -472,7 +473,7 @@ namespace Barotrauma
|
||||
di.Delete();
|
||||
break;
|
||||
}
|
||||
catch (IOException)
|
||||
catch (System.IO.IOException)
|
||||
{
|
||||
if (i >= maxRetries) { throw; }
|
||||
Thread.Sleep(250);
|
||||
|
||||
@@ -4,7 +4,7 @@ using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
@@ -325,15 +325,12 @@ namespace Barotrauma
|
||||
{
|
||||
try
|
||||
{
|
||||
using (StreamReader file = new StreamReader(filePath))
|
||||
lines = File.ReadAllLines(filePath).ToList();
|
||||
cachedLines.Add(filePath, lines);
|
||||
if (lines.Count == 0)
|
||||
{
|
||||
lines = File.ReadLines(filePath).ToList();
|
||||
cachedLines.Add(filePath, lines);
|
||||
if (lines.Count == 0)
|
||||
{
|
||||
DebugConsole.ThrowError("File \"" + filePath + "\" is empty!");
|
||||
return "";
|
||||
}
|
||||
DebugConsole.ThrowError("File \"" + filePath + "\" is empty!");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Barotrauma.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Xml.Linq;
|
||||
@@ -15,7 +15,7 @@ namespace Barotrauma
|
||||
{
|
||||
XDocument doc = new XDocument(CreateFileList());
|
||||
|
||||
doc.Save(filePath);
|
||||
doc.SaveSafe(filePath);
|
||||
}
|
||||
|
||||
public static XElement CreateFileList()
|
||||
@@ -23,7 +23,7 @@ namespace Barotrauma
|
||||
XElement root = new XElement("filelist");
|
||||
string currentDir = Directory.GetCurrentDirectory();
|
||||
|
||||
string[] files = Directory.GetFiles(currentDir, "*", SearchOption.AllDirectories);
|
||||
IEnumerable<string> files = Directory.GetFiles(currentDir, "*", System.IO.SearchOption.AllDirectories);
|
||||
|
||||
foreach (string file in files)
|
||||
{
|
||||
@@ -122,7 +122,7 @@ namespace Barotrauma
|
||||
/// <param name="updateFileFolder"></param>
|
||||
public static void InstallUpdatedFiles(string updateFileFolder)
|
||||
{
|
||||
string[] files = Directory.GetFiles(updateFileFolder, "*", SearchOption.AllDirectories);
|
||||
IEnumerable<string> files = Directory.GetFiles(updateFileFolder, "*", System.IO.SearchOption.AllDirectories);
|
||||
|
||||
string currentDir = Directory.GetCurrentDirectory();
|
||||
|
||||
@@ -166,7 +166,7 @@ namespace Barotrauma
|
||||
{
|
||||
string currentDir = Directory.GetCurrentDirectory();
|
||||
|
||||
string[] files = Directory.GetFiles(currentDir, "*", SearchOption.AllDirectories);
|
||||
IEnumerable<string> files = Directory.GetFiles(currentDir, "*", System.IO.SearchOption.AllDirectories);
|
||||
|
||||
foreach (string file in files)
|
||||
{
|
||||
@@ -199,7 +199,7 @@ namespace Barotrauma
|
||||
{
|
||||
string currentDir = Directory.GetCurrentDirectory();
|
||||
|
||||
string[] files = Directory.GetFiles(currentDir, "*", SearchOption.AllDirectories);
|
||||
IEnumerable<string> files = Directory.GetFiles(currentDir, "*", System.IO.SearchOption.AllDirectories);
|
||||
|
||||
foreach (string file in files)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user