refactored ResourceOptions handling.

This commit is contained in:
morkt
2014-07-27 07:39:58 +04:00
parent 5253f8c776
commit 1c33e4c9d5
7 changed files with 137 additions and 66 deletions

View File

@@ -16,6 +16,11 @@ using GameRes.Formats.Properties;
namespace GameRes.Formats
{
public class YpfOptions : ResourceOptions
{
public uint Key { get; set; }
}
[Export(typeof(ArchiveFormat))]
public class YpfOpener : ArchiveFormat
{
@@ -55,21 +60,38 @@ namespace GameRes.Formats
return new ZLibStream (input, CompressionMode.Decompress);
}
public override ResourceOptions GetDefaultOptions ()
{
return new YpfOptions { Key = Settings.Default.YPFKey };
}
public override ResourceOptions GetOptions (object w)
{
var widget = w as GUI.WidgetYPF;
if (null != widget)
{
uint last_key = widget.GetKey() ?? DefaultKey;
Settings.Default.YPFKey = last_key;
return new YpfOptions { Key = last_key };
}
return this.GetDefaultOptions();
}
public override object GetAccessWidget ()
{
return new GUI.WidgetYPF();
}
uint QueryEncryptionKey ()
{
var widget = new GUI.WidgetYPF();
var args = new ParametersRequestEventArgs
{
Notice = arcStrings.YPFNotice,
InputWidget = widget,
};
FormatCatalog.Instance.InvokeParametersRequest (this, args);
if (!args.InputResult)
throw new OperationCanceledException();
uint last_key = widget.GetKey() ?? DefaultKey;
Settings.Default.YPFKey = last_key;
return last_key;
return GetOptions<YpfOptions> (args.Options).Key;
}
private class Parser