Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Confuser.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:");
Expand Down
46 changes: 41 additions & 5 deletions Confuser.Core/Project/ConfuserProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ public XmlDocument Save() {
/// <exception cref="Confuser.Core.Project.ProjectValidationException">
/// The project XML contains schema errors.
/// </exception>
public void Load(XmlDocument doc) {
public void Load(XmlDocument doc, string baseDirRoot = null) {
doc.Schemas.Add(Schema);
var exceptions = new List<XmlSchemaException>();
doc.Validate((sender, e) => {
Expand All @@ -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
Expand Down Expand Up @@ -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.TopDirectoryOnly);
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;
}
/// <summary>
/// Clones this instance.
/// </summary>
Expand Down