Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新:AutoPluginManager 检查重复安装插件 #469

Merged
merged 4 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/AutoPluginManager/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Plugin : TerrariaPlugin
{
public override string Name => "AutoPluginManager";

public override Version Version => new(2, 0, 1, 5);
public override Version Version => new(2, 0, 1, 6);

public override string Author => "少司命,Cai";

Expand Down Expand Up @@ -80,6 +80,7 @@ private void AutoCheckUpdate(EventArgs args)
try
{
var updates = GetUpdates();
PluginRepeat(TSPlayer.Server);
if (updates.Any())
{
TShock.Log.ConsoleInfo(GetString("[以下插件有新的版本更新]\n" + string.Join("\n", updates.Select(i => $"[{i.Name}] V{i.OldVersion} >>> V{i.NewVersion}"))));
Expand All @@ -106,6 +107,20 @@ private void AutoCheckUpdate(EventArgs args)
this._timer.Start();
}

private static void PluginRepeat(TSPlayer ply)
{
if (typeof(ServerApi)
.GetField("loadedAssemblies", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance)
!.GetValue(null) is Dictionary<string, Assembly> loadassemblys)
{
var mutexs = loadassemblys
.GroupBy(x => x.Value.GetName().FullName)
.Where(x => x.Count() > 1)
.SelectMany(x => x);
ply.SendErrorMessage("[插件重复安装]" + string.Join(" >>> ", mutexs.Select(x => x.Key + ".dll")));
}
}

private void PluginManager(CommandArgs args)
{
if (args.Parameters.Count == 1 && (args.Parameters[0].ToLower() == "-c" || args.Parameters[0].ToLower() == "c"))
Expand Down Expand Up @@ -150,6 +165,10 @@ private void PluginManager(CommandArgs args)
Config.PluginConfig.Write();
args.Player.SendSuccessMessage(GetString("排除成功, 已跳过此插件的更新检查~"));
}
else if (args.Parameters.Count == 1 && (args.Parameters[0].ToLower() == "-r" || args.Parameters[0].ToLower() == "r"))
{
PluginRepeat(args.Player);
}
else if (args.Parameters.Count == 2 && (args.Parameters[0].ToLower() == "-rb" || args.Parameters[0].ToLower() == "rb"))
{
if (!Config.PluginConfig.UpdateBlackList.Contains(args.Parameters[1]))
Expand Down Expand Up @@ -515,4 +534,4 @@ private static List<PluginUpdateInfo> UpdatePlugin(List<PluginUpdateInfo> plugin
return pluginUpdateInfos;
}
#endregion
}
}
1 change: 1 addition & 0 deletions src/AutoPluginManager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ V2.0.0.0
| /apm -l | AutoUpdatePlugin | 查看仓库插件列表 |
| /apm -i [插件序号] | AutoUpdatePlugin | 安装插件,需重启服务器,插件序号多选`英文逗号隔开`配合`/apm -i`指令使用 |
| /apm -b [插件名] | AutoUpdatePlugin | 将插件排除更新 |
| /apm -r | AutoUpdatePlugin | 检查重复安装的插件 |
| /apm -rb [插件名] | AutoUpdatePlugin | 移除排除更新 |
| /apm -lb | AutoUpdatePlugin | 列出排除更新的插件 |
## 配置
Expand Down
1 change: 1 addition & 0 deletions src/AutoPluginManager/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
| /apm -l | AutoUpdatePlugin | View the list of repository plugins |
| /apm -i [plugin number] | AutoUpdatePlugin | Install plugins, requires server restart. Multiple plugin numbers can be separated by `commas` and used with the `/apm -i` command |
| /apm -b [plugin name] | AutoUpdatePlugin | Exclude plugin from updates |
| /apm -r | AutoUpdatePlugin | Check for duplicate installed plugins |
| /apm -rb [plugin name] | AutoUpdatePlugin | Remove update exclusion |
| /apm -lb | AutoUpdatePlugin | List plugins excluded from updates |

Expand Down
Loading