mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Workshop - Replace non-workshop plugins when installing them from the workshop
This commit is contained in:
parent
fa8b03104f
commit
18d75318d9
@ -671,7 +671,19 @@ internal class PluginManagementService : IPluginManagementService
|
|||||||
UnloadPlugin(plugin);
|
UnloadPlugin(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
directory.Delete(true);
|
// 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);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.Warning(e, "Failed to fully remove plugin directory {Directory}", directory.FullName);
|
||||||
|
}
|
||||||
|
|
||||||
if (removeSettings)
|
if (removeSettings)
|
||||||
RemovePluginSettings(plugin);
|
RemovePluginSettings(plugin);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,11 +63,17 @@ public class PluginEntryInstallationHandler : IEntryInstallationHandler
|
|||||||
using ZipArchive archive = new(stream);
|
using ZipArchive archive = new(stream);
|
||||||
archive.ExtractToDirectory(releaseDirectory.FullName);
|
archive.ExtractToDirectory(releaseDirectory.FullName);
|
||||||
|
|
||||||
// If there is already a version of the plugin installed, disable it
|
PluginInfo pluginInfo = CoreJson.Deserialize<PluginInfo>(await File.ReadAllTextAsync(Path.Combine(releaseDirectory.FullName, "plugin.json"), cancellationToken))!;
|
||||||
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)
|
||||||
{
|
{
|
||||||
Plugin? currentVersion = _pluginManagementService.GetAllPlugins().FirstOrDefault(p => p.Guid == pluginId);
|
// If the current version isn't from the workshop, remove it first
|
||||||
if (currentVersion != null)
|
if (currentVersion.Directory.FullName.StartsWith(Constants.PluginsFolder))
|
||||||
|
_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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +102,8 @@ 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);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user