OCStackResult PIStartPlugin(const char * comPort, PIPluginType pluginType, PIPlugin ** plugin)
{
    if (!plugin || !comPort || strlen(comPort) == 0)
    {
        return OC_STACK_INVALID_PARAM;
    }
    OCStackResult result = OC_STACK_ERROR;
    if (pluginType == PLUGIN_ZIGBEE)
    {
        result = ZigbeeInit(comPort,
                            (PIPlugin_Zigbee **) plugin,
                            piNewResourceCB,
                            piObserveNotificationUpdate);
        if (result != OC_STACK_OK)
        {
            return result;
        }
        if (!*plugin)
        {
            return OC_STACK_ERROR;
        }
        result = AddPlugin((PIPluginBase *)*plugin);
        if(result != OC_STACK_OK)
        {
            return result;
        }
    }
    return result;
}
Exemple #2
0
BOOL CMediaVisDlg::OnInitDialog()
{
	CString strMessage;

	CSkinDialog::OnInitDialog();

	SkinMe( L"CMediaVisDlg", ID_MEDIA_VIS );

	CRect rc;
	m_wndList.GetClientRect( &rc );
	rc.right -= GetSystemMetrics( SM_CXVSCROLL ) + 1;

	CoolInterface.SetImageListTo( m_wndList, LVSIL_SMALL );
	m_wndList.InsertColumn( 0, L"Description", LVCFMT_LEFT, rc.right, -1 );
	m_wndList.InsertColumn( 1, L"CLSID", LVCFMT_LEFT, 0, 0 );
	m_wndList.InsertColumn( 2, L"Subpath", LVCFMT_LEFT, 0, 1 );

	m_wndList.SetExtendedStyle( LVS_EX_FULLROWSELECT );

	m_nIcon = CoolInterface.ImageForID( ID_MEDIA_VIS );
	m_hIcon = CoolInterface.ExtractIcon( ID_MEDIA_VIS, FALSE );
	if ( m_hIcon )
		SetIcon( m_hIcon, FALSE );

	LoadString( strMessage, IDS_MEDIAVIS_NOVIS );
	AddPlugin( strMessage, NULL, NULL );
	Enumerate();

	m_nSize = Settings.MediaPlayer.VisSize + 1;
	UpdateData( FALSE );

	m_wndSetup.EnableWindow( m_wndList.GetSelectedCount() == 1 );

	return TRUE;
}
Exemple #3
0
void cPluginManager::AddPlugin(const char *Args)
{
  if (strcmp(Args, "*") == 0) {
     cReadDir d(directory);
     struct dirent *e;
     while ((e = d.Next()) != NULL) {
           if (strstr(e->d_name, LIBVDR_PREFIX) == e->d_name) {
              char *p = strstr(e->d_name, SO_INDICATOR);
              if (p) {
                 *p = 0;
                 p += strlen(SO_INDICATOR);
                 if (strcmp(p, APIVERSION) == 0) {
                    char *name = e->d_name + strlen(LIBVDR_PREFIX);
                    if (strcmp(name, "*") != 0) { // let's not get into a loop!
                       AddPlugin(e->d_name + strlen(LIBVDR_PREFIX));
                       }
                    }
                 }
              }
           }
     return;
     }
  char *s = strdup(skipspace(Args));
  char *p = strchr(s, ' ');
  if (p)
     *p = 0;
  char *buffer = NULL;
  asprintf(&buffer, "%s/%s%s%s%s", directory, LIBVDR_PREFIX, s, SO_INDICATOR, APIVERSION);
  dlls.Add(new cDll(buffer, Args));
  free(buffer);
  free(s);
}
/**	VirtualFS constructor
 *
 *	Sets the subsystems name and file it was loaded from (The filename of the DLL module)
 *	Obtains a ptr to Fusions Module Database
 */
