(ZIP): query password for encrypted archives.

This commit is contained in:
morkt
2018-01-30 06:34:24 +04:00
parent 98e42a1f66
commit 07c69a4866
13 changed files with 137 additions and 1 deletions

View File

@@ -83,6 +83,12 @@ namespace GameRes.Formats.PkWare
#endregion
}
[Serializable]
public class ZipScheme : ResourceScheme
{
public Dictionary<string, string> 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<ZipOptions> (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<Entry> list, ResourceOptions options,
@@ -209,11 +229,20 @@ namespace GameRes.Formats.PkWare
}
}
}
ZipScheme DefaultScheme = new ZipScheme { KnownKeys = new Dictionary<string, string>() };
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; }
}
}

View File

@@ -0,0 +1,15 @@
<StackPanel x:Class="GameRes.Formats.GUI.WidgetZIP"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:GameRes.Formats.Strings"
xmlns:p="clr-namespace:GameRes.Formats.Properties"
xmlns:zip="clr-namespace:GameRes.Formats.PkWare"
Orientation="Vertical">
<Label Content="{x:Static s:arcStrings.ZIPChoose}" HorizontalAlignment="Left"/>
<ComboBox Name="Title" Width="200" HorizontalAlignment="Left"
ItemsSource="{Binding RelativeSource={RelativeSource Self}, Path=DataContext}"
SelectedValue="{Binding ElementName=Password, Path=Text, Mode=TwoWay}" SelectedValuePath="Value"
DisplayMemberPath="Key"/>
<TextBox x:Name="Password" Width="200" HorizontalAlignment="Left" Margin="0,5,0,0"
Text="{Binding Source={x:Static p:Settings.Default}, Path=ZIPPassword, Mode=OneWay}"/>
</StackPanel>

View File

@@ -0,0 +1,17 @@
using System.Collections;
using System.Windows.Controls;
namespace GameRes.Formats.GUI
{
/// <summary>
/// Interaction logic for WidgetZIP.xaml
/// </summary>
public partial class WidgetZIP : StackPanel
{
public WidgetZIP (IEnumerable titles)
{
InitializeComponent();
this.DataContext = titles;
}
}
}