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

View File

@@ -5,41 +5,16 @@
xmlns:p="clr-namespace:GameRes.Formats.Properties" xmlns:p="clr-namespace:GameRes.Formats.Properties"
xmlns:local="clr-namespace:GameRes.Formats.GUI" xmlns:local="clr-namespace:GameRes.Formats.GUI"
MaxWidth="250" Orientation="Vertical"> 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"> <Label HorizontalAlignment="Left" Margin="0,0,5,5" Padding="0">
<TextBlock Text="{x:Static s:arcStrings.GALChoose}" TextWrapping="WrapWithOverflow"/> <TextBlock Text="{x:Static s:arcStrings.GALChoose}" TextWrapping="WrapWithOverflow"/>
</Label> </Label>
<ComboBox Name="Title" ItemsSource="{Binding}" <ComboBox Name="Title" ItemsSource="{Binding}"
SelectedValue="{Binding ElementName=Key, Path=Text, Converter={StaticResource keyConverter}}" SelectedValue="{Binding ElementName=Key, Path=Text}"
SelectedValuePath="Value" DisplayMemberPath="Key" SelectedValuePath="Value" DisplayMemberPath="Key"
Width="200" HorizontalAlignment="Left"/> Width="200" HorizontalAlignment="Left"/>
<TextBox Name="Key" Width="200" HorizontalAlignment="Left" Margin="0,5,0,0"> <TextBox Name="Key" Width="200" HorizontalAlignment="Left" Margin="0,5,0,0">
<TextBox.Text> <TextBox.Text>
<Binding Source="{x:Static p:Settings.Default}" Path="GALKey" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" Converter="{StaticResource keyConverter}"> <Binding Source="{x:Static p:Settings.Default}" Path="GALKey" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged"/>
<Binding.ValidationRules>
<local:GaleKeyRule/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text> </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> </TextBox>
</StackPanel> </StackPanel>

View File

@@ -18,56 +18,9 @@ namespace GameRes.Formats.GUI
public WidgetGAL() public WidgetGAL()
{ {
InitializeComponent(); InitializeComponent();
var first_item = new KeyValuePair<string, uint> (arcStrings.ArcIgnoreEncryption, 0u); var first_item = new KeyValuePair<string, string> (arcStrings.ArcIgnoreEncryption, "");
var items = new KeyValuePair<string, uint>[] { first_item }; var items = new KeyValuePair<string, string>[] { first_item };
this.Title.ItemsSource = items.Concat (GalFormat.KnownKeys.OrderBy (x => x.Key)); 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.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0")] [global::System.Configuration.DefaultSettingValueAttribute("")]
public uint GALKey { public string GALKey {
get { get {
return ((uint)(this["GALKey"])); return ((string)(this["GALKey"]));
} }
set { set {
this["GALKey"] = value; this["GALKey"] = value;

View File

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

View File

@@ -189,7 +189,7 @@ namespace GameRes.Formats.Strings {
} }
/// <summary> /// <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> /// </summary>
public static string GALChoose { public static string GALChoose {
get { get {

View File

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

View File

@@ -376,6 +376,6 @@ choose appropriate encryption scheme.</value>
Choose appropriate encryption scheme.</value> Choose appropriate encryption scheme.</value>
</data> </data>
<data name="GALChoose" xml:space="preserve"> <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> </data>
</root> </root>

View File

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

View File

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

View File

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