From 7c7d91eda91373531b14f940b69b00116e64dfb4 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 22 Dec 2025 20:47:26 +0100 Subject: [PATCH] Hotfix workshop auto-update --- .../Services/WorkshopService.cs | 76 +++++++++++++------ 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/src/Artemis.WebClient.Workshop/Services/WorkshopService.cs b/src/Artemis.WebClient.Workshop/Services/WorkshopService.cs index 17ad95888..493ec8131 100644 --- a/src/Artemis.WebClient.Workshop/Services/WorkshopService.cs +++ b/src/Artemis.WebClient.Workshop/Services/WorkshopService.cs @@ -26,9 +26,8 @@ public class WorkshopService : IWorkshopService private readonly IWorkshopClient _workshopClient; private readonly PluginSetting _migratedBuiltInPlugins; - - private bool _initialized; + private bool _mutating; public WorkshopService(ILogger logger, IHttpClientFactory httpClientFactory, @@ -173,27 +172,45 @@ public class WorkshopService : IWorkshopService /// public async Task InstallEntry(IEntrySummary entry, IRelease release, Progress progress, CancellationToken cancellationToken) { - IEntryInstallationHandler handler = _factory.CreateHandler(entry.EntryType); - EntryInstallResult result = await handler.InstallAsync(entry, release, progress, cancellationToken); - if (result.IsSuccess && result.Entry != null) - OnEntryInstalled?.Invoke(this, result.Entry); - else - _logger.Warning("Failed to install entry {Entry}: {Message}", entry, result.Message); + _mutating = true; - return result; + try + { + IEntryInstallationHandler handler = _factory.CreateHandler(entry.EntryType); + EntryInstallResult result = await handler.InstallAsync(entry, release, progress, cancellationToken); + if (result.IsSuccess && result.Entry != null) + OnEntryInstalled?.Invoke(this, result.Entry); + else + _logger.Warning("Failed to install entry {Entry}: {Message}", entry, result.Message); + + return result; + } + finally + { + _mutating = false; + } } /// public async Task UninstallEntry(InstalledEntry installedEntry, CancellationToken cancellationToken) { - IEntryInstallationHandler handler = _factory.CreateHandler(installedEntry.EntryType); - EntryUninstallResult result = await handler.UninstallAsync(installedEntry, cancellationToken); - if (result.IsSuccess) - OnEntryUninstalled?.Invoke(this, installedEntry); - else - _logger.Warning("Failed to uninstall entry {EntryId}: {Message}", installedEntry.Id, result.Message); + _mutating = true; - return result; + try + { + IEntryInstallationHandler handler = _factory.CreateHandler(installedEntry.EntryType); + EntryUninstallResult result = await handler.UninstallAsync(installedEntry, cancellationToken); + if (result.IsSuccess) + OnEntryUninstalled?.Invoke(this, installedEntry); + else + _logger.Warning("Failed to uninstall entry {EntryId}: {Message}", installedEntry.Id, result.Message); + + return result; + } + finally + { + _mutating = false; + } } /// @@ -316,16 +333,28 @@ public class WorkshopService : IWorkshopService // If already migrated, do nothing if (_migratedBuiltInPlugins.Value) return; - - MigratingBuildInPlugins?.Invoke(this, EventArgs.Empty); - bool migrated = await BuiltInPluginsMigrator.Migrate(this, _workshopClient, _logger, _pluginRepository); - _migratedBuiltInPlugins.Value = migrated; - _migratedBuiltInPlugins.Save(); + _mutating = true; + + try + { + MigratingBuildInPlugins?.Invoke(this, EventArgs.Empty); + + bool migrated = await BuiltInPluginsMigrator.Migrate(this, _workshopClient, _logger, _pluginRepository); + _migratedBuiltInPlugins.Value = migrated; + _migratedBuiltInPlugins.Save(); + } + finally + { + _mutating = false; + } } private void ProfileServiceOnProfileRemoved(object? sender, ProfileConfigurationEventArgs e) { + if (_mutating) + return; + InstalledEntry? entry = GetInstalledEntryByProfile(e.ProfileConfiguration); if (entry == null) return; @@ -336,6 +365,9 @@ public class WorkshopService : IWorkshopService private void PluginManagementServiceOnPluginRemoved(object? sender, PluginEventArgs e) { + if (_mutating) + return; + InstalledEntry? entry = GetInstalledEntryByPlugin(e.Plugin); if (entry == null) return; @@ -349,6 +381,6 @@ public class WorkshopService : IWorkshopService public event EventHandler? OnEntryUninstalled; public event EventHandler? OnEntryInstalled; - + public event EventHandler? MigratingBuildInPlugins; } \ No newline at end of file