From 1b46da45a6e69aec7ba60549669bffbb73cd0288 Mon Sep 17 00:00:00 2001 From: morkt Date: Sat, 2 Aug 2014 10:01:06 +0400 Subject: [PATCH] refactoring. (ArchiveFormat): added Query protected method for convenient invocation of parameters requests. (FormatCatalog): changed misguiding method name 'LookupTag' to 'LookupExtension'. --- ArcFormats/ArcAMI.cs | 2 +- ArcFormats/ArcINT.cs | 10 +--------- ArcFormats/ArcNPA.cs | 10 +--------- ArcFormats/ArcXP3.cs | 11 ++--------- ArcFormats/ArcYPF.cs | 10 ++-------- GameRes/GameRes.cs | 20 +++++++++++++++----- 6 files changed, 22 insertions(+), 41 deletions(-) diff --git a/ArcFormats/ArcAMI.cs b/ArcFormats/ArcAMI.cs index e6837226..5c88d328 100644 --- a/ArcFormats/ArcAMI.cs +++ b/ArcFormats/ArcAMI.cs @@ -294,7 +294,7 @@ namespace GameRes.Formats uint WriteImageEntry (PackedEntry entry, Stream input, Stream output) { - var grp = FormatCatalog.Instance.LookupTag ("GRP").FirstOrDefault(); + var grp = FormatCatalog.Instance.LookupExtension ("GRP").FirstOrDefault(); if (null == grp) // probably never happens throw new FileFormatException ("GRP image encoder not available"); bool is_grp = grp.Signature == FormatCatalog.ReadSignature (input); diff --git a/ArcFormats/ArcINT.cs b/ArcFormats/ArcINT.cs index 5b1058c6..0ac68e89 100644 --- a/ArcFormats/ArcINT.cs +++ b/ArcFormats/ArcINT.cs @@ -334,15 +334,7 @@ namespace GameRes.Formats uint? QueryEncryptionInfo () { - var args = new ParametersRequestEventArgs - { - Notice = arcStrings.INTNotice, - }; - FormatCatalog.Instance.InvokeParametersRequest (this, args); - if (!args.InputResult) - throw new OperationCanceledException(); - - var options = GetOptions (args.Options); + var options = Query (arcStrings.INTNotice); return options.EncryptionInfo.GetKey(); } } diff --git a/ArcFormats/ArcNPA.cs b/ArcFormats/ArcNPA.cs index 97abb1ae..6ad4aa4c 100644 --- a/ArcFormats/ArcNPA.cs +++ b/ArcFormats/ArcNPA.cs @@ -333,15 +333,7 @@ namespace GameRes.Formats NpaTitleId QueryGameEncryption () { - var args = new ParametersRequestEventArgs - { - Notice = arcStrings.ArcEncryptedNotice, - }; - FormatCatalog.Instance.InvokeParametersRequest (this, args); - if (!args.InputResult) - throw new OperationCanceledException(); - - var options = GetOptions (args.Options); + var options = Query (arcStrings.ArcEncryptedNotice); return options.TitleId; } diff --git a/ArcFormats/ArcXP3.cs b/ArcFormats/ArcXP3.cs index 22e0c911..c1d32a90 100644 --- a/ArcFormats/ArcXP3.cs +++ b/ArcFormats/ArcXP3.cs @@ -281,15 +281,8 @@ NextEntry: ICrypt QueryCryptAlgorithm () { - var args = new ParametersRequestEventArgs - { - Notice = arcStrings.ArcEncryptedNotice, - }; - FormatCatalog.Instance.InvokeParametersRequest (this, args); - if (!args.InputResult) - throw new OperationCanceledException(); - - return GetOptions (args.Options).Scheme; + var options = Query (arcStrings.ArcEncryptedNotice); + return options.Scheme; } public static ICrypt GetScheme (string scheme) diff --git a/ArcFormats/ArcYPF.cs b/ArcFormats/ArcYPF.cs index 69895d8f..b9c1e885 100644 --- a/ArcFormats/ArcYPF.cs +++ b/ArcFormats/ArcYPF.cs @@ -104,14 +104,8 @@ namespace GameRes.Formats uint QueryEncryptionKey () { - var args = new ParametersRequestEventArgs - { - Notice = arcStrings.YPFNotice, - }; - FormatCatalog.Instance.InvokeParametersRequest (this, args); - if (!args.InputResult) - throw new OperationCanceledException(); - return GetOptions (args.Options).Key; + var options = Query (arcStrings.YPFNotice); + return options.Key; } private class Parser diff --git a/GameRes/GameRes.cs b/GameRes/GameRes.cs index 4987ffe1..0dcc244f 100644 --- a/GameRes/GameRes.cs +++ b/GameRes/GameRes.cs @@ -225,6 +225,16 @@ namespace GameRes options = this.GetDefaultOptions() as OptType; return options; } + + protected OptType Query (string notice) where OptType : ResourceOptions + { + var args = new ParametersRequestEventArgs { Notice = notice }; + FormatCatalog.Instance.InvokeParametersRequest (this, args); + if (!args.InputResult) + throw new OperationCanceledException(); + + return GetOptions (args.Options); + } } public delegate void ParametersRequestEventHandler (object sender, ParametersRequestEventArgs e); @@ -317,17 +327,17 @@ namespace GameRes string ext = Path.GetExtension (filename); if (null == ext) return new IResource[0]; - return LookupTag (ext.TrimStart ('.')); + return LookupExtension (ext.TrimStart ('.')); } - public IEnumerable LookupTag (string tag) + public IEnumerable LookupExtension (string ext) { - return m_extension_map.GetValues (tag.ToUpper(), true); + return m_extension_map.GetValues (ext.ToUpper(), true); } - public IEnumerable LookupTag (string tag) where Type : IResource + public IEnumerable LookupExtension (string ext) where Type : IResource { - return LookupTag (tag).OfType(); + return LookupExtension (ext).OfType(); } public IEnumerable LookupSignature (uint signature)