|
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Diagnostics; |
4 | 4 | using System.IO; |
| 5 | +using System.Linq; |
5 | 6 | using System.Xml; |
6 | 7 | using Confuser.Core; |
7 | 8 | using Confuser.Core.Project; |
@@ -78,24 +79,68 @@ static int Main(string[] args) { |
78 | 79 | } |
79 | 80 |
|
80 | 81 | var proj = new ConfuserProject(); |
| 82 | + var templateModules = new List<ProjectModule>(); |
81 | 83 |
|
82 | 84 | if (Path.GetExtension(files[files.Count - 1]) == ".crproj") { |
83 | 85 | var templateProj = new ConfuserProject(); |
84 | 86 | var xmlDoc = new XmlDocument(); |
85 | 87 | xmlDoc.Load(files[files.Count - 1]); |
86 | 88 | templateProj.Load(xmlDoc); |
87 | 89 | files.RemoveAt(files.Count - 1); |
88 | | - |
| 90 | + |
89 | 91 | foreach (var rule in templateProj.Rules) |
90 | 92 | 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); |
91 | 107 | } |
92 | 108 |
|
93 | 109 | // Generate a ConfuserProject for input modules |
94 | 110 | // Assuming first file = main module |
95 | | - foreach (var input in files) |
96 | | - proj.Add(new ProjectModule { Path = input }); |
97 | | - |
98 | 111 | 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 | + |
99 | 144 | proj.OutputDirectory = outDir; |
100 | 145 | foreach (var path in probePaths) |
101 | 146 | proj.ProbePaths.Add(path); |
|
0 commit comments