Skip to content

Commit 73c1031

Browse files
committed
append new guid as zip and file name, update error messaging
1 parent 9940539 commit 73c1031

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

Plugins/Flow.Launcher.Plugin.PluginsManager/Languages/en.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
<system:String x:Key="plugin_pluginsmanager_install_prompt">{0} by {1} {2}{3}Would you like to install this plugin? After the installation Flow will automatically restart.</system:String>
1111
<system:String x:Key="plugin_pluginsmanager_install_title">Plugin Install</system:String>
1212
<system:String x:Key="plugin_pluginsmanager_uninstall_title">Plugin Uninstall</system:String>
13-
<system:String x:Key="plugin_pluginsmanager_install_in_progress">Plugin installation in progress... Please wait</system:String>
13+
<system:String x:Key="plugin_pluginsmanager_install_in_progress">Plugin installation in progress. Please wait...</system:String>
1414
<system:String x:Key="plugin_pluginsmanager_install_success_restart">Plugin successfully installed. Restarting Flow, please wait...</system:String>
15-
<system:String x:Key="plugin_pluginsmanager_install_errormetadatafile">Install failed: unable to find the plugin.json metadata file from the new plugin</system:String>
15+
<system:String x:Key="plugin_pluginsmanager_install_errormetadatafile">Unable to find the plugin.json metadata file from the extracted zip file.</system:String>
1616
<system:String x:Key="plugin_pluginsmanager_install_error_title">Error installing plugin</system:String>
1717
<system:String x:Key="plugin_pluginsmanager_install_error_subtitle">Error occured while trying to install {0}</system:String>
1818
<system:String x:Key="plugin_pluginsmanager_update_noresult_title">No update available</system:String>

Plugins/Flow.Launcher.Plugin.PluginsManager/PluginsManager.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ internal List<Result> GetDefaultHotKeys()
103103

104104
internal async Task InstallOrUpdate(UserPlugin plugin)
105105
{
106-
if (PluginExists(plugin.ID) || Directory.Exists(Path.Combine(DataLocation.PluginsDirectory, plugin.Name)))
106+
if (PluginExists(plugin.ID))
107107
{
108108
if (Context.API.GetAllPlugins()
109109
.Any(x => x.Metadata.ID == plugin.ID && x.Metadata.Version.CompareTo(plugin.Version) < 0))
@@ -137,7 +137,12 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
137137
MessageBoxButton.YesNo) == MessageBoxResult.No)
138138
return;
139139

140-
var filePath = Path.Combine(DataLocation.PluginsDirectory, $"{plugin.Name}-{plugin.Version}.zip");
140+
// at minimum should provide a name, but handle plugin that is not downloaded from plugins manifest and is a url download
141+
var downloadFilename = string.IsNullOrEmpty(plugin.Version)
142+
? $"{plugin.Name}-{Guid.NewGuid()}.zip"
143+
: $"{plugin.Name}-{plugin.Version}.zip";
144+
145+
var filePath = Path.Combine(DataLocation.PluginsDirectory, downloadFilename);
141146

142147
try
143148
{
@@ -153,11 +158,10 @@ internal async Task InstallOrUpdate(UserPlugin plugin)
153158
Context.API.GetTranslation("plugin_pluginsmanager_install_in_progress"));
154159

155160
Install(plugin, filePath);
156-
157161
}
158162
catch (Exception e)
159163
{
160-
Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
164+
Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
161165
string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"),
162166
plugin.Name));
163167

@@ -316,6 +320,7 @@ internal List<Result> InstallFromWeb(string url)
316320
{
317321
ID = "",
318322
Name = fileName.Split(".").First(),
323+
Version = string.Empty,
319324
Author = "N/A",
320325
UrlDownload = url
321326
};
@@ -411,11 +416,15 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
411416

412417
if (string.IsNullOrEmpty(metadataJsonFilePath) || string.IsNullOrEmpty(pluginFolderPath))
413418
{
414-
MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_install_errormetadatafile"));
415-
return;
419+
MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_install_errormetadatafile"),
420+
Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"));
421+
422+
throw new FileNotFoundException (
423+
string.Format("Unable to find plugin.json from the extracted zip file, or this path {0} does not exist", pluginFolderPath));
416424
}
417-
var directory = String.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}" : $"{plugin.Name}-{plugin.Version}";
418-
string newPluginPath = Path.Combine(DataLocation.PluginsDirectory, directory);
425+
426+
var directory = string.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}-{Guid.NewGuid()}" : $"{plugin.Name}-{plugin.Version}";
427+
var newPluginPath = Path.Combine(DataLocation.PluginsDirectory, directory);
419428

420429
FilesFolders.CopyAll(pluginFolderPath, newPluginPath);
421430

0 commit comments

Comments
 (0)