1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2026-01-02 10:43:31 +00:00

Compare commits

..

No commits in common. "91d1d16f2476c80442afa9fa9d222c2239df6e78" and "8c1fef28833fabc7182322c0b063b7e05fbec613" have entirely different histories.

2 changed files with 7 additions and 36 deletions

View File

@ -425,18 +425,10 @@ internal class PluginManagementService : IPluginManagementService
); );
} }
bool addedNewFeature = false;
foreach (Type featureType in featureTypes) foreach (Type featureType in featureTypes)
{ {
// Load the enabled state and if not found, default to true // Load the enabled state and if not found, default to true
PluginFeatureEntity? featureEntity = plugin.Entity.Features.FirstOrDefault(i => i.Type == featureType.FullName); PluginFeatureEntity featureEntity = plugin.Entity.Features.FirstOrDefault(i => i.Type == featureType.FullName) ?? new PluginFeatureEntity {Type = featureType.FullName!};
if (featureEntity == null)
{
featureEntity = new PluginFeatureEntity {Type = featureType.FullName!};
entity.Features.Add(featureEntity);
addedNewFeature = true;
}
PluginFeatureInfo feature = new(plugin, featureType, featureEntity, (PluginFeatureAttribute?) Attribute.GetCustomAttribute(featureType, typeof(PluginFeatureAttribute))); PluginFeatureInfo feature = new(plugin, featureType, featureEntity, (PluginFeatureAttribute?) Attribute.GetCustomAttribute(featureType, typeof(PluginFeatureAttribute)));
// If the plugin only has a single feature, it should always be enabled // If the plugin only has a single feature, it should always be enabled
@ -451,8 +443,7 @@ internal class PluginManagementService : IPluginManagementService
// It is appropriate to call this now that we have the features of this plugin // It is appropriate to call this now that we have the features of this plugin
bool autoEnabled = plugin.AutoEnableIfNew(); bool autoEnabled = plugin.AutoEnableIfNew();
if (autoEnabled)
if (autoEnabled || addedNewFeature)
_pluginRepository.SavePlugin(entity); _pluginRepository.SavePlugin(entity);
List<Type> bootstrappers = plugin.Assembly.GetTypes().Where(t => typeof(PluginBootstrapper).IsAssignableFrom(t)).ToList(); List<Type> bootstrappers = plugin.Assembly.GetTypes().Where(t => typeof(PluginBootstrapper).IsAssignableFrom(t)).ToList();
@ -671,19 +662,7 @@ internal class PluginManagementService : IPluginManagementService
UnloadPlugin(plugin); UnloadPlugin(plugin);
} }
// Delete plugin.json since that should never be in use and prevents future loads
File.Delete(Path.Combine(directory.FullName, "plugin.json"));
try
{
// Give a good effort to remove the directory, files may be in use though :\
directory.Delete(true); directory.Delete(true);
}
catch (Exception e)
{
_logger.Warning(e, "Failed to fully remove plugin directory {Directory}", directory.FullName);
}
if (removeSettings) if (removeSettings)
RemovePluginSettings(plugin); RemovePluginSettings(plugin);
} }

View File

@ -63,17 +63,11 @@ public class PluginEntryInstallationHandler : IEntryInstallationHandler
using ZipArchive archive = new(stream); using ZipArchive archive = new(stream);
archive.ExtractToDirectory(releaseDirectory.FullName); archive.ExtractToDirectory(releaseDirectory.FullName);
PluginInfo pluginInfo = CoreJson.Deserialize<PluginInfo>(await File.ReadAllTextAsync(Path.Combine(releaseDirectory.FullName, "plugin.json"), cancellationToken))!; // If there is already a version of the plugin installed, disable it
if (installedEntry.TryGetMetadata("PluginId", out Guid pluginId))
// If there is already a version of the plugin installed, remove it
Plugin? currentVersion = _pluginManagementService.GetAllPlugins().FirstOrDefault(p => p.Guid == pluginInfo.Guid);
if (currentVersion != null)
{ {
// If the current version isn't from the workshop, remove it first Plugin? currentVersion = _pluginManagementService.GetAllPlugins().FirstOrDefault(p => p.Guid == pluginId);
if (currentVersion.Directory.FullName.StartsWith(Constants.PluginsFolder)) if (currentVersion != null)
_pluginManagementService.RemovePlugin(currentVersion, false);
// If the current version is from the workshop only unload it, the old folder will be orphaned and cleaned up later
else
_pluginManagementService.UnloadPlugin(currentVersion); _pluginManagementService.UnloadPlugin(currentVersion);
} }
@ -102,8 +96,6 @@ public class PluginEntryInstallationHandler : IEntryInstallationHandler
return EntryInstallResult.FromFailure(e.Message); return EntryInstallResult.FromFailure(e.Message);
} }
installedEntry.ApplyRelease(release);
_workshopService.SaveInstalledEntry(installedEntry); _workshopService.SaveInstalledEntry(installedEntry);
return EntryInstallResult.FromSuccess(installedEntry); return EntryInstallResult.FromSuccess(installedEntry);
} }