Store PerformanceOverlay settings in .ini

This commit is contained in:
Kamil Trzciński 2022-12-08 10:35:53 +01:00
parent 36d83032c7
commit 1ffc9255e6
6 changed files with 42 additions and 180 deletions

View file

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="PerformanceOverlay.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="PerformanceOverlay.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<PerformanceOverlay.Settings>
<setting name="ShowOSD" serializeAs="String">
<value>True</value>
</setting>
<setting name="OSDMode" serializeAs="String">
<value>FPS</value>
</setting>
</PerformanceOverlay.Settings>
</userSettings>
<applicationSettings>
<PerformanceOverlay.Settings>
<setting name="ShowOSDShortcut" serializeAs="String">
<value>Shift+F11</value>
</setting>
<setting name="CycleOSDShortcut" serializeAs="String">
<value>Alt+Shift+F11</value>
</setting>
<setting name="EnableFullOnPowerControl" serializeAs="String">
<value>False</value>
</setting>
</PerformanceOverlay.Settings>
</applicationSettings>
</configuration>

View file

@ -42,7 +42,7 @@ namespace PerformanceOverlay
modeItem.Tag = mode;
modeItem.Click += delegate
{
Settings.Default.OSDModeParsed = mode;
Settings.Default.OSDMode = mode;
updateContextItems(contextMenu);
};
contextMenu.Items.Add(modeItem);
@ -95,7 +95,6 @@ namespace PerformanceOverlay
GlobalHotKey.RegisterHotKey(Settings.Default.ShowOSDShortcut, () =>
{
Settings.Default.ShowOSD = !Settings.Default.ShowOSD;
Settings.Default.Save();
updateContextItems(contextMenu);
});
@ -107,10 +106,9 @@ namespace PerformanceOverlay
{
var values = Enum.GetValues<OverlayMode>().ToList();
int index = values.IndexOf(Settings.Default.OSDModeParsed);
Settings.Default.OSDModeParsed = values[(index + 1) % values.Count];
int index = values.IndexOf(Settings.Default.OSDMode);
Settings.Default.OSDMode = values[(index + 1) % values.Count];
Settings.Default.ShowOSD = true;
Settings.Default.Save();
updateContextItems(contextMenu);
});
@ -132,7 +130,7 @@ namespace PerformanceOverlay
foreach (ToolStripItem item in contextMenu.Items)
{
if (item.Tag is OverlayMode)
((ToolStripMenuItem)item).Checked = ((OverlayMode)item.Tag == Settings.Default.OSDModeParsed);
((ToolStripMenuItem)item).Checked = ((OverlayMode)item.Tag == Settings.Default.OSDMode);
}
showItem.Checked = Settings.Default.ShowOSD;
@ -146,7 +144,6 @@ namespace PerformanceOverlay
private void ShowItem_Click(object? sender, EventArgs e)
{
Settings.Default.ShowOSD = !Settings.Default.ShowOSD;
Settings.Default.Save();
updateContextItems(contextMenu);
}
@ -156,16 +153,14 @@ namespace PerformanceOverlay
{
if (Enum.IsDefined<OverlayMode>(value.Desired))
{
Settings.Default.OSDModeParsed = (OverlayMode)value.Desired;
Settings.Default.OSDMode = (OverlayMode)value.Desired;
Settings.Default.ShowOSD = true;
Settings.Default.Save();
updateContextItems(contextMenu);
}
if (Enum.IsDefined<OverlayEnabled>(value.DesiredEnabled))
{
Settings.Default.ShowOSD = (OverlayEnabled)value.DesiredEnabled == OverlayEnabled.Yes;
Settings.Default.Save();
updateContextItems(contextMenu);
}
@ -178,7 +173,7 @@ namespace PerformanceOverlay
sharedData.SetValue(new OverlayModeSetting()
{
Current = Settings.Default.OSDModeParsed,
Current = Settings.Default.OSDMode,
CurrentEnabled = Settings.Default.ShowOSD ? OverlayEnabled.Yes : OverlayEnabled.No,
KernelDriversLoaded = Instance.UseKernelDrivers ? KernelDriversLoaded.Yes : KernelDriversLoaded.No
});
@ -212,7 +207,7 @@ namespace PerformanceOverlay
sensors.Update();
var osdMode = Settings.Default.OSDModeParsed;
var osdMode = Settings.Default.OSDMode;
// If Power Control is visible use temporarily full OSD
if (Settings.Default.EnableFullOnPowerControl)

View file

@ -44,11 +44,6 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Update="Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
@ -58,11 +53,4 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Update="Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project>

View file

@ -1,77 +0,0 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace PerformanceOverlay {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.3.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool ShowOSD {
get {
return ((bool)(this["ShowOSD"]));
}
set {
this["ShowOSD"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("FPS")]
public string OSDMode {
get {
return ((string)(this["OSDMode"]));
}
set {
this["OSDMode"] = value;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("Shift+F11")]
public string ShowOSDShortcut {
get {
return ((string)(this["ShowOSDShortcut"]));
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("Alt+Shift+F11")]
public string CycleOSDShortcut {
get {
return ((string)(this["CycleOSDShortcut"]));
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool EnableFullOnPowerControl {
get {
return ((bool)(this["EnableFullOnPowerControl"]));
}
}
}
}

View file

@ -1,33 +1,44 @@
using CommonHelpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static PerformanceOverlay.Overlays;
namespace PerformanceOverlay
{
internal partial class Settings
internal sealed class Settings : BaseSettings
{
public OverlayMode OSDModeParsed
public static readonly Settings Default = new Settings();
public Settings() : base("Settings")
{
get
{
try
{
return (OverlayMode)Enum.Parse<OverlayMode>(OSDMode);
}
catch (ArgumentException)
{
return OverlayMode.FPS;
}
}
set
{
OSDMode = value.ToString();
Save();
}
TouchSettings = true;
}
public OverlayMode OSDMode
{
get { return Get<OverlayMode>("OSDMode", OverlayMode.FPS); }
set { Set("OSDMode", value); }
}
public string ShowOSDShortcut
{
get { return Get<string>("ShowOSDShortcut", "Shift+F11"); }
set { Set("ShowOSDShortcut", value); }
}
public string CycleOSDShortcut
{
get { return Get<string>("CycleOSDShortcut", "Alt+Shift+F11"); }
set { Set("CycleOSDShortcut", value); }
}
public bool ShowOSD
{
get { return Get<bool>("ShowOSD", true); }
set { Set("ShowOSD", value); }
}
public bool EnableFullOnPowerControl
{
get { return Get<bool>("EnableFullOnPowerControl", false); }
set { Set("EnableFullOnPowerControl", value); }
}
}
}

View file

@ -1,21 +0,0 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="PerformanceOverlay" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="ShowOSD" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="OSDMode" Type="System.String" Scope="User">
<Value Profile="(Default)">FPS</Value>
</Setting>
<Setting Name="ShowOSDShortcut" Type="System.String" Scope="Application">
<Value Profile="(Default)">Shift+F11</Value>
</Setting>
<Setting Name="CycleOSDShortcut" Type="System.String" Scope="Application">
<Value Profile="(Default)">Alt+Shift+F11</Value>
</Setting>
<Setting Name="EnableFullOnPowerControl" Type="System.Boolean" Scope="Application">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>