private static void PrintDurationTime(Int64 startTime, OutputManager outputManager) { TimeSpan duration = TimeSpan.FromTicks((DateTime.Now.Ticks - startTime)); String hourString = "hours"; String minuteString = "minutes"; if (duration.Hours == 1) { hourString = "hour"; // singular } if (duration.Minutes == 1) { minuteString = "minute"; } outputManager.DisplayMessage(String.Format( "\nDuration: {0} {1} {2} {3} ", duration.Hours, hourString, duration.Minutes, minuteString), ConsoleColor.White); } // PrintDurationTime()
// ParseCommandLine() /// <summary> /// Check if target directory exists. If not, it will tried to create it. /// Messages should help the user with problems. /// </summary> /// <param name="path">path of target directory</param> /// <param name="outputManager">Used to created coloured console outputs.</param> private static void VerifyTargetDirectory(String path, OutputManager outputManager) { if (path == null) { path = ""; } // create directory try { Directory.CreateDirectory(path); Directory.SetCurrentDirectory(path); outputManager.Action(String.Format("Using target directory: {0} ", path)); } catch (Exception e) { outputManager.Error(String.Format( "Can not use target directory {0}\n" + "Error message: {1} ", path, e.Message)); throw new ParseException(); // stop application } } // VerifyTargetDirectory()
public RepositoryTask(InputManager inputManager, OutputManager outputManager) : base(inputManager, outputManager) { }
/// <summary> /// Create a list of all needed tasks (related to the choosed options). /// </summary> private static List <Task> BuildTaskList(InputManager inputManager, OutputManager outputManager) { List <Task> taskList = new List <Task>(); MsBuildManager msBuildManager = new MsBuildManager(outputManager); taskList.Add(new CheckTools(inputManager, outputManager)); if (inputManager.Option_OnlyAddons == false) { //--- tasks to build Ogre/Mogre --- taskList.Add(new CloneMogreSource(inputManager, outputManager)); taskList.Add(new CloneOgreSource(inputManager, outputManager)); // patch taskList.Add(new PatchOgreCode(inputManager, outputManager)); // Dependencies taskList.Add(new CloneDependenciesRepository(inputManager, outputManager)); if (inputManager.Option_SkipCMake == false) { taskList.Add(new OgreCmake(inputManager, outputManager)); } // Auto-wrapping taskList.Add(new AutoWrap(inputManager, outputManager, msBuildManager)); // Building taskList.Add(new BuildOgreWithoutMogreLinking(inputManager, outputManager, msBuildManager)); taskList.Add(new UpdateMogreVersion(inputManager, outputManager)); taskList.Add(new BuildMogre(inputManager, outputManager, msBuildManager)); taskList.Add(new BuildOgreWithMogreLinking(inputManager, outputManager, msBuildManager)); } //--- optional add-on tasks --- // clone official Mogre-addons repository (if one of the included add-ons is needed) if (inputManager.Option_MogreNewt || inputManager.Option_Hikari || inputManager.Option_Makuri || inputManager.Option_MogreDesignSupport || inputManager.Option_MogreFreeSL || inputManager.Option_Mois) { taskList.Add(new CloneAddonsRepository(inputManager, outputManager)); } // build MogreNewt if (inputManager.Option_MogreNewt) { taskList.Add(new NewtonLibraryDownload(inputManager, outputManager)); taskList.Add(new NewtonPrepatation(inputManager, outputManager)); } // build Mois if (inputManager.Option_Mois) { taskList.Add(new BuildMoisTask(inputManager, outputManager, msBuildManager)); } // Organizing the result taskList.Add(new AssembleBinaryFiles(inputManager, outputManager)); return(taskList); } // BuildTaskList()
public TaskManager(InputManager inputManager, OutputManager outputManager) { _inputManager = inputManager; _outputManager = outputManager; }
public MsBuildManager(OutputManager outputManager) { this.outputManager = outputManager; }
public ThreadParams(ProcessPriorityClass priority, OutputManager outputManager) { this.priority = priority; this.outputManager = outputManager; }
protected CommandResult RunCommand(string command, string arguments, string workingDirectory) { Process process = new Process(); process.EnableRaisingEvents = false; process.StartInfo.FileName = command; process.StartInfo.EnvironmentVariables["Path"] = inputManager.PathEnvironmentVariable; if (arguments != null) { process.StartInfo.Arguments = arguments; } if (workingDirectory != null) { if (!Directory.Exists(workingDirectory)) { throw new Exception(String.Format("{0} does not exist", workingDirectory)); } if (Path.IsPathRooted(workingDirectory)) { process.StartInfo.WorkingDirectory = workingDirectory; } else { process.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory() + "\\" + workingDirectory; } } else { process.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory(); } process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; StringBuilder output = new StringBuilder(); StringBuilder error = new StringBuilder(); process.OutputDataReceived += (sender, e) => { if (e.Data == null) { return; } if (!string.IsNullOrWhiteSpace(e.Data)) { //-- console output (optionally as warning) -- if (OutputManager.ContainsWarningKeyword(e.Data)) { // contains warning keyword outputManager.Warning(e.Data); } else { // normal message outputManager.Info(e.Data); } //-- catch Ogre features -- // NOTE: The information is printed line by line. (not a single message) // So catch every line (of following outputs) between the 2 following rulers "----------------" // check: disable logging? if (e.Data.Contains("----------------") && (outputManager.FeatureSummary.Length > 0)) // ignore fist line of "-" symbols { outputManager.IsFeatureLoggingEnabled = false; } // do logging if (outputManager.IsFeatureLoggingEnabled && (e.Data.Contains("----------------") == false)) { outputManager.FeatureSummary += e.Data + " \n"; } // check: enable logging? if (e.Data.Contains("FEATURE SUMMARY")) { outputManager.IsFeatureLoggingEnabled = true; } } output.AppendLine(e.Data); }; process.ErrorDataReceived += (sender, e) => { if (e.Data == null) { return; } if (!string.IsNullOrWhiteSpace(e.Data)) { outputManager.Error(e.Data); } error.AppendLine(e.Data); }; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); CommandResult result = new CommandResult(output.ToString(), error.ToString(), process.ExitCode); process.Dispose(); return(result); }
public Task(InputManager inputManager, OutputManager outputManager) { this.outputManager = outputManager; this.inputManager = inputManager; }
/// <summary> /// Process all input arguments from the command line. /// The first argument is assumed to be the target pathVar. (Optional, because maybe in the future it can also be defined by a config file). /// For all other arguments it will tried to associate the wanted option. /// </summary> private static CommandLineArgs ParseCommandLine(String[] cmdLineArgs, OutputManager outputManager, ref CommandLineArgs parsedArgs) { // The inputList contains all arguments. Successfully parsed arguments will be removed. List <String> inputList = new List <String>(cmdLineArgs); // check if first argument could be a pathVar if ((inputList.Count > 0) && (inputList[0].StartsWith("-") == false)) { String directory = inputList[0]; inputList.RemoveAt(0); directory = Regex.Replace(directory, "\"", ""); // remove quotes parsedArgs.TargetDir = directory; // save } // check for config file option parsedArgs.ConfigFile = ReadValue("-config", inputList); // TODO: Check if file exists // check if user wants to compile with VS 2012 parsedArgs.Vs2012 = ReadBool("-vs2012", inputList); // check if user wants to compile with VS 2013 parsedArgs.Vs2013 = ReadBool("-vs2013", inputList); // check if user wants to compile with x64 parsedArgs.X64 = ReadBool("-x64", inputList); // check for process priority option string priority = ReadValue("-priority", inputList); if (priority != null) { try { parsedArgs.priority = (ProcessPriorityClass)Enum.Parse(typeof(ProcessPriorityClass), priority, true); } catch (ArgumentException) { outputManager.Warning(String.Format( "WARNING: Unknown priority parameter '{0}' \n" + " Useful values: 'Idle', 'BelowNormal', 'AboveNormal' (not case-sensitive) ", priority)); } } // check if user wants to disable boost if (ReadBool("-noboost", inputList)) { Misc.ModifyEnvironmentPath(ref parsedArgs, outputManager, Misc.PathRemove.Boost); Misc.ModifyEnvironmentPath(ref parsedArgs, outputManager, Misc.PathRemove.Test); // TEST } // check if user wants to skip the CMake processing parsedArgs.SkipCMake = ReadBool("-skipcmake", inputList); // check if user doesn't want to update repositories. parsedArgs.NoUpdate = ReadBool("-noupdate", inputList); // check if user wants to disable the catching of unspecific exceptions parsedArgs.DevelopmentFlag = ReadBool("-development", inputList); // check if user wants to enable MogreNewt parsedArgs.MogreNewt = ReadBool("-mogrenewt", inputList); // check if user wants to enable MOIS parsedArgs.Mois = ReadBool("-mois", inputList); // check if user wants to skip the Mogre/Ogre build parsedArgs.OnlyAddons = ReadBool("-onlyaddons", inputList); //------------------>>>>>>> ... more option here ... <<<<<<<<------------------ //--- UNKNOWN ARGUMENTS --- // show a warning for all arguments, which are not processed if (inputList.Count > 0) { outputManager.Warning( "\nWARNING \n" + "Can't assign these arguments: "); // display recent arguments String unknownArguments = ""; foreach (String unknown in inputList) { unknownArguments += unknown + " "; } outputManager.DisplayMessage(unknownArguments + "\n", ConsoleColor.White); outputManager.DisplayMessage( "Perhaps your target path has spaces? \n" + "In this case use quotes. \n", ConsoleColor.Yellow); // ask user if he want to quit outputManager.DisplayMessage( "Do you want to continue? [y/n] \n", ConsoleColor.Cyan); ConsoleKeyInfo answer = Console.ReadKey(true); if (answer.Key.ToString().ToLower() != "y") { // user want to abort outputManager.Warning( "Note: Call MogreBuilder without argument to see the help."); throw new ParseException(); // stop application } } // if return(parsedArgs); }
static void Main(string[] cmdLineArgs) { Int64 startTime = DateTime.Now.Ticks; Console.BufferHeight = 9999; // keep all messages visble Console.Title = "MogreBuilder"; // enlarge console window width Int32 width = 120; // --> 1000 pixels (with default settings of Windows 7) if (Console.WindowWidth < width) { // be shure that it fits to the monitor if (width > Console.LargestWindowWidth) { width = Console.LargestWindowWidth; } Console.BufferWidth = width; Console.WindowWidth = width; } OutputManager outputManager = new OutputManager(); // print information if started from Visual Studio PrintIfVisualStudio(cmdLineArgs, outputManager); // check if arguments available if (cmdLineArgs.Length == 0) { outputManager.Warning("\nYou need some arguments to run MogreBuilder! "); ShowHelp(); } else { // DO WORK Boolean developmentFlag = DevelopmentArgumentCheck(cmdLineArgs); if (developmentFlag == true) { // --> don't catch exceptions (better for debugging inside of Visual Studio) outputManager.DisplayMessage("Development mode enabled: No catching of unexcpected exceptions", ConsoleColor.White); DoWork(cmdLineArgs, outputManager); } else { try { // --> catch exceptions (good for common users) DoWork(cmdLineArgs, outputManager); } catch (ParseException) { outputManager.Error("Application stopped."); } catch (Exception e) { // print error message outputManager.Error(e.Message); Misc.PrintExceptionTrace(outputManager, e.StackTrace); outputManager.Error("\n BUILD PROCESS ABORTED\n\n."); outputManager.Info( "Please report crashes in our MogreBuilder forum topic. \n" + " A screenshoot of the stack trace and error messages would be nice.\n"); } } // else } // else // print duration time PrintDurationTime(startTime, outputManager); // highlight window in taskbar HighlightInTaskbar(startTime); outputManager.CloseLogfile(); #if DEBUG Console.WriteLine("\nPress any key to continue..."); Console.ReadKey(); #endif } // Main()