mirror of
https://github.com/BubbaGumpShrump/AutoTrackR2.git
synced 2025-06-19 04:59:07 +00:00
Refactor config save/load
This commit is contained in:
parent
d6ce48b475
commit
aa787d305c
3 changed files with 23 additions and 33 deletions
|
@ -508,36 +508,19 @@ namespace AutoTrackR2
|
||||||
|
|
||||||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
// Get the directory for the user's local application data
|
ConfigManager.ApiKey = ApiKey.Text;
|
||||||
string appDataDirectory = Path.Combine(
|
ConfigManager.ApiUrl = ApiUrl.Text;
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
ConfigManager.LogFile = LogFilePath.Text;
|
||||||
"AutoTrackR2"
|
ConfigManager.VideoPath = VideoPath.Text;
|
||||||
);
|
ConfigManager.VisorWipe = (int)VisorWipeSlider.Value;
|
||||||
|
ConfigManager.VideoRecord = (int)VideoRecordSlider.Value;
|
||||||
// Ensure the directory exists
|
ConfigManager.OfflineMode = (int)OfflineModeSlider.Value;
|
||||||
if (!Directory.Exists(appDataDirectory))
|
ConfigManager.Theme = (int)ThemeSlider.Value;
|
||||||
{
|
|
||||||
Directory.CreateDirectory(appDataDirectory);
|
// Save the current config values
|
||||||
}
|
ConfigManager.SaveConfig();
|
||||||
|
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the flashing effect
|
// Start the flashing effect
|
||||||
FlashSaveButton();
|
FlashSaveButton();
|
||||||
ConfigManager.LoadConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FlashSaveButton()
|
private void FlashSaveButton()
|
||||||
|
|
|
@ -342,4 +342,12 @@ public partial class HomePage : UserControl
|
||||||
// Apply the adjusted font size
|
// Apply the adjusted font size
|
||||||
textBlock.FontSize = fontSize;
|
textBlock.FontSize = fontSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void VisorWipe()
|
||||||
|
{
|
||||||
|
if (ConfigManager.VisorWipe == 1)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,9 +33,6 @@ namespace AutoTrackR2
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
// Load configuration settings before setting them in any page
|
|
||||||
ConfigManager.LoadConfig();
|
|
||||||
|
|
||||||
homePage = new HomePage(); // Create a single instance of HomePage
|
homePage = new HomePage(); // Create a single instance of HomePage
|
||||||
ContentControl.Content = homePage; // Default to HomePage
|
ContentControl.Content = homePage; // Default to HomePage
|
||||||
|
|
||||||
|
@ -205,7 +202,9 @@ namespace AutoTrackR2
|
||||||
public static int Theme { get; set; }
|
public static int Theme { get; set; }
|
||||||
|
|
||||||
static ConfigManager()
|
static ConfigManager()
|
||||||
{
|
{
|
||||||
|
LoadConfig();
|
||||||
|
|
||||||
// Set default values
|
// Set default values
|
||||||
// AppData\Local\AutoTrackR2\Kill-log.csv
|
// AppData\Local\AutoTrackR2\Kill-log.csv
|
||||||
KillHistoryFile = Path.Combine(
|
KillHistoryFile = Path.Combine(
|
||||||
|
@ -253,7 +252,7 @@ namespace AutoTrackR2
|
||||||
// Define the config file path in a writable location
|
// Define the config file path in a writable location
|
||||||
string configDirectory = Path.Combine(
|
string configDirectory = Path.Combine(
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||||
"YourAppName"
|
"AutoTrackR2"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Ensure the directory exists
|
// Ensure the directory exists
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue