From dffb5293d05205e409d0a3128a0442c9106448b0 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sat, 1 Jan 2011 15:28:07 +1300 Subject: [PATCH] hack up ZipFile to fix #464; filesystem needs rework to be sane --- OpenRA.FileFormats/Filesystem/ZipFile.cs | 41 +++++++++++++++-------- OpenRA.Game/Map.cs | 5 +-- mods/ra/maps/a-path-beyond.oramap | Bin 5752 -> 5779 bytes mods/ra/maps/coastal-influence.oramap | Bin 7859 -> 7859 bytes 4 files changed, 30 insertions(+), 16 deletions(-) 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 de342aa0b6bc49058333b85f1ba382cd31565d24..8540b64eb0aecb29382b98eac2dc0432379fe34b 100644 GIT binary patch delta 985 zcmV;~119|VER!t`P)h>@6aWAK2mm~LAwIDVWD*TLdm%p0JlQ9N0{{SjlYbHzf96y0 z0dT-K2%V~^&P-8H|`FOlR4L z5M!v<<;!6hW1PU3WnVkL>^28qRkb@V@{g|Sz}@ZJ5tdqo=0^|CoE+#D+1=Dy`)A+! zX6JwV;``XT3TE!UxEe(B0Q4VS4vci%--h zKkn{+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