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() private void ExportDataAndSettings()
{ {
logger?.WriteLine(this.GetType().ToString(), $"Exporting settings to {settings.settingsFilePath}"); logger?.WriteLine(this.GetType().ToString(), $"Exporting settings to {settings.settingsFilePath}");
while(IsFileInUse(settings.settingsFilePath)) settings.ExportSettings();
Thread.Sleep(50);
File.WriteAllText(settings.settingsFilePath, JsonConvert.SerializeObject(settings));
logger?.WriteLine(this.GetType().ToString(), $"Exporting tasks to {settings.tasksFilePath}"); logger?.WriteLine(this.GetType().ToString(), $"Exporting tasks to {settings.tasksFilePath}");
while(IsFileInUse(settings.tasksFilePath)) while(IsFileInUse(settings.tasksFilePath))

View File

@ -43,6 +43,29 @@ public class TrangaSettings
return settings; 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) public void UpdateSettings(UpdateField field, Logger? logger = null, params string[] values)
{ {
switch (field) switch (field)
@ -81,6 +104,7 @@ public class TrangaSettings
newLunaSea.SendNotification("Success!", "LunaSea was added to Tranga!"); newLunaSea.SendNotification("Success!", "LunaSea was added to Tranga!");
break; break;
} }
ExportSettings();
} }
public enum UpdateField { DownloadLocation, Komga, Kavita, Gotify, LunaSea} public enum UpdateField { DownloadLocation, Komga, Kavita, Gotify, LunaSea}