/[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 1477 by schoenebeck, Sun Oct 14 22:01:28 2007 UTC revision 1478 by senoner, Tue Nov 13 19:19:18 2007 UTC
# Line 22  Line 22 
22    
23  #include "../common/global_private.h"  #include "../common/global_private.h"
24    
25    #if defined(WIN32)
26    #include <windows.h>
27    #else
28  #include <dlfcn.h>  #include <dlfcn.h>
29  #include <errno.h>  #include <errno.h>
 #include <string.h>  
30  #include <dirent.h>  #include <dirent.h>
31    #endif
32    #include <string.h>
33    
34  #ifndef CONFIG_PLUGIN_DIR  #ifndef CONFIG_PLUGIN_DIR
35  # error "Configuration macro CONFIG_PLUGIN_DIR not defined!"  # error "Configuration macro CONFIG_PLUGIN_DIR not defined!"
# Line 93  namespace LinuxSampler { Line 97  namespace LinuxSampler {
97      void InstrumentEditorFactory::LoadPlugins() {      void InstrumentEditorFactory::LoadPlugins() {
98          if (!bPluginsLoaded) {          if (!bPluginsLoaded) {
99              dmsg(1,("Loading instrument editor plugins..."));              dmsg(1,("Loading instrument editor plugins..."));
100                #if defined(WIN32)
101                bool firstFileFound = true;
102                WIN32_FIND_DATA win32FindData;
103                String plugindir = (String)CONFIG_PLUGIN_DIR + (String)("\\*.DLL");
104                HANDLE hDir = FindFirstFile(plugindir.c_str(), &win32FindData);
105                if (hDir == INVALID_HANDLE_VALUE) {
106                    if(GetLastError() != ERROR_FILE_NOT_FOUND) {
107                        std::cerr << "Could not open instrument editor plugins directory "
108                            << "(" << CONFIG_PLUGIN_DIR << "): Error "
109                            << GetLastError() << std::endl;
110                        return;
111                    }
112                    else {
113                        firstFileFound = false;            
114                    }
115                }
116    
117                while(GetLastError() != ERROR_NO_MORE_FILES && firstFileFound) {
118                    if(!(win32FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
119                        String sPath = (String)CONFIG_PLUGIN_DIR + ((String)"\\" + (String)win32FindData.cFileName);
120                        // load the DLL (the plugins should register themselfes automatically)
121                        void* pDLL = myhinstance = LoadLibrary( sPath.c_str() );
122                        if (pDLL) LoadedDLLs.push_back(pDLL);
123                        else {
124                            std::cerr << "Failed to load instrument editor plugin: "
125                                      << sPath << std::endl;
126                        }
127                    }
128                    int res = FindNextFile(hDir, &win32FindData);
129                    if(res == 0 && GetLastError() != ERROR_NO_MORE_FILES) {
130                        std::cerr << "Error while reading plugins directory FindNextFile Error "
131                                  << GetLastError() << std::endl;
132                        return;              
133                    }
134                }
135                FindClose(hDir);
136                #else // POSIX
137              DIR* hDir = opendir(CONFIG_PLUGIN_DIR);              DIR* hDir = opendir(CONFIG_PLUGIN_DIR);
138              if (!hDir) {              if (!hDir) {
139                  std::cerr << "Could not open instrument editor plugins directory "                  std::cerr << "Could not open instrument editor plugins directory "
# Line 120  namespace LinuxSampler { Line 161  namespace LinuxSampler {
161                  }                  }
162              }              }
163              closedir(hDir);              closedir(hDir);
164                #endif
165              bPluginsLoaded = true;              bPluginsLoaded = true;
166              dmsg(1,("OK\n"));              dmsg(1,("OK\n"));
167          }          }
# Line 137  namespace LinuxSampler { Line 179  namespace LinuxSampler {
179              // free the DLLs              // free the DLLs
180              {              {
181                  std::list<void*>::iterator iter = LoadedDLLs.begin();                  std::list<void*>::iterator iter = LoadedDLLs.begin();
182                  for (; iter != LoadedDLLs.end(); iter++) dlclose(*iter);                  for (; iter != LoadedDLLs.end(); iter++) {
183                        #if defined(WIN32)
184                        FreeLibrary((HINSTANCE)*iter);
185                        #else
186                        dlclose(*iter);
187                        #endif
188                    }
189                  LoadedDLLs.clear();                  LoadedDLLs.clear();
190                  dmsg(1,("OK\n"));                  dmsg(1,("OK\n"));
191              }              }

Legend:
Removed from v.1477  
changed lines
  Added in v.1478

  ViewVC Help
Powered by ViewVC