diff --git a/Resizor/Immediate Resize.cs b/Resizor/Immediate Resize.cs
index a9a52e0..7848188 100644
--- a/Resizor/Immediate Resize.cs
+++ b/Resizor/Immediate Resize.cs
@@ -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()));
diff --git a/Resizor/Program.cs b/Resizor/Program.cs
index af7e4fb..037e8f3 100644
--- a/Resizor/Program.cs
+++ b/Resizor/Program.cs
@@ -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();
}
diff --git a/Resizor/Properties/Settings.Designer.cs b/Resizor/Properties/Settings.Designer.cs
deleted file mode 100644
index 47791a1..0000000
--- a/Resizor/Properties/Settings.Designer.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 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.
-//
-//------------------------------------------------------------------------------
-
-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;
- }
- }
- }
-}
diff --git a/Resizor/Properties/Settings.settings b/Resizor/Properties/Settings.settings
deleted file mode 100644
index bdb2aed..0000000
--- a/Resizor/Properties/Settings.settings
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
- NumPad4
-
-
- 4, 4
-
-
-
\ No newline at end of file
diff --git a/Resizor/Resizor.csproj b/Resizor/Resizor.csproj
index 7f28f12..1b86977 100644
--- a/Resizor/Resizor.csproj
+++ b/Resizor/Resizor.csproj
@@ -16,7 +16,7 @@
-
+
diff --git a/Resizor/Settings.cs b/Resizor/Settings.cs
new file mode 100644
index 0000000..a188a9a
--- /dev/null
+++ b/Resizor/Settings.cs
@@ -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(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);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Resizor/SettingsForm.cs b/Resizor/SettingsForm.cs
index db12e9e..912e828 100644
--- a/Resizor/SettingsForm.cs
+++ b/Resizor/SettingsForm.cs
@@ -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)