|
10 | 10 | using System.IO;
|
11 | 11 | using System.Linq;
|
12 | 12 | using System.Net.Http;
|
| 13 | +using System.Text.Json; |
13 | 14 | using System.Threading;
|
14 | 15 | using System.Threading.Tasks;
|
15 | 16 | using System.Windows;
|
@@ -438,6 +439,17 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
|
438 | 439 | string.Format("Unable to find plugin.json from the extracted zip file, or this path {0} does not exist", pluginFolderPath));
|
439 | 440 | }
|
440 | 441 |
|
| 442 | + if (SameOrLesserPluginVersionExists(metadataJsonFilePath)) |
| 443 | + { |
| 444 | + MessageBox.Show(string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_duplicate"), plugin.Name), |
| 445 | + Context.API.GetTranslation("plugin_pluginsmanager_install_error_title")); |
| 446 | + |
| 447 | + throw new InvalidOperationException( |
| 448 | + string.Format("A plugin with the same ID and version already exists, " + |
| 449 | + "or the version is greater than this downloaded plugin {0}", |
| 450 | + plugin.Name)); |
| 451 | + } |
| 452 | + |
441 | 453 | var directory = string.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}-{Guid.NewGuid()}" : $"{plugin.Name}-{plugin.Version}";
|
442 | 454 | var newPluginPath = Path.Combine(DataLocation.PluginsDirectory, directory);
|
443 | 455 |
|
@@ -532,5 +544,14 @@ private List<Result> AutoCompleteReturnAllResults(string search, string hotkey,
|
532 | 544 |
|
533 | 545 | return new List<Result>();
|
534 | 546 | }
|
| 547 | + |
| 548 | + private bool SameOrLesserPluginVersionExists(string metadataPath) |
| 549 | + { |
| 550 | + var newMetadata = JsonSerializer.Deserialize<PluginMetadata>(File.ReadAllText(metadataPath)); |
| 551 | + return Context.API.GetAllPlugins() |
| 552 | + .Any(x => x.Metadata.ID == newMetadata.ID |
| 553 | + && (x.Metadata.Version == newMetadata.Version) |
| 554 | + || newMetadata.Version.CompareTo(x.Metadata.Version) < 0); |
| 555 | + } |
535 | 556 | }
|
536 | 557 | }
|
0 commit comments