From 07c69a4866c1ff334a2b4af92376ca01b12c0df6 Mon Sep 17 00:00:00 2001 From: morkt Date: Tue, 30 Jan 2018 06:34:24 +0400 Subject: [PATCH] (ZIP): query password for encrypted archives. --- ArcFormats/ArcFormats.csproj | 7 +++++ ArcFormats/PkWare/ArcZIP.cs | 31 +++++++++++++++++++++- ArcFormats/PkWare/WidgetZIP.xaml | 15 +++++++++++ ArcFormats/PkWare/WidgetZIP.xaml.cs | 17 ++++++++++++ ArcFormats/Properties/Settings.Designer.cs | 12 +++++++++ ArcFormats/Properties/Settings.settings | 3 +++ ArcFormats/Strings/arcStrings.Designer.cs | 18 +++++++++++++ ArcFormats/Strings/arcStrings.ja-JP.resx | 8 ++++++ ArcFormats/Strings/arcStrings.ko-KR.resx | 6 +++++ ArcFormats/Strings/arcStrings.resx | 6 +++++ ArcFormats/Strings/arcStrings.ru-RU.resx | 6 +++++ ArcFormats/Strings/arcStrings.zh-Hans.resx | 6 +++++ ArcFormats/app.config | 3 +++ 13 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 ArcFormats/PkWare/WidgetZIP.xaml create mode 100644 ArcFormats/PkWare/WidgetZIP.xaml.cs diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index ca9a2fd3..491fa76f 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -192,6 +192,9 @@ + + WidgetZIP.xaml + @@ -944,6 +947,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/ArcFormats/PkWare/ArcZIP.cs b/ArcFormats/PkWare/ArcZIP.cs index 825d7c61..18ab2568 100644 --- a/ArcFormats/PkWare/ArcZIP.cs +++ b/ArcFormats/PkWare/ArcZIP.cs @@ -83,6 +83,12 @@ namespace GameRes.Formats.PkWare #endregion } + [Serializable] + public class ZipScheme : ResourceScheme + { + public Dictionary KnownKeys; + } + [Export(typeof(ArchiveFormat))] public class ZipOpener : ArchiveFormat { @@ -167,7 +173,8 @@ namespace GameRes.Formats.PkWare string QueryPassword (ArcView file) { - return ""; // TODO + var options = Query (arcStrings.ZIPEncryptedNotice); + return options.Password; } public override ResourceOptions GetDefaultOptions () @@ -184,9 +191,22 @@ namespace GameRes.Formats.PkWare return new ZipOptions { CompressionLevel = Properties.Settings.Default.ZIPCompression, FileNameEncoding = enc, + Password = Properties.Settings.Default.ZIPPassword, }; } + public override ResourceOptions GetOptions (object widget) + { + if (widget is GUI.WidgetZIP) + Properties.Settings.Default.ZIPPassword = ((GUI.WidgetZIP)widget).Password.Text; + return GetDefaultOptions(); + } + + public override object GetAccessWidget () + { + return new GUI.WidgetZIP (DefaultScheme.KnownKeys); + } + // TODO: GUI widget for options public override void Create (Stream output, IEnumerable list, ResourceOptions options, @@ -209,11 +229,20 @@ namespace GameRes.Formats.PkWare } } } + + ZipScheme DefaultScheme = new ZipScheme { KnownKeys = new Dictionary() }; + + public override ResourceScheme Scheme + { + get { return DefaultScheme; } + set { DefaultScheme = (ZipScheme)value; } + } } public class ZipOptions : ResourceOptions { public CompressionLevel CompressionLevel { get; set; } public Encoding FileNameEncoding { get; set; } + public string Password { get; set; } } } diff --git a/ArcFormats/PkWare/WidgetZIP.xaml b/ArcFormats/PkWare/WidgetZIP.xaml new file mode 100644 index 00000000..c4e8cfcd --- /dev/null +++ b/ArcFormats/PkWare/WidgetZIP.xaml @@ -0,0 +1,15 @@ + + diff --git a/ArcFormats/PkWare/WidgetZIP.xaml.cs b/ArcFormats/PkWare/WidgetZIP.xaml.cs new file mode 100644 index 00000000..8be7506d --- /dev/null +++ b/ArcFormats/PkWare/WidgetZIP.xaml.cs @@ -0,0 +1,17 @@ +using System.Collections; +using System.Windows.Controls; + +namespace GameRes.Formats.GUI +{ + /// + /// Interaction logic for WidgetZIP.xaml + /// + public partial class WidgetZIP : StackPanel + { + public WidgetZIP (IEnumerable titles) + { + InitializeComponent(); + this.DataContext = titles; + } + } +} diff --git a/ArcFormats/Properties/Settings.Designer.cs b/ArcFormats/Properties/Settings.Designer.cs index e4aef5bc..1ed014a5 100644 --- a/ArcFormats/Properties/Settings.Designer.cs +++ b/ArcFormats/Properties/Settings.Designer.cs @@ -717,5 +717,17 @@ namespace GameRes.Formats.Properties { this["UpgradeRequired"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string ZIPPassword { + get { + return ((string)(this["ZIPPassword"])); + } + set { + this["ZIPPassword"] = value; + } + } } } diff --git a/ArcFormats/Properties/Settings.settings b/ArcFormats/Properties/Settings.settings index 48c76550..512a0bd6 100644 --- a/ArcFormats/Properties/Settings.settings +++ b/ArcFormats/Properties/Settings.settings @@ -176,5 +176,8 @@ True + + + \ No newline at end of file diff --git a/ArcFormats/Strings/arcStrings.Designer.cs b/ArcFormats/Strings/arcStrings.Designer.cs index ea92a018..200638f4 100644 --- a/ArcFormats/Strings/arcStrings.Designer.cs +++ b/ArcFormats/Strings/arcStrings.Designer.cs @@ -862,5 +862,23 @@ namespace GameRes.Formats.Strings { return ResourceManager.GetString("YPFTryGuess", resourceCulture); } } + + /// + /// Looks up a localized string similar to Choose title or enter a password. + /// + public static string ZIPChoose { + get { + return ResourceManager.GetString("ZIPChoose", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Archive content is encrypted.. + /// + public static string ZIPEncryptedNotice { + get { + return ResourceManager.GetString("ZIPEncryptedNotice", resourceCulture); + } + } } } diff --git a/ArcFormats/Strings/arcStrings.ja-JP.resx b/ArcFormats/Strings/arcStrings.ja-JP.resx index d644c6e6..53683a45 100644 --- a/ArcFormats/Strings/arcStrings.ja-JP.resx +++ b/ArcFormats/Strings/arcStrings.ja-JP.resx @@ -491,4 +491,12 @@ Choose encryption scheme or enter a passphrase. 増分フレームを自動的に結合する Automatically combine incremental frames + + タイトルを選択するか、パスワードを入力してください。 + Choose title or enter a password + + + アーカイブコンテンツは暗号化されています。 + Archive content is encrypted. + \ No newline at end of file diff --git a/ArcFormats/Strings/arcStrings.ko-KR.resx b/ArcFormats/Strings/arcStrings.ko-KR.resx index 9ac02a44..177f522a 100644 --- a/ArcFormats/Strings/arcStrings.ko-KR.resx +++ b/ArcFormats/Strings/arcStrings.ko-KR.resx @@ -391,4 +391,10 @@ Automatically combine incremental frames translation pending + + 제목을 선택하거나 암호를 입력하세요 + + + 아카이브 내용이 암호화됨. + \ No newline at end of file diff --git a/ArcFormats/Strings/arcStrings.resx b/ArcFormats/Strings/arcStrings.resx index e39275bd..6d5f0888 100644 --- a/ArcFormats/Strings/arcStrings.resx +++ b/ArcFormats/Strings/arcStrings.resx @@ -392,4 +392,10 @@ Choose encryption scheme or enter a passphrase. Automatically combine incremental frames + + Choose title or enter a password + + + Archive content is encrypted. + \ No newline at end of file diff --git a/ArcFormats/Strings/arcStrings.ru-RU.resx b/ArcFormats/Strings/arcStrings.ru-RU.resx index 98dab381..bc758385 100644 --- a/ArcFormats/Strings/arcStrings.ru-RU.resx +++ b/ArcFormats/Strings/arcStrings.ru-RU.resx @@ -347,4 +347,10 @@ Попытаться подобрать + + Выберите наименование или введите пароль + + + Содержимое архива зашифровано. + \ No newline at end of file diff --git a/ArcFormats/Strings/arcStrings.zh-Hans.resx b/ArcFormats/Strings/arcStrings.zh-Hans.resx index 89063eb8..49050774 100644 --- a/ArcFormats/Strings/arcStrings.zh-Hans.resx +++ b/ArcFormats/Strings/arcStrings.zh-Hans.resx @@ -392,4 +392,10 @@ Automatically combine incremental frames translation pending + + 压缩文件的内容已被加密。 + + + 请选择游戏名称或输入密码 + \ No newline at end of file diff --git a/ArcFormats/app.config b/ArcFormats/app.config index 8acef89e..a101ec1e 100644 --- a/ArcFormats/app.config +++ b/ArcFormats/app.config @@ -178,6 +178,9 @@ True + + +