From aa787d305ce661d35b408bd9b30913ff2f4668e0 Mon Sep 17 00:00:00 2001
From: Dork Normalize <nope>
Date: Fri, 28 Mar 2025 17:15:40 -0700
Subject: [PATCH] Refactor config save/load

---
 AutoTrackR2/ConfigPage.xaml.cs | 39 ++++++++++------------------------
 AutoTrackR2/HomePage.xaml.cs   |  8 +++++++
 AutoTrackR2/MainWindow.xaml.cs |  9 ++++----
 3 files changed, 23 insertions(+), 33 deletions(-)

diff --git a/AutoTrackR2/ConfigPage.xaml.cs b/AutoTrackR2/ConfigPage.xaml.cs
index 5e7f366..7dcfc7a 100644
--- a/AutoTrackR2/ConfigPage.xaml.cs
+++ b/AutoTrackR2/ConfigPage.xaml.cs
@@ -508,36 +508,19 @@ namespace AutoTrackR2
 
         private void SaveButton_Click(object sender, RoutedEventArgs e)
         {
-            // Get the directory for the user's local application data
-            string appDataDirectory = Path.Combine(
-                Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
-                "AutoTrackR2"
-            );
-
-            // Ensure the directory exists
-            if (!Directory.Exists(appDataDirectory))
-            {
-                Directory.CreateDirectory(appDataDirectory);
-            }
-
-            // Combine the app data directory with the config file name
-            string configFilePath = Path.Combine(appDataDirectory, "config.ini");
-
-            using (StreamWriter writer = new StreamWriter(configFilePath))
-            {
-                writer.WriteLine($"LogFile={LogFilePath.Text}");
-                writer.WriteLine($"ApiUrl={ApiUrl.Text}");
-                writer.WriteLine($"ApiKey={ApiKey.Text}");
-                writer.WriteLine($"VideoPath={VideoPath.Text}");
-                writer.WriteLine($"VisorWipe={(int)VisorWipeSlider.Value}");
-                writer.WriteLine($"VideoRecord={(int)VideoRecordSlider.Value}");
-                writer.WriteLine($"OfflineMode={(int)OfflineModeSlider.Value}");
-                writer.WriteLine($"Theme={(int)ThemeSlider.Value}"); // Assumes you are saving the theme slider value (0, 1, or 2)
-            }
-
+            ConfigManager.ApiKey = ApiKey.Text;
+            ConfigManager.ApiUrl = ApiUrl.Text;
+            ConfigManager.LogFile = LogFilePath.Text;
+            ConfigManager.VideoPath = VideoPath.Text;
+            ConfigManager.VisorWipe = (int)VisorWipeSlider.Value;
+            ConfigManager.VideoRecord = (int)VideoRecordSlider.Value;
+            ConfigManager.OfflineMode = (int)OfflineModeSlider.Value;
+            ConfigManager.Theme = (int)ThemeSlider.Value;
+            
+            // Save the current config values
+            ConfigManager.SaveConfig();
             // Start the flashing effect
             FlashSaveButton();
-            ConfigManager.LoadConfig();
         }
 
         private void FlashSaveButton()
diff --git a/AutoTrackR2/HomePage.xaml.cs b/AutoTrackR2/HomePage.xaml.cs
index fe47e59..c4b3371 100644
--- a/AutoTrackR2/HomePage.xaml.cs
+++ b/AutoTrackR2/HomePage.xaml.cs
@@ -342,4 +342,12 @@ public partial class HomePage : UserControl
         // Apply the adjusted font size
         textBlock.FontSize = fontSize;
     }
+
+    private void VisorWipe()
+    {
+        if (ConfigManager.VisorWipe == 1)
+        {
+            
+        }
+    }
 }
diff --git a/AutoTrackR2/MainWindow.xaml.cs b/AutoTrackR2/MainWindow.xaml.cs
index 3d143d0..94b6149 100644
--- a/AutoTrackR2/MainWindow.xaml.cs
+++ b/AutoTrackR2/MainWindow.xaml.cs
@@ -33,9 +33,6 @@ namespace AutoTrackR2
         {
             InitializeComponent();
 
-            // Load configuration settings before setting them in any page
-            ConfigManager.LoadConfig();
-
             homePage = new HomePage(); // Create a single instance of HomePage
             ContentControl.Content = homePage; // Default to HomePage
 
@@ -205,7 +202,9 @@ namespace AutoTrackR2
         public static int Theme { get; set; }
         
         static ConfigManager()
-        {
+        {   
+            LoadConfig();
+            
             // Set default values
             // AppData\Local\AutoTrackR2\Kill-log.csv
             KillHistoryFile = Path.Combine(
@@ -253,7 +252,7 @@ namespace AutoTrackR2
             // Define the config file path in a writable location
             string configDirectory = Path.Combine(
                 Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
-                "YourAppName"
+                "AutoTrackR2"
             );
 
             // Ensure the directory exists