diff --git a/OpenRA.FileFormats/Filesystem/ZipFile.cs b/OpenRA.FileFormats/Filesystem/ZipFile.cs index 0cd43ecbee..e1c57801dc 100644 --- a/OpenRA.FileFormats/Filesystem/ZipFile.cs +++ b/OpenRA.FileFormats/Filesystem/ZipFile.cs @@ -17,15 +17,18 @@ namespace OpenRA.FileFormats { public class ZipFile : IFolder { - readonly SZipFile pkg; + string filename; + SZipFile pkg; int priority; public ZipFile(string filename, int priority) { + this.filename = filename; this.priority = priority; try { - pkg = new SZipFile(File.OpenRead(filename)); + // pull the file into memory, dont keep it open. + pkg = new SZipFile(new MemoryStream(File.ReadAllBytes(filename))); } catch (ZipException e) { @@ -46,15 +49,18 @@ namespace OpenRA.FileFormats public Stream GetContent(string 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; + + using (var z = pkg.GetInputStream(pkg.GetEntry(filename))) + { + var ms = new MemoryStream(); + 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 AllFileHashes() @@ -75,14 +81,21 @@ namespace OpenRA.FileFormats public void Write(Dictionary contents) { + pkg.Close(); + + pkg = SZipFile.Create(filename); + pkg.BeginUpdate(); // TODO: Clear existing content? - + foreach (var kvp in contents) - { pkg.Add(new StaticMemoryDataSource(kvp.Value), kvp.Key); - } + pkg.CommitUpdate(); + + pkg.Close(); + + pkg = new SZipFile(new MemoryStream(File.ReadAllBytes(filename))); } } diff --git a/OpenRA.Game/Map.cs b/OpenRA.Game/Map.cs index a9ad6b3f6a..4598a9934f 100644 --- a/OpenRA.Game/Map.cs +++ b/OpenRA.Game/Map.cs @@ -16,6 +16,7 @@ using System.Linq; using System.Reflection; using System.Security.Cryptography; using OpenRA.FileFormats; +using System.Text; namespace OpenRA { @@ -202,7 +203,7 @@ namespace OpenRA var root = new List(); foreach (var field in new string[] {"Selectable", "MapFormat", "Title", "Description", "Author", "PlayerCount", "Tileset", "MapSize", "TopLeft", "BottomRight", "UseAsShellmap", "Type"}) { - FieldInfo f = this.GetType().GetField(field); + var f = this.GetType().GetField(field); if (f.GetValue(this) == null) continue; root.Add( new MiniYamlNode( field, FieldSaver.FormatValue( this, f ) ) ); } @@ -227,7 +228,7 @@ namespace OpenRA Dictionary entries = new Dictionary(); entries.Add("map.bin", SaveBinaryData()); var s = root.WriteToString(); - entries.Add("map.yaml", System.Text.Encoding.UTF8.GetBytes(s)); + entries.Add("map.yaml", Encoding.UTF8.GetBytes(s)); // Saving the map to a new location if (toPath != Path) diff --git a/mods/ra/maps/a-path-beyond.oramap b/mods/ra/maps/a-path-beyond.oramap index de342aa0b6..8540b64eb0 100644 Binary files a/mods/ra/maps/a-path-beyond.oramap and b/mods/ra/maps/a-path-beyond.oramap differ diff --git a/mods/ra/maps/coastal-influence.oramap b/mods/ra/maps/coastal-influence.oramap index 0c6ec3e529..13edb3e9cb 100644 Binary files a/mods/ra/maps/coastal-influence.oramap and b/mods/ra/maps/coastal-influence.oramap differ