@@ -121,17 +121,20 @@ qtractorPluginFile *qtractorPluginFile::addFile ( const QString& sFilename )
121121{
122122 qtractorPluginFile *pFile = g_files.value (sFilename , nullptr );
123123
124- if (pFile == nullptr && QLibrary::isLibrary (sFilename )
124+ if (pFile == nullptr && ( QLibrary::isLibrary (sFilename )
125125 #ifdef CONFIG_CLAP
126126 || QFileInfo (sFilename ).suffix () == " clap"
127127 #endif
128- ) {
128+ )) {
129129 pFile = new qtractorPluginFile (sFilename );
130130 g_files.insert (pFile->filename (), pFile);
131131 }
132132
133- if (pFile && !pFile->open ())
133+ if (pFile && !pFile->open ()) {
134+ g_files.remove (pFile->filename ());
135+ delete pFile;
134136 pFile = nullptr ;
137+ }
135138
136139 if (pFile)
137140 pFile->addRef ();
@@ -149,6 +152,14 @@ void qtractorPluginFile::removeFile ( qtractorPluginFile *pFile )
149152}
150153
151154
155+ void qtractorPluginFile::clearAll (void )
156+ {
157+ qDeleteAll (g_files.values ());
158+
159+ g_files.clear ();
160+ }
161+
162+
152163// ----------------------------------------------------------------------------
153164// qtractorPluginType -- Plugin type instance.
154165//
@@ -1605,12 +1616,14 @@ bool qtractorPlugin::savePlugin (
16051616 freezeValues ();
16061617
16071618 qtractorPluginType *pType = type ();
1619+ const qtractorPluginType::Hint typeHint
1620+ = pType->typeHint ();
16081621 pElement->setAttribute (" type" ,
1609- qtractorPluginType::textFromHint (pType-> typeHint () ));
1622+ qtractorPluginType::textFromHint (typeHint));
16101623
16111624 // Pseudo-plugins don't have a file...
1612- const QString& sFilename = pType->filename ();
1613- if (! sFilename . isEmpty ( )) {
1625+ QString sFilename = pType->filename ();
1626+ if (savePluginFilename ( sFilename , typeHint )) {
16141627 pDocument->saveTextElement (" filename" ,
16151628 sFilename , pElement);
16161629 }
@@ -1717,6 +1730,38 @@ bool qtractorPlugin::savePluginEx (
17171730}
17181731
17191732
1733+ // Check/sanitize plugin file-path to save (absolute->relative)...
1734+ bool qtractorPlugin::savePluginFilename (
1735+ QString& sFilename , qtractorPluginType::Hint typeHint ) const
1736+ {
1737+ // Care of internal pseudo-plugins...
1738+ if (sFilename .isEmpty ())
1739+ return false ;
1740+
1741+ // LV2 plug-ins are identified by URI...
1742+ if (typeHint == qtractorPluginType::Lv2)
1743+ return true ;
1744+
1745+ // Search for a match with
1746+ // one of the plugin search paths...
1747+ qtractorPluginFactory *pPluginFactory
1748+ = qtractorPluginFactory::getInstance ();
1749+ if (pPluginFactory) {
1750+ QStringListIterator iter (pPluginFactory->pluginPaths (typeHint));
1751+ while (iter.hasNext ()) {
1752+ const QString spath = iter.next ();
1753+ if (sFilename .indexOf (spath) == 0 ) {
1754+ sFilename .remove (0 , spath.length () + 1 ); // include trailing slash!
1755+ return true ;
1756+ }
1757+ }
1758+ }
1759+
1760+ // No match is found, leave it unchanged...
1761+ return true ;
1762+ }
1763+
1764+
17201765// ----------------------------------------------------------------------------
17211766// qtractorPlugin::Param -- Plugin parameter (control input port) instance.
17221767//
@@ -2320,7 +2365,7 @@ qtractorPlugin *qtractorPluginList::loadPlugin ( QDomElement *pElement )
23202365 int iEditorType = -1 ;
23212366
23222367 const QString& sTypeHint = pElement->attribute (" type" );
2323- qtractorPluginType::Hint typeHint
2368+ const qtractorPluginType::Hint typeHint
23242369 = qtractorPluginType::hintFromText (sTypeHint );
23252370 for (QDomNode nParam = pElement->firstChild ();
23262371 !nParam.isNull ();
@@ -2396,7 +2441,7 @@ qtractorPlugin *qtractorPluginList::loadPlugin ( QDomElement *pElement )
23962441 }
23972442
23982443 // Try to find some alternative, if it doesn't exist...
2399- if (checkPluginFile (sFilename , typeHint)) {
2444+ if (loadPluginFilename (sFilename , typeHint)) {
24002445 pPlugin = qtractorPluginFactory::createPlugin (this ,
24012446 sFilename , iIndex, typeHint);
24022447 }
@@ -2639,8 +2684,8 @@ bool qtractorPluginList::isAutoDeactivated (void) const
26392684}
26402685
26412686
2642- // Check/sanitize plugin file-path;
2643- bool qtractorPluginList::checkPluginFile (
2687+ // Check/sanitize plugin file-path to load (relative->absolute)...
2688+ bool qtractorPluginList::loadPluginFilename (
26442689 QString& sFilename , qtractorPluginType::Hint typeHint ) const
26452690{
26462691 // Care of internal pseudo-plugins...
@@ -2654,17 +2699,17 @@ bool qtractorPluginList::checkPluginFile (
26542699 if (typeHint == qtractorPluginType::Lv2)
26552700 return true ;
26562701
2657- // Primary check for plugin pathname ...
2702+ // Check for the original plugin path ...
26582703 QFileInfo fi (sFilename );
26592704 if (fi.exists () && fi.isReadable ())
26602705 return true ;
26612706
26622707 // Otherwise search for an alternative
2663- // under each respective search paths...
2708+ // under one of the plugin search paths...
26642709 qtractorPluginFactory *pPluginFactory
26652710 = qtractorPluginFactory::getInstance ();
26662711 if (pPluginFactory) {
2667- const QString fname = fi.fileName ();
2712+ const QString& fname = ( fi.isRelative () ? sFilename : fi. fileName () );
26682713 QStringListIterator iter (pPluginFactory->pluginPaths (typeHint));
26692714 while (iter.hasNext ()) {
26702715 fi.setFile (QDir (iter.next ()), fname);
0 commit comments