Files
LightlessClient/LightlessSync/LightlessConfiguration/ConfigurationMigrator.cs
defnotken 23c57aedc4 Add Nameplates + Clean up.
* Yeet Token!

* Cleaning up workflow

* Testing auto version bump

* ExistingNames

* Remove a key

* Github Token no work

* Changing Assembly Version

* Version Fix

* Fixing version v2

* Cleanup naming

* Update LightlessSync.csproj

* Add nameplate settings + run code clean up

* purple
2025-08-29 18:48:01 -05:00

46 lines
1.5 KiB
C#

using LightlessSync.WebAPI;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace LightlessSync.LightlessConfiguration;
public class ConfigurationMigrator(ILogger<ConfigurationMigrator> logger, TransientConfigService transientConfigService,
ServerConfigService serverConfigService) : IHostedService
{
private readonly ILogger<ConfigurationMigrator> _logger = logger;
public void Migrate()
{
if (transientConfigService.Current.Version == 0)
{
_logger.LogInformation("Migrating Transient Config V0 => V1");
transientConfigService.Current.TransientConfigs.Clear();
transientConfigService.Current.Version = 1;
transientConfigService.Save();
}
if (serverConfigService.Current.Version == 1)
{
_logger.LogInformation("Migrating Server Config V1 => V2");
var centralServer = serverConfigService.Current.ServerStorage.Find(f => f.ServerName.Equals("Follow the light (Central Server EU)", StringComparison.Ordinal));
if (centralServer != null)
{
centralServer.ServerName = ApiController.MainServer;
}
serverConfigService.Current.Version = 2;
serverConfigService.Save();
}
}
public Task StartAsync(CancellationToken cancellationToken)
{
Migrate();
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}