Skip to content

Commit 0619efd

Browse files
committed
Fix dll overwrite error when updating plugins on Windows via Plugin Installer
1 parent 700b38f commit 0619efd

3 files changed

Lines changed: 104 additions & 41 deletions

File tree

Source/Processors/PluginManager/PluginManager.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ int PluginManager::loadPlugin(const String& pluginLoc) {
250250
info.name = pInfo.processor.name;
251251
info.type = pInfo.processor.type;
252252
info.libIndex = libArray.size()-1;
253-
processorPlugins.add(info);
253+
Plugin::ProcessorInfo pi = getProcessorInfo(String::fromUTF8(info.name));
254+
if(pi.name == nullptr)
255+
processorPlugins.add(info);
254256
break;
255257
}
256258
case Plugin::PLUGIN_TYPE_RECORD_ENGINE:
@@ -259,7 +261,9 @@ int PluginManager::loadPlugin(const String& pluginLoc) {
259261
info.creator = pInfo.recordEngine.creator;
260262
info.name = pInfo.recordEngine.name;
261263
info.libIndex = libArray.size() - 1;
262-
recordEnginePlugins.add(info);
264+
Plugin::RecordEngineInfo rei = getRecordEngineInfo(String::fromUTF8(info.name));
265+
if(rei.name == nullptr)
266+
recordEnginePlugins.add(info);
263267
break;
264268
}
265269
case Plugin::PLUGIN_TYPE_DATA_THREAD:
@@ -268,7 +272,9 @@ int PluginManager::loadPlugin(const String& pluginLoc) {
268272
info.creator = pInfo.dataThread.creator;
269273
info.name = pInfo.dataThread.name;
270274
info.libIndex = libArray.size() - 1;
271-
dataThreadPlugins.add(info);
275+
Plugin::DataThreadInfo dti = getDataThreadInfo(String::fromUTF8(info.name));
276+
if(dti.name == nullptr)
277+
dataThreadPlugins.add(info);
272278
break;
273279
}
274280
case Plugin::PLUGIN_TYPE_FILE_SOURCE:
@@ -278,7 +284,9 @@ int PluginManager::loadPlugin(const String& pluginLoc) {
278284
info.name = pInfo.fileSource.name;
279285
info.extensions = pInfo.fileSource.extensions;
280286
info.libIndex = libArray.size();
281-
fileSourcePlugins.add(info);
287+
Plugin::FileSourceInfo fsi = getFileSourceInfo(String::fromUTF8(info.name));
288+
if(fsi.name == nullptr)
289+
fileSourcePlugins.add(info);
282290
break;
283291
}
284292
default:

Source/UI/PluginInstaller.cpp

Lines changed: 91 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@
2727
#include "../CoreServices.h"
2828
#include "../AccessClass.h"
2929
#include "../Processors/PluginManager/PluginManager.h"
30+
#include "../Processors/ProcessorGraph/ProcessorGraph.h"
3031
#include "ProcessorList.h"
3132
#include "ControlPanel.h"
33+
#ifdef WIN32
34+
#include <Windows.h>
35+
#endif
36+
37+
3238
//-----------------------------------------------------------------------
3339

3440
static inline File getPluginsLocationDirectory() {
@@ -785,7 +791,7 @@ void PluginInfoComponent::buttonClicked(Button* button)
785791
{
786792
if (button == &downloadButton)
787793
{
788-
std::cout << "Downloading Plugin: " << pInfo.pluginName << "... ";
794+
std::cout << "\nDownloading Plugin: " << pInfo.pluginName << "... " << std::endl;
789795

790796
// If a plugin has depencies outside its zip, download them
791797
for (int i = 0; i < pInfo.dependencies.size(); i++)
@@ -803,9 +809,9 @@ void PluginInfoComponent::buttonClicked(Button* button)
803809
if (retCode == 2)
804810
{
805811
AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon,
806-
"Plugin Installer " + pInfo.dependencies[i],
807-
"Could not install dependency: " + pInfo.dependencies[i]
808-
+ ". Please contact the developers.");
812+
"[Plugin Installer] " + pInfo.dependencies[i],
813+
"Could not install dependency: " + pInfo.dependencies[i]
814+
+ ". Please contact the developers.");
809815

810816
std::cout << "Download Failed!!" << std::endl;
811817
return;
@@ -818,8 +824,8 @@ void PluginInfoComponent::buttonClicked(Button* button)
818824
if (dlReturnCode == SUCCESS)
819825
{
820826
AlertWindow::showMessageBoxAsync(AlertWindow::InfoIcon,
821-
"Plugin Installer " + pInfo.pluginName,
822-
pInfo.pluginName + " Installed Successfully");
827+
"[Plugin Installer] " + pInfo.displayName,
828+
pInfo.displayName + " Installed Successfully");
823829

824830
std::cout << "Download Successfull!!" << std::endl;
825831

@@ -830,55 +836,66 @@ void PluginInfoComponent::buttonClicked(Button* button)
830836
else if (dlReturnCode == ZIP_NOTFOUND)
831837
{
832838
AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon,
833-
"Plugin Installer " + pInfo.pluginName,
834-
"Could not find the ZIP file for " + pInfo.pluginName + ". Please contact the developers.");
839+
"[Plugin Installer] " + pInfo.displayName,
840+
"Could not find the ZIP file for " + pInfo.displayName
841+
+ ". Please contact the developers.");
835842

836843
std::cout << "Download Failed!!" << std::endl;
837844
}
838845
else if (dlReturnCode == UNCMP_ERR)
839846
{
840847
AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon,
841-
"Plugin Installer " + pInfo.pluginName,
842-
"Could not uncompress the ZIP file. Please try again.");
848+
"[Plugin Installer] " + pInfo.displayName,
849+
"Could not uncompress the ZIP file. Please try again.");
843850

