From ca8eb6b7bf2e5fb3b7418902e5e564b3ac347265 Mon Sep 17 00:00:00 2001 From: Lasse Ylinen Date: Tue, 31 Mar 2015 17:20:43 +0300 Subject: [PATCH] Add support for saving specifically marked files into a subfolder under OutputDirectory. --- Confuser.Core/ConfuserEngine.cs | 5 +++++ Confuser.Core/Marker.cs | 6 ++++++ Confuser.Core/Project/ConfuserPrj.xsd | 1 + Confuser.Core/Project/ConfuserProject.cs | 15 +++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/Confuser.Core/ConfuserEngine.cs b/Confuser.Core/ConfuserEngine.cs index baabf6703..154f8de0e 100644 --- a/Confuser.Core/ConfuserEngine.cs +++ b/Confuser.Core/ConfuserEngine.cs @@ -355,6 +355,11 @@ static void EndModule(ConfuserContext context) { else { output = context.CurrentModule.Name; } + var belongsToSubFolder = context.Annotations.Get(context.CurrentModule, Marker.SubDirKey); + if(!String.IsNullOrWhiteSpace(belongsToSubFolder)) + { + output = Path.Combine(Path.GetDirectoryName(output), belongsToSubFolder, Path.GetFileName(output)); + } context.OutputPaths[context.CurrentModuleIndex] = output; } diff --git a/Confuser.Core/Marker.cs b/Confuser.Core/Marker.cs index 1c6904d95..9cb454878 100644 --- a/Confuser.Core/Marker.cs +++ b/Confuser.Core/Marker.cs @@ -25,6 +25,11 @@ public class Marker { /// public static readonly object RulesKey = new object(); + /// + /// Annotation key of subdirectories. + /// + public static readonly object SubDirKey = new object(); + /// /// The packers available to use. /// @@ -136,6 +141,7 @@ protected internal virtual MarkerResult MarkProject(ConfuserProject proj, Confus context.Annotations.Set(module.Item2, SNKey, LoadSNKey(context, module.Item1.SNKeyPath == null ? null : Path.Combine(proj.BaseDirectory, module.Item1.SNKeyPath), module.Item1.SNKeyPassword)); context.Annotations.Set(module.Item2, RulesKey, rules); + context.Annotations.Set(module.Item2, SubDirKey, module.Item1.BelongsToSubFolder); foreach (IDnlibDef def in module.Item2.FindDefinitions()) { ApplyRules(context, def, rules); diff --git a/Confuser.Core/Project/ConfuserPrj.xsd b/Confuser.Core/Project/ConfuserPrj.xsd index bdad775b7..7bc4ea30b 100644 --- a/Confuser.Core/Project/ConfuserPrj.xsd +++ b/Confuser.Core/Project/ConfuserPrj.xsd @@ -54,6 +54,7 @@ + diff --git a/Confuser.Core/Project/ConfuserProject.cs b/Confuser.Core/Project/ConfuserProject.cs index 0969b6f0a..eac7f4a0f 100644 --- a/Confuser.Core/Project/ConfuserProject.cs +++ b/Confuser.Core/Project/ConfuserProject.cs @@ -40,6 +40,11 @@ public ProjectModule() { /// The password of the strong name private key, or null if not necessary. public string SNKeyPassword { get; set; } + /// + /// Gets or sets the subfolder into which the resulting obfuscated file should be placed. + /// + public string BelongsToSubFolder { get; set; } + /// /// Gets a list of protection rules applies to the module. /// @@ -102,6 +107,11 @@ internal XmlElement Save(XmlDocument xmlDoc) { snKeyPassAttr.Value = SNKeyPassword; elem.Attributes.Append(snKeyPassAttr); } + if (BelongsToSubFolder != null) { + XmlAttribute toSubFolderAttr = xmlDoc.CreateAttribute("belongsToSubFolder"); + toSubFolderAttr.Value = BelongsToSubFolder; + elem.Attributes.Append(toSubFolderAttr); + } foreach (Rule i in Rules) @@ -132,6 +142,11 @@ internal void Load(XmlElement elem) { else SNKeyPassword = null; + if (elem.Attributes["belongsToSubFolder"] != null) + BelongsToSubFolder = elem.Attributes["belongsToSubFolder"].Value.NullIfEmpty(); + else + BelongsToSubFolder = null; + Rules.Clear(); foreach (XmlElement i in elem.ChildNodes.OfType()) { var rule = new Rule();