Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added batch modules loading using a wildcard #481

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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))
{
ozaiats marked this conversation as resolved.
Show resolved Hide resolved
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.AllDirectories); // TODO: recursive
if (files.Length <= 0)
{
ozaiats marked this conversation as resolved.
Show resolved Hide resolved
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