@@ -366,18 +366,28 @@ public static bool PluginModified(string uuid)
366
366
return _modifiedPlugins . Contains ( uuid ) ;
367
367
}
368
368
369
- public static void UpdatePlugin ( PluginMetadata existingVersion , UserPlugin newVersion , string downloadedFilePath )
369
+
370
+ /// <summary>
371
+ /// Update a plugin to new version, from a zip file. Will Delete zip after updating.
372
+ /// </summary>
373
+ public static void UpdatePlugin ( PluginMetadata existingVersion , UserPlugin newVersion , string zipFilePath )
370
374
{
371
- InstallPlugin ( newVersion , downloadedFilePath , checkModified : false ) ;
375
+ InstallPlugin ( newVersion , zipFilePath , checkModified : false ) ;
372
376
UninstallPlugin ( existingVersion , removeSettings : false , checkModified : false ) ;
373
377
_modifiedPlugins . Add ( existingVersion . ID ) ;
374
378
}
375
379
376
- public static void InstallPlugin ( UserPlugin plugin , string downloadedFilePath )
380
+ /// <summary>
381
+ /// Install a plugin. Will Delete zip after updating.
382
+ /// </summary>
383
+ public static void InstallPlugin ( UserPlugin plugin , string zipFilePath )
377
384
{
378
- InstallPlugin ( plugin , downloadedFilePath , true ) ;
385
+ InstallPlugin ( plugin , zipFilePath , true ) ;
379
386
}
380
387
388
+ /// <summary>
389
+ /// Uninstall a plugin.
390
+ /// </summary>
381
391
public static void UninstallPlugin ( PluginMetadata plugin , bool removeSettings = true )
382
392
{
383
393
UninstallPlugin ( plugin , removeSettings , true ) ;
@@ -387,29 +397,18 @@ public static void UninstallPlugin(PluginMetadata plugin, bool removeSettings =
387
397
388
398
#region Internal functions
389
399
390
- internal static void InstallPlugin ( UserPlugin plugin , string downloadedFilePath , bool checkModified )
400
+ internal static void InstallPlugin ( UserPlugin plugin , string zipFilePath , bool checkModified )
391
401
{
392
402
if ( checkModified && PluginModified ( plugin . ID ) )
393
403
{
394
404
// Distinguish exception from installing same or less version
395
405
throw new ArgumentException ( $ "Plugin { plugin . Name } { plugin . ID } has been modified.", nameof ( plugin ) ) ;
396
406
}
397
407
398
- var tempFolderPath = Path . Combine ( Path . GetTempPath ( ) , "flowlauncher" ) ;
399
- var tempFolderPluginPath = Path . Combine ( tempFolderPath , "plugin" ) ;
400
-
401
- if ( Directory . Exists ( tempFolderPath ) )
402
- Directory . Delete ( tempFolderPath , true ) ;
403
-
404
- Directory . CreateDirectory ( tempFolderPath ) ;
405
-
406
- var zipFilePath = Path . Combine ( tempFolderPath , Path . GetFileName ( downloadedFilePath ) ) ;
407
-
408
- File . Copy ( downloadedFilePath , zipFilePath ) ;
409
-
410
- File . Delete ( downloadedFilePath ) ;
411
-
408
+ // Unzip plugin files to temp folder
409
+ var tempFolderPluginPath = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( ) ) ;
412
410
System . IO . Compression . ZipFile . ExtractToDirectory ( zipFilePath , tempFolderPluginPath ) ;
411
+ File . Delete ( zipFilePath ) ;
413
412
414
413
var pluginFolderPath = GetContainingFolderPathAfterUnzip ( tempFolderPluginPath ) ;
415
414
@@ -454,7 +453,7 @@ internal static void InstallPlugin(UserPlugin plugin, string downloadedFilePath,
454
453
455
454
FilesFolders . CopyAll ( pluginFolderPath , newPluginPath ) ;
456
455
457
- Directory . Delete ( pluginFolderPath , true ) ;
456
+ Directory . Delete ( tempFolderPluginPath , true ) ;
458
457
459
458
if ( checkModified )
460
459
{
0 commit comments