private static void MainMenu() { var menu = new MenuPage("Main Menu"); menu.Add("Manage Service", ManageServiceMenu, () => true); menu.Add("Run in console", () => { Console.Clear(); Console.ResetColor(); var service = new TTService(); service.Initialize(); Console.ReadKey(true); service.Finalize(ComputerStateType.Shutdown); Console.WriteLine("Press any key to return to the menu..."); Console.ReadKey(true); return(false); }, () => Service == null || Service.Status != ServiceControllerStatus.Running); menu.Add("Debug", DebugMenu, () => Service != null && Service.Status != ServiceControllerStatus.Running); menu.Add("Exit", () => true, () => true, '0'); while (true) { Console.Clear(); var selected = menu.Show(); if (selected.Callback()) { return; } } }
public BaseButton(MenuPage page, MenuButton newButton) { Parent = page; Button = newButton; GameObject = Button.gameObject; Parent.Add(GameObject); GameObject.transform.localPosition = Vector3.zero; newButton.AddEvent(InvokeOnClick); newButton.customCancelAction = (s) => InvokeOnCancel(); OnCancel = page.GoBack; }
private static void Main(string[] args) { if (Environment.UserInteractive) { var menu = new MenuPage("Main Menu"); menu.Add("Manage Service", ManageService, () => true); menu.Add("Run in console", () => { Console.Clear(); Console.ResetColor(); var service = new TTService(); service.Initialize(); Console.ReadKey(true); service.Finalize(ComputerStateType.Shutdown); Console.WriteLine("Press any key to return to the menu..."); Console.ReadKey(true); return(false); }, () => Service == null || Service.Status != ServiceControllerStatus.Running); menu.Add("Show hardware info", () => { ShowHardwareInfo(); return(false); }, () => Service != null && Service.Status != ServiceControllerStatus.Running); menu.Add("Exit", () => true, () => true, '0'); while (true) { Console.Clear(); var selected = menu.Show(); if (selected.Callback()) { return; } } } else { ServiceBase.Run(new TTService()); } }
private static bool ManageServiceMenu() { void StopService() { Console.WriteLine("Stopping the service..."); Service?.Stop(); Service?.WaitForStatus(ServiceControllerStatus.Stopped); } void StartService() { Console.WriteLine("Starting the service..."); try { Service?.Start(); Service?.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(30)); } catch (Exception e) { Console.WriteLine("Failed to start the service..."); Console.WriteLine(e); Console.WriteLine("Press any key to return to the menu..."); Console.ReadKey(true); } } var menu = new MenuPage("Main Menu > Manage Service"); menu.Add("Start", () => { StartService(); return(false); }, () => Service != null && Service.Status != ServiceControllerStatus.Running); menu.Add("Stop", () => { StopService(); return(false); }, () => Service?.Status == ServiceControllerStatus.Running); menu.Add("Restart", () => { StopService(); StartService(); return(false); }, () => Service?.Status == ServiceControllerStatus.Running); menu.Add("Uninstall", () => { if (Service?.Status != ServiceControllerStatus.Stopped) { StopService(); } try { ManagedInstallerClass.InstallHelper(new[] { "/u", "/LogFile=", "/LogToConsole=true", Assembly.GetExecutingAssembly().Location }); } catch (Exception e) { Console.WriteLine("Failed to uninstall the service..."); Console.WriteLine(e); } Console.WriteLine("Press any key to return to the menu..."); Console.ReadKey(true); return(false); }, () => Service != null); menu.Add("Install", () => { try { ManagedInstallerClass.InstallHelper(new[] { "/LogFile=", "/LogToConsole=true", Assembly.GetExecutingAssembly().Location }); } catch (Exception e) { Console.WriteLine("Failed to install the service..."); Console.WriteLine(e); } Console.WriteLine("Press any key to return to the menu..."); Console.ReadKey(true); return(false); }, () => Service == null); menu.Add("Back", () => true, () => true, '0'); while (true) { Console.Clear(); var selected = menu.Show(); if (selected.Callback()) { return(false); } } }
private static bool DebugMenu() { if (!LogManager.Configuration.LoggingRules.Any(r => r.IsLoggingEnabledForLevel(LogLevel.Trace))) { LogManager.DisableLogging(); } void WriteHeader(string header) { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(header); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("-------------------------------"); Console.ForegroundColor = ConsoleColor.Gray; } void WriteFooter() { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("-------------------------------"); Console.ForegroundColor = ConsoleColor.White; Console.ResetColor(); } void WriteProperty(int indent, string propertyName, object value = null) { Console.ForegroundColor = ConsoleColor.DarkGray; Console.Write($"» {new string('\t', indent)} "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write($"{propertyName}"); if (value != null) { Console.ForegroundColor = ConsoleColor.Cyan; Console.Write($"{value}"); } Console.WriteLine(); Console.ResetColor(); } void WaitForInput() { Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } void ListInfo() { WriteHeader("Info"); WriteProperty(0, ""); var osName = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", null)?.ToString() ?? string.Empty; var osReleaseId = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ReleaseId", null)?.ToString() ?? string.Empty; var osBuild = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "BuildLabEx", null)?.ToString() ?? string.Empty; var appVersion = FileVersionInfo.GetVersionInfo(Assembly.GetCallingAssembly().Location)?.ProductVersion; WriteProperty(1, "OS: ", $"{osName} {osReleaseId} [{osBuild}]"); WriteProperty(1, "Build: ", appVersion); WriteProperty(0, ""); WriteFooter(); } void ListApplications() { WriteHeader("Applications"); WriteProperty(0, ""); var thermaltakeExecutables = new[] { "TT RGB Plus", "ThermaltakeUpdate", "Thermaltake DPS POWER", "NeonMaker Light Editing Software" }; foreach (var process in Process.GetProcesses()) { if (thermaltakeExecutables.Any(e => string.CompareOrdinal(process.ProcessName, e) == 0)) { WriteProperty(0, $"{Path.GetFileName(process.ProcessName)}.exe ", process.Id); } } WriteProperty(0, ""); WriteFooter(); } void ListHid() { WriteHeader("HID"); WriteProperty(0, ""); foreach (var device in DeviceList.Local.GetHidDevices(vendorID: 0x264a)) { WriteProperty(0, $"[0x{device.VendorID:x}, 0x{device.ProductID:x}]: ", device.DevicePath); } WriteProperty(0, ""); WriteFooter(); } void ListControllers() { WriteHeader("Controllers"); WriteProperty(0, ""); PluginLoader.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins"), typeof(IControllerDefinition)); using (var deviceManager = new DeviceManager()) { foreach (var controller in deviceManager.Controllers) { WriteProperty(0, "Name: ", controller.Name); WriteProperty(1, "VendorId: ", controller.VendorId); WriteProperty(1, "ProductId: ", controller.ProductId); WriteProperty(1, "Version: ", controller.Version); WriteProperty(1, "Ports: "); foreach (var port in controller.Ports) { WriteProperty(2, $"{port.Id}: "); WriteProperty(3, "Data: ", controller.GetPortData(port.Id)); WriteProperty(3, "Identifier: ", port); } WriteProperty(1, "Available effect types: ", string.Join(", ", controller.EffectTypes)); } } WriteProperty(0, ""); WriteFooter(); } void ListSensors(params SensorType[] types) { WriteHeader("Sensors"); WriteProperty(0, ""); string FormatValue(SensorType type, float value) { switch (type) { case SensorType.Voltage: return($"{value:F2} V"); case SensorType.Clock: return($"{value:F0} MHz"); case SensorType.Load: return($"{value:F1} %"); case SensorType.Temperature: return($"{value:F1} °C"); case SensorType.Fan: return($"{value:F0} RPM"); case SensorType.Flow: return($"{value:F0} L/h"); case SensorType.Control: return($"{value:F1} %"); case SensorType.Level: return($"{value:F1} %"); case SensorType.Power: return($"{value:F0} W"); case SensorType.Data: return($"{value:F0} GB"); case SensorType.SmallData: return($"{value:F1} MB"); case SensorType.Factor: return($"{value:F3}"); case SensorType.Frequency: return($"{value:F1} Hz"); case SensorType.Throughput: return($"{value:F1} B/s"); } return($"{value}"); } using (var _libreHardwareMonitorFacade = new LibreHardwareMonitorFacade()) { var availableSensors = _libreHardwareMonitorFacade.Sensors.Where(s => types.Length == 0 || types.Contains(s.SensorType)); foreach (var(hardware, sensors) in availableSensors.GroupBy(s => s.Hardware)) { WriteProperty(0, $"{hardware.Name}:"); hardware.Update(); foreach (var(type, group) in sensors.GroupBy(s => s.SensorType)) { WriteProperty(1, $"{type}:"); foreach (var sensor in group) { WriteProperty(2, $"{ sensor.Name} ({ sensor.Identifier}): ", FormatValue(type, sensor.Value ?? float.NaN)); } } WriteProperty(0, ""); } } WriteFooter(); } void ListPlugins() { WriteHeader("Plugins"); WriteProperty(0, ""); var pluginAssemblies = PluginLoader.SearchAll(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins")); WriteProperty(0, "Detected plugins:"); foreach (var assembly in pluginAssemblies) { WriteProperty(1, Path.GetFileName(assembly.Location)); } WriteProperty(0, ""); WriteFooter(); } var enabled = Service != null && Service.Status != ServiceControllerStatus.Running; var menu = new MenuPage("Main Menu > Debug"); menu.Add("Report", () => { Console.Clear(); ListInfo(); ListApplications(); ListHid(); ListControllers(); ListSensors(SensorType.Temperature); WaitForInput(); return(false); }, () => enabled); menu.Add("Controllers", () => { Console.Clear(); ListHid(); ListControllers(); WaitForInput(); return(false); }, () => enabled); menu.Add("Sensors", () => { Console.Clear(); ListSensors(); WaitForInput(); return(false); }, () => enabled); menu.Add("Plugins", () => { Console.Clear(); ListPlugins(); WaitForInput(); return(false); }, () => enabled); menu.Add("Back", () => { LogManager.EnableLogging(); return(true); }, () => true, '0'); while (true) { Console.Clear(); var selected = menu.Show(); if (selected.Callback()) { return(false); } } }
private static bool DebugMenu() { if (!LogManager.Configuration.LoggingRules.Any(r => r.IsLoggingEnabledForLevel(LogLevel.Trace))) { LogManager.DisableLogging(); } void WriteHeader(string header) { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(header); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("-------------------------------"); Console.ForegroundColor = ConsoleColor.Gray; } void WriteFooter() { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("-------------------------------"); Console.ForegroundColor = ConsoleColor.White; Console.ResetColor(); } void WriteProperty(int indent, string propertyName, object value = null) { Console.ForegroundColor = ConsoleColor.DarkGray; Console.Write($"» {new string('\t', indent)} "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write($"{propertyName}"); if (value != null) { Console.ForegroundColor = ConsoleColor.Cyan; Console.Write($"{value}"); } Console.WriteLine(); Console.ResetColor(); } void WaitForInput() { Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } void ListControllers() { WriteHeader("Controllers"); WriteProperty(0, ""); PluginLoader.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins"), typeof(IControllerDefinition)); using (var deviceManager = new DeviceManager()) { foreach (var controller in deviceManager.Controllers) { WriteProperty(0, "Name: ", controller.Name); WriteProperty(1, "VendorId: ", controller.VendorId); WriteProperty(1, "ProductId: ", controller.ProductId); WriteProperty(1, "Ports: "); foreach (var port in controller.Ports) { var data = controller.GetPortData(port.Id); WriteProperty(2, $"{port.Id}: "); WriteProperty(3, "Data: ", data); WriteProperty(3, "Identifier: ", port); } WriteProperty(1, "Available effect types: ", string.Join(", ", controller.EffectTypes)); } } WriteProperty(0, ""); WriteFooter(); } void ListSensors(params SensorType[] types) { WriteHeader("Sensors"); WriteProperty(0, ""); string FormatValue(SensorType type, float value) { switch (type) { case SensorType.Voltage: return($"{value:F2} V"); case SensorType.Clock: return($"{value:F0} MHz"); case SensorType.Load: return($"{value:F1} %"); case SensorType.Temperature: return($"{value:F1} °C"); case SensorType.Fan: return($"{value:F0} RPM"); case SensorType.Flow: return($"{value:F0} L/h"); case SensorType.Control: return($"{value:F1} %"); case SensorType.Level: return($"{value:F1} %"); case SensorType.Power: return($"{value:F0} W"); case SensorType.Data: return($"{value:F0} GB"); case SensorType.SmallData: return($"{value:F1} MB"); case SensorType.Factor: return($"{value:F3}"); case SensorType.Frequency: return($"{value:F1} Hz"); case SensorType.Throughput: return($"{value:F1} B/s"); } return($"{value}"); } using (var _libreHardwareMonitorFacade = new LibreHardwareMonitorFacade()) { var availableSensors = _libreHardwareMonitorFacade.Sensors.Where(s => types.Length > 0 ? types.Contains(s.SensorType) : true); foreach (var(hardware, sensors) in availableSensors.GroupBy(s => s.Hardware)) { WriteProperty(0, $"{hardware.Name}:"); hardware.Update(); foreach (var(type, group) in sensors.GroupBy(s => s.SensorType)) { WriteProperty(1, $"{type}:"); foreach (var sensor in group) { WriteProperty(2, $"{ sensor.Name} ({ sensor.Identifier}): ", FormatValue(type, sensor.Value ?? float.NaN)); } } WriteProperty(0, ""); } } WriteFooter(); } void ListPlugins() { WriteHeader("Plugins"); WriteProperty(0, ""); var pluginAssemblies = PluginLoader.SearchAll(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins")); WriteProperty(0, "Detected plugins:"); foreach (var assembly in pluginAssemblies) { WriteProperty(1, Path.GetFileName(assembly.Location)); } WriteProperty(0, ""); WriteFooter(); } var enabled = Service != null && Service.Status != ServiceControllerStatus.Running; var menu = new MenuPage("Main Menu > Debug"); menu.Add("Report", () => { Console.Clear(); ListControllers(); ListSensors(SensorType.Temperature); WaitForInput(); return(false); }, () => enabled); menu.Add("Controllers", () => { Console.Clear(); ListControllers(); WaitForInput(); return(false); }, () => enabled); menu.Add("Sensors", () => { Console.Clear(); ListSensors(); WaitForInput(); return(false); }, () => enabled); menu.Add("Plugins", () => { Console.Clear(); ListPlugins(); WaitForInput(); return(false); }, () => enabled); menu.Add("Back", () => { LogManager.EnableLogging(); return(true); }, () => true, '0'); while (true) { Console.Clear(); var selected = menu.Show(); if (selected.Callback()) { return(false); } } }
private IEnumerator <ICoroutineOperation> ShowCoroutine() { MenuPage mainPage = new MenuPage(150); mainPage.Add(new MenuLabel(mainPage, "Level " + _world.Player.Level + " " + _world.Player.Name + ", " + _world.Map.Info.Name)); mainPage.Add(new MenuSpacer(8)); mainPage.Add(new MenuButton(mainPage, "Resume Game", "icons/start_game.png")). RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h) { _closed = true; } }); mainPage.Add(new MenuButton(mainPage, "Options", "icons/settings.png", "", "")). RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h) { _options.SwitchToOptionsPage(); } }); mainPage.Add(new MenuButton(mainPage, "Return To Main Menu", "icons/arrow_left.png")). RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h) { _menu.SwitchPage("confirm"); } }); MenuPage confirmPage = new MenuPage(180); confirmPage.Add(new MenuLabel(confirmPage, "Are you sure you want to quit?")); confirmPage.Add(new MenuLabel(confirmPage, "Unsaved progress will be lost", "", "", 0.8f)); confirmPage.Add(new MenuSpacer(4)); confirmPage.Add(new MenuButton(confirmPage, "Go Back", "icons/arrow_right.png")). RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h) { _menu.SwitchPage("main", true); } }); confirmPage.Add(new MenuButton(confirmPage, "Return To Main Menu", "icons/arrow_left.png")). RegisterEvent(MenuElement.EventType.Clicked, (e, h) => { if (!h) { _world.Game.CurrentState = new MainMenuState(); } }); _menu = new MenuUI(_world, "main", mainPage, true); _options = new MenuOptions(_menu, "main"); _menu.AddPage("confirm", confirmPage); _alpha = new TweenedDouble(_world.Game, 0); _world.Paused = true; _world.UpdateHook += UpdateHook; _world.DrawHook += DrawHook; IEnumerator <ICoroutineOperation> uiEnumerator = _menu.Toggle(); _alpha.TweenTo(1, TweenEaseType.Linear, 0.08f); yield return(Wait.Seconds(_world.Game, 0.18f)); while (!_closed) { yield return(null); } uiEnumerator = _menu.Toggle(); yield return(Wait.Seconds(_world.Game, 0.18f - 0.08f)); _alpha.TweenTo(0, TweenEaseType.Linear, 0.08f); yield return(Wait.Seconds(_world.Game, 0.08f)); _world.UpdateHook -= UpdateHook; _world.DrawHook -= DrawHook; _world.Paused = false; if (_completedEvent != null) { _completedEvent(); } IsShowingCompleted = true; }