Tranga-Website/Tranga/Migrate.cs

33 lines
1.1 KiB
C#
Raw Normal View History

using Newtonsoft.Json;
2023-07-30 16:26:29 +02:00
using Tranga.TrangaTasks;
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));
}
}