2
0

Fix Settings not loading on reload

This commit is contained in:
Glax 2024-08-26 13:09:33 +02:00
parent 63b493fa9c
commit 7b91bb699f
3 changed files with 8 additions and 7 deletions

View File

@ -49,6 +49,8 @@ internal sealed class TrangaCli : Command<TrangaCli.Settings>
if(settings.workingDirectory is not null) if(settings.workingDirectory is not null)
TrangaSettings.LoadFromWorkingDirectory(settings.workingDirectory); TrangaSettings.LoadFromWorkingDirectory(settings.workingDirectory);
else
TrangaSettings.CreateOrUpdate();
if(settings.downloadLocation is not null) if(settings.downloadLocation is not null)
TrangaSettings.CreateOrUpdate(downloadDirectory: settings.downloadLocation); TrangaSettings.CreateOrUpdate(downloadDirectory: settings.downloadLocation);

View File

@ -41,6 +41,8 @@ public partial class Tranga : GlobalBase
if (wdp) if (wdp)
TrangaSettings.LoadFromWorkingDirectory(workingDirectoryPath![0]); TrangaSettings.LoadFromWorkingDirectory(workingDirectoryPath![0]);
else
TrangaSettings.CreateOrUpdate();
if(dlp) if(dlp)
TrangaSettings.CreateOrUpdate(downloadDirectory: downloadLocationPath![0]); TrangaSettings.CreateOrUpdate(downloadDirectory: downloadLocationPath![0]);

View File

@ -37,14 +37,9 @@ public static class TrangaSettings
public static void LoadFromWorkingDirectory(string directory) public static void LoadFromWorkingDirectory(string directory)
{ {
TrangaSettings.workingDirectory = directory; TrangaSettings.workingDirectory = directory;
if (!File.Exists(settingsFilePath)) if(File.Exists(settingsFilePath))
{
return;
}
else
{
Deserialize(File.ReadAllText(settingsFilePath)); Deserialize(File.ReadAllText(settingsFilePath));
} else return;
Directory.CreateDirectory(downloadLocation); Directory.CreateDirectory(downloadLocation);
Directory.CreateDirectory(workingDirectory); Directory.CreateDirectory(workingDirectory);
@ -53,6 +48,8 @@ public static class TrangaSettings
public static void CreateOrUpdate(string? downloadDirectory = null, string? pWorkingDirectory = null, int? pApiPortNumber = null, string? pUserAgent = null, bool? pAprilFoolsMode = null) public static void CreateOrUpdate(string? downloadDirectory = null, string? pWorkingDirectory = null, int? pApiPortNumber = null, string? pUserAgent = null, bool? pAprilFoolsMode = null)
{ {
if(pWorkingDirectory is null && File.Exists(settingsFilePath))
LoadFromWorkingDirectory(workingDirectory);
TrangaSettings.downloadLocation = downloadDirectory ?? TrangaSettings.downloadLocation; TrangaSettings.downloadLocation = downloadDirectory ?? TrangaSettings.downloadLocation;
TrangaSettings.workingDirectory = pWorkingDirectory ?? TrangaSettings.workingDirectory; TrangaSettings.workingDirectory = pWorkingDirectory ?? TrangaSettings.workingDirectory;
TrangaSettings.apiPortNumber = pApiPortNumber ?? TrangaSettings.apiPortNumber; TrangaSettings.apiPortNumber = pApiPortNumber ?? TrangaSettings.apiPortNumber;