From 58a65baec6c1720d17ab64dc58ee5b77aa26cfbb Mon Sep 17 00:00:00 2001 From: Oleh Zaiats Date: Wed, 4 May 2022 12:54:44 +0300 Subject: [PATCH 1/3] Added batch modules loading using a wildcard --- Confuser.CLI/Program.cs | 3 +- Confuser.Core/Project/ConfuserProject.cs | 46 +++++++++++++++++++++--- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/Confuser.CLI/Program.cs b/Confuser.CLI/Program.cs index 2586fff31..0bc1451ab 100644 --- a/Confuser.CLI/Program.cs +++ b/Confuser.CLI/Program.cs @@ -60,8 +60,7 @@ static int Main(string[] args) { try { var xmlDoc = new XmlDocument(); xmlDoc.Load(files[0]); - proj.Load(xmlDoc); - proj.BaseDirectory = Path.Combine(Path.GetDirectoryName(files[0]), proj.BaseDirectory); + proj.Load(xmlDoc, Path.GetDirectoryName(files[0])); } catch (Exception ex) { WriteLineWithColor(ConsoleColor.Red, "Failed to load project:"); diff --git a/Confuser.Core/Project/ConfuserProject.cs b/Confuser.Core/Project/ConfuserProject.cs index d8dc25a54..3fc80ed48 100644 --- a/Confuser.Core/Project/ConfuserProject.cs +++ b/Confuser.Core/Project/ConfuserProject.cs @@ -626,7 +626,7 @@ public XmlDocument Save() { /// /// The project XML contains schema errors. /// - public void Load(XmlDocument doc) { + public void Load(XmlDocument doc, string baseDirRoot = null) { doc.Schemas.Add(Schema); var exceptions = new List(); doc.Validate((sender, e) => { @@ -641,7 +641,11 @@ public void Load(XmlDocument doc) { OutputDirectory = docElem.Attributes["outputDir"].Value; BaseDirectory = docElem.Attributes["baseDir"].Value; - + if (!string.IsNullOrEmpty(baseDirRoot)) + { + BaseDirectory = Path.Combine(baseDirRoot, BaseDirectory); + } + if (docElem.Attributes["seed"] != null) Seed = docElem.Attributes["seed"].Value.NullIfEmpty(); else @@ -674,13 +678,45 @@ public void Load(XmlDocument doc) { PluginPaths.Add(i.InnerText); } else { - var asm = new ProjectModule(); - asm.Load(i); - Add(asm); + AddModule(i); } } } + internal void AddModule(XmlElement elem) { + if (IsWildcard(elem.Attributes["path"].Value)) { + BatchLoadModules(elem); + } + else { + var asm = new ProjectModule(); + asm.Load(elem); + Add(asm); + } + } + + internal bool IsWildcard(string path) { + return !string.IsNullOrEmpty(path) && path.Contains(@"*"); + } + + internal bool BatchLoadModules(XmlElement elem) { + string wildCardPath = elem.Attributes["path"].Value; + string[] files = Directory.GetFiles(BaseDirectory, wildCardPath, SearchOption.AllDirectories); // TODO: recursive + if (files.Length <= 0) + { + return false; + } + + var asmPrototype = new ProjectModule(); + asmPrototype.Load(elem); + + foreach (string fileName in files) { + var moduleEntry = asmPrototype.Clone(); + moduleEntry.Path = fileName; + Add(moduleEntry); + } + + return true; + } /// /// Clones this instance. /// From 17de63f7d73b2ab8f08de3997808c999fdeae3a5 Mon Sep 17 00:00:00 2001 From: Oleh Zaiats Date: Wed, 4 May 2022 13:36:13 +0300 Subject: [PATCH 2/3] minor: replaced spaces with tabs --- Confuser.Core/Project/ConfuserProject.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Confuser.Core/Project/ConfuserProject.cs b/Confuser.Core/Project/ConfuserProject.cs index 3fc80ed48..eeef633b7 100644 --- a/Confuser.Core/Project/ConfuserProject.cs +++ b/Confuser.Core/Project/ConfuserProject.cs @@ -642,7 +642,7 @@ public void Load(XmlDocument doc, string baseDirRoot = null) { OutputDirectory = docElem.Attributes["outputDir"].Value; BaseDirectory = docElem.Attributes["baseDir"].Value; if (!string.IsNullOrEmpty(baseDirRoot)) - { + { BaseDirectory = Path.Combine(baseDirRoot, BaseDirectory); } @@ -702,7 +702,7 @@ internal bool BatchLoadModules(XmlElement elem) { string wildCardPath = elem.Attributes["path"].Value; string[] files = Directory.GetFiles(BaseDirectory, wildCardPath, SearchOption.AllDirectories); // TODO: recursive if (files.Length <= 0) - { + { return false; } From 9ecca8b996eb02482a8a374d296179772d84143a Mon Sep 17 00:00:00 2001 From: Oleh Zaiats Date: Wed, 4 May 2022 13:39:06 +0300 Subject: [PATCH 3/3] batch load modules: search top directory only --- Confuser.Core/Project/ConfuserProject.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Confuser.Core/Project/ConfuserProject.cs b/Confuser.Core/Project/ConfuserProject.cs index eeef633b7..6c673d9fd 100644 --- a/Confuser.Core/Project/ConfuserProject.cs +++ b/Confuser.Core/Project/ConfuserProject.cs @@ -700,7 +700,7 @@ internal bool IsWildcard(string path) { internal bool BatchLoadModules(XmlElement elem) { string wildCardPath = elem.Attributes["path"].Value; - string[] files = Directory.GetFiles(BaseDirectory, wildCardPath, SearchOption.AllDirectories); // TODO: recursive + string[] files = Directory.GetFiles(BaseDirectory, wildCardPath, SearchOption.TopDirectoryOnly); if (files.Length <= 0) { return false;