Move settings to an XML file
This commit is contained in:
parent
7edea95b2a
commit
c87a15ee5c
|
@ -5,7 +5,6 @@ using System.Linq;
|
|||
using System.Windows.Forms;
|
||||
using CC_Functions.W32;
|
||||
using CC_Functions.W32.Hooks;
|
||||
using Resizor.Properties;
|
||||
|
||||
namespace Resizor
|
||||
{
|
||||
|
@ -52,7 +51,7 @@ namespace Resizor
|
|||
g.CompositingMode = CompositingMode.SourceCopy;
|
||||
g.CompositingQuality = CompositingQuality.HighSpeed;
|
||||
g.PixelOffsetMode = PixelOffsetMode.None;
|
||||
PointF divisor = Settings.Default.ResizeDividor;
|
||||
PointF divisor = Settings.ResizeDividor;
|
||||
Rectangle rect = _down ? FRect() : CRect();
|
||||
g.FillRectangle(new SolidBrush(Color.LightBlue), rect);
|
||||
Pen gridPen = new Pen(Color.Black, 2);
|
||||
|
@ -63,8 +62,8 @@ namespace Resizor
|
|||
g.DrawRectangle(new Pen(Color.Red, 2), _window.Position);
|
||||
}
|
||||
|
||||
private PointF GetDiv() => new PointF(_screen.Width / (float) Settings.Default.ResizeDividor.X,
|
||||
_screen.Height / (float) Settings.Default.ResizeDividor.Y);
|
||||
private PointF GetDiv() => new PointF(_screen.Width / (float) Settings.ResizeDividor.X,
|
||||
_screen.Height / (float) Settings.ResizeDividor.Y);
|
||||
|
||||
private Rectangle CRect() => P2R(F2S(MousePosition, GetDiv()), C2S(MousePosition, GetDiv()));
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ namespace Resizor
|
|||
|
||||
private static void KeyDown(KeyboardHookEventArgs e)
|
||||
{
|
||||
if (e.Key != Settings.Default.ImmediateResizeKey || (_rez != null && !_rez.IsDisposed)) return;
|
||||
if (e.Key != Settings.ImmediateResizeKey || (_rez != null && !_rez.IsDisposed)) return;
|
||||
_rez = new ImmResize();
|
||||
_rez.Show();
|
||||
}
|
||||
|
|
|
@ -1,50 +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 Resizor.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.2.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("NumPad4")]
|
||||
public global::System.Windows.Forms.Keys ImmediateResizeKey {
|
||||
get {
|
||||
return ((global::System.Windows.Forms.Keys)(this["ImmediateResizeKey"]));
|
||||
}
|
||||
set {
|
||||
this["ImmediateResizeKey"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("4, 4")]
|
||||
public global::System.Drawing.Point ResizeDividor {
|
||||
get {
|
||||
return ((global::System.Drawing.Point)(this["ResizeDividor"]));
|
||||
}
|
||||
set {
|
||||
this["ResizeDividor"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Resizor.Properties" GeneratedClassName="Settings">
|
||||
<Profiles />
|
||||
<Settings>
|
||||
<Setting Name="ImmediateResizeKey" Type="System.Windows.Forms.Keys" Scope="User">
|
||||
<Value Profile="(Default)">NumPad4</Value>
|
||||
</Setting>
|
||||
<Setting Name="ResizeDividor" Type="System.Drawing.Point" Scope="User">
|
||||
<Value Profile="(Default)">4, 4</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
|
@ -16,7 +16,7 @@
|
|||
<Content Include="Resizor.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CC-Functions.W32" Version="1.1.7384.27745" />
|
||||
<PackageReference Include="CC-Functions.W32" Version="1.1.7388.28729" />
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Resizor
|
||||
{
|
||||
internal static class Settings
|
||||
{
|
||||
private static bool loaded;
|
||||
|
||||
private static readonly string dir = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),
|
||||
"Settings.xml");
|
||||
|
||||
private static Keys immediateResizeKey;
|
||||
private static Point resizeDividor;
|
||||
|
||||
public static Keys ImmediateResizeKey
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!loaded)
|
||||
Load();
|
||||
return immediateResizeKey;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!loaded)
|
||||
Load();
|
||||
immediateResizeKey = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Point ResizeDividor
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!loaded)
|
||||
Load();
|
||||
return resizeDividor;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!loaded)
|
||||
Load();
|
||||
resizeDividor = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Save() =>
|
||||
new XElement("settings",
|
||||
new XElement("ImmediateResizeKey", ImmediateResizeKey),
|
||||
new XElement("ResizeDividorX", ResizeDividor.X),
|
||||
new XElement("ResizeDividorY", ResizeDividor.Y))
|
||||
.Save(dir);
|
||||
|
||||
private static void Load()
|
||||
{
|
||||
if (!File.Exists(dir))
|
||||
Reset();
|
||||
else
|
||||
try
|
||||
{
|
||||
XElement settings = XDocument.Load(dir).Element("settings");
|
||||
immediateResizeKey = Enum.Parse<Keys>(settings.Element("ImmediateResizeKey").Value);
|
||||
resizeDividor = new Point(
|
||||
int.Parse(settings.Element("ResizeDividorX").Value),
|
||||
int.Parse(settings.Element("ResizeDividorY").Value));
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Something went wrong while loading. Resetting to defaults", "Resizor Settings");
|
||||
Reset();
|
||||
}
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
private static void Reset()
|
||||
{
|
||||
immediateResizeKey = Keys.NumPad4;
|
||||
resizeDividor = new Point(4, 4);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ using System.IO;
|
|||
using System.Windows.Forms;
|
||||
using CC_Functions.W32.Hooks;
|
||||
using Microsoft.Win32;
|
||||
using Resizor.Properties;
|
||||
|
||||
namespace Resizor
|
||||
{
|
||||
|
@ -17,10 +16,10 @@ namespace Resizor
|
|||
{
|
||||
InitializeComponent();
|
||||
Program.Kh = new KeyboardHook();
|
||||
keySelectButton.Text = Settings.Default.ImmediateResizeKey.ToString();
|
||||
keySelectButton.Text = Settings.ImmediateResizeKey.ToString();
|
||||
keySelectButton.Tag = false;
|
||||
rowsSelect.Value = Settings.Default.ResizeDividor.Y;
|
||||
columnsSelect.Value = Settings.Default.ResizeDividor.X;
|
||||
rowsSelect.Value = Settings.ResizeDividor.Y;
|
||||
columnsSelect.Value = Settings.ResizeDividor.X;
|
||||
_rkApp = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
|
||||
startupBox.Checked = _rkApp.GetValue(AppName) != null;
|
||||
}
|
||||
|
@ -32,7 +31,7 @@ namespace Resizor
|
|||
Program.Kh.OnKeyPress -= Hook_OnKeyPress;
|
||||
keySelectButton.BackColor = SystemColors.Control;
|
||||
keySelectButton.Tag = false;
|
||||
keySelectButton.Text = Settings.Default.ImmediateResizeKey.ToString();
|
||||
keySelectButton.Text = Settings.ImmediateResizeKey.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -49,27 +48,27 @@ namespace Resizor
|
|||
keySelectButton.BackColor = SystemColors.Control;
|
||||
if (e.Key != Keys.Escape)
|
||||
{
|
||||
Settings.Default.ImmediateResizeKey = e.Key;
|
||||
Settings.Default.Save();
|
||||
Settings.ImmediateResizeKey = e.Key;
|
||||
Settings.Save();
|
||||
}
|
||||
keySelectButton.Text = Settings.Default.ImmediateResizeKey.ToString();
|
||||
keySelectButton.Text = Settings.ImmediateResizeKey.ToString();
|
||||
keySelectButton.Tag = false;
|
||||
}
|
||||
|
||||
private void RowsSelect_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
Point tmp = Settings.Default.ResizeDividor;
|
||||
Point tmp = Settings.ResizeDividor;
|
||||
tmp.Y = (int) rowsSelect.Value;
|
||||
Settings.Default.ResizeDividor = tmp;
|
||||
Settings.Default.Save();
|
||||
Settings.ResizeDividor = tmp;
|
||||
Settings.Save();
|
||||
}
|
||||
|
||||
private void ColumnsSelect_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
Point tmp = Settings.Default.ResizeDividor;
|
||||
Point tmp = Settings.ResizeDividor;
|
||||
tmp.X = (int) columnsSelect.Value;
|
||||
Settings.Default.ResizeDividor = tmp;
|
||||
Settings.Default.Save();
|
||||
Settings.ResizeDividor = tmp;
|
||||
Settings.Save();
|
||||
}
|
||||
|
||||
private void StartupBox_CheckedChanged(object sender, EventArgs e)
|
||||
|
|
Reference in New Issue