Beispiel #1
0
void LoadModule(wxString fname)
{
   wxLogDebug(wxT("About to load module %s"), fname.c_str());
   tModuleInit mainFn = NULL;
#if defined(__WXMAC__)
   wxLogNull logNo;
#endif

   // As a courtesy to some modules that might be bridges to
   // open other modules, we set the current working
   // directory to be the module's directory.

   wxString saveOldCWD = ::wxGetCwd();
   wxString prefix = ::wxPathOnly(fname);
   ::wxSetWorkingDirectory(prefix);

   wxDynamicLibrary* pDLL = new wxDynamicLibrary();
   if (pDLL && pDLL->Load(fname, wxDL_LAZY)) 
   {
      int result = 1;
      mainFn   = (tModuleInit)(pDLL->GetSymbol(wxT(initFnName)));

      if (mainFn) 
         result = mainFn( 0 );

      // If the module provides a version string, check that it matches the
      // Audacity version string. (For now, they must match exactly)
      // For compatibility reasons, if no version string is provided we try to
      // load the module anyway.
      tVersionFn versionFn = (tVersionFn)(pDLL->GetSymbol(wxT(versionFnName)));
      if (versionFn)
      {
         wxString moduleVersion = versionFn();
         if (!moduleVersion.IsSameAs(AUDACITY_VERSION_STRING))
         {
            wxLogError(wxT("The module %s is designed to work with Audacity version %s; it will not be loaded."), fname.c_str(), moduleVersion.c_str());
            delete pDLL;
            return;
         }
      }
      else
      {
         wxLogWarning(wxT("The module %s does not provide a version string. Attempting to load it anyway."), fname.c_str());
      }

      if(( scriptFn == NULL ) &&(result>=0 ))
         scriptFn = (tpRegScriptServerFunc)(pDLL->GetSymbol(wxT(scriptFnName)));

      if((pPanelHijack==NULL ) && (result>=0))
         pPanelHijack = (tPanelFn)(pDLL->GetSymbol(wxT(mainPanelFnName)));
   }

   ::wxSetWorkingDirectory(saveOldCWD);
}
Beispiel #2
0
bool Module::Load()
{
   if (mLib->IsLoaded()) {
      if (mDispatch) {
         return true;
      }
      return false;
   }

   if (!mLib->Load(mName, wxDL_LAZY)) {
      return false;
   }

   // Check version string matches.  (For now, they must match exactly)
   tVersionFn versionFn = (tVersionFn)(mLib->GetSymbol(wxT(versionFnName)));
   if (versionFn == NULL){
      wxString ShortName = wxFileName( mName ).GetName();
      wxMessageBox(wxString::Format(_("The module %s does not provide a version string.\nIt will not be loaded."), ShortName.c_str()), _("Module Unsuitable"));
      wxLogMessage(wxString::Format(_("The module %s does not provide a version string.  It will not be loaded."), mName.c_str()));
      mLib->Unload();
      return false;
   }

   wxString moduleVersion = versionFn();
   if( !moduleVersion.IsSameAs(AUDACITY_VERSION_STRING)) {
      wxString ShortName = wxFileName( mName ).GetName();
      wxMessageBox(wxString::Format(_("The module %s is matched with Audacity version %s.\n\nIt will not be loaded."), ShortName.c_str(), moduleVersion.c_str()), _("Module Unsuitable"));
      wxLogMessage(wxString::Format(_("The module %s is matched with Audacity version %s.  It will not be loaded."), mName.c_str(), moduleVersion.c_str()));
      mLib->Unload();
      return false;
   }

   mDispatch = (fnModuleDispatch) mLib->GetSymbol(wxT(ModuleDispatchName));
   if (!mDispatch) {
      // Module does not provide a dispatch function...
      // That can be OK, as long as we never try to call it.
      return true;
   }

   // However if we do have it and it does not work, 
   // then the module is bad.
   bool res = ((mDispatch(ModuleInitialize))!=0);
   if (res) {
      return true;
   }

   mDispatch = NULL;
   return false;
}