diff --git a/OpenRA.Mods.Common/ModContent.cs b/OpenRA.Mods.Common/ModContent.cs index 1ba8a4b628..553409ef72 100644 --- a/OpenRA.Mods.Common/ModContent.cs +++ b/OpenRA.Mods.Common/ModContent.cs @@ -74,14 +74,17 @@ namespace OpenRA public class ModDownload { + public readonly ObjectCreator ObjectCreator; public readonly string Title; public readonly string URL; public readonly string MirrorList; public readonly string SHA1; + public readonly string Type; public readonly Dictionary Extract; - public ModDownload(MiniYaml yaml) + public ModDownload(MiniYaml yaml, ObjectCreator objectCreator) { + ObjectCreator = objectCreator; Title = yaml.Value; FieldLoader.Load(this, yaml); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs index 4548360c76..7be63650f1 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs @@ -15,7 +15,7 @@ using System.IO; using System.Net.Http; using System.Threading; using System.Threading.Tasks; -using ICSharpCode.SharpZipLib.Zip; +using OpenRA.FileSystem; using OpenRA.Support; using OpenRA.Widgets; @@ -217,26 +217,29 @@ namespace OpenRA.Mods.Common.Widgets.Logic try { using (var stream = File.OpenRead(file)) - using (var z = new ZipFile(stream)) { - foreach (var kv in download.Extract) + var packageLoader = download.ObjectCreator.CreateObject($"{download.Type}Loader"); + + if (packageLoader.TryParsePackage(stream, file, modData.ModFiles, out var package)) { - var entry = z.GetEntry(kv.Value); - if (entry == null || !entry.IsFile) - continue; + foreach (var kv in download.Extract) + { + if (!package.Contains(kv.Value)) + continue; - onExtractProgress(modData.Translation.GetString(ExtractingEntry, Translation.Arguments("entry", entry.Name))); - Log.Write("install", "Extracting " + entry.Name); - var targetPath = Platform.ResolvePath(kv.Key); - Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); - extracted.Add(targetPath); + onExtractProgress(modData.Translation.GetString(ExtractingEntry, Translation.Arguments("entry", kv.Value))); + Log.Write("install", "Extracting " + kv.Value); + var targetPath = Platform.ResolvePath(kv.Key); + Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); + extracted.Add(targetPath); - using (var zz = z.GetInputStream(entry)) - using (var f = File.Create(targetPath)) - zz.CopyTo(f); + using (var zz = package.GetStream(kv.Value)) + using (var f = File.Create(targetPath)) + zz.CopyTo(f); + } + + package.Dispose(); } - - z.Close(); } Game.RunAfterTick(() => diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs index 84032db0c7..4370e7dcae 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs @@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var downloadYaml = MiniYaml.Load(modFileSystem, content.Downloads, null); foreach (var d in downloadYaml) - downloads.Add(d.Key, new ModContent.ModDownload(d.Value)); + downloads.Add(d.Key, new ModContent.ModDownload(d.Value, modObjectCreator)); modFileSystem.UnmountAll(); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentPromptLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentPromptLogic.cs index a126b91917..801b4199c4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentPromptLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentPromptLogic.cs @@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Ui.OpenWindow("PACKAGE_DOWNLOAD_PANEL", new WidgetArgs { - { "download", new ModContent.ModDownload(download.Value) }, + { "download", new ModContent.ModDownload(download.Value, modObjectCreator) }, { "onSuccess", continueLoading } }); }; diff --git a/mods/cnc/installer/downloads.yaml b/mods/cnc/installer/downloads.yaml index 0279546010..4e80766a9c 100644 --- a/mods/cnc/installer/downloads.yaml +++ b/mods/cnc/installer/downloads.yaml @@ -1,4 +1,5 @@ basefiles: Base Freeware Content + Type: ZipFile SHA1: 72f337464963fa37d3688eb03e80eefd33669a3d MirrorList: http://www.openra.net/packages/cnc-mirrors.txt Extract: diff --git a/mods/d2k/installer/downloads.yaml b/mods/d2k/installer/downloads.yaml index 40edb1a931..be78f665d2 100644 --- a/mods/d2k/installer/downloads.yaml +++ b/mods/d2k/installer/downloads.yaml @@ -1,4 +1,5 @@ quickinstall: Quick Install Package + Type: ZipFile SHA1: eb9ff88ca24858bd06a752f923156a6480c25c06 MirrorList: http://www.openra.net/packages/d2k-quickinstall-mirrors.txt Extract: @@ -269,6 +270,7 @@ quickinstall: Quick Install Package ^SupportDir|Content/d2k/v2/DATA.R8: v2/DATA.R8 basefiles: Base Content + Type: ZipFile SHA1: 82221691fe843a5a245969095f147e929c364234 MirrorList: http://www.openra.net/packages/d2k-base-mirrors.txt Extract: @@ -537,6 +539,7 @@ basefiles: Base Content ^SupportDir|Content/d2k/v2/SOUND.RS: v2/SOUND.RS patch106: Patch 1.06 Content + Type: ZipFile SHA1: 90924e5254468ec79c71e456384f5895a6c84bae MirrorList: http://www.openra.net/packages/d2k-patch106-mirrors.txt Extract: diff --git a/mods/ra/installer/downloads.yaml b/mods/ra/installer/downloads.yaml index 18a1f48277..96f5d24f1f 100644 --- a/mods/ra/installer/downloads.yaml +++ b/mods/ra/installer/downloads.yaml @@ -1,4 +1,5 @@ quickinstall: Quick Install Package + Type: ZipFile SHA1: 44241f68e69db9511db82cf83c174737ccda300b MirrorList: http://www.openra.net/packages/ra-quickinstall-mirrors.txt Extract: @@ -43,6 +44,7 @@ quickinstall: Quick Install Package ^SupportDir|Content/ra/v2/cnc/desert.mix: cnc/desert.mix basefiles: Base Freeware Content + Type: ZipFile SHA1: aa022b208a3b45b4a45c00fdae22ccf3c6de3e5c MirrorList: http://www.openra.net/packages/ra-base-mirrors.txt Extract: @@ -59,6 +61,7 @@ basefiles: Base Freeware Content ^SupportDir|Content/ra/v2/temperat.mix: temperat.mix aftermath: Aftermath Expansion Files + Type: ZipFile SHA1: d511d4363b485e11c63eecf96d4365d42ec4ef5e MirrorList: http://www.openra.net/packages/ra-aftermath-mirrors.txt Extract: @@ -91,6 +94,7 @@ aftermath: Aftermath Expansion Files ^SupportDir|Content/ra/v2/expand/myes1.aud: expand/myes1.aud cncdesert: C&C Desert Tileset + Type: ZipFile SHA1: 039849f16e39e4722e8c838a393c8a0d6529fd59 MirrorList: http://www.openra.net/packages/ra-cncdesert-mirrors.txt Extract: diff --git a/mods/ts/installer/downloads.yaml b/mods/ts/installer/downloads.yaml index e8ed828c91..96f79ba54a 100644 --- a/mods/ts/installer/downloads.yaml +++ b/mods/ts/installer/downloads.yaml @@ -1,4 +1,5 @@ basefiles: Base Freeware Content + Type: ZipFile SHA1: 824df30de0004ad13fac29cf16450caafee9fb1b MirrorList: http://www.openra.net/packages/ts-mirrors.txt Extract: @@ -18,6 +19,7 @@ basefiles: Base Freeware Content ^SupportDir|Content/ts/temperat.mix: temperat.mix fstorm: Expansion Freeware Content + Type: ZipFile SHA1: 8bff90870a9348b72cbe91314aec7d3a50311aa9 MirrorList: http://www.openra.net/packages/fs-mirrors.txt Extract: @@ -201,6 +203,7 @@ fstorm: Expansion Freeware Content ^SupportDir|Content/ts/firestorm/bigblue3.tem: firestorm/bigblue3.tem quickinstall: Quick Install Package + Type: ZipFile SHA1: d9339e7b6ecf624ac6ca91d25c58b88fb88a49d2 MirrorList: http://www.openra.net/packages/ts-quickinstall-mirrors.txt Extract: