Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion vmPing/Classes/ApplicationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ public enum LatencyMode
public static bool IsMinimizeToTrayEnabled { get; set; } = false;
public static bool IsExitToTrayEnabled { get; set; } = false;

// Window position & size options (NEW - REMEMBER WINDOW POSITION)
public static double WindowLeft { get; set; } = 100;
public static double WindowTop { get; set; } = 100;
public static double WindowWidth { get; set; } = 800;
public static double WindowHeight { get; set; } = 400;
public static string WindowState { get; set; } = "Normal";
public static bool RememberWindowPosition { get; set; } = true;

// Fonts.
public static int FontSize_Probe { get; set; } = 11;
public static int FontSize_Scanner { get; set; } = 16;
Expand Down Expand Up @@ -156,4 +164,4 @@ public static IEnumerable<Visual> GetChildren(this Visual parent, bool recurse =
}
}
}
}
}
84 changes: 84 additions & 0 deletions vmPing/Classes/ApplicationSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using System.IO;
using System.Xml.Linq;
using vmPing.Classes;

namespace vmPing.Classes
{
public class ApplicationSettings
{
private readonly string _settingsPath;
private readonly string _settingsFile = "vmping_settings.xml";

public ApplicationSettings()
{
_settingsPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"vmPing"
);

if (!Directory.Exists(_settingsPath))
{
Directory.CreateDirectory(_settingsPath);
}
}

public void LoadSettings()
{
try
{
string filePath = Path.Combine(_settingsPath, _settingsFile);
if (File.Exists(filePath))
{
XDocument doc = XDocument.Load(filePath);
XElement root = doc.Root;

// Load window position settings
if (double.TryParse(root.Element("WindowLeft")?.Value, out var left))
ApplicationOptions.WindowLeft = left;
if (double.TryParse(root.Element("WindowTop")?.Value, out var top))
ApplicationOptions.WindowTop = top;
if (double.TryParse(root.Element("WindowWidth")?.Value, out var width))
ApplicationOptions.WindowWidth = width;
if (double.TryParse(root.Element("WindowHeight")?.Value, out var height))
ApplicationOptions.WindowHeight = height;

var windowState = root.Element("WindowState")?.Value;
if (!string.IsNullOrEmpty(windowState))
ApplicationOptions.WindowState = windowState;

if (bool.TryParse(root.Element("RememberWindowPosition")?.Value, out var remember))
ApplicationOptions.RememberWindowPosition = remember;
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Error loading settings: {ex.Message}");
}
}

public void SaveSettings()
{
try
{
XDocument doc = new XDocument(
new XElement("Settings",
new XElement("WindowLeft", ApplicationOptions.WindowLeft),
new XElement("WindowTop", ApplicationOptions.WindowTop),
new XElement("WindowWidth", ApplicationOptions.WindowWidth),
new XElement("WindowHeight", ApplicationOptions.WindowHeight),
new XElement("WindowState", ApplicationOptions.WindowState),
new XElement("RememberWindowPosition", ApplicationOptions.RememberWindowPosition)
)
);

string filePath = Path.Combine(_settingsPath, _settingsFile);
doc.Save(filePath);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Error saving settings: {ex.Message}");
}
}
}
}
Loading