Add dryRun checks to provider and chat template configuration logic

This commit is contained in:
Thorsten Sommer 2025-08-17 16:32:10 +02:00
parent f221119d71
commit 3963da1366
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -90,6 +90,8 @@ public sealed class PluginConfiguration(bool isInternal, LuaState state, PluginT
// Apply the configured providers to the system settings:
//
#pragma warning disable MWAIS0001
if (!dryRun)
{
foreach (var configuredProvider in configuredProviders)
{
// The iterating variable is immutable, so we need to create a local copy:
@ -110,6 +112,7 @@ public sealed class PluginConfiguration(bool isInternal, LuaState state, PluginT
SETTINGS_MANAGER.ConfigurationData.Providers.Add(provider);
}
}
}
#pragma warning restore MWAIS0001
//
@ -135,23 +138,29 @@ public sealed class PluginConfiguration(bool isInternal, LuaState state, PluginT
}
// Apply configured chat templates to the system settings:
if (!dryRun)
{
foreach (var configuredTemplate in configuredTemplates)
{
// The iterating variable is immutable, so we need to create a local copy:
var template = configuredTemplate;
var tplIndex = SETTINGS_MANAGER.ConfigurationData.ChatTemplates.FindIndex(t => t.Id == template.Id);
if (tplIndex > -1)
{
// Case: The template already exists, we update it:
var existingTemplate = SETTINGS_MANAGER.ConfigurationData.ChatTemplates[tplIndex];
template = template with { Num = existingTemplate.Num };
SETTINGS_MANAGER.ConfigurationData.ChatTemplates[tplIndex] = template;
}
else
{
// Case: The template does not exist, we add it:
template = template with { Num = SETTINGS_MANAGER.ConfigurationData.NextChatTemplateNum++ };
SETTINGS_MANAGER.ConfigurationData.ChatTemplates.Add(template);
}
}
}
}
return true;
}