Exemplo n.º 1
0
        public static RegistryProfileDeviceSettings[] getProfile(string profileName)
        {
            profileName = sanitizeProfileName(profileName);
            RegistryProfileDeviceSettings[] settings = new RegistryProfileDeviceSettings[] { };
            createSoftwareRegistryKeys();
            using (RegistryKey SoftwareNameKey = Registry.CurrentUser.OpenSubKey("Software\\" + SoftwareVendor + "\\" + SoftwareName, false))
            {
                try
                {
                    if (SoftwareNameKey.GetValueKind("Profile" + profileName) != RegistryValueKind.Binary)
                    {
                        throw new RegistryHandlerException("Failed to load the profile \"" + profileName + "\", because it is not a binary entry.");
                    }
                }
                catch (IOException e) { throw new RegistryHandlerException("The profile \"" + profileName + "\" does not exist in the registry.", e); }

                using (MemoryStream memStream = new MemoryStream((byte[])SoftwareNameKey.GetValue("Profile" + profileName, new byte[] { })))
                {
                    if (memStream.Length <= 1)
                    {
                        throw new RegistryHandlerException("Failed to load the profile \"" + profileName + "\", because it is not a valid profile serialization.");
                    }
                    BinaryFormatter formatter = new BinaryFormatter();
                    settings = (RegistryProfileDeviceSettings[])formatter.Deserialize(memStream);
                }
            }
            return(settings);
        }
Exemplo n.º 2
0
        static void SaveCurrentResolution(string[] args)
        {
            string    profileName = "Default";
            bool      silent      = false;
            OptionSet p           = new OptionSet()
            {
                {
                    "p|profile=", "the {PROFILENAME} of the screen resolution. (\"Default\" is the default profile.)",
                    v => profileName = RegistryHandler.sanitizeProfileName(v)
                },
                {
                    "q|quiet", "be quiet",
                    v => silent = v != null
                }
            };
            List <string> extra;

            try
            {
                extra = p.Parse(args);
            }
            catch (OptionException e)
            {
                if (!silent)
                {
                    Console.WriteLine("ERROR: " + e.Message);
                }
                return;
            }

            DisplaySet[] dsa = ScreenDevice.GetAllCurrentResolutions().ToArray();
            RegistryProfileDeviceSettings[] rpds = new RegistryProfileDeviceSettings[dsa.Length];
            int i = 0;

            foreach (DisplaySet ds in dsa)
            {
                rpds[i] = new RegistryProfileDeviceSettings
                {
                    DeviceName = ds.DisplayDevice.DeviceName,
                    Width      = ds.DeviceMode.dmPelsWidth,
                    Height     = ds.DeviceMode.dmPelsHeight,
                    Bits       = ds.DeviceMode.dmBitsPerPel,
                    Frequency  = ds.DeviceMode.dmDisplayFrequency
                };
                if (!silent)
                {
                    Console.WriteLine("Saving Screen resolution: " + rpds[i]);
                }
                i++;
            }
            RegistryHandler.setProfile(profileName, rpds);
            if (!silent)
            {
                Console.WriteLine("Screen resolution has been saved to profile \"" + profileName + "\".");
            }
        }