#33 Preparation:

TrangaSettings now stores Hashset of LibraryManagers
This commit is contained in:
2023-06-03 15:17:08 +02:00
parent 0c580933f9
commit 5d98295c59
8 changed files with 72 additions and 47 deletions

View File

@ -12,26 +12,27 @@ public class TrangaSettings
[JsonIgnore]public string tasksFilePath => Path.Join(workingDirectory, "tasks.json");
[JsonIgnore]public string knownPublicationsPath => Path.Join(workingDirectory, "knownPublications.json");
[JsonIgnore] public string coverImageCache => Path.Join(workingDirectory, "imageCache");
public Komga? komga { get; set; }
public readonly HashSet<LibraryManager> libraryManagers;
public TrangaSettings(string downloadLocation, string workingDirectory, Komga? komga)
public TrangaSettings(string downloadLocation, string workingDirectory, HashSet<LibraryManager> libraryManagers)
{
if (downloadLocation.Length < 1 || workingDirectory.Length < 1)
throw new ArgumentException("Download-location and working-directory paths can not be empty!");
this.workingDirectory = workingDirectory;
this.downloadLocation = downloadLocation;
this.komga = komga;
this.libraryManagers = libraryManagers;
}
public static TrangaSettings LoadSettings(string importFilePath, Logger? logger)
{
if (!File.Exists(importFilePath))
return new TrangaSettings(Path.Join(Directory.GetCurrentDirectory(), "Downloads"), Directory.GetCurrentDirectory(), null);
return new TrangaSettings(Path.Join(Directory.GetCurrentDirectory(), "Downloads"), Directory.GetCurrentDirectory(), new HashSet<LibraryManager>());
string toRead = File.ReadAllText(importFilePath);
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(toRead)!;
if(settings.komga is not null && logger is not null)
settings.komga.AddLogger(logger);
if(logger is not null)
foreach(LibraryManager lm in settings.libraryManagers)
lm.AddLogger(logger);
return settings;
}