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
This commit is contained in:
Jaidyn Ann 2022-02-23 12:11:17 -06:00
parent b7b45a8db0
commit e092128200
3 changed files with 18 additions and 2 deletions

View File

@ -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
{

View File

@ -17,6 +17,7 @@ class ChatProtocolAddOn {
public:
ChatProtocolAddOn(image_id image, const char* path,
int32 subProto=0);
~ChatProtocolAddOn();
status_t InitCheck() const;

View File

@ -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 || 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