From 6be947bbf02dd58c8767c3fb7a006837ad5a517d Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 17 Apr 2025 17:45:48 +0100 Subject: [PATCH] Support serializing/loading ReadWriteZipFile as base64 string. --- OpenRA.Game/FileSystem/ZipFile.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/OpenRA.Game/FileSystem/ZipFile.cs b/OpenRA.Game/FileSystem/ZipFile.cs index c28036dd80..39dc6ec3b1 100644 --- a/OpenRA.Game/FileSystem/ZipFile.cs +++ b/OpenRA.Game/FileSystem/ZipFile.cs @@ -120,6 +120,23 @@ namespace OpenRA.FileSystem entry.ExtraData = null; } + public ReadWriteZipFile(byte[] data) + { + using (var copy = new MemoryStream(data)) + { + pkgStream.Capacity = (int)copy.Length; + copy.CopyTo(pkgStream); + } + + pkgStream.Position = 0; + pkg = new ZipFile(pkgStream); + Name = null; + + // Remove subfields that can break ZIP updating. + foreach (ZipEntry entry in pkg) + entry.ExtraData = null; + } + void Commit() { if (!string.IsNullOrEmpty(Name)) @@ -141,6 +158,16 @@ namespace OpenRA.FileSystem pkg.CommitUpdate(); Commit(); } + + public static ReadWriteZipFile FromBase64String(string data) + { + return new ReadWriteZipFile(Convert.FromBase64String(data)); + } + + public string ToBase64String() + { + return Convert.ToBase64String(pkgStream.ToArray()); + } } sealed class ZipFolder : IReadOnlyPackage