public static void Main() { // Initializer logger class. logger = new Logger(filePath); // Read config right off the bat since people like to not have to manually paste their config. ConfigHandler.ReadConfig(); // Creates a RPC client. rpc = new RPC(); // CHeck if the RPC client is. if (rpc != null) { rpc.Initialize(rpcLogPath); } // Set the inline method to call when the application closes. Application.ApplicationExit += (sender, e) => { if (rpc != null) { rpc.Deinitialize(); } }; new Thread(() => ConsoleThread()).Start(); }
/// <summary> /// Check console input /// TODO: Move this into <see cref="ConsoleThread"/> /// </summary> private static void CheckConsoleInput() { // Get input from console output. string input = Console.ReadLine(); // Switch from cases of the input. switch (input) { case "quit": case "exit": case "stop": // Close the application. logger.Log("Bye!"); toStop = false; // Try to close the GUI (even if it's closed already). try { gui.Invoke((MethodInvoker) delegate { gui.exit = true; gui.Close(); }); } catch (Exception ex) { logger.Log("Error: GUI Already Closed. | " + ex.Message); logger.Log(ex.StackTrace); } // Finally close the application. Application.Exit(); break; case "update": // Try to update the RPC. UpdateRPC(); break; case "gui": // Try to launch the GUI (without autoHide, because it's not necessary). try { logger.Log("Launching GUI"); StartGUI(false); } catch (Exception ex) { logger.Log("Error: When attempting to launch GUI. | " + ex.Message); logger.Log(ex.StackTrace); } break; case var loadFileCommand when new Regex(@"^load\s[a-z0-9]+$").IsMatch(loadFileCommand): try { string arguments = loadFileCommand.Substring(5, loadFileCommand.Length - 5); ConfigHandler.ReadConfig(arguments, false); } catch (Exception ex) { logger.Log("Failed to parse arguments and read config from file. | " + ex.Message); logger.Log(ex.StackTrace); } break; case var loadCommand when new Regex(@"^load$").IsMatch(loadCommand): try { ConfigHandler.ReadConfig(); } catch (Exception ex) { logger.Log("Failed to parse arguments and read config from file. | " + ex.Message); logger.Log(ex.StackTrace); } break; case var saveFileCommand when new Regex(@"^save\s[a-z0-9]+$").IsMatch(saveFileCommand): try { string arguments = saveFileCommand.Substring(5, saveFileCommand.Length - 5); ConfigHandler.WriteConfig(arguments, false); } catch (Exception ex) { logger.Log("Failed to parse arguments and write config to file. | " + ex.Message); logger.Log(ex.StackTrace); } break; case var saveCommand when new Regex(@"^save$").IsMatch(saveCommand): try { ConfigHandler.WriteConfig(); } catch (Exception ex) { logger.Log("Failed to parse arguments and write config to file. | " + ex.Message); logger.Log(ex.StackTrace); } break; default: // Output the possible command line arguments if no recognized case is used. logger.Log("Commands are as follows: [ quit/exit/stop | update | gui ]"); break; } }
/// <summary> /// Forces the <see cref="ConfigHandler"/> to load the <see cref="Config"/> from file. /// </summary> /// <param name="sender">The sending object (Typically a <see cref="Button"/>).</param> /// <param name="e">The event arguments.</param> private void LoadConfig_Button_Click(object sender, EventArgs e) => Invoke((MethodInvoker) delegate { ConfigHandler.ReadConfig(); });