diff --git a/PowerControl/Helpers/ProfileSettings.cs b/PowerControl/Helpers/ProfileSettings.cs index 98b821e..c9ead61 100644 --- a/PowerControl/Helpers/ProfileSettings.cs +++ b/PowerControl/Helpers/ProfileSettings.cs @@ -26,10 +26,10 @@ namespace PowerControl.Helper public String ProfileName { get; } - public ProfileSettings(string profileName) : base("PersistentSettings") + public ProfileSettings(string prefix, string profileName) : base("PersistentSettings") { this.ProfileName = profileName; - this.ConfigFile = Path.Combine(UserProfilesPath, String.Format("PowerControl.Process.{0}.ini", profileName)); + this.ConfigFile = Path.Combine(UserProfilesPath, String.Format("{0}.{1}.ini", prefix, profileName)); this.SettingChanging += delegate { }; this.SettingChanged += delegate { }; diff --git a/PowerControl/Menu/MenuItemWithOptions.cs b/PowerControl/Menu/MenuItemWithOptions.cs index 5a8485a..73ef0f1 100644 --- a/PowerControl/Menu/MenuItemWithOptions.cs +++ b/PowerControl/Menu/MenuItemWithOptions.cs @@ -155,10 +155,50 @@ namespace PowerControl.Menu toolStripItem.DropDownItems.Add(item); } + AddMenuItemsToModifyProfile( + PowerControl.Options.Profiles.Controller?.AutostartProfileSettings, + toolStripItem.DropDownItems + ); + toolStripItem.Visible = Visible && Options.Count > 0; }; } + private void AddMenuItemsToModifyProfile(Helper.ProfileSettings? profileSettings, ToolStripItemCollection dropDownItems) + { + if (profileSettings is null || PersistentKey is null) + return; + + dropDownItems.Add(new ToolStripSeparator()); + + var headingItem = new ToolStripMenuItem(profileSettings.ProfileName + ": "); + dropDownItems.Add(headingItem); + + var persistedValue = profileSettings.GetValue(PersistentKey); + + foreach (var option in Options) + { + var item = new ToolStripMenuItem("Set: " + option); + item.Checked = option == persistedValue; + item.Click += delegate { profileSettings.SetValue(PersistentKey, option); }; + headingItem.DropDownItems.Add(item); + } + + if (persistedValue is not null) + { + headingItem.Text += persistedValue; + headingItem.Checked = true; + + headingItem.DropDownItems.Add(new ToolStripSeparator()); + var unsetItem = headingItem.DropDownItems.Add("Unset"); + unsetItem.Click += delegate { profileSettings.DeleteKey(PersistentKey); }; + } + else + { + headingItem.Text += "Not set"; + } + } + private void SelectIndex(int index) { if (Options.Count == 0) diff --git a/PowerControl/ProfilesController.cs b/PowerControl/ProfilesController.cs index 32efe8a..30e8b2e 100644 --- a/PowerControl/ProfilesController.cs +++ b/PowerControl/ProfilesController.cs @@ -31,14 +31,20 @@ namespace PowerControl public ProfileSettings? GameProfileSettings { get; private set; } public ProfileSettings? SessionProfileSettings { get; private set; } + public ProfileSettings AutostartProfileSettings { get; private set; } public ProfilesController() { PowerControl.Options.Profiles.Controller = this; MenuStack.Root.ValueChanged += Root_OnOptionValueChange; + AutostartProfileSettings = new ProfileSettings("PowerControl", "Autostart"); + timer.Start(); timer.Tick += Timer_Tick; + + ProfileChanged(null); + ApplyProfile(AutostartProfileSettings); } ~ProfilesController() @@ -106,13 +112,13 @@ namespace PowerControl { Log.TraceLine("ProfilesController: New Process: {0}/{1}", processId, processName); - var profileSettings = new ProfileSettings(processName); + var profileSettings = new ProfileSettings("PowerControl.Process", processName); watchedProcesses.Add(processId, profileSettings); // Create memory only SessionProfileSettings if (SessionProfileSettings is null) { - SessionProfileSettings = new ProfileSettings("Session:" + processName) { UseConfigFile = false }; + SessionProfileSettings = new ProfileSettings("PowerControl.Session", "Session." + processName) { UseConfigFile = false }; SaveProfile(SessionProfileSettings); } diff --git a/RELEASE.md b/RELEASE.md index 00c1c1b..4f1d0e3 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -31,6 +31,7 @@ ## 0.6.16 +- PowerControl: Allow to set Autostart Profile Settings - PowerControl: Show Game Profiles menu item - PowerControl: Improve handling of restoring DesktopProfile - All: Support [unofficial APU drivers](https://sourceforge.net/projects/amernimezone/files/Release%20Polaris-Vega-Navi/AMD%20SOC%20Driver%20Variant/) that present themselves as `AMD Radeon 670M`