Add support for in-memory ReadWriteZipFiles.
This commit is contained in:
committed by
Gustas Kažukauskas
parent
fceb8a479d
commit
1707dbd92b
@@ -98,11 +98,11 @@ namespace OpenRA.FileSystem
|
|||||||
{
|
{
|
||||||
readonly MemoryStream pkgStream = new();
|
readonly MemoryStream pkgStream = new();
|
||||||
|
|
||||||
public ReadWriteZipFile(string filename, bool create = false)
|
public ReadWriteZipFile(string filename = null, 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
|
||||||
if (!create)
|
if (!string.IsNullOrEmpty(filename) && !create)
|
||||||
{
|
{
|
||||||
using (var copy = new MemoryStream(File.ReadAllBytes(filename)))
|
using (var copy = new MemoryStream(File.ReadAllBytes(filename)))
|
||||||
{
|
{
|
||||||
@@ -122,7 +122,8 @@ namespace OpenRA.FileSystem
|
|||||||
|
|
||||||
void Commit()
|
void Commit()
|
||||||
{
|
{
|
||||||
File.WriteAllBytes(Name, pkgStream.ToArray());
|
if (!string.IsNullOrEmpty(Name))
|
||||||
|
File.WriteAllBytes(Name, pkgStream.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(string filename, byte[] contents)
|
public void Update(string filename, byte[] contents)
|
||||||
|
|||||||
Reference in New Issue
Block a user