Make map saving independent of Container type. Saving zip/oramap/mix untested as the editor cannot load non-folder maps.

This commit is contained in:
Paul Chote
2010-12-29 11:39:26 +13:00
parent fa36c71023
commit c3ff679f3a
8 changed files with 73 additions and 81 deletions

View File

@@ -20,6 +20,7 @@ namespace OpenRA.FileFormats
Stream GetContent(string filename);
bool Exists(string filename);
IEnumerable<uint> AllFileHashes();
void Write(Dictionary<string, byte[]> contents);
int Priority { get; }
}
@@ -158,6 +159,35 @@ namespace OpenRA.FileFormats
{
get { return 1000 + priority; }
}
public void Write(Dictionary<string, byte[]> contents)
{
// Construct a list of entries for the file header
uint dataSize = 0;
var items = new List<PackageEntry>();
foreach (var kv in contents)
{
uint length = (uint)kv.Value.Length;
uint hash = PackageEntry.HashFilename(Path.GetFileName(kv.Key));
items.Add(new PackageEntry(hash, dataSize, length));
dataSize += length;
}
using (var writer = new BinaryWriter(s))
{
// Write file header
writer.Write((ushort)items.Count);
writer.Write(dataSize);
foreach (var item in items)
item.Write(writer);
writer.Flush();
// Copy file data
foreach (var file in contents)
s.Write(file.Value);
}
}
}
[Flags]