844851
std::cout << "Download Failed!!" << std::endl;
845852
}
846853
else if (dlReturnCode == XML_MISSING)
847854
{
848855
AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon,
849-
"Plugin Installer " + pInfo.pluginName,
850-
"Unable to locate installedPlugins.xml. Please restart Plugin Installer and try again.");
856+
"[Plugin Installer] " + pInfo.displayName,
857+
"Unable to locate installedPlugins.xml \n Please restart Plugin Installer and try again.");
851858

852859
std::cout << "XML File Missing!!" << std::endl;
853860
}
854861
else if (dlReturnCode == VER_EXISTS_ERR)
855862
{
856863
AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon,
857-
"Plugin Installer " + pInfo.pluginName,
858-
pInfo.pluginName + " v" + pInfo.selectedVersion + " already exists. Please download another version.");
864+
"[Plugin Installer] " + pInfo.displayName,
865+
pInfo.displayName + " v" + pInfo.selectedVersion
866+
+ " already exists. Please download another version.");
859867

860868
std::cout << "Download Failed!!" << std::endl;
861869
}
862870
else if (dlReturnCode == XML_WRITE_ERR)
863871
{
864872
AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon,
865-
"Plugin Installer " + pInfo.pluginName,
866-
"Unable to write to installedPlugins.xml \n Please try again.");
873+
"[Plugin Installer] " + pInfo.displayName,
874+
"Unable to write to installedPlugins.xml \n Please try again.");
867875

868876
std::cout << "Writing to XML Failed!!" << std::endl;
869877
}
870878
else if (dlReturnCode == LOAD_ERR)
871879
{
872880
AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon,
873-
"Plugin Installer " + pInfo.pluginName,
874-
"Unable to load " + pInfo.pluginName + " in the Processor List.\nLook at console output for more details.");
881+
"[Plugin Installer] " + pInfo.displayName,
882+
"Unable to load " + pInfo.displayName
883+
+ " in the Processor List.\nLook at console output for more details.");
875884

876885
std::cout << "Loading Plugin Failed!!" << std::endl;
877886

878887
pInfo.installedVersion = pInfo.selectedVersion;
879888
downloadButton.setEnabled(false);
880889
downloadButton.setButtonText("Installed");
881890
}
891+
else if (dlReturnCode == PROC_IN_USE)
892+
{
893+
AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon,
894+
"[Plugin Installer] " + pInfo.displayName,
895+
"Plugin already in use. Please remove it from the signal chain and try again.");
896+
897+
std::cout << "Error.. Plugin already in use. Please remove it from the signal chain and try again." << std::endl;
898+
}
882899

