2
0

TrangaSettings export after change

This commit is contained in:
glax 2023-06-21 18:04:12 +02:00
parent 0f0902c932
commit ed4bdb5b33
2 changed files with 25 additions and 3 deletions

View File

@ -363,9 +363,7 @@ public class TaskManager
private void ExportDataAndSettings()
{
logger?.WriteLine(this.GetType().ToString(), $"Exporting settings to {settings.settingsFilePath}");
while(IsFileInUse(settings.settingsFilePath))
Thread.Sleep(50);
File.WriteAllText(settings.settingsFilePath, JsonConvert.SerializeObject(settings));
settings.ExportSettings();
logger?.WriteLine(this.GetType().ToString(), $"Exporting tasks to {settings.tasksFilePath}");
while(IsFileInUse(settings.tasksFilePath))

View File

@ -43,6 +43,29 @@ public class TrangaSettings
return settings;
}
public void ExportSettings()
{
if (File.Exists(settingsFilePath))
{
bool inUse = true;
while (inUse)
{
try
{
using FileStream stream = new (settingsFilePath, FileMode.Open, FileAccess.Read, FileShare.None);
stream.Close();
inUse = false;
}
catch (IOException)
{
inUse = true;
Thread.Sleep(50);
}
}
}
File.WriteAllText(settingsFilePath, JsonConvert.SerializeObject(this));
}
public void UpdateSettings(UpdateField field, Logger? logger = null, params string[] values)
{
switch (field)
@ -81,6 +104,7 @@ public class TrangaSettings
newLunaSea.SendNotification("Success!", "LunaSea was added to Tranga!");
break;
}
ExportSettings();
}
public enum UpdateField { DownloadLocation, Komga, Kavita, Gotify, LunaSea}