From e65e19fd72fcb3d037e37117c5e804366751f2a6 Mon Sep 17 00:00:00 2001 From: yck1509 Date: Sun, 21 Dec 2014 16:38:28 +0800 Subject: [PATCH] Add TryGet method to runtime compression service --- Confuser.Core/Services/CompressionService.cs | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Confuser.Core/Services/CompressionService.cs b/Confuser.Core/Services/CompressionService.cs index 8ef442481..f3dcba40d 100644 --- a/Confuser.Core/Services/CompressionService.cs +++ b/Confuser.Core/Services/CompressionService.cs @@ -22,6 +22,17 @@ public CompressionService(ConfuserContext context) { this.context = context; } + /// + public MethodDef TryGetRuntimeDecompressor(ModuleDef module, Action init) { + var decompressor = context.Annotations.Get>>(module, Decompressor); + if (decompressor == null) + return null; + + foreach (IDnlibDef member in decompressor.Item2) + init(member); + return decompressor.Item1; + } + /// public MethodDef GetRuntimeDecompressor(ModuleDef module, Action init) { Tuple> decompressor = context.Annotations.GetOrCreate(module, Decompressor, m => { @@ -123,6 +134,17 @@ public void SetProgress(long inSize, long outSize) { /// public interface ICompressionService { + /// + /// Gets the runtime decompression method in the module, or null if it's not yet injected. + /// + /// The module which the decompression method resides in. + /// The initializing method for compression helper definitions. + /// + /// The requested decompression method with signature 'static Byte[] (Byte[])', + /// or null if it hasn't been injected yet. + /// + MethodDef TryGetRuntimeDecompressor(ModuleDef module, Action init); + /// /// Gets the runtime decompression method in the module and inject if it does not exists. ///