static void Main(string[] args) { ArgumentParser pp = new ArgumentParser(args); pp.AddExpanded("-l", "--light"); pp.AddExpanded("-nl", "--no-light"); pp.Parse(); var lcdProvider = new RaspPiGPIOMemLcdTransferProvider(GPIOPins.GPIO_07, GPIOPins.GPIO_08, GPIOPins.GPIO_25, GPIOPins.GPIO_24, GPIOPins.GPIO_23, GPIOPins.GPIO_18); var lcd = new Lcd(lcdProvider); GPIOMem backlit = new GPIOMem(GPIOPins.GPIO_15, GPIODirection.Out); //backlit.Write(false); lcd.Begin(16, 2); lcd.Clear(); lcd.SetCursorPosition(0, 0); if (pp.SwitchExists("--light")) { backlit.Write(true); } if (pp.SwitchExists("--no-light")) { backlit.Write(false); } string text = String.Empty; try { var isKey = System.Console.KeyAvailable; text = Console.ReadLine(); } catch (InvalidOperationException) { // when we're in piped output, InvalidOperationException is thrown for KeyAvaliable // and we're using it here to check... dirty, dirty hack! text = Console.In.ReadToEnd(); } //Console.WriteLine(text); text = text.Replace("\r\n", "\n"); if (text.Length > 32) text = text.Substring(0, 32); if (text.Length > 16) text = text.Insert(16, "\n"); if (text.IndexOf('\n') > -1) { lcd.Write(text.Substring(0, text.IndexOf('\n'))); lcd.SetCursorPosition(0, 1); lcd.Write(text.Substring(text.IndexOf('\n') +1)); } else lcd.Write(text); }
static void Main() { Application.EnableVisualStyles(); try { _pp = new ArgumentParser(Environment.GetCommandLineArgs()); _pp.AddExpanded("/s", "/silent"); _pp.AddExpanded("/?", "--help"); _pp.AddExpanded("/tls", "--tls"); _pp.Parse(); _silentMode = _pp.SwitchExists("/silent"); if (_pp.VersionRequested()) { ShowVersion(); Exit(ExitCode.NoError); } if (_pp.HelpRequested()) ShowHelp(); if (!IsRunningAsAdministrator()) { var selfName = Process.GetCurrentProcess().MainModule.FileName; ProcessStartInfo self = new ProcessStartInfo(selfName); self.Verb = "runas"; self.WindowStyle = ProcessWindowStyle.Hidden; if (_silentMode) self.Arguments = "/silent"; try { Process.Start(self); } catch (Win32Exception) { if (!_silentMode) MessageBox.Show(AppResources.NeedAdmin, AppResources.AppName, MessageBoxButtons.OK, MessageBoxIcon.Error); Exit(ExitCode.NoAdmin); } Exit(ExitCode.NoError); } if ((!_silentMode) && (!IsSystemSupported())) { if (MessageBox.Show(AppResources.SystemNotSupported, AppResources.AppName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) Exit(ExitCode.SystemNotSupported); } if ((_silentMode) || (MessageBox.Show(AppResources.Info, AppResources.AppName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)) { var exc = ExitCode.NoError; try { InstallCaCertificate(); } catch (CommandException e) { ErrorMessage(AppResources.CertFail, e); exc = ExitCode.CertInstallError; } try { if (_pp.SwitchExists("--tls")) InstallNetworkProfile(ProfileType.Tls); else InstallNetworkProfile(ProfileType.Peap); } catch (CommandException e) { ErrorMessage(AppResources.ProfFail, e); exc = exc | ExitCode.ProfileInstallError; } if (exc == ExitCode.NoError) if (!_silentMode) MessageBox.Show(AppResources.Success, AppResources.AppName, MessageBoxButtons.OK, MessageBoxIcon.Information); Exit(exc); } Exit(ExitCode.NoError); } catch (Exception ex) { ErrorMessage(AppResources.UnhandledException, ex); Exit(ExitCode.UnhandledException); } }