static void EnableRestoreAtLogon(string[] args) { string profileName = "Default"; OptionSet p = new OptionSet() { { "p|profile=", "the {PROFILENAME} of the screen resolution. (\"Default\" is the default profile.)", v => profileName = RegistryHandler.sanitizeProfileName(v) } }; List <string> extra; try { extra = p.Parse(args); } catch (OptionException e) { Console.WriteLine("ERROR: " + e.Message); return; } string command = RegistryHandler.RegisterCurrentVersionRun(profileName); Console.WriteLine("Setting command = " + command); Console.WriteLine("Profile \"" + profileName + "\" has been registered."); }
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 + "\"."); } }
static void DeleteRegistryResolutionProfile(string[] args) { string profileName = null; OptionSet p = new OptionSet() { { "p|profile=", "the {PROFILENAME} of the screen resolution. (\"Default\" is the default profile.)", v => profileName = RegistryHandler.sanitizeProfileName(v) } }; List <string> extra; try { extra = p.Parse(args); } catch (OptionException e) { Console.WriteLine("ERROR: " + e.Message); return; } if (profileName == null) { Console.WriteLine("ERROR: No profile name has not been specified."); return; } if (RegistryHandler.hasProfile(profileName)) { Console.WriteLine("Deleting the profile " + profileName); RegistryHandler.deleteProfile(profileName); } else { Console.WriteLine("The profile " + profileName + " does not exist."); } }
static void RestoreCurrentResolution(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; } foreach (RegistryProfileDeviceSettings rpds in RegistryHandler.getProfile(profileName)) { try { if (!silent) { Console.WriteLine("Restoring Screen resolution: " + rpds); } DISPLAY_DEVICE d = ScreenDevice.GetDesktopDeviceByName(rpds.DeviceName); if (rpds.Frequency > 0 && rpds.Bits > 0) { try { ScreenDevice.ChangeResolution(ref d, rpds.Width, rpds.Height, rpds.Bits, rpds.Frequency); } catch (User32Exception) { rpds.Frequency = 0; if (!silent) { Console.WriteLine("Failed to change resolution, restoring without frequency: " + rpds); } ScreenDevice.ChangeResolution(ref d, rpds.Width, rpds.Height, rpds.Bits); } } else if (rpds.Bits > 0) { ScreenDevice.ChangeResolution(ref d, rpds.Width, rpds.Height, rpds.Bits); } else { ScreenDevice.ChangeResolution(ref d, rpds.Width, rpds.Height); } } catch (Exception e) { if (!silent) { Console.WriteLine("ERROR: " + e.Message); } } } if (!silent) { Console.WriteLine("Screen resolution has been restored from profile \"" + profileName + "\"."); } }