public static void Main(String[] args) {
// Tell build we had an error, then set this to 0 if we complete successfully.
Environment.ExitCode = errorCode;
if (args.Length < 1 || args[0].Equals("-h") || args[0].Equals("-?") ||
args[0].Equals("/h") || args[0].Equals("/?")) {
Usage();
return;
}
String[] inFiles = null;
String[] outFiles = null;
// Default resource class options for all classes
ResourceClassOptions resourceClassOptions = null;
int argIndex = 0;
bool setSimpleInputFile = false; // For resgen a.resources a.resx
bool gotOutputFileName = false; // For resgen a.txt a.resources b.txt
bool useSourcePath = false;
bool isClassInternal = true;
while(argIndex < args.Length && errors == 0) {
if (args[argIndex].Equals("/compile")) {
inFiles = new String[args.Length - argIndex - 1];
outFiles = new String[args.Length - argIndex - 1];
for(int i=0; i<inFiles.Length; i++) {
inFiles[i] = args[argIndex+1];
int index = inFiles[i].IndexOf(",");
if (index != -1) {
String tmp = inFiles[i];
inFiles[i] = tmp.Substring(0, index);
if (!ValidResourceFileName(inFiles[i])) {
Error(SR.GetString(SR.BadFileExtension, inFiles[i]));
break;
}
if (index == tmp.Length-1) {
Error(SR.GetString(SR.MalformedCompileString, tmp));
inFiles = new String[0];
break;
}
outFiles[i] = tmp.Substring(index+1);
if (!ValidResourceFileName(outFiles[i])) {
Error(SR.GetString(SR.BadFileExtension, outFiles[i]));
break;
}
}
else {
if (!ValidResourceFileName(inFiles[i])) {
if (inFiles[i][0] == '/' || inFiles[i][0] == '-') {
Error(SR.GetString(SR.InvalidCommandLineSyntax, "/compile", inFiles[i]));
}
else
Error(SR.GetString(SR.BadFileExtension, inFiles[i]));
break;
}
string resourceFileName = GetResourceFileName(inFiles[i]);
Debug.Assert(resourceFileName != null, "Unexpected null file name!");
outFiles[i] = resourceFileName;
}
argIndex++;
}
}
else if (args[argIndex].StartsWith("/r:") || args[argIndex].StartsWith("-r:")) {
// assembly names syntax /r:c:\system\System.Drawing.dll
String s = args[argIndex];
s = s.Substring(3); // Skip over "/r:"
if(assemblyList == null) {
assemblyList = new List<AssemblyName>();
}
try {
assemblyList.Add(AssemblyName.GetAssemblyName(s));
}
catch(Exception e) {
Error(SR.GetString(SR.CantLoadAssembly, s, e.GetType().Name, e.Message));
}
}
else if (args[argIndex].ToLower(CultureInfo.InvariantCulture).Equals("/usesourcepath") ||
args[argIndex].ToLower(CultureInfo.InvariantCulture).Equals("-usesourcepath")) {
useSourcePath = true;
} else if (args[argIndex].ToLower(CultureInfo.InvariantCulture).Equals("/publicclass") ||
args[argIndex].ToLower(CultureInfo.InvariantCulture).Equals("-publicclass")) {
isClassInternal = false;
} else {
if (ValidResourceFileName(args[argIndex])) {
if (!setSimpleInputFile) {
inFiles = new String[1];
inFiles[0] = args[argIndex];
outFiles = new String[1];
outFiles[0] = GetResourceFileName(inFiles[0]);
setSimpleInputFile = true;
}
else {
if (!gotOutputFileName) {
outFiles[0] = args[argIndex];
gotOutputFileName = true;
}
else {
Error(SR.GetString(SR.InvalidCommandLineSyntax, "<none>", args[argIndex]));
break;
}
}
}
else {
if (args[argIndex][0] == '/' || args[argIndex][0] == '-') {
Error(SR.GetString(SR.BadCommandLineOption, args[argIndex]));
}
else
Error(SR.GetString(SR.BadFileExtension, args[argIndex]));
return;
}
}
argIndex++;
}
if ((inFiles == null || inFiles.Length == 0) && errors == 0) {
Usage();
return;
}
if (resourceClassOptions != null) {
resourceClassOptions.InternalClass = isClassInternal;
// Verify we don't produce two identically named resource classes,
// or write different classes to the same file when using the
// /compile option.
if (inFiles.Length > 1) {
if (resourceClassOptions.ClassName != null || resourceClassOptions.OutputFileName != null) {
Error(SR.GetString(SR.CompileAndSTRDontMix));
}
}
}
// Do all the work.
if (errors == 0) {
for(int i=0; i<inFiles.Length; i++) {
ProcessFile(inFiles[i], outFiles[i], resourceClassOptions, useSourcePath);
}
}
// Quit & report errors, if necessary.
if (warnings != 0)
Console.Error.WriteLine(SR.GetString(SR.WarningCount, warnings));
if (errors != 0) {
Console.Error.WriteLine(SR.GetString(SR.ErrorCount, errors));
Debug.Assert(Environment.ExitCode != 0);
// Now delete all the output files, ensuring the build won't
// continue using half-generated output files. This is a
// backstop for other errors up above.
if (outFiles != null) {
foreach(String outFile in outFiles) {
if (File.Exists(outFile)) {
try {
File.Delete(outFile);
}
catch {}
}
}
}
}
else {
// Tell build we succeeded.
Environment.ExitCode = 0;
}
}