Skip to content

Commit 2606faa

Browse files
committed
minor fixes & refactor
1 parent 1dd526a commit 2606faa

File tree

7 files changed

+149
-203
lines changed

7 files changed

+149
-203
lines changed

Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22

33
namespace Flow.Launcher.Core.ExternalPlugins
44
{
@@ -13,9 +13,11 @@ public record UserPlugin
1313
public string Website { get; set; }
1414
public string UrlDownload { get; set; }
1515
public string UrlSourceCode { get; set; }
16+
public string LocalInstallPath { get; set; }
1617
public string IcoPath { get; set; }
1718
public DateTime LatestReleaseDate { get; set; }
1819
public DateTime DateAdded { get; set; }
1920

21+
public bool IsFromLocalInstallPath => !string.IsNullOrEmpty(LocalInstallPath);
2022
}
2123
}

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ public static bool PluginModified(string uuid)
380380

381381

382382
/// <summary>
383-
/// Update a plugin to new version, from a zip file. Will Delete zip after updating.
383+
/// Update a plugin to new version, from a zip file. By default will remove the zip file if update is via url,
384+
/// unless it's a local path installation
384385
/// </summary>
385386
public static void UpdatePlugin(PluginMetadata existingVersion, UserPlugin newVersion, string zipFilePath)
386387
{
@@ -390,11 +391,11 @@ public static void UpdatePlugin(PluginMetadata existingVersion, UserPlugin newVe
390391
}
391392

392393
/// <summary>
393-
/// Install a plugin. Will Delete zip after updating.
394+
/// Install a plugin. By default will remove the zip file if installation is from url, unless it's a local path installation
394395
/// </summary>
395396
public static void InstallPlugin(UserPlugin plugin, string zipFilePath)
396397
{
397-
InstallPlugin(plugin, zipFilePath, true);
398+
InstallPlugin(plugin, zipFilePath, checkModified: true);
398399
}
399400

400401
/// <summary>
@@ -420,7 +421,9 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
420421
// Unzip plugin files to temp folder
421422
var tempFolderPluginPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
422423
System.IO.Compression.ZipFile.ExtractToDirectory(zipFilePath, tempFolderPluginPath);
423-
File.Delete(zipFilePath);
424+
425+
if(!plugin.IsFromLocalInstallPath)
426+
File.Delete(zipFilePath);
424427

425428
var pluginFolderPath = GetContainingFolderPathAfterUnzip(tempFolderPluginPath);
426429

Flow.Launcher.Plugin/SharedCommands/FilesFolders.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using System.IO;
4+
using System.Linq;
45
#pragma warning disable IDE0005
56
using System.Windows;
67
#pragma warning restore IDE0005
@@ -200,6 +201,24 @@ public static void OpenFile(string filePath, string workingDir = "", bool asAdmi
200201
}
201202
}
202203

204+
///<summary>
205+
/// This checks whether a given string is a zip file path.
206+
/// By default does not check if the zip file actually exist on disk, can do so by
207+
/// setting checkFileExists = true.
208+
///</summary>
209+
public static bool IsZipFilePath(string querySearchString, bool checkFileExists = false)
210+
{
211+
if (IsLocationPathString(querySearchString) && querySearchString.Split('.').Last() == "zip")
212+
{
213+
if (checkFileExists)
214+
return FileExists(querySearchString);
215+
216+
return true;
217+
}
218+
219+
return false;
220+
}
221+
203222
///<summary>
204223
/// This checks whether a given string is a directory path or network location string.
205224
/// It does not check if location actually exists.

Flow.Launcher.Test/Plugins/ExplorerTest.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,20 @@ public void GivenQuery_WhenActionKeywordForFileContentSearchExists_ThenFileConte
186186
$"Actual result was: {result}{Environment.NewLine}");
187187
}
188188

189-
[TestCase(@"c:\\", false)]
190-
[TestCase(@"i:\", true)]
191-
[TestCase(@"\c:\", false)]
192-
[TestCase(@"cc:\", false)]
193-
[TestCase(@"\\\SomeNetworkLocation\", false)]
194-
[TestCase("RandomFile", false)]
195-
[TestCase(@"c:\>*", true)]
196-
[TestCase(@"c:\>", true)]
197-
[TestCase(@"c:\SomeLocation\SomeOtherLocation\>", true)]
198-
[TestCase(@"c:\SomeLocation\SomeOtherLocation", true)]
189+
//[TestCase(@"c:\\", false)]
190+
//[TestCase(@"i:\", true)]
191+
//[TestCase(@"\c:\", false)]
192+
//[TestCase(@"cc:\", false)]
193+
//[TestCase(@"\\\SomeNetworkLocation\", false)]
194+
//[TestCase(@"\\SomeNetworkLocation\", true)]
195+
//[TestCase("RandomFile", false)]
196+
//[TestCase(@"c:\>*", true)]
197+
//[TestCase(@"c:\>", true)]
198+
//[TestCase(@"c:\SomeLocation\SomeOtherLocation\>", true)]
199+
//[TestCase(@"c:\SomeLocation\SomeOtherLocation", true)]
200+
//[TestCase(@"c:\SomeLocation\SomeOtherLocation\SomeFile.exe", true)]
201+
[TestCase(@"\\SomeNetworkLocation\SomeFile.exe", true)]
202+
199203
public void WhenGivenQuerySearchString_ThenShouldIndicateIfIsLocationPathString(string querySearchString, bool expectedResult)
200204
{
201205
// When, Given

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
<system:String x:Key="plugin_pluginsmanager_update_prompt">{0} by {1} {2}{3}Would you like to update this plugin? After the update Flow will automatically restart.</system:String>
2727
<system:String x:Key="plugin_pluginsmanager_update_prompt_no_restart">{0} by {1} {2}{2}Would you like to update this plugin?</system:String>
2828
<system:String x:Key="plugin_pluginsmanager_update_title">Plugin Update</system:String>
29-
<system:String x:Key="plugin_pluginsmanager_update_exists">This plugin has an update, would you like to see it?</system:String>
3029
<system:String x:Key="plugin_pluginsmanager_update_alreadyexists">This plugin is already installed</system:String>
3130
<system:String x:Key="plugin_pluginsmanager_update_failed_title">Plugin Manifest Download Failed</system:String>
3231
<system:String x:Key="plugin_pluginsmanager_update_failed_subtitle">Please check if you can connect to github.com. This error means you may not be able to install or update plugins.</system:String>

0 commit comments

Comments
 (0)