Tranga-Website/Tranga/Migrate.cs

33 lines
1.0 KiB
C#
Raw Normal View History

2023-07-21 00:32:18 +02:00
using Logging;
using Newtonsoft.Json;
namespace Tranga;
public static class Migrate
{
private static readonly ushort CurrentVersion = 16;
public static void Files(TrangaSettings settings)
{
settings.version ??= 15;
switch (settings.version)
{
case 15:
RemoveUpdateLibraryTask(settings);
break;
}
settings.version = CurrentVersion;
settings.ExportSettings();
}
private static void RemoveUpdateLibraryTask(TrangaSettings settings)
{
2023-07-21 00:32:18 +02:00
if (!File.Exists(settings.tasksFilePath))
return;
string tasksJsonString = File.ReadAllText(settings.tasksFilePath);
2023-07-29 18:55:06 +02:00
HashSet<TrangaTask> tasks = JsonConvert.DeserializeObject<HashSet<TrangaTask>>(tasksJsonString, new JsonSerializerSettings { Converters = { new TrangaTask.TrangaTaskJsonConverter() } })!;
tasks.RemoveWhere(t => t.task == TrangaTask.Task.UpdateLibraries);
File.WriteAllText(settings.tasksFilePath, JsonConvert.SerializeObject(tasks));
}
}