V3 configuration migration no longer supported, you had enough time to upgrade

This commit is contained in:
RisaDev
2024-10-18 23:26:10 +03:00
parent 0a8104ccdb
commit cbb5e7ccd9
5 changed files with 39 additions and 146 deletions

View File

@@ -44,74 +44,22 @@ public class ConfigurationMigrator
if (configVersion >= Constants.ConfigurationVersion)
return;
//V3 migration code
//We no longer support migrations of any versions < 4
if (configVersion < 3)
{
_messageService.NotificationMessage($"Unable to migrate your Customize+ configuration because it is too old. Manually install latest version of Customize+ 1.x to migrate your configuration to supported version first.", NotificationType.Error);
return;
}
MigrateV3ToV4();
// /V3 migration code
if (configVersion < 4)
{
_messageService.NotificationMessage($"Unable to migrate your Customize+ configuration because it is too old. Manually install Customize+ 2.0.6.5 to migrate your configuration to supported version first.", NotificationType.Error);
return;
}
throw new NotImplementedException();
config.Version = Constants.ConfigurationVersion;
_saveService.ImmediateSave(config);
}
private void MigrateV3ToV4()
{
_backupService.CreateV3Backup();
//I'm sorry, I'm too lazy so v3's enable root position setting is not getting migrated
bool anyMigrationFailures = false;
var usedGuids = new HashSet<Guid>();
foreach (var file in Directory.EnumerateFiles(_saveService.FileNames.ConfigDirectory, "*.profile", SearchOption.TopDirectoryOnly))
{
try
{
_logger.Debug($"Migrating v3 profile {file}");
var legacyProfile = JsonConvert.DeserializeObject<Version3Profile>(File.ReadAllText(file));
if (legacyProfile == null)
continue;
_logger.Debug($"v3 profile {file} loaded as {legacyProfile.ProfileName}");
(var profile, var template) = V3ProfileToV4Converter.Convert(legacyProfile);
//regenerate guids just to be safe
do
{
profile.UniqueId = Guid.NewGuid();
}
while (profile.UniqueId == Guid.Empty || usedGuids.Contains(profile.UniqueId));
usedGuids.Add(profile.UniqueId);
do
{
template.UniqueId = Guid.NewGuid();
}
while (template.UniqueId == Guid.Empty || usedGuids.Contains(template.UniqueId));
usedGuids.Add(template.UniqueId);
_saveService.ImmediateSaveSync(template);
_saveService.ImmediateSaveSync(profile);
_logger.Debug($"Migrated v3 profile {legacyProfile.ProfileName} to profile {profile.UniqueId} and template {template.UniqueId}");
File.Delete(file);
}
catch(Exception ex)
{
anyMigrationFailures = true;
_logger.Error($"Error while migrating {file}: {ex}");
}
}
if (anyMigrationFailures)
_messageService.NotificationMessage($"Some of your Customize+ profiles failed to migrate correctly.\nDetails have been printed to Dalamud log (/xllog in chat).", NotificationType.Error);
_reloadEvent.Invoke(ReloadEvent.Type.ReloadAll);
}
}