public override void Run(SwitchOptions Options) { string id = Options.ID.ToLower(); string name = Options.Name.ToLower(); Func <VideoCard, bool> predicate = string.IsNullOrEmpty(id) ? new Func <VideoCard, bool>(x => x.Name.ToLower().Contains(name)) : x => x.ID.ToLower().Contains(id) || id.Contains(x.ID.ToLower()); VideoCard card = VideoCard.EnumerateVideoCards().FirstOrDefault(predicate); if (card is null) { if (!string.IsNullOrEmpty(Options.ID)) { try { SetupAPI.ChangeDeviceState(VideoCard.VideoAdaptersClass, Options.ID, !Options.Disable); return; } catch { } } PrintException("The specified video card was not found"); } else { try { if (Options.Disable) { card.Disable(); } else { card.Enable(); } } catch (Exception e) { PrintException(e); } } }
public override void Run(CrutchRunOptions Options) { if (File.Exists(Options.Path)) { string id = Options.ID.ToLower(); string name = Options.Name.ToLower(); Func <VideoCard, bool> predicate = string.IsNullOrEmpty(id) ? new Func <VideoCard, bool>(x => x.Name.ToLower().Contains(name)) : x => x.ID.ToLower().Contains(id) || id.Contains(x.ID.ToLower()); VideoCard card = VideoCard.EnumerateVideoCards().FirstOrDefault(predicate); if (card is null) { PrintException("The specified video card was not found"); } else { ProcessStartInfo info = new ProcessStartInfo { FileName = Options.Path, WorkingDirectory = Options.WorkingDirectory }; try { card.Disable(); Thread.Sleep(100); Process.Start(info); Thread.Sleep(Options.Wait); card.Enable(); } catch (Exception e) { PrintException(e); } } } else { PrintException($"File doesn't exist: {Options.Path}"); } }
public override void Run(CardOptions Options) { string id = Options.ID.ToLower(); string name = Options.Name.ToLower(); Func <VideoCard, bool> predicate = !string.IsNullOrEmpty(name) ? x => x.Name.ToLower().Contains(name) : !string.IsNullOrEmpty(id) ? x => x.ID.ToLower().Contains(id) || id.Contains(x.ID.ToLower()) : new Func <VideoCard, bool>(x => true); Console.WriteLine(); foreach (VideoCard card in VideoCard.EnumerateVideoCards().Where(predicate)) { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("{0}:", card.Name); Console.ResetColor(); Console.WriteLine("ID: {0}", card.ID); Console.WriteLine("State: {0}", card.StateFlags); Console.WriteLine("Devices: {0}", string.Join(", ", card.Devices.Select(x => $"\"{x}\""))); Console.WriteLine("Keys: {0}", string.Join(", ", card.RegistryKeys.Select(x => $"\"{x}\""))); Console.WriteLine(); } }