示例#1
0
        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);
                }
            }
        }
示例#2
0
        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}");
            }
        }