public static bool ParseArgs(string[] args) { ConsoleColorState state = RC.ColorState; Parser.Reset(); try { Parser.Parse(args); return(true); } catch (Exception ex) { RC.WriteException(0199, ex); return(false); } finally { #region Reset The Color State RC.ColorState = state; #endregion } }
public SerialTerminal() { if ((RC.Sys is NullConsole) == false) { RC.Sys = new NullConsole(); } ConsoleColorState state = RC.ColorState; try { RC.BackgroundColor = ConsoleColorExt.Black; InitializeComponent(); m_Console = consoleControl1.Buffer; } finally { RC.ColorState = state; } }
static void Main() { ConsoleColorState state = RC.ColorState; try { RC.Sys = new NullConsole(); RC.App = RC.Sys; Options.Load(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } finally { Options.Save(); RC.ColorState = state; } }
static void Main(string[] args) { ConsoleColorState state = RC.ColorState; // create the argument parser ArgumentParser parser = new ArgumentParser("SettingsObjectModelCodeGenerator", "Generates settings object model code for the ImuApi project"); StringArgument XmlArg = new StringArgument("XML", "The path of the settings XML file", "The path of the settings XML file"); StringArgument CodeArg = new StringArgument("Code", "The destination code .cs file", "The destination code .cs file"); StringArgument DocumentationArg = new StringArgument("Documentation", "The documentation .XML file", "The documentation .XML file"); // add the arguments to the parser parser.Add("/", "XML", XmlArg); parser.Add("/", "Code", CodeArg); parser.Add("/", "Documentation", DocumentationArg); try { RC.IsBuildMode = true; RC.Verbosity = ConsoleVerbosity.Debug; RC.ApplicationBuildReportPrefix = "SGEN"; RC.Theme = ConsoleColorTheme.Load(ConsoleColorDefaultThemes.Colorful); RC.WriteLine(ConsoleThemeColor.TitleText, "Settings Object Model Code Generator"); // parse arguemnts parser.Parse(args); // did the parser detect a /? arguemnt if (parser.HelpMode == true) { return; } if (XmlArg.Defined == false) { RC.WriteError(001, "No settings XML file supplied."); return; } if (CodeArg.Defined == false) { RC.WriteError(001, "No destination file supplied."); return; } if (DocumentationArg.Defined == false) { RC.WriteError(001, "No documentation file supplied."); return; } string xmlFilePath = XmlArg.Value; if (File.Exists(xmlFilePath) == false) { RC.WriteError(002, "Settings XML file does not exist."); return; } string codeFilePath = CodeArg.Value; try { FileInfo info = new FileInfo(codeFilePath); } catch { RC.WriteError(002, "Settings destination file is not valid."); return; } string documentationFilePath = DocumentationArg.Value; try { FileInfo info = new FileInfo(documentationFilePath); } catch { RC.WriteError(002, "Settings documentation file is not valid."); return; } Generate(xmlFilePath, codeFilePath, documentationFilePath); } catch (Exception ex) { RC.WriteException(04, System.Reflection.Assembly.GetExecutingAssembly().Location, 0, 0, ex); } finally { //RC.PromptForKey("Press any key to exit..", true, false); RC.ColorState = state; } }
public static void Run() { ConsoleColorState state = RC.ColorState; try { if (!Parser.HelpMode) { #region Setup if (VerboseSwitch.Defined) { RC.Verbosity = (ConsoleVerbosity)VerboseSwitch.Value; } else if (QuietSwitch.Defined) { RC.Verbosity = ConsoleVerbosity.Quiet; } if (WarningsAsErrors.Defined) { RC.WarningsAsErrors = WarningsAsErrors.Value; RC.ReportWarnings = WarningsAsErrors.Value; } RC.IsBuildMode = BuildSwitch.Defined; RC.WriteLine(ConsoleVerbosity.Normal, ""); RC.WriteLine(ConsoleVerbosity.Minimal, ConsoleThemeColor.TitleText, Title); //RC.WriteLine(ConsoleVerbosity.Minimal, ""); RC.ForegroundThemeColor = ConsoleThemeColor.Text; #endregion #region Check First Argument if (Helper.IsNullOrEmpty(PathString.Value)) { RC.WriteError(0101, Strings.Error_0101); return; } #endregion #region Create Process CompileProcess compressionProcess = new CompileProcess(); compressionProcess.LogToConsole = true; // ExecutableTypeMode if (ConsoleSwitch.Defined) { compressionProcess.ExecutableTypeLookupMode = ExecutableTypeMode.Explicit; compressionProcess.ExecutableType = ConsoleSwitch.Value ? ExecutableType.Console : ExecutableType.Forms; } else { compressionProcess.ExecutableTypeLookupMode = ExecutableTypeMode.Reflected; compressionProcess.ExecutableType = ExecutableType.Console; } #endregion #region Parse Optional Arguments #region ToolsCsv Argument Switch Arround if (ToolsCsv.Defined) { if (!OutputPath.Defined) { // If the output path argument has not been defined then manually set its value // to the value of the first argument. e.g. 'rug-tool.exe' OutputPath.Defined = true; OutputPath.SetValue(PathString.Value); } else { // if the output path argument has been defined then the fist argument must be an // additional .dll file so move the value to additional file list argument FileList.Value.Add(PathString.Value); } // Zero the value of the fist argument PathString.Reset(); if (compressionProcess.ExecutableTypeLookupMode != ExecutableTypeMode.Explicit) { compressionProcess.ExecutableTypeLookupMode = ExecutableTypeMode.Default; } } #endregion #region Additional Assembly Paths List <string> assemblyPaths = new List <string>(FileList.Value.Count + 1); if (PathString.Defined) { assemblyPaths.Add(PathString.Value); } foreach (object obj in FileList.Value) { assemblyPaths.Add(obj.ToString()); } compressionProcess.Assemblys.AddRange(assemblyPaths); compressionProcess.Compression.Files.AddRange(assemblyPaths); #endregion #region Output Path string output; if (OutputPath.Defined) { output = OutputPath.Value; } else if (PathString.Defined) { output = PathString.Value; } else { RC.WriteError(0104, Strings.Error_0104); return; } #endregion #region Initial Assembly Path string initial; if (PathString.Defined) { initial = PathString.Value; initial = "/" + initial.Substring(initial.LastIndexOf('\\') + 1); } else { initial = null; } compressionProcess.InitialAssemblyPath = initial; #endregion #region Icon Path string icon = ""; if (IconPath.Defined) { icon = IconPath.Value; } compressionProcess.IconFile = icon; #endregion #region AssemblyInfoPath string assemblyinfoFile = null; if (AssemblyInfoPath.Defined) { if (!File.Exists(AssemblyInfoPath.Value)) { RC.WriteError(0102, string.Format(Strings.Error_0102, AssemblyInfoPath.Value)); return; } assemblyinfoFile = AssemblyInfoPath.Value; } else if (!PathString.Defined) { RC.WriteError(0106, Strings.Error_0106); return; } compressionProcess.AssembyInfoSourceFilePath = assemblyinfoFile; #endregion #region Pass Arguments bool passArgs = compressionProcess.ExecutableType == ExecutableType.Console ? true : false; if (PassArgsSwitch.Defined) { passArgs = PassArgsSwitch.Value; } compressionProcess.PassArguments = passArgs; #endregion #region Decorate compressionProcess.Decorate = DecorateSwitch.Defined; #endregion #region Protect Zip compressionProcess.Compression.Protected = ProtectZipSwitch.Defined; compressionProcess.Compression.Password = ProtectZipSwitch.Value; #endregion #region Build Tools foreach (string toolString in ToolsCsv.Value) { int index = toolString.IndexOf(':'); if (index < 1) { RC.WriteError(0105, string.Format(Strings.Error_0105, toolString)); return; } string toolName = toolString.Substring(0, index); string toolPath = toolString.Substring(index + 1); compressionProcess.Tools.Add(toolName, toolPath); compressionProcess.Compression.Files.Add(toolPath); } #endregion #endregion #region Execute Bundle and Compile RC.ForegroundThemeColor = ConsoleThemeColor.Text; compressionProcess.Compression.CreatePackage(); #endregion if (compressionProcess.RunProcess(output)) { #region Print Size Summary RC.WriteLine(ConsoleVerbosity.Verbose, ConsoleThemeColor.TitleText, "\n\n" + Strings.Text_FinalSummary); RC.WriteLine(ConsoleThemeColor.SubText, " " + new string(ConsoleChars.SingleLines[1], 41)); Rug.Cmd.CmdHelper.WriteInfoToConsole(Strings.Text_UncompressedSize, CmdHelper.GetMemStringFromBytes(compressionProcess.InitialSize, true), RC.Theme[ConsoleThemeColor.Text]); if (compressionProcess.IconFileSize > 0) { Rug.Cmd.CmdHelper.WriteInfoToConsole(Strings.Text_IconFileSize, CmdHelper.GetMemStringFromBytes(compressionProcess.IconFileSize, true), RC.Theme[ConsoleThemeColor.Text]); Rug.Cmd.CmdHelper.WriteInfoToConsole(Strings.Text_TotalSize, CmdHelper.GetMemStringFromBytes(compressionProcess.InitialSize + compressionProcess.IconFileSize, true), RC.Theme[ConsoleThemeColor.Text]); } Rug.Cmd.CmdHelper.WriteInfoToConsole(Strings.Text_StartupOverhead, CmdHelper.GetMemStringFromBytes(compressionProcess.OverheadSize, true), RC.Theme[ConsoleThemeColor.Text]); ConsoleThemeColor compColor = ConsoleThemeColor.Text; if (compressionProcess.FinalFileSize < compressionProcess.TotalInitialFileSize / 2) { compColor = ConsoleThemeColor.TextGood; } else if (compressionProcess.FinalFileSize < (compressionProcess.TotalInitialFileSize / 4) * 3) { compColor = ConsoleThemeColor.SubTextGood; } else if ((compressionProcess.FinalFileSize >= ((compressionProcess.TotalInitialFileSize / 4) * 3)) && (compressionProcess.FinalFileSize < compressionProcess.TotalInitialFileSize)) { compColor = ConsoleThemeColor.SubTextNutral; } else if (compressionProcess.FinalFileSize == compressionProcess.TotalInitialFileSize) { compColor = ConsoleThemeColor.Text; } else if (compressionProcess.FinalFileSize > compressionProcess.TotalInitialFileSize) { compColor = ConsoleThemeColor.TextBad; } Rug.Cmd.CmdHelper.WriteInfoToConsole(Strings.Text_FinalSize, CmdHelper.GetMemStringFromBytes(compressionProcess.FinalFileSize, true), RC.Theme[compColor]); RC.WriteLine(ConsoleThemeColor.SubText, " " + new string(ConsoleChars.SingleLines[1], 41)); RC.Write(ConsoleVerbosity.Minimal, ConsoleThemeColor.TitleText, " " + Strings.Text_OverallCompression); #endregion if (compressionProcess.FinalFileSize > 0) { #region Print Final Success Message string valueString = ((100 - (((double)compressionProcess.FinalFileSize / (double)compressionProcess.TotalInitialFileSize) * 100.0)).ToString("N2") + "%"); RC.Write(ConsoleVerbosity.Minimal, ConsoleThemeColor.SubText, " :".PadRight(22 - valueString.Length, '.')); RC.WriteLine(ConsoleVerbosity.Minimal, compColor, valueString); int offset = 6; if (compColor == ConsoleThemeColor.TextBad) { offset += 3; RC.WriteLine(""); RC.WriteWarning(0103, " " + Strings.Error_0103); } if (RC.CanManipulateBuffer && (int)RC.Verbosity >= (int)ConsoleVerbosity.Normal) { Rug.Cmd.CmdHelper.WriteRuglandLogo(48, RC.CursorTop - offset, 3, 2, false, ConsoleShade.Opaque); } #endregion } else { #region The Final Size Is Invlaid So Print A Message RC.Write(ConsoleVerbosity.Minimal, ConsoleThemeColor.SubText, new string('.', 19 - Strings.Text_Invalid.Length)); RC.WriteLine(ConsoleVerbosity.Minimal, ConsoleThemeColor.ErrorColor1, Strings.Text_Invalid); #endregion } } } } catch (Exception ex) { RC.WriteException(0199, ex); } finally { #region Reset The Color State RC.ColorState = state; RC.WriteLine(ConsoleVerbosity.Minimal, ""); #endregion } }
public void Render() { if (this.Maximum >= 1) { string str = null; if (this.TextAlignment != ConsoleProgressBarTextAlignment.None) { string str2 = ""; if (this.TextPadding > 0) { str2 = new string(' ', this.TextPadding); } switch (this.TextFormat) { case ConsoleProgressBarTextFormat.Value: str2 = str2 + this.Value.ToString().PadLeft(this.Maximum.ToString().Length, ' '); break; case ConsoleProgressBarTextFormat.ValueOfMax: { string introduced18 = this.Value.ToString().PadLeft(this.Maximum.ToString().Length, ' '); str2 = str2 + string.Format(Strings.ConsoleProgressBar_ValueOfMax, introduced18, this.Maximum.ToString()); break; } case ConsoleProgressBarTextFormat.Percent: { double num = (100.0 / ((double)this.Maximum)) * this.Value; str2 = str2 + num.ToString("N1").PadLeft(5, ' ') + "%"; break; } case ConsoleProgressBarTextFormat.Decimal: { double num2 = (1.0 / ((double)this.Maximum)) * this.Value; str2 = str2 + num2.ToString("N3").PadLeft(this.Maximum.ToString("N3").Length, ' '); break; } } str = string.Format(this.CustomFormat, str2); } int num3 = (str != null) ? str.Length : 0; int length = this.Width - (2 + num3); double num5 = length; double num6 = (num5 / ((double)this.Maximum)) * this.Value; int num7 = (int)num6; if (num7 > length) { num7 = length; } ConsoleColorState colorState = RugConsole.ColorState; RugConsole.SetCursorPosition(this.Location.X, this.Location.Y); RugConsole.ForegroundColor = this.ForeColor; RugConsole.BackgroundColor = this.BackColor; this.WriteEndCap(true, this.Caps); string str3 = (this.Message.Length > length) ? this.Message.Substring(0, length) : this.Message; if (num7 > 0) { RugConsole.ForegroundColor = this.BarLitForeColor; RugConsole.BackgroundColor = this.BarLitBackColor; if (str3.Length < num7) { RugConsole.Write(str3); RugConsole.Write(new string(ConsoleChars.GetShade(this.BarLitShade), num7 - str3.Length)); } else if (str3.Length == num7) { RugConsole.Write(str3); } else if (str3.Length > num7) { RugConsole.Write(str3.Substring(0, num7)); } if (num7 < length) { RugConsole.ForegroundColor = this.BarDimForeColor; RugConsole.BackgroundColor = this.BarDimBackColor; int count = length - num7; if (str3.Length <= num7) { RugConsole.Write(new string(ConsoleChars.GetShade(this.BarDimShade), count)); } else if (str3.Length > num7) { string str4 = str3.Substring(num7); RugConsole.Write(str4); RugConsole.Write(new string(ConsoleChars.GetShade(this.BarDimShade), count - str4.Length)); } } } else { RugConsole.ForegroundColor = this.BarDimForeColor; RugConsole.BackgroundColor = this.BarDimBackColor; RugConsole.Write(str3); RugConsole.Write(new string(ConsoleChars.GetShade(this.BarDimShade), length - str3.Length)); } RugConsole.ForegroundColor = this.ForeColor; RugConsole.BackgroundColor = this.BackColor; this.WriteEndCap(false, this.Caps); if (this.TextAlignment != ConsoleProgressBarTextAlignment.None) { RugConsole.SetCursorPosition(this.Location.X + (this.Width - num3), this.Location.Y); RugConsole.ForegroundColor = this.ForeColor; RugConsole.BackgroundColor = this.BackColor; RugConsole.Write(str); } RugConsole.ColorState = colorState; } }