~hikiko/nux/arb-srgba-shader

« back to all changes in this revision

Viewing changes to NuxCore/Plugin/NPluginManager.cpp

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-01 19:25:37 UTC
  • Revision ID: neil.patel@canonical.com-20100901192537-mfz7rm6q262pewg6
Import and build NuxCore

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "../NKernel.h"
 
2
#include "NPluginInterface.h"
 
3
#include "NPluginManager.h"
 
4
 
 
5
 
 
6
NAMESPACE_BEGIN
 
7
 
 
8
void NPluginManager::GetPluginList(TCHAR * dirPath, bool addToList)
 
9
{               
 
10
        if(!addToList) ClearPluginList();
 
11
 
 
12
        WIN32_FIND_DATA fd;
 
13
        TCHAR fname[MAX_PATH];
 
14
        STRCPY_S(fname, MAX_PATH, dirPath);
 
15
    size_t len = _tcslen(fname);
 
16
        if(fname[len-1] == TEXT('/') || fname[len-1] == TEXT('\\'))
 
17
        STRCAT_S(fname, MAX_PATH, TEXT("*.dll"));
 
18
        else
 
19
        STRCAT_S(fname, MAX_PATH, TEXT("\\*.dll"));
 
20
        HANDLE hFind = FindFirstFile(fname, &fd); 
 
21
 
 
22
    NFileName Path = dirPath;
 
23
    Path.RemoveBackSlashAtEnd();
 
24
    Path.RemoveSlashAtEnd();
 
25
 
 
26
        if (hFind == INVALID_HANDLE_VALUE) 
 
27
        {
 
28
                FindClose(hFind);
 
29
                return;
 
30
        }
 
31
 
 
32
        do 
 
33
        { 
 
34
                HINSTANCE dllHandle = NULL;
 
35
                try
 
36
                {
 
37
                        if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
 
38
                        {                                       
 
39
                NFileName FilePath = Path + INL_PATH_SEPARATOR_STRING + fd.cFileName;
 
40
                                dllHandle = LoadLibrary(FilePath.GetTCharPtr());
 
41
                                if (dllHandle != NULL) 
 
42
                                {
 
43
                                        PLUGIN_FACTORYFUNC funcHandle;
 
44
                                        funcHandle = reinterpret_cast<PLUGIN_FACTORYFUNC>(GetProcAddress(dllHandle, "makePlugin"));
 
45
                                        if(funcHandle !=NULL)
 
46
                                        {                                                       
 
47
                                                NPlugin * curPlugin = new NPlugin();
 
48
                                                curPlugin->SetFileName(FilePath.GetTCharPtr());
 
49
 
 
50
                                                PLUGIN_TEXTFUNC textFunc;
 
51
                                                textFunc = reinterpret_cast<PLUGIN_TEXTFUNC>(GetProcAddress(dllHandle, "getPluginType"));
 
52
                                                curPlugin->SetType(textFunc());
 
53
                                                textFunc = reinterpret_cast<PLUGIN_TEXTFUNC>(GetProcAddress(dllHandle, "getPluginName"));
 
54
                                                curPlugin->SetName(textFunc());
 
55
 
 
56
                                                pluginRegister.push_back(curPlugin);
 
57
                                        }
 
58
                                        FreeLibrary(dllHandle);
 
59
                                }
 
60
                        }
 
61
                }
 
62
                catch(...)
 
63
                {
 
64
                        if (dllHandle != NULL) FreeLibrary(dllHandle);
 
65
                }
 
66
        } while (FindNextFile(hFind, &fd));
 
67
        FindClose(hFind); 
 
68
}
 
69
 
 
70
NAMESPACE_END