Skip to content

Commit

Permalink
Fixed configuration migration not performing correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
RisaDev committed Jan 9, 2024
1 parent a9700f2 commit e77037f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
4 changes: 2 additions & 2 deletions CustomizePlus/Configuration/Services/ConfigurationMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ private void MigrateV3ToV4()
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);
Expand Down
19 changes: 5 additions & 14 deletions CustomizePlus/Profiles/ProfileFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,15 @@ private void OnProfileChange(ProfileChanged.Type type, Profile? profile, object?

private void Reload()
{
if (Load(new FileInfo(_saveService.FileNames.ProfileFileSystem), _profileManager.Profiles, ProfileToIdentifier, ProfileToName))
if (!File.Exists(_saveService.FileNames.ProfileFileSystem))
{
var shouldReloadAgain = false;

if (!File.Exists(_saveService.FileNames.ProfileFileSystem))
shouldReloadAgain = true;
_logger.Debug("WORKAROUND: saving filesystem file");
_saveService.ImmediateSaveSync(this);
}

if (Load(new FileInfo(_saveService.FileNames.ProfileFileSystem), _profileManager.Profiles, ProfileToIdentifier, ProfileToName))
_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("Reloaded profile filesystem.");
}

Expand Down
20 changes: 6 additions & 14 deletions CustomizePlus/Templates/TemplateFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,16 @@ private void OnTemplateChange(TemplateChanged.Type type, Template? template, obj

private void Reload()
{
if (Load(new FileInfo(_saveService.FileNames.TemplateFileSystem), _templateManager.Templates, TemplateToIdentifier, TemplateToName))
//this is a workaround for FileSystem's weird behavior where it doesn't load objects into itself if its file does not exist
if (!File.Exists(_saveService.FileNames.TemplateFileSystem))
{
var shouldReloadAgain = false;

if (!File.Exists(_saveService.FileNames.TemplateFileSystem))
shouldReloadAgain = true;
_logger.Debug("WORKAROUND: saving filesystem file");
_saveService.ImmediateSaveSync(this);
}

if (Load(new FileInfo(_saveService.FileNames.TemplateFileSystem), _templateManager.Templates, TemplateToIdentifier, TemplateToName))
_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 template filesystem again");
Reload();
return;
}
}

_logger.Debug("Reloaded template filesystem.");
}

Expand Down

0 comments on commit e77037f

Please sign in to comment.