883900
}
884901
else if (button == &documentationButton)
@@ -1097,16 +1114,15 @@ int PluginInfoComponent::downloadPlugin(const String& plugin, const String& vers
10971114
auto entry = pluginZip.getEntry(1);
10981115
#endif
10991116

1100-
if (!isDependency)
1101-
{
1117+
// Open installedPluings.xml file
1118+
String fileStr = "plugins" + File::separatorString + "installedPlugins.xml";
1119+
File xmlFile = pluginsPath.getChildFile(fileStr);
11021120

1103-
String fileStr = "plugins" + File::separatorString + "installedPlugins.xml";
1104-
File xmlFile = pluginsPath.getChildFile(fileStr);
1121+
XmlDocument doc(xmlFile);
1122+
std::unique_ptr<XmlElement> xml (doc.getDocumentElement());
11051123

1106-
// Open installedPlugins.xml file
1107-
XmlDocument doc(xmlFile);
1108-
std::unique_ptr<XmlElement> xml (doc.getDocumentElement());
1109-
1124+
if (!isDependency)
1125+
{
11101126
// Create a new entry in xml for the downloaded plugin
11111127
std::unique_ptr<XmlElement> pluginEntry(new XmlElement(plugin));
11121128

@@ -1152,38 +1168,77 @@ int PluginInfoComponent::downloadPlugin(const String& plugin, const String& vers
11521168
if (!hasTag)
11531169
child->addChildElement(pluginEntry.release());
11541170

1155-
if (! xml->writeToFile(xmlFile, String::empty))
1156-
{
1157-
std::cout << "Error! Couldn't write to installedPlugins.xml" << std::endl;
1158-
pluginFile.deleteFile();
1159-
return 5;
1160-
}
1171+
}
1172+
1173+
// Check if plugin already present in signal chain
1174+
bool procInSignalChain;
1175+
if(pInfo.type == "Record Engine")
1176+
procInSignalChain = AccessClass::getProcessorGraph()->hasRecordNode();
1177+
else
1178+
procInSignalChain = AccessClass::getProcessorGraph()->processorWithSameNameExists(pInfo.displayName);
1179+
1180+
if(procInSignalChain)
1181+
{
1182+
pluginFile.deleteFile();
1183+
return 7;
11611184
}
11621185
}
11631186

11641187
// Uncompress the downloaded plugin's zip file
11651188
Result rs = pluginZip.uncompressTo(pluginsPath, true);
11661189

1167-
pluginFile.deleteFile(); // delete zip after uncompressing
1168-
11691190
if (rs.failed())
11701191
{
11711192
String errorMsg = rs.getErrorMessage();
11721193

1173-
if(errorMsg.containsIgnoreCase("Failed to write to target file") && isDependency)
1194+
if(errorMsg.containsIgnoreCase("Failed to write to target file"))
11741195
{
1175-
std::cout << "Dependency already installed..." << std::endl;
1196+
if(!isDependency)
1197+
{
1198+
#ifdef WIN32
1199+
String dllToUnload = errorMsg.substring(errorMsg.lastIndexOf("\\") + 1);
1200+
const char* processorLocCString = static_cast<const char*>(dllToUnload.toUTF8());
1201+
HMODULE md = GetModuleHandleA(processorLocCString);
1202+
1203+
if(FreeLibrary(md))
1204+
std::cout << "Unloaded old " << dllToUnload << std::endl;
1205+
#endif
1206+
rs = pluginZip.uncompressTo(pluginsPath, true);
1207+
1208+
if(rs.failed())
1209+
{
1210+
std::cout << rs.getErrorMessage() << std::endl;
1211+
pluginFile.deleteFile();
1212+
return 2;
1213+
}
1214+
}
1215+
else
1216+
{
1217+
std::cout << "Dependency already exists" << std::endl;
1218+
}
1219+
1220+
11761221
}
11771222
else
11781223
{
11791224
std::cout << rs.getErrorMessage() << std::endl;
1225+
pluginFile.deleteFile(); // delete zip after uncompressing
11801226
return 2;
11811227
}
11821228
}
11831229

1230+
pluginFile.deleteFile(); // delete zip after uncompressing
1231+
11841232
// if the plugin is not a dependency, load the plugin and show it in processor list
11851233
if (!isDependency)
11861234
{
1235+
// Write installed plugin's info to XML file
1236+
if (! xml->writeToFile(xmlFile, String::empty))
1237+
{
1238+
std::cout << "Error! Couldn't write to installedPlugins.xml" << std::endl;
1239+
return 5;
1240+
}
1241+
11871242
String libName = pluginsPath.getFullPathName() + File::separatorString + entry->filename;
11881243

11891244
int loadPlugin = AccessClass::getPluginManager()->loadPlugin(libName);

Source/UI/PluginInstaller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class PluginInfoComponent : public Component,
121121

122122
SelectedPluginInfo pInfo;
123123

124-
enum RetunCode {ZIP_NOTFOUND, SUCCESS, UNCMP_ERR, XML_MISSING, VER_EXISTS_ERR, XML_WRITE_ERR, LOAD_ERR};
124+
enum RetunCode {ZIP_NOTFOUND, SUCCESS, UNCMP_ERR, XML_MISSING, VER_EXISTS_ERR, XML_WRITE_ERR, LOAD_ERR, PROC_IN_USE};
125125

126126
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginInfoComponent);
127127

0 commit comments

Comments
 (0)