Refactor config save/load

This commit is contained in:
Dork Normalize 2025-03-28 17:15:40 -07:00
parent d6ce48b475
commit aa787d305c
3 changed files with 23 additions and 33 deletions

View file

@ -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()

View file

@ -342,4 +342,12 @@ public partial class HomePage : UserControl
// Apply the adjusted font size
textBlock.FontSize = fontSize;
}
private void VisorWipe()
{
if (ConfigManager.VisorWipe == 1)
{
}
}
}

View file

@ -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