public FileInfo[] GetConfigFiles() { var configs = InputDirectory.GetFiles("*.cfg", SearchOption.AllDirectories); if (configs.Length > 0) { return(configs); } return(null); }
private void Init() { VitaNexCore.TryCatch( () => { Status = CompileStatus.Initializing; if (!InputDirectory.Exists) { Status = CompileStatus.Aborted; StatusMessage = "Input directory '" + InputDirectory + "' does not exist."; return; } var infos = new List <FileInfo>(); foreach (var file in FileMasks.SelectMany( t => InputDirectory.GetFiles(t, SearchOption.AllDirectories).Where(file => !infos.Contains(file)))) { infos.Add(file); } var files = infos.ToArray(); infos.Clear(); if (files.Length == 0) { Status = CompileStatus.Aborted; StatusMessage = "No files to compile."; return; } var refs = new List <string>(); var fileNames = new List <string>(); foreach (var fName in files.Select(t => t.FullName) .Where(fName => !String.IsNullOrEmpty(fName)) .Where(fName => !fileNames.Contains(fName))) { fileNames.Add(fName); } foreach (var t in DefaultReferences.Where(t => !String.IsNullOrEmpty(t)).Where(t => !refs.Contains(t))) { refs.Add(t); } foreach (var t in References.Where(t => !String.IsNullOrEmpty(t)).Where(t => !refs.Contains(t))) { refs.Add(t); } var configs = GetConfigFiles(); if (configs != null) { foreach (var t in configs.Select(GetConfigAssemblies) .SelectMany( asm => asm.Where(t => !String.IsNullOrEmpty(t)) .Where(t => File.Exists(IOUtility.GetSafeFilePath(IOUtility.GetBaseDirectory() + "/" + t, true))) .Where(t => !refs.Contains(t)))) { refs.Add(t); } } Status = CompileStatus.Compiling; Parameters = new CompilerParameters( refs.ToArray(), IOUtility.GetUnusedFilePath(OutputDirectory.FullName, OutputFileName), Debug) { GenerateExecutable = false, WarningLevel = 4, CompilerOptions = String.Empty }; foreach (var arg in Arguments) { Parameters.CompilerOptions += arg + " "; } Results = Provider.CompileAssemblyFromFile(Parameters, fileNames.ToArray()); if (Results.Errors.Count > 0) { int errorCount = 0, warningCount = 0; foreach (CompilerError e in Results.Errors) { if (e.IsWarning) { ++warningCount; } else { ++errorCount; } } Errors = new string[Results.Errors.Count]; for (var e = 0; e < Results.Errors.Count; e++) { Errors[e] = String.Format( "[{0}][{1}][{2}]: Line {3}, Column {4}\n{5}", Results.Errors[e].IsWarning ? "Warning" : "Error", Results.Errors[e].FileName, Results.Errors[e].ErrorNumber, Results.Errors[e].Line, Results.Errors[e].Column, Results.Errors[e].ErrorText); } StatusMessage = String.Format( "Finished compiling with {0} error{1} and {2} warning{3}", errorCount, errorCount > 1 ? "s" : "", warningCount, warningCount > 1 ? "s" : ""); Status = CompileStatus.Completed; } else { StatusMessage = "Finished compiling with no errors or warnings."; Status = CompileStatus.Completed; } }, ex => { Status = CompileStatus.Aborted; StatusMessage = ex.Message; }); if (CompiledCallback != null) { CompiledCallback(Results); } }