Fixed configuration migration not performing correctly

This commit is contained in:
RisaDev
2024-01-10 00:12:54 +03:00
parent a9700f234c
commit e77037ff09
3 changed files with 15 additions and 32 deletions

View File

@@ -95,8 +95,8 @@ public class ConfigurationMigrator
while (template.UniqueId == Guid.Empty || usedGuids.Contains(template.UniqueId));
usedGuids.Add(template.UniqueId);
_saveService.ImmediateSave(template);
_saveService.ImmediateSave(profile);
_saveService.ImmediateSaveSync(template);
_saveService.ImmediateSaveSync(profile);
_logger.Debug($"Migrated v3 profile {legacyProfile.ProfileName} to profile {profile.UniqueId} and template {template.UniqueId}");
File.Delete(file);

View File

@@ -94,24 +94,15 @@ public class ProfileFileSystem : FileSystem<Profile>, IDisposable, ISavable
private void Reload()
{
if (Load(new FileInfo(_saveService.FileNames.ProfileFileSystem), _profileManager.Profiles, ProfileToIdentifier, ProfileToName))
{
var shouldReloadAgain = false;
if (!File.Exists(_saveService.FileNames.ProfileFileSystem))
shouldReloadAgain = true;
_saveService.ImmediateSave(this);
//this is a workaround for FileSystem's weird behavior where it doesn't load objects into itself if its file does not exist
if (shouldReloadAgain)
{
_logger.Debug("BUG WORKAROUND: reloading profile filesystem again");
Reload();
return;
}
_logger.Debug("WORKAROUND: saving filesystem file");
_saveService.ImmediateSaveSync(this);
}
if (Load(new FileInfo(_saveService.FileNames.ProfileFileSystem), _profileManager.Profiles, ProfileToIdentifier, ProfileToName))
_saveService.ImmediateSave(this);
_logger.Debug("Reloaded profile filesystem.");
}

View File

@@ -95,24 +95,16 @@ public sealed class TemplateFileSystem : FileSystem<Template>, IDisposable, ISav
private void Reload()
{
if (Load(new FileInfo(_saveService.FileNames.TemplateFileSystem), _templateManager.Templates, TemplateToIdentifier, TemplateToName))
{
var shouldReloadAgain = false;
if (!File.Exists(_saveService.FileNames.TemplateFileSystem))
shouldReloadAgain = true;
_saveService.ImmediateSave(this);
//this is a workaround for FileSystem's weird behavior where it doesn't load objects into itself if its file does not exist
if (shouldReloadAgain)
if (!File.Exists(_saveService.FileNames.TemplateFileSystem))
{
_logger.Debug("BUG WORKAROUND: reloading template filesystem again");
Reload();
return;
}
_logger.Debug("WORKAROUND: saving filesystem file");
_saveService.ImmediateSaveSync(this);
}
if (Load(new FileInfo(_saveService.FileNames.TemplateFileSystem), _templateManager.Templates, TemplateToIdentifier, TemplateToName))
_saveService.ImmediateSave(this);
_logger.Debug("Reloaded template filesystem.");
}