Skip to content

Commit

Permalink
fix issue with plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
insomniachi committed Jan 3, 2024
1 parent 64393fa commit e290767
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions Totoro.Plugins/PluginInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace Totoro.Plugins;

Expand All @@ -19,3 +20,17 @@ public PluginInfo()
}

public record PluginInfoSlim(string FileName, string Version, bool Exists = true, string DisplayName = "");

public class PluginInfoEqualityComparer : IEqualityComparer<PluginInfoSlim>
{
public bool Equals(PluginInfoSlim x, PluginInfoSlim y)
{
return x.FileName == y.FileName &&
x.Version == y.Version;
}

public int GetHashCode([DisallowNull] PluginInfoSlim obj)
{
return HashCode.Combine(obj.FileName, obj.Version);
}
}
6 changes: 4 additions & 2 deletions Totoro.Plugins/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ private async Task DownloadOrUpdatePlugins(List<PluginInfoSlim> listedPlugins, I
return;
}

var comparer = new PluginInfoEqualityComparer();

Directory.CreateDirectory(folder);

var newReleases = listedPlugins.Except(localPlugins).ToList();
var newReleases = listedPlugins.Except(localPlugins, comparer).ToList();
foreach (var item in newReleases)
{
var path = Path.Combine(folder, item.FileName);
Expand Down Expand Up @@ -131,7 +133,7 @@ private async Task DownloadOrUpdatePlugins(List<PluginInfoSlim> listedPlugins, I
if (!AllowSideLoadingPlugins)
{
localPlugins = Directory.GetFiles(folder).Select(x => new PluginInfoSlim(Path.GetFileName(x), FileVersionInfo.GetVersionInfo(x).FileVersion!));
foreach (var item in localPlugins.Except(listedPlugins))
foreach (var item in localPlugins.Except(listedPlugins, comparer))
{
this.Log().Info($"Removing plugin : {item.FileName}");
File.Delete(Path.Combine(folder, item.FileName));
Expand Down

0 comments on commit e290767

Please sign in to comment.