Skip to content

Commit 55008ed

Browse files
authored
Merge 58a65ba into 657fb58
2 parents 657fb58 + 58a65ba commit 55008ed

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

Confuser.CLI/Program.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ static int Main(string[] args) {
6060
try {
6161
var xmlDoc = new XmlDocument();
6262
xmlDoc.Load(files[0]);
63-
proj.Load(xmlDoc);
64-
proj.BaseDirectory = Path.Combine(Path.GetDirectoryName(files[0]), proj.BaseDirectory);
63+
proj.Load(xmlDoc, Path.GetDirectoryName(files[0]));
6564
}
6665
catch (Exception ex) {
6766
WriteLineWithColor(ConsoleColor.Red, "Failed to load project:");

Confuser.Core/Project/ConfuserProject.cs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ public XmlDocument Save() {
626626
/// <exception cref="Confuser.Core.Project.ProjectValidationException">
627627
/// The project XML contains schema errors.
628628
/// </exception>
629-
public void Load(XmlDocument doc) {
629+
public void Load(XmlDocument doc, string baseDirRoot = null) {
630630
doc.Schemas.Add(Schema);
631631
var exceptions = new List<XmlSchemaException>();
632632
doc.Validate((sender, e) => {
@@ -641,7 +641,11 @@ public void Load(XmlDocument doc) {
641641

642642
OutputDirectory = docElem.Attributes["outputDir"].Value;
643643
BaseDirectory = docElem.Attributes["baseDir"].Value;
644-
644+
if (!string.IsNullOrEmpty(baseDirRoot))
645+
{
646+
BaseDirectory = Path.Combine(baseDirRoot, BaseDirectory);
647+
}
648+
645649
if (docElem.Attributes["seed"] != null)
646650
Seed = docElem.Attributes["seed"].Value.NullIfEmpty();
647651
else
@@ -674,13 +678,45 @@ public void Load(XmlDocument doc) {
674678
PluginPaths.Add(i.InnerText);
675679
}
676680
else {
677-
var asm = new ProjectModule();
678-
asm.Load(i);
679-
Add(asm);
681+
AddModule(i);
680682
}
681683
}
682684
}
683685

686+
internal void AddModule(XmlElement elem) {
687+
if (IsWildcard(elem.Attributes["path"].Value)) {
688+
BatchLoadModules(elem);
689+
}
690+
else {
691+
var asm = new ProjectModule();
692+
asm.Load(elem);
693+
Add(asm);
694+
}
695+
}
696+
697+
internal bool IsWildcard(string path) {
698+
return !string.IsNullOrEmpty(path) && path.Contains(@"*");
699+
}
700+
701+
internal bool BatchLoadModules(XmlElement elem) {
702+
string wildCardPath = elem.Attributes["path"].Value;
703+
string[] files = Directory.GetFiles(BaseDirectory, wildCardPath, SearchOption.AllDirectories); // TODO: recursive
704+
if (files.Length <= 0)
705+
{
706+
return false;
707+
}
708+
709+
var asmPrototype = new ProjectModule();
710+
asmPrototype.Load(elem);
711+
712+
foreach (string fileName in files) {
713+
var moduleEntry = asmPrototype.Clone();
714+
moduleEntry.Path = fileName;
715+
Add(moduleEntry);
716+
}
717+
718+
return true;
719+
}
684720
/// <summary>
685721
/// Clones this instance.
686722
/// </summary>

0 commit comments

Comments
 (0)