VirtualFS::VirtualFS()
{
	object_name			= "VirtualFS Version 2.0 <*****@*****.**>";
	object_filename	= "libVFS.dll";

	m_moduledb	=	fusion->GetModuleDB();

	m_tempdir		=	NULL;

	//	Add all the built in formats, pure text and pure binary are defaults
	AddPlugin(CreateTextPlugin);
	AddPlugin(CreateBinaryPlugin);
	
	//	Setup all the built in transports
	AddTransport(CreateFileTransport);
}
void CPCMReaderFactory::AddPlugin(const string& strPluginFilename)
{
    //	マルチスレッド対応〜
    m_vCS.Enter();
    AddPlugin(smart_ptr<CAudioPlugin>(new CAudioPlugin(strPluginFilename),true));
    m_vCS.Leave();
}
Exemple #6
0
BOOL CMediaVisDlg::EnumerateWrapped(LPCTSTR pszName, REFCLSID pCLSID, LPCTSTR pszCLSID)
{
	IWrappedPluginControl* pPlugin = NULL;

	HINSTANCE hRes = AfxGetResourceHandle();

	HRESULT hr = CoCreateInstance( pCLSID, NULL, CLSCTX_ALL,
		IID_IWrappedPluginControl, (void**)&pPlugin );

	AfxSetResourceHandle( hRes );

	if ( FAILED(hr) || pPlugin == NULL ) return FALSE;

	LPSAFEARRAY pArray = NULL;
	hr = pPlugin->Enumerate( &pArray );

	pPlugin->Release();

	if ( FAILED(hr) || pArray == NULL ) return FALSE;

	LONG pIndex[2] = { 0, 0 };
	SafeArrayGetUBound( pArray, 2, &pIndex[1] );

	if ( pIndex[1] < 0 )
	{
		SafeArrayDestroy( pArray );
		return TRUE;
	}

	for ( ; pIndex[1] >= 0; pIndex[1]-- )
	{
		CString strName, strPath;
		BSTR bsValue = NULL;

		strName = pszName;
		strName += L": ";

		pIndex[0] = 0;
		SafeArrayGetElement( pArray, pIndex, &bsValue );
		strName += bsValue;
		SysFreeString( bsValue );
		bsValue = NULL;

		pIndex[0] = 1;
		SafeArrayGetElement( pArray, pIndex, &bsValue );
		strPath = bsValue;
		SysFreeString( bsValue );
		bsValue = NULL;

		AddPlugin( strName, pszCLSID, strPath );
	}

	SafeArrayDestroy( pArray );

	return TRUE;
}
   std::set<ComponentType> ComponentPluginManager::AddPlugin(const std::string& path, const std::string& libname, bool saveWithScene)
   {      
      std::string filename = GetSharedLibNameFromPluginName(libname);
      std::string p = path + "/" + filename;
      if(!GetSystemInterface()->FileExists(p))
      {
         std::set<ComponentType> ret;
         return ret;
      }

      return AddPlugin(p, saveWithScene);
   }
