mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
(INT): reworked widget backend.
This commit is contained in:
@@ -237,12 +237,14 @@ namespace GameRes.Formats.CatSystem
|
|||||||
return Encodings.cp932.GetString (name, 0, i);
|
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
|
public override ResourceScheme Scheme
|
||||||
{
|
{
|
||||||
get { return new IntScheme { KnownKeys = KnownSchemes }; }
|
get { return DefaultScheme; }
|
||||||
set { KnownSchemes = ((IntScheme)value).KnownKeys; }
|
set { DefaultScheme = (IntScheme)value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ResourceOptions GetDefaultOptions ()
|
public override ResourceOptions GetDefaultOptions ()
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
</Grid.ColumnDefinitions>
|
</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"
|
<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"/>
|
HorizontalAlignment="Left" Margin="0,0,0,10" Click="Check_Click"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right"/>
|
Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right"/>
|
||||||
<TextBox Name="Passkey" Grid.Column="1" Grid.Row="2" Margin="0,3,0,3">
|
<TextBox Name="Passkey" Grid.Column="1" Grid.Row="2" Margin="0,3,0,3">
|
||||||
<TextBox.Text>
|
<TextBox.Text>
|
||||||
<Binding Path="Key" Converter="{StaticResource keyConverter}" UpdateSourceTrigger="PropertyChanged">
|
<Binding Path="Key" Mode="TwoWay" Converter="{StaticResource keyConverter}" UpdateSourceTrigger="PropertyChanged">
|
||||||
<Binding.ValidationRules>
|
<Binding.ValidationRules>
|
||||||
<local:PasskeyRule/>
|
<local:PasskeyRule/>
|
||||||
</Binding.ValidationRules>
|
</Binding.ValidationRules>
|
||||||
@@ -60,12 +60,12 @@
|
|||||||
<Label Content="{x:Static s:arcStrings.LabelPassphrase}" Target="{Binding ElementName=Passphrase}"
|
<Label Content="{x:Static s:arcStrings.LabelPassphrase}" Target="{Binding ElementName=Passphrase}"
|
||||||
Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right"/>
|
Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right"/>
|
||||||
<TextBox Name="Passphrase" Grid.Column="1" Grid.Row="1" Margin="0,3,0,3"
|
<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}"
|
<Label Content="{x:Static s:arcStrings.LabelScheme}" Target="{Binding ElementName=EncScheme}"
|
||||||
Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right"/>
|
Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right"/>
|
||||||
<ComboBox Name="EncScheme" Grid.Column="1" Grid.Row="0" Margin="0,3,0,0"
|
<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}"
|
Width="{Binding ElementName=Passkey, Path=ActualWidth}"
|
||||||
SelectedValue="{Binding Path=Scheme}"/>
|
SelectedValue="{Binding Path=Scheme, Mode=TwoWay}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
@@ -22,14 +22,18 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
|
using System.Windows;
|
||||||
|
using Microsoft.Win32;
|
||||||
using GameRes.Formats.CatSystem;
|
using GameRes.Formats.CatSystem;
|
||||||
using GameRes.Formats.Strings;
|
using GameRes.Formats.Strings;
|
||||||
using Microsoft.Win32;
|
|
||||||
using System.Windows;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
namespace GameRes.Formats.GUI
|
namespace GameRes.Formats.GUI
|
||||||
{
|
{
|
||||||
@@ -41,43 +45,13 @@ namespace GameRes.Formats.GUI
|
|||||||
public WidgetINT ()
|
public WidgetINT ()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.DataContext = GameRes.Formats.Properties.Settings.Default.INTEncryption ?? new IntEncryptionInfo();
|
ViewModel = new IntEncryptionViewModel (GameRes.Formats.Properties.Settings.Default.INTEncryption);
|
||||||
|
this.DataContext = ViewModel;
|
||||||
Passphrase.TextChanged += OnPassphraseChanged;
|
|
||||||
EncScheme.SelectionChanged += OnSchemeChanged;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntEncryptionInfo Info { get { return this.DataContext as IntEncryptionInfo; } }
|
IntEncryptionViewModel ViewModel { get; set; }
|
||||||
|
|
||||||
void OnPasskeyChanged (object sender, TextChangedEventArgs e)
|
public IntEncryptionInfo Info { get { return ViewModel.Source; } }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Check_Click (object sender, System.Windows.RoutedEventArgs e)
|
private void Check_Click (object sender, System.Windows.RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
@@ -97,15 +71,15 @@ namespace GameRes.Formats.GUI
|
|||||||
var pass = IntOpener.GetPassFromExe (dlg.FileName);
|
var pass = IntOpener.GetPassFromExe (dlg.FileName);
|
||||||
if (null != pass)
|
if (null != pass)
|
||||||
{
|
{
|
||||||
this.ExeMessage.Text = arcStrings.INTMessage1;
|
ViewModel.ExeMessage = arcStrings.INTMessage1;
|
||||||
Passphrase.Text = pass;
|
ViewModel.Password = pass;
|
||||||
}
|
}
|
||||||
else
|
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)
|
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)
|
public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
{
|
{
|
||||||
uint? key = (uint?)value;
|
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)
|
public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
@@ -151,4 +125,78 @@ namespace GameRes.Formats.GUI
|
|||||||
return new ValidationResult (true, null);
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user