public static void GenerateFullPath(ref List <string> inputF, ref List <string> resourceF, ref List <string> moduleF) { for (int i = 0; i < inputF.Count; i++) { if (File.Exists(inputF[i])) { inputF[i] = Path.GetFullPath(inputF[i]); } else { ConsoleTools.Error($"Input file not found: {inputF[i]}", 3); } } for (int i = 0; i < resourceF.Count; i++) { if (File.Exists(resourceF[i])) { resourceF[i] = Path.GetFullPath(resourceF[i]); } } for (int i = 0; i < moduleF.Count; i++) { if (File.Exists(moduleF[i])) { moduleF[i] = Path.GetFullPath(moduleF[i]); } } inputF.Sort(); resourceF.Sort(); moduleF.Sort(); }
void GenerateCache(string path, string filename) { int error; string executeMessage = ConsoleTools.Execute(inputCompilerLine, out error); if (error == 0) { Console.WriteLine(executeMessage); File.Copy(outputFile, path + filename + "bin.cache", true); File.WriteAllText(path + filename + ".cache", executeMessage); } else { ConsoleTools.Error(executeMessage, error); } }
public Config() { if (!File.Exists(path + "config.xml")) { Console.WriteLine("Config file not found. Loading default configuration."); LoadDefaultConfig(); } ProcessConfigFile(path + "config.xml"); if (cacheLocation == null || versionArg == null || referenceArg == null || outputArg == null || defaultExtension == null || moduleArg == null || ignoredArg == null || targetArg == null || recurseArg == null) { ConsoleTools.Error("Error in file configuration.\nChange the configuration or delete the configuration and reload the program.", 3); } }
public void Cache() { int error = -1; bool showHelp = false; bool doClearCache = false; var options = new OptionSet { { "c|clear=", "clear cache. Options : =all", n => { if (n == "all") { doClearCache = true; } } }, { "v|version", "show the current version of the tool.", v => { } }, { "h|help", "show help message and exit.", h => showHelp = true }, }; List <string> extra = new List <string>(); try { extra = options.Parse(inputArgs); } catch (OptionException e) { ConsoleTools.Error($"CSCache: {e.Message} \n Try `CSCache --help' for more information.", 1); } if (showHelp) { LibArgs.ShowHelp(options); return; } if (doClearCache) { LibArgs.ClearCache(configuration.cacheLocation); return; } if (extra.Count == 1) { ProcessInputCompiler(extra[0]); } else { ConsoleTools.Error("Error reading the compiler and arguments.\nTry `CSCache --help' for more information.", 1); } foreach (var item in configuration.versionArg) { compilerInfo = ConsoleTools.Execute(compilerName + " " + item, out error); if (error == 0) { break; } } if (error == 0) { byte[] inputCache; byte[] filesCache; byte[] combinedCache; FilesTools.GenerateFullPath(ref inputFiles, ref referenceFiles, ref moduleFiles); inputCache = GenerateInputCache(); filesCache = MD5Tools.GenerateFilesCache(inputFiles); combinedCache = MD5Tools.CombineHashes(new List <byte[]> { inputCache, filesCache }); CompareCache(combinedCache); } else { ConsoleTools.Error("Error getting the version of the compiler. Check the configuration file.", 2); } }
void ProcessInputCompiler(string input) { inputCompilerLine = input; string[] compParams = ParseTools.ParseArguments(input); if (compParams.Length > 1) { string[] newArr = new string[compParams.Length - 1]; compilerName = compParams[0]; Array.Copy(compParams, 1, newArr, 0, compParams.Length - 1); newArr = ParseTools.ParseArgArrayWithResponse(newArr); string outputArgsOpt = ParseTools.generateOption(configuration.outputArg); string referenceArgsOpt = ParseTools.generateOption(configuration.referenceArg); string targetArgsOpt = ParseTools.generateOption(configuration.targetArg); string recurseArgsOpt = ParseTools.generateOption(configuration.recurseArg); string ignoredArgsOpt = ParseTools.generateOption(configuration.ignoredArg); string moduleArgsOpt = ParseTools.generateOption(configuration.moduleArg); var options = new OptionSet() { { outputArgsOpt + "=", "Output arguments", (o) => { outputFile = o; compilerArgs.Add(configuration.outputArg[0] + o); } }, { referenceArgsOpt + "=", "Reference arguments", (r) => { referenceFiles.AddRange(ParseTools.ParseComaSemicolon(r)); } }, { targetArgsOpt + "=", "Target arguments", (t) => { compilerArgs.Add(configuration.targetArg[0] + t); outputExtension = LibArgs.GetTargetExtenstion(t); } }, { recurseArgsOpt + "=", "Recurse arguments", (rc) => { inputFiles.AddRange(FilesTools.GetRecurseFiles(rc)); compilerArgs.Add(configuration.recurseArg[0] + rc); } }, { moduleArgsOpt + "=", "Add module arguments", (m) => { moduleFiles.AddRange(ParseTools.ParseComaSemicolon(m)); } }, { ignoredArgsOpt, "Ignored arguments", (i) => { } }, { "<>", "Input file", (file) => { if (file[0] != '/' && file[0] != '-') { inputFiles.Add(file); } else { compilerArgs.Add(file); } } } }; Console.WriteLine(configuration.targetArg[0]); try { options.Parse(newArr); } catch (OptionException) { ConsoleTools.Error("Invalid compiler parameters.", 1); } if (inputFiles.Count > 0) { if (outputFile == null) { string outPathFile = Path.GetFullPath(inputFiles[0]); outputFile = Path.ChangeExtension(outPathFile, (outputExtension == null) ? configuration.defaultExtension : outputExtension); } compilerArgs.Sort(); } else { ConsoleTools.Error("No input files detected.", 4); } } else { ConsoleTools.Error("Invalid compiler parameters.", 1); } }