Bugfixes: ZipFile.GetInputStream().GetAllBytes/.Length doesn't work; Divide by zero when no shellmaps are available; UseAsShellmap isn't saved by the editor; Duplicate maps crashes game.

This commit is contained in:
Paul Chote
2010-12-30 16:39:26 +13:00
parent 47bbc3a6de
commit cb50182fac
4 changed files with 28 additions and 7 deletions

View File

@@ -46,7 +46,15 @@ namespace OpenRA.FileFormats
public Stream GetContent(string filename) public Stream GetContent(string filename)
{ {
return pkg.GetInputStream(pkg.GetEntry(filename)); var ms = new MemoryStream();
var z = pkg.GetInputStream(pkg.GetEntry(filename));
int bufSize = 2048;
byte[] buf = new byte[bufSize];
while ((bufSize = z.Read(buf, 0, buf.Length)) > 0)
ms.Write(buf, 0, bufSize);
ms.Seek(0, SeekOrigin.Begin);
return ms;
} }
public IEnumerable<uint> AllFileHashes() public IEnumerable<uint> AllFileHashes()

View File

@@ -251,9 +251,13 @@ namespace OpenRA
static string ChooseShellmap() static string ChooseShellmap()
{ {
return modData.AvailableMaps var shellmaps = modData.AvailableMaps
.Where(m => m.Value.UseAsShellmap) .Where(m => m.Value.UseAsShellmap);
.Random(CosmeticRandom).Key;
if (shellmaps.Count() == 0)
throw new InvalidDataException("No valid shellmaps available");
return shellmaps.Random(CosmeticRandom).Key;
} }
static bool quit; static bool quit;

View File

@@ -195,11 +195,12 @@ namespace OpenRA
public void Save(string toPath) public void Save(string toPath)
{ {
Console.WriteLine("Saving map to path {0}",toPath);
// Todo: save to a zip file in the support dir by default // Todo: save to a zip file in the support dir by default
MapFormat = 3; MapFormat = 3;
var root = new List<MiniYamlNode>(); var root = new List<MiniYamlNode>();
foreach (var field in new string[] {"Selectable", "MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "MapSize", "TopLeft", "BottomRight"}) foreach (var field in new string[] {"Selectable", "MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "MapSize", "TopLeft", "BottomRight", "UseAsShellmap"})
{ {
FieldInfo f = this.GetType().GetField(field); FieldInfo f = this.GetType().GetField(field);
if (f.GetValue(this) == null) continue; if (f.GetValue(this) == null) continue;

View File

@@ -62,8 +62,16 @@ namespace OpenRA
{ {
var paths = mods.SelectMany(p => FindMapsIn("mods/" + p + "/maps/")); var paths = mods.SelectMany(p => FindMapsIn("mods/" + p + "/maps/"));
return paths.Select(p => new MapStub(p)) Dictionary<string, MapStub> ret = new Dictionary<string, MapStub>();
.ToDictionary(m => m.Uid); foreach (var path in paths)
{
var map = new MapStub(path);
if (ret.ContainsKey(map.Uid))
System.Console.WriteLine("Ignoring duplicate map: {0}", path);
else
ret.Add(map.Uid, map);
}
return ret;
} }
string cachedTileset = null; string cachedTileset = null;