XML files are calculated according to XML content.
This commit is contained in:
@@ -155,10 +155,10 @@ namespace Barotrauma
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var stream = File.OpenRead(file.path))
|
if (file.path.EndsWith(".xml", true, System.Globalization.CultureInfo.InvariantCulture))
|
||||||
{
|
hashes.Add(calculateXmlHash(file, ref md5));
|
||||||
hashes.Add(md5.ComputeHash(stream));
|
else
|
||||||
}
|
hashes.Add(calculateFileHash(file, ref md5));
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -179,6 +179,34 @@ namespace Barotrauma
|
|||||||
md5Hash = new Md5Hash(bytes);
|
md5Hash = new Md5Hash(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private byte[] calculateXmlHash(ContentFile file, ref MD5 md5) //todo: Change ref to in (in C# 7.2)
|
||||||
|
{
|
||||||
|
var doc = XMLExtensions.TryLoadXml(file.path);
|
||||||
|
|
||||||
|
if (doc == null)
|
||||||
|
throw new Exception($"file {file.path} could not be opened as XML document");
|
||||||
|
|
||||||
|
using (var memoryStream = new MemoryStream())
|
||||||
|
{
|
||||||
|
using (var writer = new StreamWriter(memoryStream))
|
||||||
|
{
|
||||||
|
writer.Write(doc.ToString());
|
||||||
|
writer.Flush();
|
||||||
|
|
||||||
|
return md5.ComputeHash(memoryStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] calculateFileHash(ContentFile file, ref MD5 md5)
|
||||||
|
{
|
||||||
|
using (var stream = File.OpenRead(file.path))
|
||||||
|
{
|
||||||
|
return md5.ComputeHash(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public List<string> GetFilesOfType(ContentType type)
|
public List<string> GetFilesOfType(ContentType type)
|
||||||
{
|
{
|
||||||
List<ContentFile> contentFiles = files.FindAll(f => f.type == type);
|
List<ContentFile> contentFiles = files.FindAll(f => f.type == type);
|
||||||
|
|||||||
Reference in New Issue
Block a user