/[svn]/linuxsampler/trunk/src/plugins/InstrumentEditorFactory.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/plugins/InstrumentEditorFactory.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1601 by schoenebeck, Sat Dec 29 20:27:53 2007 UTC revision 1602 by schoenebeck, Sat Dec 29 22:02:29 2007 UTC
# Line 105  namespace LinuxSampler { Line 105  namespace LinuxSampler {
105          if (!bPluginsLoaded) {          if (!bPluginsLoaded) {
106              dmsg(1,("Loading instrument editor plugins..."));              dmsg(1,("Loading instrument editor plugins..."));
107              #if defined(WIN32)              #if defined(WIN32)
             bool firstFileFound = true;  
108              WIN32_FIND_DATA win32FindData;              WIN32_FIND_DATA win32FindData;
109              String plugindir = (String)CONFIG_PLUGIN_DIR + (String)("\\*.DLL");              const String plugindir = (String)CONFIG_PLUGIN_DIR + (String)("\\*.DLL");
110              HANDLE hDir = FindFirstFile(plugindir.c_str(), &win32FindData);              HANDLE hDir = FindFirstFile(plugindir.c_str(), &win32FindData);
111              if (hDir == INVALID_HANDLE_VALUE) {              if (hDir == INVALID_HANDLE_VALUE) {
112                  if(GetLastError() != ERROR_FILE_NOT_FOUND) {                  if (GetLastError() != ERROR_FILE_NOT_FOUND) {
113                      std::cerr << "Could not open instrument editor plugins directory "                      std::cerr << "Could not open instrument editor plugins "
114                          << "(" << CONFIG_PLUGIN_DIR << "): Error "                                << "directory (" << CONFIG_PLUGIN_DIR << "), "
115                          << GetLastError() << std::endl;                                << "Error: " << GetLastError() << std::endl;
116                      return;                  } else {
117                  }                      dmsg(1,("None"));
                 else {  
                     firstFileFound = false;              
118                  }                  }
119                    // either dir doesn't exist or is empty
120                    return;
121              }              }
122    
123              while(GetLastError() != ERROR_NO_MORE_FILES && firstFileFound) {              do {
124                  if(!(win32FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {                  // skip directory entries
125                      String sPath = (String)CONFIG_PLUGIN_DIR + ((String)"\\" + (String)win32FindData.cFileName);                  if (win32FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
126                      // load the DLL (the plugins should register themselfes automatically)                      continue;
127                      HINSTANCE hinstLib;                  // dir entry name as full qualified path
128                      void* pDLL = hinstLib = LoadLibrary( sPath.c_str() );                  const String sPath = (String)CONFIG_PLUGIN_DIR + ((String)"\\" + (String)win32FindData.cFileName);
129                      if (!pDLL) {                  // load the DLL
130                          std::cerr << "Failed to load instrument editor plugin: "                  HINSTANCE hinstLib;
131                                    << sPath << std::endl;                  void* pDLL = hinstLib = LoadLibrary(sPath.c_str());
132                          continue;                  if (!pDLL) {
133                      }                      std::cerr << "Failed to load instrument editor plugin: "
134                                                      << sPath << std::endl;
135                      //(InnerFactory*) (*fn)(void);                      continue;
136                      InnerFactoryRegisterFunction fn;                  }
137                      fn = (InnerFactoryRegisterFunction)  
138                    //(InnerFactory*) (*fn)(void);
139                    InnerFactoryRegisterFunction fn =
140                        (InnerFactoryRegisterFunction)
141                          GetProcAddress(                          GetProcAddress(
142                              hinstLib,                              hinstLib,
143                              "createInstrumentEditorInnerFactory"                              "createInstrumentEditorInnerFactory"
144                          );                          );
145                      if (fn == NULL) {                  if (fn == NULL) {
146                          std::cerr << "ERROR: unable to find "                      std::cerr << "ERROR: unable to find "
147                                       "createInstrumentEditorInnerFactory() "                                   "createInstrumentEditorInnerFactory() "
148                                       "in DLL\n" << std::flush;                                   "in DLL\n" << std::flush;
149                          FreeLibrary(hinstLib);                      FreeLibrary(hinstLib);
150                          continue;                      continue;
151                      }                  }
152                        
153                      // get the plugin instance and register it to the factory                  // get the plugin instance and register it to the factory
154                        
155                      InnerFactory* pInnerFactory = (InnerFactory*)fn();                  InnerFactory* pInnerFactory = (InnerFactory*)fn();
156                      if (!pInnerFactory) {                  if (!pInnerFactory) {
157                          std::cerr << "ERROR: !pInnerFactory\n" << std::flush;                      std::cerr << "ERROR: !pInnerFactory\n" << std::flush;
158                          FreeLibrary(hinstLib);                      FreeLibrary(hinstLib);
159                          continue;                      continue;
                     }  
                     InstrumentEditor* pEditor = pInnerFactory->Create();  
                     if (InnerFactories.count(pEditor->Name())) {  
                         std::cerr << "ERROR: a plugin with name '"  
                                   << pEditor->Name()  
                                   << "' already loaded (skipping)\n"  
                                   << std::flush;  
                         pInnerFactory->Destroy(pEditor);  
                         FreeLibrary(hinstLib);  
                         continue;  
                     }  
                     InnerFactories[pEditor->Name()] = pInnerFactory;  
                     pInnerFactory->Destroy(pEditor);  
                       
                     LoadedDLLs.push_back(pDLL);  
160                  }                  }
161                  int res = FindNextFile(hDir, &win32FindData);                  InstrumentEditor* pEditor = pInnerFactory->Create();
162                  if(res == 0 && GetLastError() != ERROR_NO_MORE_FILES) {                  if (InnerFactories.count(pEditor->Name())) {
163                      std::cerr << "Error while reading plugins directory FindNextFile Error "                      std::cerr << "ERROR: a plugin with name '"
164                                << GetLastError() << std::endl;                                << pEditor->Name()
165                      return;                                              << "' already loaded (skipping)\n"
166                                  << std::flush;
167                        pInnerFactory->Destroy(pEditor);
168                        FreeLibrary(hinstLib);
169                        continue;
170                  }                  }
171              }                  InnerFactories[pEditor->Name()] = pInnerFactory;
172              FindClose(hDir);                  pInnerFactory->Destroy(pEditor);
173    
174                    LoadedDLLs.push_back(pDLL);
175                } while (FindNextFile(hDir, &win32FindData));
176                if (hDir != INVALID_HANDLE_VALUE) FindClose(hDir);
177              #else // POSIX              #else // POSIX
178              DIR* hDir = opendir(CONFIG_PLUGIN_DIR);              DIR* hDir = opendir(CONFIG_PLUGIN_DIR);
179              if (!hDir) {              if (!hDir) {

Legend:
Removed from v.1601  
changed lines
  Added in v.1602

  ViewVC Help
Powered by ViewVC