Fix crash when loading read-only ReadWriteZipFiles.
This commit is contained in:
committed by
RoosterDragon
parent
ab1a798d04
commit
f7c57cfc6f
@@ -99,16 +99,12 @@ namespace OpenRA.FileSystem
|
|||||||
{
|
{
|
||||||
readonly MemoryStream pkgStream;
|
readonly MemoryStream pkgStream;
|
||||||
|
|
||||||
public ReadWriteZipFile(Stream stream, string filename)
|
public ReadWriteZipFile(string filename, bool truncate = 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 = new MemoryStream();
|
pkgStream = File.Exists(filename) && !truncate ?
|
||||||
if (stream != null)
|
new MemoryStream(File.ReadAllBytes(filename)) : new MemoryStream();
|
||||||
{
|
|
||||||
stream.CopyTo(pkgStream);
|
|
||||||
stream.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
pkgStream.Position = 0;
|
pkgStream.Position = 0;
|
||||||
pkg = ZipFileHelper.Create(pkgStream);
|
pkg = ZipFileHelper.Create(pkgStream);
|
||||||
@@ -225,14 +221,13 @@ namespace OpenRA.FileSystem
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var s = new FileStream(filename, FileMode.Open);
|
package = new ReadWriteZipFile(filename);
|
||||||
package = new ReadWriteZipFile(s, filename);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IReadWritePackage Create(string filename)
|
public static IReadWritePackage Create(string filename)
|
||||||
{
|
{
|
||||||
return new ReadWriteZipFile(null, filename);
|
return new ReadWriteZipFile(filename, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user