Write maps to zip file from editor

This commit is contained in:
Matthew Bowra-Dean
2010-12-28 22:00:39 +13:00
committed by Matthew
parent 44e668e804
commit 13f6a13ad9
4 changed files with 50 additions and 19 deletions

View File

@@ -10,6 +10,9 @@
using System.Collections.Generic;
using System.IO;
using ICSharpCode.SharpZipLib;
using ICSharpCode.SharpZipLib.Zip;
using SZipFile = ICSharpCode.SharpZipLib.Zip.ZipFile;
namespace OpenRA.FileFormats
{
@@ -44,5 +47,31 @@ namespace OpenRA.FileFormats
s.Write(File.ReadAllBytes(file));
}
}
class StaticMemoryDataSource : IStaticDataSource
{
byte[] data;
public StaticMemoryDataSource (byte[] data)
{
this.data = data;
}
public Stream GetSource()
{
return new MemoryStream(data);
}
}
public static void CreateZip(string zipFile, Dictionary<string, byte[]> contents)
{
var z = SZipFile.Create(zipFile);
z.BeginUpdate();
foreach (var kvp in contents)
{
z.Add(new StaticMemoryDataSource(kvp.Value), kvp.Key);
}
z.CommitUpdate();
z.Close();
}
}
}