Skip to content

Commit 2ea1fd4

Browse files
authored
Merge 56e8221 into 8e93b47
2 parents 8e93b47 + 56e8221 commit 2ea1fd4

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

Confuser.CLI/Program.cs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.IO;
5+
using System.Linq;
56
using System.Xml;
67
using Confuser.Core;
78
using Confuser.Core.Project;
@@ -78,24 +79,68 @@ static int Main(string[] args) {
7879
}
7980

8081
var proj = new ConfuserProject();
82+
var templateModules = new List<ProjectModule>();
8183

8284
if (Path.GetExtension(files[files.Count - 1]) == ".crproj") {
8385
var templateProj = new ConfuserProject();
8486
var xmlDoc = new XmlDocument();
8587
xmlDoc.Load(files[files.Count - 1]);
8688
templateProj.Load(xmlDoc);
8789
files.RemoveAt(files.Count - 1);
88-
90+
8991
foreach (var rule in templateProj.Rules)
9092
proj.Rules.Add(rule);
93+
94+
proj.Packer = templateProj.Packer;
95+
96+
foreach (string pluginPath in templateProj.PluginPaths)
97+
proj.PluginPaths.Add(pluginPath);
98+
99+
foreach (string probePath in templateProj.ProbePaths)
100+
proj.ProbePaths.Add(probePath);
101+
102+
foreach (var templateModule in templateProj)
103+
if (templateModule.IsExternal)
104+
proj.Add(templateModule);
105+
else
106+
templateModules.Add(templateModule);
91107
}
92108

93109
// Generate a ConfuserProject for input modules
94110
// Assuming first file = main module
95-
foreach (var input in files)
96-
proj.Add(new ProjectModule { Path = input });
97-
98111
proj.BaseDirectory = Path.GetDirectoryName(files[0]);
112+
if (string.IsNullOrWhiteSpace(proj.BaseDirectory)) {
113+
WriteLineWithColor(ConsoleColor.Red, "Failed to identify base directory for main assembly.");
114+
PrintUsage();
115+
return -1;
116+
}
117+
118+
foreach (var input in files) {
119+
string modulePath = input;
120+
if (modulePath.StartsWith(proj.BaseDirectory, StringComparison.OrdinalIgnoreCase)) {
121+
modulePath = modulePath.Substring(proj.BaseDirectory.Length + 1);
122+
}
123+
124+
var matchedToTemplate = false;
125+
foreach (var templateModule in templateModules) {
126+
var templatePath = templateModule.Path;
127+
if (templatePath.StartsWith(@".\", StringComparison.Ordinal))
128+
templatePath = templatePath.Substring(2);
129+
130+
if (modulePath.Equals(templatePath, StringComparison.OrdinalIgnoreCase))
131+
matchedToTemplate = true;
132+
133+
if (modulePath.Equals(Path.Combine(proj.BaseDirectory, templatePath), StringComparison.OrdinalIgnoreCase))
134+
matchedToTemplate = true;
135+
136+
if (matchedToTemplate)
137+
proj.Add(templateModule);
138+
}
139+
140+
if (!matchedToTemplate)
141+
proj.Add(new ProjectModule { Path = modulePath });
142+
}
143+
99144
proj.OutputDirectory = outDir;
100145
foreach (var path in probePaths)
101146
proj.ProbePaths.Add(path);

0 commit comments

Comments
 (0)