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:
@@ -46,7 +46,15 @@ namespace OpenRA.FileFormats
|
||||
|
||||
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()
|
||||
|
||||
@@ -251,9 +251,13 @@ namespace OpenRA
|
||||
|
||||
static string ChooseShellmap()
|
||||
{
|
||||
return modData.AvailableMaps
|
||||
.Where(m => m.Value.UseAsShellmap)
|
||||
.Random(CosmeticRandom).Key;
|
||||
var shellmaps = modData.AvailableMaps
|
||||
.Where(m => m.Value.UseAsShellmap);
|
||||
|
||||
if (shellmaps.Count() == 0)
|
||||
throw new InvalidDataException("No valid shellmaps available");
|
||||
|
||||
return shellmaps.Random(CosmeticRandom).Key;
|
||||
}
|
||||
|
||||
static bool quit;
|
||||
|
||||
@@ -195,11 +195,12 @@ namespace OpenRA
|
||||
|
||||
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
|
||||
MapFormat = 3;
|
||||
|
||||
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);
|
||||
if (f.GetValue(this) == null) continue;
|
||||
|
||||
@@ -62,8 +62,16 @@ namespace OpenRA
|
||||
{
|
||||
var paths = mods.SelectMany(p => FindMapsIn("mods/" + p + "/maps/"));
|
||||
|
||||
return paths.Select(p => new MapStub(p))
|
||||
.ToDictionary(m => m.Uid);
|
||||
Dictionary<string, MapStub> ret = new Dictionary<string, MapStub>();
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user