Fix ReadWriteZipFile crashing on update.

This commit is contained in:
Paul Chote
2017-07-17 21:34:25 +01:00
committed by reaperrr
parent 7a2d2cfd5f
commit 93fcfbb131

View File

@@ -97,13 +97,14 @@ namespace OpenRA.FileSystem
sealed class ReadWriteZipFile : ReadOnlyZipFile, IReadWritePackage sealed class ReadWriteZipFile : ReadOnlyZipFile, IReadWritePackage
{ {
readonly MemoryStream pkgStream; readonly MemoryStream pkgStream = new MemoryStream();
public ReadWriteZipFile(string filename, bool create = false) public ReadWriteZipFile(string filename, bool create = false)
{ {
// SharpZipLib breaks when asked to update archives loaded from outside streams or files // SharpZipLib breaks when asked to update archives loaded from outside streams or files
// We can work around this by creating a clean in-memory-only file, cutting all outside references // We can work around this by creating a clean in-memory-only file, cutting all outside references
pkgStream = create ? new MemoryStream() : new MemoryStream(File.ReadAllBytes(filename)); if (!create)
new MemoryStream(File.ReadAllBytes(filename)).CopyTo(pkgStream);
pkgStream.Position = 0; pkgStream.Position = 0;
pkg = ZipFileHelper.Create(pkgStream); pkg = ZipFileHelper.Create(pkgStream);