From d7e8388600e24550f71e7d3519cfe7466cc98892 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 21 Nov 2010 11:36:59 +1300 Subject: [PATCH] Make our IFolder zip support actually work. --- Makefile | 2 +- OpenRA.FileFormats/Filesystem/FileSystem.cs | 2 +- .../{CompressedPackage.cs => ZipFile.cs} | 27 +++++++++--------- OpenRA.FileFormats/OpenRA.FileFormats.csproj | 6 +++- packaging/osx/buildpackage.sh | 3 +- packaging/package-all.sh | 3 -- thirdparty/WindowsBase.dll | Bin 174080 -> 0 bytes 7 files changed, 21 insertions(+), 22 deletions(-) rename OpenRA.FileFormats/Filesystem/{CompressedPackage.cs => ZipFile.cs} (52%) delete mode 100755 thirdparty/WindowsBase.dll diff --git a/Makefile b/Makefile index 803b90665f..fbbb42773a 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ COMMON_LIBS = System.dll System.Core.dll System.Drawing.dll System.Xml.dll fileformats_SRCS = $(shell find OpenRA.FileFormats/ -iname '*.cs') fileformats_TARGET = OpenRA.FileFormats.dll fileformats_KIND = library -fileformats_LIBS = $(COMMON_LIBS) thirdparty/Tao/Tao.Sdl.dll System.Windows.Forms.dll thirdparty/WindowsBase.dll +fileformats_LIBS = $(COMMON_LIBS) thirdparty/Tao/Tao.Sdl.dll System.Windows.Forms.dll thirdparty/ICSharpCode.SharpZipLib.dll rcg_SRCS = $(shell find OpenRA.Renderer.Cg/ -iname '*.cs') rcg_TARGET = OpenRA.Renderer.Cg.dll diff --git a/OpenRA.FileFormats/Filesystem/FileSystem.cs b/OpenRA.FileFormats/Filesystem/FileSystem.cs index 15ca6b14a3..77d38ac623 100644 --- a/OpenRA.FileFormats/Filesystem/FileSystem.cs +++ b/OpenRA.FileFormats/Filesystem/FileSystem.cs @@ -41,7 +41,7 @@ namespace OpenRA.FileFormats if (filename.EndsWith(".mix", StringComparison.InvariantCultureIgnoreCase)) return new MixFile(filename, order++); else if (filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase)) - return new CompressedPackage(filename, order++); + return new ZipFile(filename, order++); else if (filename.EndsWith(".Z", StringComparison.InvariantCultureIgnoreCase)) return new InstallShieldPackage(filename, order++); else diff --git a/OpenRA.FileFormats/Filesystem/CompressedPackage.cs b/OpenRA.FileFormats/Filesystem/ZipFile.cs similarity index 52% rename from OpenRA.FileFormats/Filesystem/CompressedPackage.cs rename to OpenRA.FileFormats/Filesystem/ZipFile.cs index 0dbba955dc..48699015e7 100644 --- a/OpenRA.FileFormats/Filesystem/CompressedPackage.cs +++ b/OpenRA.FileFormats/Filesystem/ZipFile.cs @@ -11,40 +11,39 @@ using System; using System.Collections.Generic; using System.IO; -using System.IO.Packaging; +using ICSharpCode.SharpZipLib.Zip; +using SZipFile = ICSharpCode.SharpZipLib.Zip.ZipFile; using System.Linq; namespace OpenRA.FileFormats { - public class CompressedPackage : IFolder + public class ZipFile : IFolder { - readonly uint[] hashes; - readonly Stream s; - readonly ZipPackage pkg; + readonly SZipFile pkg; int priority; - public CompressedPackage(string filename, int priority) + public ZipFile(string filename, int priority) { this.priority = priority; - s = FileSystem.Open(filename); - pkg = (ZipPackage)ZipPackage.Open(s, FileMode.Open); - hashes = pkg.GetParts() - .Select(p => PackageEntry.HashFilename(p.Uri.LocalPath)).ToArray(); + pkg = new SZipFile(File.OpenRead(filename)); } public Stream GetContent(string filename) { - return pkg.GetPart(new Uri(filename)).GetStream(FileMode.Open); + return pkg.GetInputStream(pkg.GetEntry(filename)); } - public IEnumerable AllFileHashes() { return hashes; } + public IEnumerable AllFileHashes() + { + foreach(ZipEntry entry in pkg) + yield return PackageEntry.HashFilename(entry.Name); + } public bool Exists(string filename) { - return hashes.Contains(PackageEntry.HashFilename(filename)); + return pkg.GetEntry(filename) != null; } - public int Priority { get { return 500 + priority; } diff --git a/OpenRA.FileFormats/OpenRA.FileFormats.csproj b/OpenRA.FileFormats/OpenRA.FileFormats.csproj index 9e933b8a3e..1f0ffe1a2f 100644 --- a/OpenRA.FileFormats/OpenRA.FileFormats.csproj +++ b/OpenRA.FileFormats/OpenRA.FileFormats.csproj @@ -54,6 +54,10 @@ 3.0 + + False + ..\thirdparty\ICSharpCode.SharpZipLib.dll + @@ -102,9 +106,9 @@ - +