Files
NebulaLauncher/Nebula.Shared/ConfigMigrations/ProfileMigration.cs

48 lines
1.9 KiB
C#
Raw Normal View History

2025-07-10 15:22:15 +03:00
using Microsoft.Extensions.DependencyInjection;
2025-08-06 21:29:00 +03:00
using Nebula.Shared.Configurations.Migrations;
2025-07-10 15:22:15 +03:00
using Nebula.Shared.Models;
using Nebula.Shared.Services;
2025-11-08 13:42:11 +03:00
using Nebula.Shared.Utils;
2025-07-10 15:22:15 +03:00
namespace Nebula.Shared.ConfigMigrations;
2025-07-10 15:22:15 +03:00
public class ProfileMigrationV2(string oldName, string newName)
2025-11-08 13:42:11 +03:00
: BaseConfigurationMigration<ProfileAuthCredentials[], string[]>(oldName, newName)
2025-07-10 15:22:15 +03:00
{
2025-11-08 13:42:11 +03:00
protected override async Task<string[]> Migrate(IServiceProvider serviceProvider, ProfileAuthCredentials[] oldValue, ILoadingHandler loadingHandler)
2025-07-10 15:22:15 +03:00
{
2025-11-08 13:42:11 +03:00
loadingHandler.SetLoadingMessage("Migrating Profile V2 -> V4");
var list = new List<string>();
2025-07-10 15:22:15 +03:00
var authService = serviceProvider.GetRequiredService<AuthService>();
var logger = serviceProvider.GetRequiredService<DebugService>().GetLogger("ProfileMigrationV2");
foreach (var oldCredentials in oldValue)
{
try
{
loadingHandler.SetLoadingMessage($"Migrating {oldCredentials.Login}");
2025-11-08 13:42:11 +03:00
await authService.Auth(oldCredentials.Login, oldCredentials.Password, oldCredentials.AuthServer);
list.Add(CryptographicStore.Encrypt(oldCredentials, CryptographicStore.GetComputerKey()));
2025-07-10 15:22:15 +03:00
}
catch (Exception e)
{
logger.Error(e);
loadingHandler.SetLoadingMessage(e.Message);
}
}
loadingHandler.SetLoadingMessage("Migration done!");
return list.ToArray();
}
}
2025-11-08 13:42:11 +03:00
public class ProfileMigrationV3V4(string oldName, string newName)
: BaseConfigurationMigration<AuthTokenCredentials[], string[]>(oldName, newName)
{
protected override Task<string[]> Migrate(IServiceProvider serviceProvider, AuthTokenCredentials[] oldValue, ILoadingHandler loadingHandler)
{
Console.WriteLine("Removing profile v3 because no password is provided");
return Task.FromResult(Array.Empty<string>());
}
}