From e0921282002a2942b1d3a25815ed4def550abdfc Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Wed, 23 Feb 2022 12:11:17 -0600 Subject: [PATCH] Don't load multiple version of the same add-on Now solely the one of highest priority is used (e.g., `non-packaged/add-ons/` over `system/add-ons/`). Fixes #20 --- application/ChatProtocolAddOn.cpp | 7 +++++++ application/ChatProtocolAddOn.h | 1 + application/ProtocolManager.cpp | 12 ++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/application/ChatProtocolAddOn.cpp b/application/ChatProtocolAddOn.cpp index 2fa16fe..744a3a9 100644 --- a/application/ChatProtocolAddOn.cpp +++ b/application/ChatProtocolAddOn.cpp @@ -27,6 +27,13 @@ ChatProtocolAddOn::ChatProtocolAddOn(image_id image, const char* path, int32 sub } +ChatProtocolAddOn::~ChatProtocolAddOn() +{ + delete fIcon; + unload_add_on(fImage); +} + + status_t ChatProtocolAddOn::InitCheck() const { diff --git a/application/ChatProtocolAddOn.h b/application/ChatProtocolAddOn.h index 4fd4629..aaf7c0a 100644 --- a/application/ChatProtocolAddOn.h +++ b/application/ChatProtocolAddOn.h @@ -17,6 +17,7 @@ class ChatProtocolAddOn { public: ChatProtocolAddOn(image_id image, const char* path, int32 subProto=0); + ~ChatProtocolAddOn(); status_t InitCheck() const; diff --git a/application/ProtocolManager.cpp b/application/ProtocolManager.cpp index d6829ff..ad174f8 100644 --- a/application/ProtocolManager.cpp +++ b/application/ProtocolManager.cpp @@ -47,10 +47,18 @@ ProtocolManager::Init(BDirectory dir, BHandler* target) if (id < 0) continue; - // If add-on's API version fits then load accounts… + // Refuse to load add-on under some circumstances… ChatProtocolAddOn* addOn = new ChatProtocolAddOn(id, path.Path()); - if (addOn->Version() != APP_VERSION) + if (addOn->Version() != APP_VERSION || ProtocolAddOn(addOn->Signature()) != NULL) { + if (addOn->Version() != APP_VERSION) + printf("%s not loaded, due to insufficient version (%i v %i).\n", + addOn->Signature(), addOn->Version(), APP_VERSION); + else if (ProtocolAddOn(addOn->Signature()) != NULL) + printf("%s not loaded, due to another instance already having been loaded.\n", + addOn->Signature()); + delete addOn; continue; + } ret = true; // If add-on has multiple protocols, also load them