dont use the .uid file hack -- compute them on demand
This commit is contained in:
@@ -12,6 +12,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace OpenRA.FileFormats
|
namespace OpenRA.FileFormats
|
||||||
{
|
{
|
||||||
@@ -45,10 +46,22 @@ namespace OpenRA.FileFormats
|
|||||||
var yaml = MiniYaml.FromStream(Container.GetContent("map.yaml"));
|
var yaml = MiniYaml.FromStream(Container.GetContent("map.yaml"));
|
||||||
FieldLoader.Load( this, new MiniYaml( null, yaml ) );
|
FieldLoader.Load( this, new MiniYaml( null, yaml ) );
|
||||||
|
|
||||||
Bounds = Rectangle.FromLTRB(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
|
Bounds = Rectangle.FromLTRB(TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
|
||||||
Uid = Container.GetContent("map.uid").ReadAllText();
|
Uid = ComputeHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string ComputeHash()
|
||||||
|
{
|
||||||
|
// UID is calculated by taking an SHA1 of the yaml and binary data
|
||||||
|
// Read the relevant data into a buffer
|
||||||
|
var data = Container.GetContent("map.yaml").ReadAllBytes()
|
||||||
|
.Concat(Container.GetContent("map.bin").ReadAllBytes()).ToArray();
|
||||||
|
|
||||||
|
// Take the SHA1
|
||||||
|
using (var csp = SHA1.Create())
|
||||||
|
return new string(csp.ComputeHash(data).SelectMany(a => a.ToString("x2")).ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
static object LoadWaypoints( MiniYaml y )
|
static object LoadWaypoints( MiniYaml y )
|
||||||
{
|
{
|
||||||
var ret = new Dictionary<string, int2>();
|
var ret = new Dictionary<string, int2>();
|
||||||
|
|||||||
@@ -225,7 +225,6 @@ namespace OpenRA
|
|||||||
|
|
||||||
SaveBinaryData(Path.Combine(filepath, "map.bin"));
|
SaveBinaryData(Path.Combine(filepath, "map.bin"));
|
||||||
root.WriteToFile(Path.Combine(filepath, "map.yaml"));
|
root.WriteToFile(Path.Combine(filepath, "map.yaml"));
|
||||||
SaveUid(Path.Combine(filepath, "map.uid"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte ReadByte(Stream s)
|
static byte ReadByte(Stream s)
|
||||||
@@ -308,20 +307,6 @@ namespace OpenRA
|
|||||||
File.Move(filepath + ".tmp", filepath);
|
File.Move(filepath + ".tmp", filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveUid(string filename)
|
|
||||||
{
|
|
||||||
// UID is calculated by taking an SHA1 of the yaml and binary data
|
|
||||||
// Read the relevant data into a buffer
|
|
||||||
var data = Container.GetContent("map.yaml").ReadAllBytes()
|
|
||||||
.Concat(Container.GetContent("map.bin").ReadAllBytes()).ToArray();
|
|
||||||
|
|
||||||
// Take the SHA1
|
|
||||||
using (var csp = SHA1.Create())
|
|
||||||
Uid = new string(csp.ComputeHash(data).SelectMany(a => a.ToString("x2")).ToArray());
|
|
||||||
|
|
||||||
File.WriteAllText(filename, Uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsInMap(int2 xy)
|
public bool IsInMap(int2 xy)
|
||||||
{
|
{
|
||||||
return IsInMap(xy.X, xy.Y);
|
return IsInMap(xy.X, xy.Y);
|
||||||
|
|||||||
Reference in New Issue
Block a user