Skip to content

Commit

Permalink
Quick hack fix for migrations not working due to V3 config not existing
Browse files Browse the repository at this point in the history
  • Loading branch information
RisaDev committed Jan 27, 2024
1 parent 10d3a71 commit 4067aa5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using CustomizePlus.Core.Services;
using OtterGui.Log;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CustomizePlus.Configuration.Services.Temporary;

//V3 has bug when it doesn't create config file. We need to have one to migrate stuff properly.
internal class Version3ConfigFixer
{
private readonly Logger _logger;
private readonly FilenameService _filenameService;

public Version3ConfigFixer(
Logger logger,
FilenameService filenameService)
{
_logger = logger;
_filenameService = filenameService;
}

public void FixV3ConfigIfNeeded()
{
var oldVersionProfiles = Directory.EnumerateFiles(_filenameService.ConfigDirectory, "*.profile", SearchOption.TopDirectoryOnly);
if (oldVersionProfiles.Count() > 0 && !File.Exists(_filenameService.ConfigFile))
{
_logger.Warning("V3 config not found while profiles are available, creating dummy V3 config");
File.WriteAllText(_filenameService.ConfigFile, "{\r\n \"ViewedMessageWindows\": [],\r\n \"Version\": 3,\r\n \"PluginEnabled\": true,\r\n \"DebuggingModeEnabled\": false,\r\n \"RootPositionEditingEnabled\": false\r\n}");
}
}
}
3 changes: 2 additions & 1 deletion CustomizePlus/Core/ServiceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ private static IServiceCollection AddConfigServices(this IServiceCollection serv
services
.AddSingleton<PluginConfiguration>()
.AddSingleton<ConfigurationMigrator>()
.AddSingleton<FantasiaPlusConfigMover>();
.AddSingleton<FantasiaPlusConfigMover>()
.AddSingleton<Version3ConfigFixer>();

return services;
}
Expand Down
3 changes: 3 additions & 0 deletions CustomizePlus/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public Plugin(DalamudPluginInterface pluginInterface)
var configMover = _services.GetRequiredService<FantasiaPlusConfigMover>();
configMover.MoveConfigsIfNeeded();

var v3ConfigFixer = _services.GetRequiredService<Version3ConfigFixer>();
v3ConfigFixer.FixV3ConfigIfNeeded();

_services.GetRequiredService<CustomizePlusIpc>();
_services.GetRequiredService<CPlusWindowSystem>();
_services.GetRequiredService<CommandService>();
Expand Down

0 comments on commit 4067aa5

Please sign in to comment.