Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

delete plugin folder when uninstall plugin #860

Merged
merged 15 commits into from
Jun 10, 2022
Merged
38 changes: 8 additions & 30 deletions neo-cli/CLI/MainService.Plugins.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (C) 2016-2021 The Neo Project.
//
// The neo-cli is free software distributed under the MIT software
// Copyright (C) 2016-2022 The Neo Project.
//
// The neo-cli is free software distributed under the MIT software
// license, see the accompanying file LICENSE in the main directory of
// the project or http://www.opensource.org/licenses/mit-license.php
// the project or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

Expand Down Expand Up @@ -174,7 +174,7 @@ private async Task InstallDependenciesAsync(Stream config, HashSet<string> insta
/// <returns></returns>
private static bool PluginExists(string pluginName)
{
return File.Exists($"Plugins/{pluginName}.dll");
return Plugin.Plugins.Any(p => p.Name.ToLower() == pluginName);
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
}

/// <summary>
Expand Down Expand Up @@ -225,36 +225,14 @@ private void OnUnInstallCommand(string pluginName)
// ignored
}
}

try
{
DeleteFiles(new[] { $"Plugins/{pluginName}.dll", $"Plugins/{pluginName}/config.json" });
Directory.Delete($"Plugins/{pluginName}", false);
}
catch (IOException)
{
Directory.Delete($"Plugins/{pluginName}", true);
}

catch (IOException) { }
ConsoleHelper.Info("Uninstall successful, please restart neo-cli.");
}

private static void DeleteFiles(IEnumerable<string> list)
{
foreach (var file in list)
{
try
{
if (!File.Exists(file)) continue;
ConsoleHelper.Info("Deleting ", file);
File.Delete(file);
}
catch (Exception)
{
// ignored
}
}
}

/// <summary>
/// Process "plugins" command
/// </summary>
Expand Down