mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-23 07:40:13 +01:00
Fix settings not being loaded from settingsfile
This commit is contained in:
parent
b4708c5d10
commit
e2adac937a
@ -47,7 +47,28 @@ internal sealed class TrangaCli : Command<TrangaCli.Settings>
|
|||||||
string? logFilePath = settings.fileLoggerPath ?? "";
|
string? logFilePath = settings.fileLoggerPath ?? "";
|
||||||
Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, logFilePath);
|
Logger logger = new(enabledLoggers.ToArray(), Console.Out, Console.OutputEncoding, logFilePath);
|
||||||
|
|
||||||
TrangaSettings trangaSettings = new (settings.downloadLocation, settings.workingDirectory, settings.apiPort);
|
TrangaSettings? trangaSettings = null;
|
||||||
|
|
||||||
|
if (settings.downloadLocation is not null && settings.workingDirectory is not null)
|
||||||
|
{
|
||||||
|
trangaSettings = new TrangaSettings(settings.downloadLocation, settings.workingDirectory);
|
||||||
|
}else if (settings.downloadLocation is not null)
|
||||||
|
{
|
||||||
|
if (trangaSettings is null)
|
||||||
|
trangaSettings = new TrangaSettings(downloadLocation: settings.downloadLocation);
|
||||||
|
else
|
||||||
|
trangaSettings = new TrangaSettings(downloadLocation: settings.downloadLocation, settings.workingDirectory);
|
||||||
|
}else if (settings.workingDirectory is not null)
|
||||||
|
{
|
||||||
|
if (trangaSettings is null)
|
||||||
|
trangaSettings = new TrangaSettings(downloadLocation: settings.workingDirectory);
|
||||||
|
else
|
||||||
|
trangaSettings = new TrangaSettings(settings.downloadLocation, settings.workingDirectory);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
trangaSettings = new TrangaSettings();
|
||||||
|
}
|
||||||
|
|
||||||
Directory.CreateDirectory(trangaSettings.downloadLocation);
|
Directory.CreateDirectory(trangaSettings.downloadLocation);
|
||||||
Directory.CreateDirectory(trangaSettings.workingDirectory);
|
Directory.CreateDirectory(trangaSettings.workingDirectory);
|
||||||
|
@ -36,21 +36,28 @@ public class TrangaSettings
|
|||||||
|
|
||||||
public TrangaSettings(string? downloadLocation = null, string? workingDirectory = null, int? apiPortNumber = null)
|
public TrangaSettings(string? downloadLocation = null, string? workingDirectory = null, int? apiPortNumber = null)
|
||||||
{
|
{
|
||||||
string lockFilePath = $"{settingsFilePath}.lock";
|
string wd = workingDirectory ?? Path.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/usr/share" : Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "tranga-api");
|
||||||
if (File.Exists(settingsFilePath) && !File.Exists(lockFilePath))
|
string sfp = Path.Join(wd, "settings.json");
|
||||||
|
|
||||||
|
string lockFilePath = $"{sfp}.lock";
|
||||||
|
if (File.Exists(sfp) && !File.Exists(lockFilePath))
|
||||||
{//Load from settings file
|
{//Load from settings file
|
||||||
FileStream lockFile = File.Create(lockFilePath,0, FileOptions.DeleteOnClose); //lock settingsfile
|
FileStream lockFile = File.Create(lockFilePath,0, FileOptions.DeleteOnClose); //lock settingsfile
|
||||||
string settingsStr = File.ReadAllText(settingsFilePath);
|
string settingsStr = File.ReadAllText(sfp);
|
||||||
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(settingsStr)!;
|
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(settingsStr)!;
|
||||||
|
this.requestLimits = settings.requestLimits;
|
||||||
|
this.userAgent = settings.userAgent;
|
||||||
this.downloadLocation = downloadLocation ?? settings.downloadLocation;
|
this.downloadLocation = downloadLocation ?? settings.downloadLocation;
|
||||||
this.workingDirectory = workingDirectory ?? settings.workingDirectory;
|
this.workingDirectory = workingDirectory ?? settings.workingDirectory;
|
||||||
this.apiPortNumber = apiPortNumber ?? settings.apiPortNumber;
|
this.apiPortNumber = apiPortNumber ?? settings.apiPortNumber;
|
||||||
lockFile.Close(); //unlock settingsfile
|
lockFile.Close(); //unlock settingsfile
|
||||||
}
|
}
|
||||||
else if(!File.Exists(settingsFilePath))
|
else if(!File.Exists(sfp))
|
||||||
{//No settings file exists
|
{//No settings file exists
|
||||||
if (downloadLocation?.Length < 1 || workingDirectory?.Length < 1)
|
if (downloadLocation?.Length < 1 || workingDirectory?.Length < 1)
|
||||||
throw new ArgumentException("Download-location and working-directory paths can not be empty!");
|
throw new ArgumentException("Download-location and working-directory paths can not be empty!");
|
||||||
|
this.requestLimits = DefaultRequestLimits;
|
||||||
|
this.userAgent = DefaultUserAgent;
|
||||||
this.apiPortNumber = apiPortNumber ?? 6531;
|
this.apiPortNumber = apiPortNumber ?? 6531;
|
||||||
this.downloadLocation = downloadLocation ?? (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(Directory.GetCurrentDirectory(), "Downloads"));
|
this.downloadLocation = downloadLocation ?? (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/Manga" : Path.Join(Directory.GetCurrentDirectory(), "Downloads"));
|
||||||
this.workingDirectory = workingDirectory ?? Path.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/usr/share" : Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "tranga-api");
|
this.workingDirectory = workingDirectory ?? Path.Join(RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "/usr/share" : Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "tranga-api");
|
||||||
@ -58,6 +65,8 @@ public class TrangaSettings
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{//Settingsfile is locked
|
{//Settingsfile is locked
|
||||||
|
this.requestLimits = DefaultRequestLimits;
|
||||||
|
this.userAgent = DefaultUserAgent;
|
||||||
this.apiPortNumber = apiPortNumber!.Value;
|
this.apiPortNumber = apiPortNumber!.Value;
|
||||||
this.downloadLocation = downloadLocation!;
|
this.downloadLocation = downloadLocation!;
|
||||||
this.workingDirectory = workingDirectory!;
|
this.workingDirectory = workingDirectory!;
|
||||||
@ -130,24 +139,12 @@ public class TrangaSettings
|
|||||||
{
|
{
|
||||||
if (File.Exists(settingsFilePath))
|
if (File.Exists(settingsFilePath))
|
||||||
{
|
{
|
||||||
bool inUse = true;
|
while(GlobalBase.IsFileInUse(settingsFilePath))
|
||||||
while (inUse)
|
Thread.Sleep(100);
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using FileStream stream = new(settingsFilePath, FileMode.Open, FileAccess.Read, FileShare.None);
|
|
||||||
stream.Close();
|
|
||||||
inUse = false;
|
|
||||||
}
|
|
||||||
catch (IOException)
|
|
||||||
{
|
|
||||||
Thread.Sleep(100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Directory.CreateDirectory(new FileInfo(settingsFilePath).DirectoryName!);
|
Directory.CreateDirectory(new FileInfo(settingsFilePath).DirectoryName!);
|
||||||
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(this));
|
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(this, Formatting.Indented));
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetFullCoverPath(Manga manga)
|
public string GetFullCoverPath(Manga manga)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user