|
10 | 10 | using System.IO;
|
11 | 11 | using System.Linq;
|
12 | 12 | using System.Net.Http;
|
13 |
| -using System.Text.Json; |
14 | 13 | using System.Threading;
|
15 | 14 | using System.Threading.Tasks;
|
16 | 15 | using System.Windows;
|
@@ -151,19 +150,19 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
|
151 | 150 | catch (HttpRequestException e)
|
152 | 151 | {
|
153 | 152 | Context.API.ShowMsgError(string.Format(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"), plugin.Name),
|
154 |
| - Context.API.GetTranslation("plugin_pluginsmanager_download_error")); |
| 153 | + Context.API.GetTranslation("plugin_pluginsmanager_download_error")); |
155 | 154 | Log.Exception("PluginsManager", "An error occurred while downloading plugin", e);
|
156 | 155 | return;
|
157 | 156 | }
|
158 | 157 | catch (Exception e)
|
159 | 158 | {
|
160 | 159 | Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
|
161 |
| - string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"), |
162 |
| - plugin.Name)); |
| 160 | + string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"), |
| 161 | + plugin.Name)); |
163 | 162 | Log.Exception("PluginsManager", "An error occurred while downloading plugin", e);
|
164 | 163 | return;
|
165 | 164 | }
|
166 |
| - |
| 165 | + |
167 | 166 | if (Settings.AutoRestartAfterChanging)
|
168 | 167 | {
|
169 | 168 | Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_installing_plugin"),
|
@@ -411,77 +410,22 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
|
411 | 410 | {
|
412 | 411 | if (!File.Exists(downloadedFilePath))
|
413 | 412 | return;
|
414 |
| - |
415 |
| - var tempFolderPath = Path.Combine(Path.GetTempPath(), "flowlauncher"); |
416 |
| - var tempFolderPluginPath = Path.Combine(tempFolderPath, "plugin"); |
417 |
| - |
418 |
| - if (Directory.Exists(tempFolderPath)) |
419 |
| - Directory.Delete(tempFolderPath, true); |
420 |
| - |
421 |
| - Directory.CreateDirectory(tempFolderPath); |
422 |
| - |
423 |
| - var zipFilePath = Path.Combine(tempFolderPath, Path.GetFileName(downloadedFilePath)); |
424 |
| - |
425 |
| - File.Copy(downloadedFilePath, zipFilePath); |
426 |
| - |
427 |
| - File.Delete(downloadedFilePath); |
428 |
| - |
429 |
| - Utilities.UnZip(zipFilePath, tempFolderPluginPath, true); |
430 |
| - |
431 |
| - var pluginFolderPath = Utilities.GetContainingFolderPathAfterUnzip(tempFolderPluginPath); |
432 |
| - |
433 |
| - var metadataJsonFilePath = string.Empty; |
434 |
| - if (File.Exists(Path.Combine(pluginFolderPath, Constant.PluginMetadataFileName))) |
435 |
| - metadataJsonFilePath = Path.Combine(pluginFolderPath, Constant.PluginMetadataFileName); |
436 |
| - |
437 |
| - if (string.IsNullOrEmpty(metadataJsonFilePath) || string.IsNullOrEmpty(pluginFolderPath)) |
| 413 | + try |
| 414 | + { |
| 415 | + PluginManager.Install(plugin, downloadedFilePath); |
| 416 | + } |
| 417 | + catch(FileNotFoundException e) |
438 | 418 | {
|
| 419 | + Log.Exception("Flow.Launcher.Plugin.PluginsManager", e.Message, e); |
439 | 420 | MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_install_errormetadatafile"),
|
440 |
| - Context.API.GetTranslation("plugin_pluginsmanager_install_error_title")); |
441 |
| - |
442 |
| - throw new FileNotFoundException( |
443 |
| - string.Format("Unable to find plugin.json from the extracted zip file, or this path {0} does not exist", pluginFolderPath)); |
| 421 | + Context.API.GetTranslation("plugin_pluginsmanager_install_error_title")); |
444 | 422 | }
|
445 |
| - |
446 |
| - if (SameOrLesserPluginVersionExists(metadataJsonFilePath)) |
| 423 | + catch(InvalidOperationException e) |
447 | 424 | {
|
| 425 | + Log.Exception("Flow.Launcher.Plugin.PluginsManager", e.Message, e); |
448 | 426 | MessageBox.Show(string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_duplicate"), plugin.Name),
|
449 |
| - Context.API.GetTranslation("plugin_pluginsmanager_install_error_title")); |
450 |
| - |
451 |
| - throw new InvalidOperationException( |
452 |
| - string.Format("A plugin with the same ID and version already exists, " + |
453 |
| - "or the version is greater than this downloaded plugin {0}", |
454 |
| - plugin.Name)); |
| 427 | + Context.API.GetTranslation("plugin_pluginsmanager_install_error_title")); |
455 | 428 | }
|
456 |
| - |
457 |
| - var folderName = string.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}-{Guid.NewGuid()}" : $"{plugin.Name}-{plugin.Version}"; |
458 |
| - |
459 |
| - var defaultPluginIDs = new List<string> |
460 |
| - { |
461 |
| - "0ECADE17459B49F587BF81DC3A125110", // BrowserBookmark |
462 |
| - "CEA0FDFC6D3B4085823D60DC76F28855", // Calculator |
463 |
| - "572be03c74c642baae319fc283e561a8", // Explorer |
464 |
| - "6A122269676E40EB86EB543B945932B9", // PluginIndicator |
465 |
| - "9f8f9b14-2518-4907-b211-35ab6290dee7", // PluginsManager |
466 |
| - "b64d0a79-329a-48b0-b53f-d658318a1bf6", // ProcessKiller |
467 |
| - "791FC278BA414111B8D1886DFE447410", // Program |
468 |
| - "D409510CD0D2481F853690A07E6DC426", // Shell |
469 |
| - "CEA08895D2544B019B2E9C5009600DF4", // Sys |
470 |
| - "0308FD86DE0A4DEE8D62B9B535370992", // URL |
471 |
| - "565B73353DBF4806919830B9202EE3BF", // WebSearch |
472 |
| - "5043CETYU6A748679OPA02D27D99677A" // WindowsSettings |
473 |
| - }; |
474 |
| - |
475 |
| - // Treat default plugin differently, it needs to be removable along with each flow release |
476 |
| - var installDirectory = !defaultPluginIDs.Any(x => x == plugin.ID) |
477 |
| - ? DataLocation.PluginsDirectory |
478 |
| - : Constant.PreinstalledDirectory; |
479 |
| - |
480 |
| - var newPluginPath = Path.Combine(installDirectory, folderName); |
481 |
| - |
482 |
| - FilesFolders.CopyAll(pluginFolderPath, newPluginPath); |
483 |
| - |
484 |
| - Directory.Delete(pluginFolderPath, true); |
485 | 429 | }
|
486 | 430 |
|
487 | 431 | internal List<Result> RequestUninstall(string search)
|
@@ -537,24 +481,9 @@ internal List<Result> RequestUninstall(string search)
|
537 | 481 | return Search(results, search);
|
538 | 482 | }
|
539 | 483 |
|
540 |
| - private void Uninstall(PluginMetadata plugin, bool removedSetting = true) |
541 |
| - { |
542 |
| - if (removedSetting) |
543 |
| - { |
544 |
| - PluginManager.Settings.Plugins.Remove(plugin.ID); |
545 |
| - PluginManager.AllPlugins.RemoveAll(p => p.Metadata.ID == plugin.ID); |
546 |
| - } |
547 |
| - |
548 |
| - // Marked for deletion. Will be deleted on next start up |
549 |
| - using var _ = File.CreateText(Path.Combine(plugin.PluginDirectory, "NeedDelete.txt")); |
550 |
| - } |
551 |
| - |
552 |
| - private bool SameOrLesserPluginVersionExists(string metadataPath) |
| 484 | + private static void Uninstall(PluginMetadata plugin, bool removeSettings = true) |
553 | 485 | {
|
554 |
| - var newMetadata = JsonSerializer.Deserialize<PluginMetadata>(File.ReadAllText(metadataPath)); |
555 |
| - return Context.API.GetAllPlugins() |
556 |
| - .Any(x => x.Metadata.ID == newMetadata.ID |
557 |
| - && newMetadata.Version.CompareTo(x.Metadata.Version) <= 0); |
| 486 | + PluginManager.Uninstall(plugin, removeSettings); |
558 | 487 | }
|
559 | 488 | }
|
560 | 489 | }
|
0 commit comments