File save updates

This commit is contained in:
BubbaGumpShrump 2024-12-04 22:41:56 -05:00
parent d74a14948d
commit 10e88866f5
6 changed files with 55 additions and 17 deletions

View file

@ -17,8 +17,10 @@
<None Remove="Assets\NW.png" /> <None Remove="Assets\NW.png" />
<None Remove="Assets\VOX.png" /> <None Remove="Assets\VOX.png" />
<None Remove="Assets\WRITH.jpg" /> <None Remove="Assets\WRITH.jpg" />
<None Remove="config.ini" />
<None Remove="Fonts\Orbitron-Bold.ttf" /> <None Remove="Fonts\Orbitron-Bold.ttf" />
<None Remove="Fonts\Roboto-Regular.ttf" /> <None Remove="Fonts\Roboto-Regular.ttf" />
<None Remove="kill-log.csv" />
<None Remove="KillTrackR_MainScript.ps1" /> <None Remove="KillTrackR_MainScript.ps1" />
</ItemGroup> </ItemGroup>
@ -45,12 +47,14 @@
<Resource Include="Assets\WRITH.jpg"> <Resource Include="Assets\WRITH.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource> </Resource>
<Resource Include="config.ini" />
<Resource Include="Fonts\Orbitron-Bold.ttf"> <Resource Include="Fonts\Orbitron-Bold.ttf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource> </Resource>
<Resource Include="Fonts\Roboto-Regular.ttf"> <Resource Include="Fonts\Roboto-Regular.ttf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource> </Resource>
<Resource Include="kill-log.csv" />
<EmbeddedResource Include="KillTrackR_MainScript.ps1"> <EmbeddedResource Include="KillTrackR_MainScript.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource> </EmbeddedResource>

View file

@ -350,11 +350,20 @@ namespace AutoTrackR2
private void SaveButton_Click(object sender, RoutedEventArgs e) private void SaveButton_Click(object sender, RoutedEventArgs e)
{ {
// Get the directory of the running executable // Get the directory for the user's local application data
string exeDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string appDataDirectory = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"AutoTrackR2"
);
// Combine the executable directory with the config file name // Ensure the directory exists
string configFilePath = Path.Combine(exeDirectory, "config.ini"); 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)) using (StreamWriter writer = new StreamWriter(configFilePath))
{ {

View file

@ -1,7 +1,8 @@
$TrackRver = "2.0" $TrackRver = "2.0"
# Path to the config file # Path to the config file
$scriptFolder = Split-Path -Parent $MyInvocation.MyCommand.Path $appName = "AutoTrackR2"
$scriptFolder = Join-Path -Path (Join-Path -Path $env:LOCALAPPDATA -ChildPath $appName)
$configFile = Join-Path -Path $scriptFolder -ChildPath "config.ini" $configFile = Join-Path -Path $scriptFolder -ChildPath "config.ini"
# Read the config file into a hashtable # Read the config file into a hashtable

View file

@ -188,8 +188,12 @@ namespace AutoTrackR2
public static void LoadConfig() public static void LoadConfig()
{ {
string exeDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); // Define the config file path in a writable location
string configFilePath = Path.Combine(exeDirectory, "config.ini"); string configDirectory = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"AutoTrackR2"
);
string configFilePath = Path.Combine(configDirectory, "config.ini");
if (File.Exists(configFilePath)) if (File.Exists(configFilePath))
{ {
@ -217,19 +221,31 @@ namespace AutoTrackR2
public static void SaveConfig() public static void SaveConfig()
{ {
string exeDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); // Define the config file path in a writable location
string configFilePath = Path.Combine(exeDirectory, "config.ini"); string configDirectory = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"YourAppName"
);
// Ensure the directory exists
if (!Directory.Exists(configDirectory))
{
Directory.CreateDirectory(configDirectory);
}
string configFilePath = Path.Combine(configDirectory, "config.ini");
// Write the configuration to the file
using (StreamWriter writer = new StreamWriter(configFilePath)) using (StreamWriter writer = new StreamWriter(configFilePath))
{ {
writer.WriteLine($"LogFile=\"{LogFile}\""); writer.WriteLine($"LogFile={LogFile}");
writer.WriteLine($"ApiUrl=\"{ApiUrl}\""); writer.WriteLine($"ApiUrl={ApiUrl}");
writer.WriteLine($"ApiKey=\"{ApiKey}\""); writer.WriteLine($"ApiKey={ApiKey}");
writer.WriteLine($"VideoPath=\"{VideoPath}\""); writer.WriteLine($"VideoPath={VideoPath}");
writer.WriteLine($"VisorWipe=\"{VisorWipe}\""); writer.WriteLine($"VisorWipe={VisorWipe}");
writer.WriteLine($"VideoRecord=\"{VideoRecord}\""); writer.WriteLine($"VideoRecord={VideoRecord}");
writer.WriteLine($"OfflineMode=\"{OfflineMode}\""); writer.WriteLine($"OfflineMode={OfflineMode}");
writer.WriteLine($"Theme=\"{Theme}\""); writer.WriteLine($"Theme={Theme}");
} }
} }
} }

8
AutoTrackR2/config.ini Normal file
View file

@ -0,0 +1,8 @@
LogFile=
ApiUrl=
ApiKey=
VideoPath=
VisorWipe=0
VideoRecord=0
OfflineMode=0
Theme=0

0
AutoTrackR2/kill-log.csv Normal file
View file