Example #1
0
        protected override void ProcessRecord()
        {
            DisplayData data = Display.GetCurrentDisplaySettings();

            data.Width             = this.Width;
            data.Height            = this.Height;
            data.ColorDepth        = this.ColorDepth < 0 ? data.ColorDepth : this.ColorDepth;
            data.ScreenRefreshRate = this.Frequency < 0 ? data.ScreenRefreshRate : this.Frequency;

            // ensure the new settings exist, unless forcing the display
            if (!_force)
            {
                IList <DisplayData> list = Display.GetDisplaySettings();
                data = Display.FindData(list, data);
                if (data == null)
                {
                    throw new NotSupportedException("No matching display setting found.");
                }
            }

            // check the -whatif parameter
            string msg = "Display settings " + data.GetDisplayText();

            if (!ShouldProcess(msg))
            {
                return;
            }

            // check the users intention
            if (!_noPrompt)
            {
                msg = "Set display settings to " + data.GetDisplayText() + "?";
                if (!ShouldContinue(msg, "Warning!"))
                {
                    return;
                }
            }

            // and finally go
            string err;

            if (Display.ChangeSettings(data, out err) != 0)
            {
                throw new NotSupportedException("Error setting values: " + err);
            }
            if (err != null)
            {
                WriteWarning("Error setting values: " + err);
            }
            else
            {
                msg = "Display settings set to " + data.GetDisplayText();
                WriteVerbose(msg);
            }
        }