mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-23 13:45:34 +08:00
refactoring.
(ArchiveFormat): added Query<ResourceOptions> protected method for convenient invocation of parameters requests. (FormatCatalog): changed misguiding method name 'LookupTag' to 'LookupExtension'.
This commit is contained in:
parent
16efe95597
commit
1b46da45a6
@ -294,7 +294,7 @@ namespace GameRes.Formats
|
||||
|
||||
uint WriteImageEntry (PackedEntry entry, Stream input, Stream output)
|
||||
{
|
||||
var grp = FormatCatalog.Instance.LookupTag<GrpFormat> ("GRP").FirstOrDefault();
|
||||
var grp = FormatCatalog.Instance.LookupExtension<GrpFormat> ("GRP").FirstOrDefault();
|
||||
if (null == grp) // probably never happens
|
||||
throw new FileFormatException ("GRP image encoder not available");
|
||||
bool is_grp = grp.Signature == FormatCatalog.ReadSignature (input);
|
||||
|
@ -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<IntOptions> (args.Options);
|
||||
var options = Query<IntOptions> (arcStrings.INTNotice);
|
||||
return options.EncryptionInfo.GetKey();
|
||||
}
|
||||
}
|
||||
|
@ -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<NpaOptions> (args.Options);
|
||||
var options = Query<NpaOptions> (arcStrings.ArcEncryptedNotice);
|
||||
return options.TitleId;
|
||||
}
|
||||
|
||||
|
@ -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<Xp3Options> (args.Options).Scheme;
|
||||
var options = Query<Xp3Options> (arcStrings.ArcEncryptedNotice);
|
||||
return options.Scheme;
|
||||
}
|
||||
|
||||
public static ICrypt GetScheme (string scheme)
|
||||
|
@ -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<YpfOptions> (args.Options).Key;
|
||||
var options = Query<YpfOptions> (arcStrings.YPFNotice);
|
||||
return options.Key;
|
||||
}
|
||||
|
||||
private class Parser
|
||||
|
@ -225,6 +225,16 @@ namespace GameRes
|
||||
options = this.GetDefaultOptions() as OptType;
|
||||
return options;
|
||||
}
|
||||
|
||||
protected OptType Query<OptType> (string notice) where OptType : ResourceOptions
|
||||
{
|
||||
var args = new ParametersRequestEventArgs { Notice = notice };
|
||||
FormatCatalog.Instance.InvokeParametersRequest (this, args);
|
||||
if (!args.InputResult)
|
||||
throw new OperationCanceledException();
|
||||
|
||||
return GetOptions<OptType> (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<IResource> LookupTag (string tag)
|
||||
public IEnumerable<IResource> LookupExtension (string ext)
|
||||
{
|
||||
return m_extension_map.GetValues (tag.ToUpper(), true);
|
||||
return m_extension_map.GetValues (ext.ToUpper(), true);
|
||||
}
|
||||
|
||||
public IEnumerable<Type> LookupTag<Type> (string tag) where Type : IResource
|
||||
public IEnumerable<Type> LookupExtension<Type> (string ext) where Type : IResource
|
||||
{
|
||||
return LookupTag (tag).OfType<Type>();
|
||||
return LookupExtension (ext).OfType<Type>();
|
||||
}
|
||||
|
||||
public IEnumerable<IResource> LookupSignature (uint signature)
|
||||
|
Loading…
Reference in New Issue
Block a user