mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-23 15:50:13 +01:00
TrangaSettings corrected logic for loading settingsfile, and overwriting settings
This commit is contained in:
parent
a9417dbba6
commit
21d53dabec
@ -20,24 +20,34 @@ public class TrangaSettings
|
|||||||
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
|
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
|
||||||
public ushort? version { get; set; }
|
public ushort? version { get; set; }
|
||||||
|
|
||||||
public TrangaSettings(string? downloadLocation = null, string? workingDirectory = null, int apiPortNumber = 6531)
|
public TrangaSettings(string? downloadLocation = null, string? workingDirectory = null, int? apiPortNumber = null)
|
||||||
{
|
{
|
||||||
this.apiPortNumber = apiPortNumber;
|
string lockFilePath = $"{settingsFilePath}.lock";
|
||||||
downloadLocation ??= Path.Join(Directory.GetCurrentDirectory(), "Downloads");
|
if (File.Exists(settingsFilePath) && !File.Exists(lockFilePath))
|
||||||
workingDirectory ??= Directory.GetCurrentDirectory();
|
{//Load from settings file
|
||||||
if (downloadLocation.Length < 1 || workingDirectory.Length < 1)
|
FileStream lockFile = File.Create(lockFilePath,0, FileOptions.DeleteOnClose);
|
||||||
throw new ArgumentException("Download-location and working-directory paths can not be empty!");
|
string settingsStr = File.ReadAllText(settingsFilePath);
|
||||||
this.workingDirectory = workingDirectory;
|
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(settingsStr)!;
|
||||||
this.downloadLocation = downloadLocation;
|
this.downloadLocation = downloadLocation ?? settings.downloadLocation;
|
||||||
|
this.workingDirectory = workingDirectory ?? settings.workingDirectory;
|
||||||
if (File.Exists(settingsFilePath))
|
this.apiPortNumber = apiPortNumber ?? settings.apiPortNumber;
|
||||||
{
|
lockFile.Close();
|
||||||
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(File.ReadAllText(settingsFilePath))!;
|
|
||||||
this.downloadLocation = settings.downloadLocation;
|
|
||||||
this.workingDirectory = settings.workingDirectory;
|
|
||||||
}
|
}
|
||||||
|
else if(!File.Exists(settingsFilePath))
|
||||||
UpdateDownloadLocation(this.downloadLocation, false);
|
{//No settings file exists
|
||||||
|
if (downloadLocation?.Length < 1 || workingDirectory?.Length < 1)
|
||||||
|
throw new ArgumentException("Download-location and working-directory paths can not be empty!");
|
||||||
|
this.apiPortNumber = apiPortNumber ?? 6531;
|
||||||
|
this.downloadLocation = downloadLocation ?? Path.Join(Directory.GetCurrentDirectory(), "Downloads");
|
||||||
|
this.workingDirectory = workingDirectory ?? Directory.GetCurrentDirectory();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{//Settingsfile is locked
|
||||||
|
this.apiPortNumber = apiPortNumber!.Value;
|
||||||
|
this.downloadLocation = downloadLocation!;
|
||||||
|
this.workingDirectory = workingDirectory!;
|
||||||
|
}
|
||||||
|
UpdateDownloadLocation(this.downloadLocation!, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<LibraryConnector> LoadLibraryConnectors()
|
public HashSet<LibraryConnector> LoadLibraryConnectors()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user