mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-27 07:34:00 +08:00
(INT): reworked widget backend.
This commit is contained in:
parent
dc436d4ccb
commit
1c0c9e62c7
@ -237,12 +237,14 @@ namespace GameRes.Formats.CatSystem
|
||||
return Encodings.cp932.GetString (name, 0, i);
|
||||
}
|
||||
|
||||
public static Dictionary<string, KeyData> KnownSchemes = new Dictionary<string, KeyData>();
|
||||
public static Dictionary<string, KeyData> KnownSchemes { get { return DefaultScheme.KnownKeys; } }
|
||||
|
||||
static IntScheme DefaultScheme = new IntScheme { KnownKeys = new Dictionary<string, KeyData>() };
|
||||
|
||||
public override ResourceScheme Scheme
|
||||
{
|
||||
get { return new IntScheme { KnownKeys = KnownSchemes }; }
|
||||
set { KnownSchemes = ((IntScheme)value).KnownKeys; }
|
||||
get { return DefaultScheme; }
|
||||
set { DefaultScheme = (IntScheme)value; }
|
||||
}
|
||||
|
||||
public override ResourceOptions GetDefaultOptions ()
|
||||
|
@ -10,7 +10,7 @@
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Name="ExeMessage" Grid.Column="0" Text="{x:Static s:arcStrings.INTMessage1}" TextWrapping="Wrap" Margin="0,0,10,10"/>
|
||||
<TextBlock Name="ExeMessage" Grid.Column="0" Text="{Binding ExeMessage}" TextWrapping="Wrap" Margin="0,0,10,10"/>
|
||||
<Button Content="{x:Static s:arcStrings.INTExeButton}" Grid.Column="1" Grid.Row="0" Width="75" Height="25"
|
||||
HorizontalAlignment="Left" Margin="0,0,0,10" Click="Check_Click"/>
|
||||
</Grid>
|
||||
@ -40,7 +40,7 @@
|
||||
Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right"/>
|
||||
<TextBox Name="Passkey" Grid.Column="1" Grid.Row="2" Margin="0,3,0,3">
|
||||
<TextBox.Text>
|
||||
<Binding Path="Key" Converter="{StaticResource keyConverter}" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding Path="Key" Mode="TwoWay" Converter="{StaticResource keyConverter}" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<local:PasskeyRule/>
|
||||
</Binding.ValidationRules>
|
||||
@ -60,12 +60,12 @@
|
||||
<Label Content="{x:Static s:arcStrings.LabelPassphrase}" Target="{Binding ElementName=Passphrase}"
|
||||
Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right"/>
|
||||
<TextBox Name="Passphrase" Grid.Column="1" Grid.Row="1" Margin="0,3,0,3"
|
||||
Text="{Binding Path=Password}"/>
|
||||
Text="{Binding Path=Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
<Label Content="{x:Static s:arcStrings.LabelScheme}" Target="{Binding ElementName=EncScheme}"
|
||||
Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right"/>
|
||||
<ComboBox Name="EncScheme" Grid.Column="1" Grid.Row="0" Margin="0,3,0,0"
|
||||
ItemsSource="{Binding Source={x:Static fmt:IntOpener.KnownSchemes}, Path=Keys, Mode=OneWay}"
|
||||
ItemsSource="{Binding Path=KnownKeys.Keys}"
|
||||
Width="{Binding ElementName=Passkey, Path=ActualWidth}"
|
||||
SelectedValue="{Binding Path=Scheme}"/>
|
||||
SelectedValue="{Binding Path=Scheme, Mode=TwoWay}"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
@ -22,14 +22,18 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows;
|
||||
using Microsoft.Win32;
|
||||
using GameRes.Formats.CatSystem;
|
||||
using GameRes.Formats.Strings;
|
||||
using Microsoft.Win32;
|
||||
using System.Windows;
|
||||
using System.IO;
|
||||
|
||||
namespace GameRes.Formats.GUI
|
||||
{
|
||||
@ -41,43 +45,13 @@ namespace GameRes.Formats.GUI
|
||||
public WidgetINT ()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.DataContext = GameRes.Formats.Properties.Settings.Default.INTEncryption ?? new IntEncryptionInfo();
|
||||
|
||||
Passphrase.TextChanged += OnPassphraseChanged;
|
||||
EncScheme.SelectionChanged += OnSchemeChanged;
|
||||
ViewModel = new IntEncryptionViewModel (GameRes.Formats.Properties.Settings.Default.INTEncryption);
|
||||
this.DataContext = ViewModel;
|
||||
}
|
||||
|
||||
public IntEncryptionInfo Info { get { return this.DataContext as IntEncryptionInfo; } }
|
||||
IntEncryptionViewModel ViewModel { get; set; }
|
||||
|
||||
void OnPasskeyChanged (object sender, TextChangedEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
void OnPassphraseChanged (object sender, TextChangedEventArgs e)
|
||||
{
|
||||
var widget = sender as TextBox;
|
||||
uint key = KeyData.EncodePassPhrase (widget.Text);
|
||||
Passkey.Text = key.ToString ("X8");
|
||||
}
|
||||
|
||||
void OnSchemeChanged (object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
var widget = sender as ComboBox;
|
||||
KeyData keydata;
|
||||
if (IntOpener.KnownSchemes.TryGetValue (widget.SelectedItem as string, out keydata))
|
||||
{
|
||||
Passphrase.TextChanged -= OnPassphraseChanged;
|
||||
try
|
||||
{
|
||||
Passphrase.Text = keydata.Passphrase;
|
||||
Passkey.Text = keydata.Key.ToString ("X8");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Passphrase.TextChanged += OnPassphraseChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
public IntEncryptionInfo Info { get { return ViewModel.Source; } }
|
||||
|
||||
private void Check_Click (object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
@ -97,15 +71,15 @@ namespace GameRes.Formats.GUI
|
||||
var pass = IntOpener.GetPassFromExe (dlg.FileName);
|
||||
if (null != pass)
|
||||
{
|
||||
this.ExeMessage.Text = arcStrings.INTMessage1;
|
||||
Passphrase.Text = pass;
|
||||
ViewModel.ExeMessage = arcStrings.INTMessage1;
|
||||
ViewModel.Password = pass;
|
||||
}
|
||||
else
|
||||
this.ExeMessage.Text = string.Format (arcStrings.INTKeyNotFound, Path.GetFileName (dlg.FileName));
|
||||
ViewModel.ExeMessage = string.Format (arcStrings.INTKeyNotFound, Path.GetFileName (dlg.FileName));
|
||||
}
|
||||
catch (Exception X)
|
||||
{
|
||||
this.ExeMessage.Text = X.Message;
|
||||
ViewModel.ExeMessage = X.Message;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -116,7 +90,7 @@ namespace GameRes.Formats.GUI
|
||||
public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
uint? key = (uint?)value;
|
||||
return null != key ? key.Value.ToString ("X") : "";
|
||||
return null != key ? key.Value.ToString ("X8") : "";
|
||||
}
|
||||
|
||||
public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture)
|
||||
@ -151,4 +125,78 @@ namespace GameRes.Formats.GUI
|
||||
return new ValidationResult (true, null);
|
||||
}
|
||||
}
|
||||
|
||||
internal class IntEncryptionViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public IntEncryptionViewModel (IntEncryptionInfo src)
|
||||
{
|
||||
Source = src ?? new IntEncryptionInfo();
|
||||
KnownKeys = IntOpener.KnownSchemes;
|
||||
m_message = Strings.arcStrings.INTMessage1;
|
||||
}
|
||||
|
||||
public IntEncryptionInfo Source { get; set; }
|
||||
public Dictionary<string, KeyData> KnownKeys { get; private set; }
|
||||
|
||||
public string Scheme {
|
||||
get { return Source.Scheme; }
|
||||
set {
|
||||
if (Source.Scheme != value)
|
||||
{
|
||||
Source.Scheme = value;
|
||||
NotifyPropertyChanged();
|
||||
KeyData keydata;
|
||||
if (!string.IsNullOrEmpty (value)
|
||||
&& KnownKeys.TryGetValue (value, out keydata))
|
||||
{
|
||||
Source.Password = keydata.Passphrase;
|
||||
NotifyPropertyChanged ("Password");
|
||||
Key = keydata.Key;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public string Password {
|
||||
get { return Source.Password; }
|
||||
set {
|
||||
if (Source.Password != value)
|
||||
{
|
||||
Source.Password = value;
|
||||
NotifyPropertyChanged();
|
||||
var scheme = KnownKeys.FirstOrDefault (s => s.Value.Passphrase == value);
|
||||
Scheme = scheme.Key;
|
||||
Key = KeyData.EncodePassPhrase (value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public uint? Key {
|
||||
get { return Source.Key; }
|
||||
set {
|
||||
if (Source.Key != value)
|
||||
{
|
||||
Source.Key = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
string m_message;
|
||||
public string ExeMessage {
|
||||
get { return m_message; }
|
||||
set {
|
||||
if (m_message != value)
|
||||
{
|
||||
m_message = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void NotifyPropertyChanged ([CallerMemberName] string propertyName = "")
|
||||
{
|
||||
if (PropertyChanged != null)
|
||||
PropertyChanged (this, new PropertyChangedEventArgs (propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user