(GalFormat): use string representation of keys instead of numeric.

This commit is contained in:
morkt 2016-06-10 06:27:21 +04:00
parent cb04b322f2
commit dd9ed869c5
11 changed files with 25 additions and 92 deletions

View File

@ -57,7 +57,7 @@ namespace GameRes.Formats.LiveMaker
[Serializable]
public class GalScheme : ResourceScheme
{
public Dictionary<string, uint> KnownKeys;
public Dictionary<string, string> KnownKeys;
}
[Export(typeof(ImageFormat))]
@ -67,7 +67,7 @@ namespace GameRes.Formats.LiveMaker
public override string Description { get { return "LiveMaker image format"; } }
public override uint Signature { get { return 0x656C6147; } } // 'Gale'
public static Dictionary<string, uint> KnownKeys = new Dictionary<string, uint>();
public static Dictionary<string, string> KnownKeys = new Dictionary<string, string>();
public override ResourceScheme Scheme
{
@ -145,7 +145,7 @@ namespace GameRes.Formats.LiveMaker
public override ResourceOptions GetDefaultOptions ()
{
return new GalOptions { Key = Settings.Default.GALKey };
return new GalOptions { Key = KeyFromString (Settings.Default.GALKey) };
}
public override object GetAccessWidget ()
@ -160,6 +160,13 @@ namespace GameRes.Formats.LiveMaker
var options = Query<GalOptions> (arcStrings.ArcImageEncrypted);
return options.Key;
}
public static uint KeyFromString (string key)
{
if (string.IsNullOrWhiteSpace (key) || key.Length < 4)
return 0;
return (uint)(key[0] | key[1] << 8 | key[2] << 16 | key[3] << 24);
}
}
internal sealed class GalReader : IDisposable

View File

@ -5,41 +5,16 @@
xmlns:p="clr-namespace:GameRes.Formats.Properties"
xmlns:local="clr-namespace:GameRes.Formats.GUI"
MaxWidth="250" Orientation="Vertical">
<StackPanel.Resources>
<local:GaleKeyConverter x:Key="keyConverter"/>
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<Label HorizontalAlignment="Left" Margin="0,0,5,5" Padding="0">
<TextBlock Text="{x:Static s:arcStrings.GALChoose}" TextWrapping="WrapWithOverflow"/>
</Label>
<ComboBox Name="Title" ItemsSource="{Binding}"
SelectedValue="{Binding ElementName=Key, Path=Text, Converter={StaticResource keyConverter}}"
SelectedValue="{Binding ElementName=Key, Path=Text}"
SelectedValuePath="Value" DisplayMemberPath="Key"
Width="200" HorizontalAlignment="Left"/>
<TextBox Name="Key" Width="200" HorizontalAlignment="Left" Margin="0,5,0,0">
<TextBox.Text>
<Binding Source="{x:Static p:Settings.Default}" Path="GALKey" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" Converter="{StaticResource keyConverter}">
<Binding.ValidationRules>
<local:GaleKeyRule/>
</Binding.ValidationRules>
</Binding>
<Binding Source="{x:Static p:Settings.Default}" Path="GALKey" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged"/>
</TextBox.Text>
<Validation.ErrorTemplate>
<ControlTemplate>
<DockPanel>
<TextBlock DockPanel.Dock="Right" Foreground="Red" FontWeight="Bold" Text="!" VerticalAlignment="Center"/>
<Border BorderBrush="Red" BorderThickness="1">
<AdornedElementPlaceholder Name="ValidationAdorner" />
</Border>
</DockPanel>
</ControlTemplate>
</Validation.ErrorTemplate>
</TextBox>
</StackPanel>

View File

@ -18,56 +18,9 @@ namespace GameRes.Formats.GUI
public WidgetGAL()
{
InitializeComponent();
var first_item = new KeyValuePair<string, uint> (arcStrings.ArcIgnoreEncryption, 0u);
var items = new KeyValuePair<string, uint>[] { first_item };
var first_item = new KeyValuePair<string, string> (arcStrings.ArcIgnoreEncryption, "");
var items = new KeyValuePair<string, string>[] { first_item };
this.Title.ItemsSource = items.Concat (GalFormat.KnownKeys.OrderBy (x => x.Key));
}
}
[ValueConversion(typeof(uint), typeof(string))]
public class GaleKeyConverter : IValueConverter
{
public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is uint)
return ((uint)value).ToString ("X");
else if (value is string)
return ConvertBack (value, targetType, parameter, culture);
else
return "";
}
public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is uint)
return Convert (value, targetType, parameter, culture);
string strValue = value as string;
uint result_key;
if (!string.IsNullOrWhiteSpace (strValue)
&& uint.TryParse (strValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out result_key))
return result_key;
else
return null;
}
}
public class GaleKeyRule : ValidationRule
{
public override ValidationResult Validate (object value, CultureInfo cultureInfo)
{
uint key = 0;
try
{
if (value is uint)
key = (uint)value;
else if (!string.IsNullOrWhiteSpace (value as string))
key = UInt32.Parse ((string)value, NumberStyles.HexNumber);
}
catch
{
return new ValidationResult (false, arcStrings.INTKeyRequirement);
}
return new ValidationResult (true, null);
}
}
}

View File

@ -552,10 +552,10 @@ namespace GameRes.Formats.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0")]
public uint GALKey {
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string GALKey {
get {
return ((uint)(this["GALKey"]));
return ((string)(this["GALKey"]));
}
set {
this["GALKey"] = value;

View File

@ -134,8 +134,8 @@
<Setting Name="MEDScriptScheme" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="GALKey" Type="System.UInt32" Scope="User">
<Value Profile="(Default)">0</Value>
<Setting Name="GALKey" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

View File

@ -189,7 +189,7 @@ namespace GameRes.Formats.Strings {
}
/// <summary>
/// Looks up a localized string similar to Choose title or enter 32-bit hex key.
/// Looks up a localized string similar to Choose title or enter a key.
/// </summary>
public static string GALChoose {
get {

View File

@ -373,7 +373,6 @@
적절한 암호체계를 선택하세요.</value>
</data>
<data name="GALChoose" xml:space="preserve">
<value>Choose title or enter 32-bit hex key</value>
<comment>translation pending</comment>
<value>제목을 선택하거나 암호값 입력하기</value>
</data>
</root>

View File

@ -376,6 +376,6 @@ choose appropriate encryption scheme.</value>
Choose appropriate encryption scheme.</value>
</data>
<data name="GALChoose" xml:space="preserve">
<value>Choose title or enter 32-bit hex key</value>
<value>Choose title or enter a key</value>
</data>
</root>

View File

@ -159,7 +159,7 @@
<value>Ключи шифрования</value>
</data>
<data name="GALChoose" xml:space="preserve">
<value>Выберите наименование или введите 32-битный ключ</value>
<value>Выберите наименование или введите ключ</value>
</data>
<data name="INTChooseExe" xml:space="preserve">
<value>Выберите исполняемый файл</value>

View File

@ -378,7 +378,6 @@ Choose appropriate encryption scheme.</value>
<comment>translation pending</comment>
</data>
<data name="GALChoose" xml:space="preserve">
<value>Choose title or enter 32-bit hex key</value>
<comment>translation pending</comment>
<value>请选择游戏名称或输入密钥</value>
</data>
</root>

View File

@ -137,7 +137,7 @@
<value />
</setting>
<setting name="GALKey" serializeAs="String">
<value>0</value>
<value />
</setting>
</GameRes.Formats.Properties.Settings>
</userSettings>