Skip to content

Commit 4af0649

Browse files
committed
Refactor plugin update/uninstall process
When updating a plugin, the plugin is now uninstalled and then new version is installed. This is to ensure that the plugin metadata is properly updated. When uninstalling a plugin, the plugin library is now unloaded by the plugin manager.
1 parent 809dd85 commit 4af0649

4 files changed

Lines changed: 137 additions & 111 deletions

File tree

Source/Processors/PluginManager/PluginManager.cpp

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ PluginManager::PluginManager()
106106

107107
if(appDir.contains("plugin-GUI\\Build\\"))
108108
{
109-
SetDllDirectory(sharedPath.getFullPathName().toUTF8());
109+
SetDllDirectory(sharedPath.getFullPathName().toRawUTF8());
110110
}
111111
else
112112
{
@@ -115,7 +115,7 @@ PluginManager::PluginManager()
115115
LOGD("Copying shared dependencies to ", installSharedPath.getFullPathName());
116116
sharedPath.copyDirectoryTo(installSharedPath);
117117
}
118-
SetDllDirectory(installSharedPath.getFullPathName().toUTF8());
118+
SetDllDirectory(installSharedPath.getFullPathName().toRawUTF8());
119119
}
120120

121121
#elif __linux__
@@ -238,7 +238,8 @@ int PluginManager::loadPlugin(const String& pluginLoc) {
238238

239239
#ifdef _WIN32
240240
HINSTANCE handle;
241-
handle = LoadLibrary(processorLocCString);
241+
const wchar_t* processorLocLPCWSTR = pluginLoc.toWideCharPointer();
242+
handle = LoadLibraryW(processorLocLPCWSTR);
242243
#elif defined(__APPLE__)
243244
CF::CFURLRef bundleURL = CF::CFURLCreateFromFileSystemRepresentation(CF::kCFAllocatorDefault,
244245
reinterpret_cast<const CF::UInt8 *>(processorLocCString),
@@ -311,7 +312,7 @@ int PluginManager::loadPlugin(const String& pluginLoc) {
311312
return -1;
312313
}
313314

314-
LoadedLibInfo lib;
315+
LoadedLibInfo lib{};
315316
lib.apiVersion = libInfo.apiVersion;
316317
lib.name = libInfo.name;
317318
lib.libVersion = libInfo.libVersion;
@@ -335,9 +336,8 @@ int PluginManager::loadPlugin(const String& pluginLoc) {
335336
info.name = pInfo.processor.name;
336337
info.type = pInfo.processor.type;
337338
info.libIndex = libArray.size()-1;
338-
Plugin::ProcessorInfo pi = getProcessorInfo(String::fromUTF8(info.name));
339-
if(pi.name == nullptr)
340-
processorPlugins.add(info);
339+
processorPlugins.add(info);
340+
341341
break;
342342
}
343343
case Plugin::RECORD_ENGINE:
@@ -347,9 +347,8 @@ int PluginManager::loadPlugin(const String& pluginLoc) {
347347
info.creator = pInfo.recordEngine.creator;
348348
info.name = pInfo.recordEngine.name;
349349
info.libIndex = libArray.size() - 1;
350-
Plugin::RecordEngineInfo rei = getRecordEngineInfo(String::fromUTF8(info.name));
351-
if(rei.name == nullptr)
352-
recordEnginePlugins.add(info);
350+
recordEnginePlugins.add(info);
351+
353352
break;
354353
}
355354
case Plugin::DATA_THREAD:
@@ -359,9 +358,8 @@ int PluginManager::loadPlugin(const String& pluginLoc) {
359358
info.creator = pInfo.dataThread.creator;
360359
info.name = pInfo.dataThread.name;
361360
info.libIndex = libArray.size() - 1;
362-
Plugin::DataThreadInfo dti = getDataThreadInfo(String::fromUTF8(info.name));
363-
if(dti.name == nullptr)
364-
dataThreadPlugins.add(info);
361+
dataThreadPlugins.add(info);
362+
365363
break;
366364
}
367365
case Plugin::FILE_SOURCE:
@@ -372,9 +370,8 @@ int PluginManager::loadPlugin(const String& pluginLoc) {
372370
info.name = pInfo.fileSource.name;
373371
info.extensions = pInfo.fileSource.extensions;
374372
info.libIndex = libArray.size();
375-
Plugin::FileSourceInfo fsi = getFileSourceInfo(String::fromUTF8(info.name));
376-
if(fsi.name == nullptr)
377-
fileSourcePlugins.add(info);
373+
fileSourcePlugins.add(info);
374+
378375
break;
379376
}
380377
default:
@@ -539,8 +536,10 @@ bool PluginManager::findPlugin(String name, String libName, const Array<LoadedPl
539536
for (int i = 0; i < pluginArray.size(); i++)
540537
{
541538
String pName = String(pluginArray[i].name);
542-
if (pName == name)
539+
LOGC("********** PluginArray[", i, "]: ", pName);
540+
if (pName.equalsIgnoreCase(name))
543541
{
542+
LOGC ("Found plugin: ", name, " in pluginArray");
544543
if ((libName.isEmpty()) || (libName == String(libArray[pluginArray[i].libIndex].name)))
545544
{
546545
pluginInfo = pluginArray[i];
@@ -591,6 +590,8 @@ bool PluginManager::removePlugin(String libName)
591590
{
592591
if (piFunction(i, &pInfo)) //if somehow there are fewer plugins than stated, stop removing
593592
break;
593+
594+
int pluginIndex = -1;
594595
switch (pInfo.type)
595596
{
596597
case Plugin::PROCESSOR:
@@ -599,11 +600,14 @@ bool PluginManager::removePlugin(String libName)
599600
for(int j = 0; j < processorPlugins.size(); j++)
600601
{
601602
if(processorPlugins[j].name == pInfo.processor.name)
602-
{
603-
processorPlugins.remove(j);
604-
break;
605-
}
603+
pluginIndex = j;
604+
605+
if (processorPlugins[j].libIndex > indexToRemove)
606+
processorPlugins[j].setLibIndex(processorPlugins[j].libIndex - 1);
606607
}
608+
if(pluginIndex != -1)
609+
processorPlugins.remove(pluginIndex);
610+
607611
break;
608612
}
609613
case Plugin::RECORD_ENGINE:
@@ -612,37 +616,46 @@ bool PluginManager::removePlugin(String libName)
612616
for(int j = 0; j < recordEnginePlugins.size(); j++)
613617
{
614618
if(recordEnginePlugins[j].name == pInfo.recordEngine.name)
615-
{
616-
recordEnginePlugins.remove(j);
617-
break;
618-
}
619+
pluginIndex = j;
620+
621+
if (recordEnginePlugins[j].libIndex > indexToRemove)
622+
recordEnginePlugins[j].setLibIndex(recordEnginePlugins[j].libIndex - 1);
619623
}
624+
if(pluginIndex != -1)
625+
recordEnginePlugins.remove(pluginIndex);
626+
620627
break;
621628
}
622629
case Plugin::DATA_THREAD:
623630
{
624-
LOGD("Adding data thread plugin");
631+
LOGD("Removing data thread plugin");
625632
for(int j = 0; j < dataThreadPlugins.size(); j++)
626633
{
627634
if(dataThreadPlugins[j].name == pInfo.dataThread.name)
628-
{
629-
dataThreadPlugins.remove(j);
630-
break;
631-
}
635+
pluginIndex = j;
636+
637+
if (dataThreadPlugins[j].libIndex > indexToRemove)
638+
dataThreadPlugins[j].setLibIndex(dataThreadPlugins[j].libIndex - 1);
632639
}
640+
if(pluginIndex != -1)
641+
dataThreadPlugins.remove(pluginIndex);
642+
633643
break;
634644
}
635645
case Plugin::FILE_SOURCE:
636646
{
637-
LOGD("Adding file source plugin");
647+
LOGD("Removing file source plugin");
638648
for(int j = 0; j < fileSourcePlugins.size(); j++)
639649
{
640650
if(fileSourcePlugins[j].name == pInfo.fileSource.name)
641-
{
642-
fileSourcePlugins.remove(j);
643-
break;
644-
}
651+
pluginIndex = j;
652+
653+
if (fileSourcePlugins[j].libIndex > indexToRemove)
654+
fileSourcePlugins[j].setLibIndex(fileSourcePlugins[j].libIndex - 1);
645655
}
656+
if(pluginIndex != -1)
657+
fileSourcePlugins.remove(pluginIndex);
658+
646659
break;
647660
}
648661
default:
@@ -653,6 +666,7 @@ bool PluginManager::removePlugin(String libName)
653666
}
654667
}
655668

669+
closeHandle(lib.handle);
656670
libArray.remove(indexToRemove);
657671
return true;
658672
}

Source/Processors/PluginManager/PluginManager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <list>
2828
#include <string>
29+
#include <cstring>
2930
#include <sys/types.h>
3031
#include "../../../JuceLibraryCode/JuceHeader.h"
3132
#include "OpenEphysPlugin.h"
@@ -54,6 +55,12 @@ template<class T>
5455
struct LoadedPluginInfo : public T
5556
{
5657
int libIndex;
58+
59+
// Setter function to modify the libIndex
60+
void setLibIndex(int index)
61+
{
62+
libIndex = index;
63+
}
5764
};
5865

5966

0 commit comments

Comments
 (0)