void CMediaVisDlg::Enumerate()
{
	CWaitCursor pCursor;
	HKEY hKey;

	if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
		_T("Software\\Shareaza\\Shareaza\\Plugins\\AudioVis"),
		NULL, KEY_READ, &hKey ) != ERROR_SUCCESS ) return;

	for ( DWORD nKey = 0 ; ; nKey++ )
	{
		DWORD dwType, dwName = sizeof(TCHAR) * 128, dwCLSID = 64 * sizeof(TCHAR);
		TCHAR szName[128], szCLSID[64];

		if ( RegEnumValue( hKey, nKey, szName, &dwName, NULL, &dwType, (LPBYTE)szCLSID, &dwCLSID )
			 != ERROR_SUCCESS ) break;

		if ( dwType != REG_SZ || dwCLSID / sizeof(TCHAR) != 39 || szCLSID[0] != '{' || szName[0] == '{' ) continue;
		szCLSID[ 38 ] = 0;

		CLSID pCLSID;
		if ( ! GUIDX::Decode( szCLSID, &pCLSID ) ) continue;
		if ( ! Plugins.LookupEnable( pCLSID, TRUE ) ) continue;

		if ( _tcsistr( szName, _T("wrap") ) )
		{
			if ( ! EnumerateWrapped( szName, pCLSID, szCLSID ) )
			{
				AddPlugin( szName, szCLSID, NULL );
			}
		}
		else
		{
			AddPlugin( szName, szCLSID, NULL );
		}
	}

	RegCloseKey( hKey );
}
Exemple #9
0
void CMediaVisDlg::Enumerate()
{
	CWaitCursor pCursor;
	HKEY hKey;

	if ( RegOpenKeyEx( HKEY_CURRENT_USER,
		REGISTRY_KEY _T("\\Plugins\\AudioVis"),
		NULL, KEY_READ, &hKey ) != ERROR_SUCCESS ) return;

	for ( DWORD nKey = 0 ; ; nKey++ )
	{
		DWORD dwType, dwName = 256, dwCLSID = 64 * sizeof(TCHAR);
		TCHAR szName[256], szCLSID[64];

		if ( RegEnumValue( hKey, nKey, szName, &dwName, NULL, &dwType, (LPBYTE)szCLSID, &dwCLSID )
			 != ERROR_SUCCESS ) break;

		if ( dwType != REG_SZ || dwCLSID / sizeof(TCHAR) != 39 || szCLSID[0] != '{' || szName[0] == '{' ) continue;
		szCLSID[ 38 ] = 0;

		CLSID pCLSID;
		if ( ! Hashes::fromGuid( szCLSID, &pCLSID ) ) continue;
		if ( ! Plugins.LookupEnable( pCLSID ) ) continue;

		if ( _tcsistr( szName, _T("wrap") ) )
		{
			if ( ! EnumerateWrapped( szName, pCLSID, szCLSID ) )
			{
				AddPlugin( szName, szCLSID, NULL );
			}
		}
		else
		{
			AddPlugin( szName, szCLSID, NULL );
		}
	}

	RegCloseKey( hKey );
}
        PluginPtr Application::LoadPlugin( const std::wstring& filename )
        {            
            fs::wpath filePath( filename );
            fs::wpath pluginName = filePath.stem();
            PluginPtr pluginPtr = GetPluginByName( pluginName.wstring() );

            if ( !pluginPtr )
            {
                // Try to load the dynamic lib from the provided filename.
                DynamicLibPtr pluginLib = m_DynamicLibSubsystem->Load( filename );
                if ( pluginLib )
                {
                    CreatePluginFP createPluginFunc = (CreatePluginFP)pluginLib->GetSymbol( "CreatePlugin" );
                    if ( createPluginFunc != NULL )
                    {
                        pluginPtr = createPluginFunc();
                        if ( pluginPtr != NULL )
                        {
                            pluginPtr->FileName = filePath.wstring();
                            pluginPtr->PluginName = filePath.stem().wstring();
                            if ( m_IsInitialized )
                            {
                                pluginPtr->Initialize();
                            }

                            AddPlugin( pluginPtr );
                        }
                        else
                        {
                            std::cerr << "Application::LoadPlugin: Plug-in creation failed in library \"";
                            std::wcerr << filename;
                            std::wcerr << "\"" << std::endl;
                        }
                    }
                    else
                    {

                        std::cerr << "Application::LoadPlugin: Could not find symbol \"CreatePlugin\" in library \"";
                        std::wcerr << filename;
                        std::cerr << "\"" << std::endl;
                    }
                }
            }

            return pluginPtr;
        }
   /** load all dlls in dir and check for plugin factories */
   void ComponentPluginManager::LoadPluginsInDir(const std::string& path)
   {
      std::string cleanedPath(path);
      if (path[path.size() - 1] == GetNativePathSeparator())
      {
         // remove the trailing path separator as this causes issues...
         cleanedPath = path.substr(0, path.size() - 1);
      }

      if(!GetSystemInterface()->FileExists(cleanedPath))
      {
         LOG_ALWAYS("Plugin folder not found! Path: " + cleanedPath);
         return;
      }

      std::string libExtension = GetLibExtension();
      LOG_DEBUG("Looking for plugins with extension: " + libExtension);

      // get libs from directory
      SystemInterface::DirectoryContents files = GetSystemInterface()->GetDirectoryContents(cleanedPath);

      // for each library in dir
      SystemInterface::DirectoryContents::const_iterator i;
      for(i = files.begin(); i != files.end(); ++i)
      {
         std::string fileName = *i;

         if(fileName.size() <= libExtension.size())
            continue;

         std::string ending = fileName.substr(fileName.size() - libExtension.size(), fileName.size());
         if(ending.compare(libExtension) != 0)
         {
            continue;
         }

         std::ostringstream libpath;
         libpath << cleanedPath << GetNativePathSeparator() << fileName;
         AddPlugin(libpath.str());
         LOG_DEBUG("Loaded plugin: " + libpath.str());
      }
   }
