From 55d72aa9bbae884c5c5b443032cfbbf71d83b069 Mon Sep 17 00:00:00 2001 From: morkt Date: Sat, 5 Mar 2016 19:05:47 +0400 Subject: [PATCH] implemented ZIP archive creation. because why not. --- ArcFormats/ArcZIP.cs | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/ArcFormats/ArcZIP.cs b/ArcFormats/ArcZIP.cs index 18539fd6..bfef5488 100644 --- a/ArcFormats/ArcZIP.cs +++ b/ArcFormats/ArcZIP.cs @@ -29,6 +29,7 @@ using System.ComponentModel.Composition; using System.IO; using System.IO.Compression; using System.Linq; +using System.Text; namespace GameRes.Formats.PkWare { @@ -84,7 +85,7 @@ namespace GameRes.Formats.PkWare public override string Description { get { return "PKWARE archive format"; } } public override uint Signature { get { return 0; } } public override bool IsHierarchic { get { return true; } } - public override bool CanCreate { get { return false; } } + public override bool CanCreate { get { return true; } } public override ArcFile TryOpen (ArcView file) { @@ -143,5 +144,39 @@ namespace GameRes.Formats.PkWare } } } + + public override ResourceOptions GetDefaultOptions () + { + return new ZipOptions { + CompressionLevel = CompressionLevel.Optimal, + FileNameEncoding = Encodings.cp932, + }; + } + + // TODO: GUI widget for options + + public override void Create (Stream output, IEnumerable list, ResourceOptions options, + EntryCallback callback) + { + var zip_options = (ZipOptions)options; + using (var zip = new ZipArchive (output, ZipArchiveMode.Create, true, zip_options.FileNameEncoding)) + { + foreach (var entry in list) + { + var zip_entry = zip.CreateEntry (entry.Name, zip_options.CompressionLevel); + using (var input = File.OpenRead (entry.Name)) + using (var zip_file = zip_entry.Open()) + { + input.CopyTo (zip_file); + } + } + } + } + } + + public class ZipOptions : ResourceOptions + { + public CompressionLevel CompressionLevel { get; set; } + public Encoding FileNameEncoding { get; set; } } }