Do not fail catastrophically if we can't migrate a profile

This commit is contained in:
RisaDev
2024-02-04 23:37:39 +03:00
parent f2456ef920
commit 28a08b558e

View File

@@ -11,6 +11,7 @@ using CustomizePlus.Configuration.Helpers;
using CustomizePlus.Configuration.Data;
using CustomizePlus.Core.Events;
using CustomizePlus.Configuration.Data.Version3;
using CustomizePlus.UI.Windows;
namespace CustomizePlus.Configuration.Services;
@@ -18,7 +19,7 @@ public class ConfigurationMigrator
{
private readonly SaveService _saveService;
private readonly BackupService _backupService;
private readonly MessageService _messageService;
private readonly MessageService _messageService; //we can't use popups here since they rely on PluginConfiguration and using them here hangs plugin loading
private readonly Logger _logger;
private readonly ReloadEvent _reloadEvent;
@@ -54,9 +55,6 @@ public class ConfigurationMigrator
MigrateV3ToV4();
// /V3 migration code
//I'm sorry, I'm too lazy so v3's enable root position setting is not getting migrated for now
//MigrateV3ToV4(configVersion);
config.Version = Constants.ConfigurationVersion;
_saveService.ImmediateSave(config);
}
@@ -67,8 +65,12 @@ public class ConfigurationMigrator
//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}");
@@ -101,6 +103,15 @@ public class ConfigurationMigrator
_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);
}