Example #1
0
            /// <summary>
            /// Initializes a new instance of the <see cref="SettingsStorage" /> class.
            /// </summary>
            /// <param name="path">The registry path.</param>
            /// <param name="defaults">The default values.</param>
            public SettingsStorage(string path, IDefaults defaults)
            {
                if (path == null)
                {
                    throw new ArgumentNullException(nameof(path));
                }

                if (defaults == null)
                {
                    throw new ArgumentNullException(nameof(defaults));
                }

                try
                {
                    this.registry = Registry.CurrentUser.CreateSubKey(path);
                    this.displayMode = DisplayMode.Select(this[nameof(DisplayMode)]);
                    this.useVerticalSync = this[nameof(UseVerticalSync)].ParseAsBoolean(defaults.UseVerticalSync);
                    this.useFrameRateLimit = this[nameof(UseFrameRateLimit)].ParseAsBoolean(defaults.UseFrameRateLimit);
                }
                catch (Exception error)
                {
                    Trace.TraceError("Failed to open the registry key '{0}'. {1}", path, error);
                }
            }
Example #2
0
        /// <summary>
        /// Sets the display mode.
        /// </summary>
        /// <param name="displayMode">The display mode.</param>
        /// <returns>True if the display mode was changed, otherwise false.</returns>
        public static bool Set(DisplayMode displayMode)
        {
            if (Current != displayMode)
            {
                if (displayMode != null && !displayMode.IsDefault)
                {
                    ChangeDisplaySettingsEx(null, ref displayMode.settings, NULL, CDS.FULLSCREEN, NULL);
                }
                else if (Current != null && !Current.IsDefault)
                {
                    ChangeDisplaySettingsEx(null, NULL, NULL, 0, NULL);
                }

                Current = displayMode;
                return true;
            }

            return false;
        }