void CaqExtensionRegistrator::AddPlugin(const PLUGIN_CREATION_PROC PluginCreator,
                                        const GUID&                Key,
                                        const ATL::CComBSTR&       Name,
                                        const ATL::CComBSTR&       Description,
                                        const AQ_PLUGIN_VERSION&   Version,
                                              BOOL                 DefaultSelected,
                                        const GUID_VECTOR&         Conflicts,
                                        const GUID_VECTOR&         Depends)
{
	CRegPluginInfo reg_info;
	reg_info.PluginCreator   = PluginCreator;
	reg_info.Key             = Key;
	reg_info.Name            = Name;
	reg_info.Description     = Description;
	reg_info.Version         = Version;
	reg_info.DefaultSelected = DefaultSelected;
	reg_info.Conflicts       = Conflicts;
	reg_info.Depends         = Depends;

	AddPlugin(&reg_info);
}
Exemple #13
0
Wizard::Wizard(Application* app, LibraryBackend* library, QWidget* parent)
  : QWizard(parent),
    app_(app),
    library_(library),
    type_page_(new TypePage(this)),
    finish_page_(new FinishPage(this)),
    type_index_(-1),
    type_mapper_(new QSignalMapper(this))
{
  setWindowIcon(QIcon(":/icon.png"));
  setWindowTitle(tr("Smart playlist"));
  resize(788, 628);

#ifdef Q_OS_MAC
  // MacStyle leaves an ugly empty space on the left side of the dialog.
  setWizardStyle(QWizard::ClassicStyle);
#endif // Q_OS_MAC

  // Type page
  type_page_->setTitle(tr("Playlist type"));
  type_page_->setSubTitle(tr("A smart playlist is a dynamic list of songs that come from your library.  There are different types of smart playlist that offer different ways of selecting songs."));
  type_page_->setStyleSheet(
        "QRadioButton { font-weight: bold; }"
        "QLabel { margin-bottom: 1em; margin-left: 24px; }");
  addPage(type_page_);

  // Finish page
  finish_page_->setTitle(tr("Finish"));
  finish_page_->setSubTitle(tr("Choose a name for your smart playlist"));
  finish_id_ = addPage(finish_page_);

  connect(type_mapper_, SIGNAL(mapped(int)), SLOT(TypeChanged(int)));

  new QVBoxLayout(type_page_);
  AddPlugin(new QueryWizardPlugin(app_, library_, this));

  // Skip the type page - remove this when we have more than one type
  setStartId(2);
}
MuninPluginManager::MuninPluginManager()
{
  if (g_Config.GetValueB("Plugins", "Disk", true))
    AddPlugin(new DiskMuninNodePlugin());
  if (g_Config.GetValueB("Plugins", "DiskTime", true))
	AddPlugin(new DiskTimeMuninNodePlugin());
  if (g_Config.GetValueB("Plugins", "Memory", true))
    AddPlugin(new MemoryMuninNodePlugin());
 if (g_Config.GetValueB("Plugins", "Processes", true))
    AddPlugin(new ProcessesMuninNodePlugin());
  if (g_Config.GetValueB("Plugins", "Network", true))
    AddPlugin(new NetworkMuninNodePlugin());
  if (g_Config.GetValueB("Plugins", "If", true))
    AddPlugin(new IfMuninNodePlugin());
  if (g_Config.GetValueB("Plugins", "Interrupts", true))
    AddPlugin(new InterruptsMuninNodePlugin());
  if (g_Config.GetValueB("Plugins", "IoBytes", true))
    AddPlugin(new IoBytesMuninNodePlugin());
  if (g_Config.GetValueB("Plugins", "IoOperation", true))
    AddPlugin(new IoOperationMuninNodePlugin());
  if (g_Config.GetValueB("Plugins", "Ping", true))
  {
    size_t pingCount = g_Config.NumValues("PingPlugin");
    for (size_t i = 0; i < pingCount; i++) {
      std::string valueName = g_Config.GetValueName("PingPlugin", i); 
      std::string hostname = g_Config.GetValue("PingPlugin", valueName);
      PingMuninNodePlugin *plugin = new PingMuninNodePlugin(hostname);
      if (plugin->IsLoaded()) {
        AddPlugin(plugin);
      } else {
        _Module.LogEvent("Failed to load Ping plugin: %s", hostname.c_str());
        delete plugin;
      }
    }
  }
  if (g_Config.GetValueB("Plugins", "Processes", true))
    AddPlugin(new ProcessesMuninNodePlugin());
  if (g_Config.GetValueB("Plugins", "Swap", true))
    AddPlugin(new SwapMuninNodePlugin());
  if (g_Config.GetValueB("Plugins", "Uptime", true))
    AddPlugin(new UptimeMuninNodePlugin());
  
  if (g_Config.GetValueB("Plugins", "MbmTemp", true))
    AddPlugin(new MBMMuninNodePlugin(mbm::stTemperature));
  if (g_Config.GetValueB("Plugins", "MbmVoltage", true))
    AddPlugin(new MBMMuninNodePlugin(mbm::stVoltage));
  if (g_Config.GetValueB("Plugins", "MbmFan", true))
    AddPlugin(new MBMMuninNodePlugin(mbm::stFan));
  if (g_Config.GetValueB("Plugins", "MbmMhz", true))
    AddPlugin(new MBMMuninNodePlugin(mbm::stMhz));
  
  if (g_Config.GetValueB("Plugins", "Cpu", true))
    AddPlugin(new CpuMuninNodePlugin());
  if (g_Config.GetValueB("Plugins", "HD", true))
    AddPlugin(new HDMuninNodePlugin());

  if (g_Config.GetValueB("Plugins", "SMART", false))
    AddPlugin(new SMARTMuninNodePlugin());
  
  if (g_Config.GetValueB("Plugins", "SpeedFan", false))
    AddPlugin(new SpeedFanNodePlugin());
  
  if (g_Config.GetValueB("Plugins", "External", true)) {
    int externalTimeout = g_Config.GetValueI("Plugins", "ExternalTimeout", 0);
    size_t externalCount = g_Config.NumValues("ExternalPlugin");
    for (size_t i = 0; i < externalCount; i++) {
      std::string valueName = g_Config.GetValueName("ExternalPlugin", i); 
      std::string filename = g_Config.GetValue("ExternalPlugin", valueName);
      ExternalMuninNodePlugin *plugin = new ExternalMuninNodePlugin(filename, externalTimeout);
      if (plugin->IsLoaded()) {
		  AddPlugin(plugin);
      } else {
        _Module.LogError("Failed to load External plugin: %s", filename.c_str());
        delete plugin;
      }
    }
  }

  const char *perfPrefix = PerfCounterMuninNodePlugin::SectionPrefix;
  size_t perfPrefixLen = strlen(perfPrefix);
  for (size_t i = 0; i < g_Config.GetNumKeys(); i++) {
    std::string keyName = g_Config.GetKeyName(i);
    if (keyName.compare(0, perfPrefixLen, perfPrefix) == 0) {
      PerfCounterMuninNodePlugin *plugin = new PerfCounterMuninNodePlugin(keyName);
      if (plugin->IsLoaded()) {
        AddPlugin(plugin);
      } else {
        _Module.LogError("Failed to load PerfCounter plugin: [%s]", keyName.c_str());
        delete plugin;
      }
    }
  }
  
#ifdef _DEBUG
  t = new MuninPluginManagerTestThread(this);
  t->JCThread_AddRef();
  t->Run();  
#endif
}
Exemple #15
0
bool cPluginManager::LoadPlugin(const AString & a_PluginName)
{
	return AddPlugin(new cPluginLua(a_PluginName.c_str()));
}
void VirtualFS::LoadPlugin(VFSTransport::transport_t t, VFSPlugin::plugin_t p, VFSFilter::filter_t f)
{
	AddTransport(t);
	AddPlugin(p);
	AddFilter(f);
}
Exemple #17
0
void CApplication::LoadPlugins()
{
	IPlugin **pp = g_BuiltInPlugins;
	while(*pp)
	{
		AddPlugin(*pp);
		pp ++;
	}

	tstring plgdir, plgmask, path;
	WIN32_FIND_DATA fd;
	HANDLE hfind;
	HINSTANCE hlib;
	IPlugin *pplg;

	m_pConfig->SetPlugin(APP_CFG_PLUGINNAME);

	plgdir = m_pConfig->GetStringValue(APP_CFG_PLUGINSPATH, APP_DEFAULT_PLUGINSPATH);
	plgmask = m_pConfig->GetStringValue(APP_CFG_PLUGINSMASK, APP_DEFAULT_PLUGINSMASK);
	path = plgdir;
	path += plgmask;
	hfind = FindFirstFile(path.c_str(), &fd);
	if(INVALID_HANDLE_VALUE != hfind)
	{
		do
		{
			path.resize(plgdir.size());
			path += fd.cFileName;

			hlib = LoadLibrary(path.c_str());
			if(NULL == hlib)
			{
				// TODO: log error
				continue;
			}

			GETPLUGINPROC proc =
				reinterpret_cast<GETPLUGINPROC>(GetProcAddress(hlib, PLUGIN_PROC_NAME));
			if(NULL == proc)
			{
				// TODO: log error
				FreeLibrary(hlib);
				continue;
			}

			pplg = proc();
			if(NULL == pplg)
			{
				// TODO: log error
				FreeLibrary(hlib);
				continue;
			}

			AddPlugin(pplg);
			m_PluginLibraries.push_back(hlib);
		}
		while(FindNextFile(hfind, &fd));

		FindClose(hfind);
	}
}
BOOL OpenThemeClass(HWND hwnd, char szFilename[], CBZDATA * pCBZData, char szClassName[])
{
    PLUGIN_LIST List;
    char szError[128], tempText[64];
    int i, i2, index;
    HWND hwndControl;
    PAPPLYFN pApplyFn;

    if (!runParser(szFilename, szClassName, &List, szError))
    {
        PSUTErrorFunc(NULLHANDLE, "Error", "OpenThemeClass", szError, 0UL);
        return FALSE;
    }

    //Clear the current selected plugins by placing them back into the
    // AvailablePlugins ListBox
    hwndControl = WinWindowFromID(hwnd, LBID_SELECTEDPLUGINS);
    index = (SHORT) WinSendMsg(hwndControl, LM_QUERYITEMCOUNT,
                               MPFROMLONG(0),
                               MPFROMLONG(0));
    for (i = 0; i < index; i++)
    {
        hwndControl = WinWindowFromID(hwnd, LBID_SELECTEDPLUGINS);

        //Save the text so it can be added to Available Plugin Listbox
        WinSendMsg(hwndControl, LM_QUERYITEMTEXT,
                   MPFROM2SHORT((SHORT) 0, 64),
                   MPFROMP((PSZ) tempText));
        //remove item from Selected Plugin ListBox
        WinSendMsg(hwndControl, LM_DELETEITEM,
                   MPFROMSHORT((SHORT) 0),
                   MPFROMLONG(0));

        //Add the item to the Available Plugins ListBox
        hwndControl = WinWindowFromID(hwnd, LBID_AVAILABLEPLUGINS);
        i2 = (SHORT) WinSendMsg(hwndControl, LM_INSERTITEM,
                                MPFROMSHORT((SHORT) LIT_SORTASCENDING),
                                MPFROMP((PSZ) tempText));

        //Add the dll name to the AvailablePluginsDLL ListBox at the correct index
        strcpy(tempText, pCBZData->Plugins[0].szPluginDLL);
        hwndControl = WinWindowFromID(hwnd, LBID_AVAILABLEPLUGINDLLS);
        WinSendMsg(hwndControl, LM_INSERTITEM,
                   MPFROMSHORT((SHORT) i2),
                   MPFROMP((PSZ) tempText));

        //remove the plugin from the pTBData structure
        if (!RemovePlugin(pCBZData, 0))
        {
            PSUTErrorFunc(hwnd,
                          "Error",
                          "OpenThemeClass",
                          "Error Removing Plugin!",
                          0UL);
            //Put it back in Selected Plugin ListBox?
            break;
        }

    }

    //Try selecting each plugin from the themeFile out of the AvailablePlugins ListBox
    for (i = 0; i < List.cbPlugins; i++)
    {
        hwndControl = WinWindowFromID(hwnd, LBID_AVAILABLEPLUGINDLLS);
        //find the index of the plugin in the AvailablePlugins ListBox
        index = (SHORT) WinSendMsg(hwndControl, LM_SEARCHSTRING,
                                   MPFROM2SHORT(LSS_CASESENSITIVE, LIT_FIRST),
                                   MPFROMP(List.pPluginAttributes[i].szPluginName));

        if (index == LIT_NONE)  //Plugin not found

        {
            PSUTErrorFunc(hwnd,
                          "Error",
                          "OpenThemeClass - Plugin Not Found",
                          List.pPluginAttributes[i].szPluginName,
                          0UL);
            break;
        }

        hwndControl = WinWindowFromID(hwnd, LBID_AVAILABLEPLUGINS);
        //Get the text from the Available Plugin ListBox
        WinSendMsg(hwndControl, LM_QUERYITEMTEXT,
                   MPFROM2SHORT((SHORT) index, 64),
                   MPFROMP((PSZ) tempText));
        //remove the selected item from the Available Plugins ListBox
        WinSendMsg(hwndControl, LM_DELETEITEM,
                   MPFROMSHORT((SHORT) index),
                   MPFROMLONG(0));

        //Add the queried text to the Selected Plugin ListBox
        hwndControl = WinWindowFromID(hwnd, LBID_SELECTEDPLUGINS);
        i2 = (SHORT) WinSendMsg(hwndControl, LM_INSERTITEM,
                                MPFROMSHORT((SHORT) LIT_END),
                                MPFROMP((PSZ) tempText));

        //Get the selected plugin DLL name from the AvailablePluginDLLS listbox
        hwndControl = WinWindowFromID(hwnd, LBID_AVAILABLEPLUGINDLLS);
        WinSendMsg(hwndControl, LM_QUERYITEMTEXT,
                   MPFROM2SHORT((SHORT) index, 64),
                   MPFROMP((PSZ) tempText));
        //remove it from the AvailablePluginDLLS listbox
        WinSendMsg(hwndControl, LM_DELETEITEM,
                   MPFROMSHORT((SHORT) index),
                   MPFROMLONG(0));

        if (!AddPlugin(hwnd, pCBZData, List.pPluginAttributes[i].szPluginName, ""))
        {
            //Error in AddPlugin... Put the plugin back into AvailableListbox?
            DosBeep(500, 50);
        }

        if (DosQueryProcAddr(pCBZData->Plugins[pCBZData->cbPlugins - 1].hModDll,
                             0, "CBZApply", (PFN *) & pApplyFn) == NO_ERROR)
        {
            //check return code from this to make sure it was sucessful.. if not disable the plugin
            pApplyFn(szClassName, (List.pPluginAttributes[i].keyValue),
                     List.pPluginAttributes[i].cbAttributes,
                     List.pPluginAttributes[i].enabledState,
                     pCBZData->Plugins[i].pData);
        }
        else
        {
            PSUTErrorFunc(NULLHANDLE, "Error", "ApplyPreviewBlock", "Failed Querying Procedure Address for CBZApply", 0UL);
        }
    }

    CBZFreePLUGIN_LIST(&List);
    return TRUE;
}
Exemple #19
0
// Create an instance of a plugin.
bool CVstPluginManager::CreateMixPlugin(SNDMIXPLUGIN &mixPlugin, CSoundFile &sndFile)
//-----------------------------------------------------------------------------------
{
	VSTPluginLib *pFound = nullptr;

	// Find plugin in library
	int match = 0;
	for(const_iterator p = begin(); p != end(); p++)
	{
		VSTPluginLib *plug = *p;
		const bool matchID = (plug->pluginId1 == mixPlugin.Info.dwPluginId1)
			&& (plug->pluginId2 == mixPlugin.Info.dwPluginId2);
		const bool matchName = !mpt::PathString::CompareNoCase(plug->libraryName, mpt::PathString::FromUTF8(mixPlugin.GetLibraryName()));

		if(matchID && matchName)
		{
			pFound = plug;
			break;
		} else if(matchID && match < 2)
		{
			match = 2;
			pFound = plug;
		} else if(matchName && match < 1)
		{
			match = 1;
			pFound = plug;
		}
	}

	if(mixPlugin.Info.dwPluginId1 == kDmoMagic)
	{
		if (!pFound) return false;
		AEffect *pEffect = DmoToVst(*pFound);
		if(pEffect && pEffect->magic == kDmoMagic)
		{
			CVstPlugin *pVstPlug = new (std::nothrow) CVstPlugin(nullptr, *pFound, mixPlugin, *pEffect, sndFile);
			return pVstPlug != nullptr;
		}
	}

	if(!pFound && strcmp(mixPlugin.GetLibraryName(), ""))
	{
		// Try finding the plugin DLL in the plugin directory or plugin cache instead.
		mpt::PathString fullPath = TrackerDirectories::Instance().GetDefaultDirectory(DIR_PLUGINS);
		if(fullPath.empty())
		{
			fullPath = theApp.GetAppDirPath() + MPT_PATHSTRING("Plugins\\");
		}
		fullPath += mpt::PathString::FromUTF8(mixPlugin.GetLibraryName()) + MPT_PATHSTRING(".dll");

		pFound = AddPlugin(fullPath);
		if(!pFound)
		{
			// Try plugin cache (search for library name)
			SettingsContainer &cacheFile = theApp.GetPluginCache();
			std::string IDs = cacheFile.Read<std::string>(cacheSectionW, mpt::ToWide(mpt::CharsetUTF8, mixPlugin.GetLibraryName()), "");
			if(IDs.length() >= 16)
			{
				fullPath = cacheFile.Read<mpt::PathString>(cacheSection, IDs, MPT_PATHSTRING(""));
				if(!fullPath.empty())
				{
					fullPath = theApp.RelativePathToAbsolute(fullPath);
					if(PathFileExistsW(fullPath.AsNative().c_str()))
					{
						pFound = AddPlugin(fullPath);
					}
				}
			}
		}
	}

	if(pFound)
	{
		AEffect *pEffect = nullptr;
		HINSTANCE hLibrary = nullptr;
		bool validPlugin = false;

		try
		{
			pEffect = LoadPlugin(pFound->dllPath, hLibrary);

			if(pEffect != nullptr && pEffect->dispatcher != nullptr && pEffect->magic == kEffectMagic)
			{
				validPlugin = true;

				const bool oldIsInstrument = pFound->isInstrument;
				const VSTPluginLib::PluginCategory oldCategory = pFound->category;

				GetPluginInformation(pEffect, *pFound);

				if(oldIsInstrument != pFound->isInstrument || oldCategory != pFound->category)
				{
					// Update cached information
					WriteToCache(*pFound);
				}

				CVstPlugin *pVstPlug = new (std::nothrow) CVstPlugin(hLibrary, *pFound, mixPlugin, *pEffect, sndFile);
				if(pVstPlug == nullptr)
				{
					validPlugin = false;
				}
			}

			if(!validPlugin)
			{
				FreeLibrary(hLibrary);
			}
		} catch(...)
		{
			CVstPluginManager::ReportPlugException(mpt::String::PrintW(L"Exception while trying to create plugin \"%1\"!\n", pFound->libraryName));
		}

		return validPlugin;
	} else
	{
		// "plug not found" notification code MOVED to CSoundFile::Create
#ifdef VST_LOG
		Log("Unknown plugin\n");
#endif
	}
	return false;
}