1 module stormlibd.DynamicLoad;
2 
3 version(Derelict_Static) {}
4 else version(DerelictStormLib_Static) {}
5 else { version = DerelictStormLib_Dynamic; }
6 
7 version(DerelictStormLib_Dynamic):
8 
9 public import stormlibd.Types;
10 import derelict.util.exception,
11        derelict.util.loader,
12        derelict.util.system;
13 
14 extern(C) @nogc nothrow {
15 	alias da_SFileGetLocale = LCID function();
16 	alias da_SFileSetLocale = LCID function(LCID);
17 	
18 	alias da_SFileOpenArchive = bool function(const TCHAR*, DWORD, DWORD, HANDLE*);
19 	alias da_SFileCreateArchive = bool function(const TCHAR*, DWORD, DWORD, HANDLE*);
20 	alias da_SFileCreateArchive2 = bool function(const TCHAR*, PSFILE_CREATE_MPQ, HANDLE*);
21 
22 	alias da_SFileSetDownloadCallback = bool function(HANDLE, SFILE_DOWNLOAD_CALLBACK, void*);
23 	alias da_SFileFlushArchive = bool function(HANDLE);
24 	alias da_SFileCloseArchive = bool function(HANDLE);
25 
26 	alias da_SFileAddListFile = int function(HANDLE, const TCHAR*);
27 
28 	alias da_SFileSetCompactCallback = bool function(HANDLE, SFILE_COMPACT_CALLBACK, void*);
29 	alias da_SFileCompactArchive = bool function(HANDLE, const TCHAR*, bool);
30 
31 	alias da_SFileGetMaxFileCount = DWORD function(HANDLE);
32 	alias da_SFileSetMaxFileCount = bool function(HANDLE, DWORD);
33 
34 	alias da_SFileGetAttributes = DWORD function(HANDLE);
35 	alias da_SFileSetAttributes = bool function(HANDLE, DWORD);
36 	alias da_SFileUpdateFileAttributes = bool function(HANDLE, const char*);
37 
38     alias da_SFileOpenPatchArchive = bool function(HANDLE, const TCHAR*, const char*, DWORD);
39     alias da_SFileIsPatchedArchive = bool function(HANDLE);
40 
41     alias da_SFileHasFile = bool function(HANDLE, const char*);
42     alias da_SFileOpenFileEx = bool function(HANDLE, const char*, DWORD, HANDLE*);
43     alias da_SFileGetFileSize = DWORD function(HANDLE, LPDWORD);
44     alias da_SFileSetFilePointer = DWORD function(HANDLE, LONG, LONG*, DWORD);
45     alias da_SFileReadFile = bool function(HANDLE, void*, DWORD, LPDWORD, LPOVERLAPPED);
46     alias da_SFileCloseFile = bool function(HANDLE);
47 
48     alias da_SFileGetFileInfo = bool function(HANDLE, SFileInfoClass, void*, DWORD, LPDWORD);
49     alias da_SFileGetFileName = bool function(HANDLE, char*);
50     alias da_SFileFreeFileInfo = bool function(void*, SFileInfoClass);
51 
52     alias da_SFileExtractFile = bool function(HANDLE, const char*, const TCHAR*, DWORD);
53 }
54 
55 __gshared {
56 	da_SFileGetLocale SFileGetLocale;
57 	da_SFileSetLocale SFileSetLocale;
58 	
59 	da_SFileOpenArchive SFileOpenArchive;
60 	da_SFileCreateArchive SFileCreateArchive;
61 	da_SFileCreateArchive2 SFileCreateArchive2;
62 	
63 	da_SFileSetDownloadCallback SFileSetDownloadCallback;
64 	da_SFileFlushArchive SFileFlushArchive;
65 	da_SFileCloseArchive SFileCloseArchive;
66 	
67 	da_SFileAddListFile SFileAddListFile;
68 	
69 	da_SFileSetCompactCallback SFileSetCompactCallback;
70 	da_SFileCompactArchive SFileCompactArchive;
71 	
72 	da_SFileGetMaxFileCount SFileGetMaxFileCount;
73 	da_SFileSetMaxFileCount SFileSetMaxFileCount;
74 
75 	da_SFileGetAttributes SFileGetAttributes;
76 	da_SFileSetAttributes SFileSetAttributes;
77 	da_SFileUpdateFileAttributes SFileUpdateFileAttributes;
78 
79 	da_SFileOpenPatchArchive SFileOpenPatchArchive;
80 	da_SFileIsPatchedArchive SFileIsPatchedArchive;
81 
82 	da_SFileHasFile SFileHasFile;
83 	da_SFileOpenFileEx SFileOpenFileEx;
84 	da_SFileGetFileSize SFileGetFileSize;
85 	da_SFileSetFilePointer SFileSetFilePointer;
86 	da_SFileReadFile SFileReadFile;
87 	da_SFileCloseFile SFileCloseFile;
88 
89 	da_SFileGetFileInfo SFileGetFileInfo;
90 	da_SFileGetFileName SFileGetFileName;
91 	da_SFileFreeFileInfo SFileFreeFileInfo;
92 
93 	da_SFileExtractFile SFileExtractFile;
94 }
95 
96 
97 class DerelictStormLibLoader : SharedLibLoader {
98     this()
99     {
100         super(libNames);
101     }
102 
103     protected override void loadSymbols()
104     {
105         bindFunc(cast(void**)&SFileGetLocale, "SFileGetLocale");
106         bindFunc(cast(void**)&SFileSetLocale, "SFileSetLocale");
107         
108         bindFunc(cast(void**)&SFileOpenArchive, "SFileOpenArchive");
109         bindFunc(cast(void**)&SFileCreateArchive, "SFileCreateArchive");
110         bindFunc(cast(void**)&SFileCreateArchive2, "SFileCreateArchive2");
111         
112         bindFunc(cast(void**)&SFileSetDownloadCallback, "SFileSetDownloadCallback");
113         bindFunc(cast(void**)&SFileFlushArchive, "SFileFlushArchive");
114         bindFunc(cast(void**)&SFileCloseArchive, "SFileCloseArchive");
115         
116         bindFunc(cast(void**)&SFileAddListFile, "SFileAddListFile");
117         
118         bindFunc(cast(void**)&SFileSetCompactCallback, "SFileSetCompactCallback");
119         bindFunc(cast(void**)&SFileCompactArchive, "SFileCompactArchive");
120         
121         bindFunc(cast(void**)&SFileGetMaxFileCount, "SFileGetMaxFileCount");
122         bindFunc(cast(void**)&SFileSetMaxFileCount, "SFileSetMaxFileCount");
123         
124         bindFunc(cast(void**)&SFileGetAttributes, "SFileGetAttributes");
125         bindFunc(cast(void**)&SFileSetAttributes, "SFileSetAttributes");
126         bindFunc(cast(void**)&SFileUpdateFileAttributes, "SFileUpdateFileAttributes");
127 
128         bindFunc(cast(void**)&SFileOpenPatchArchive, "SFileOpenPatchArchive");
129         bindFunc(cast(void**)&SFileIsPatchedArchive, "SFileIsPatchedArchive");
130 
131         bindFunc(cast(void**)&SFileHasFile, "SFileHasFile");
132         bindFunc(cast(void**)&SFileOpenFileEx, "SFileOpenFileEx");
133         bindFunc(cast(void**)&SFileGetFileSize, "SFileGetFileSize");
134         bindFunc(cast(void**)&SFileSetFilePointer, "SFileSetFilePointer");
135         bindFunc(cast(void**)&SFileReadFile, "SFileReadFile");
136         bindFunc(cast(void**)&SFileCloseFile, "SFileCloseFile");
137 
138         bindFunc(cast(void**)&SFileGetFileInfo, "SFileGetFileInfo");
139         bindFunc(cast(void**)&SFileGetFileName, "SFileGetFileName");
140         bindFunc(cast(void**)&SFileFreeFileInfo, "SFileFreeFileInfo");
141 
142         bindFunc(cast(void**)&SFileExtractFile, "SFileExtractFile");
143     }
144 }
145 
146 __gshared DerelictStormLibLoader DerelictStormLib;
147 
148 shared static this()
149 {
150     DerelictStormLib = new DerelictStormLibLoader();
151 }
152 
153 private:
154     static if(Derelict_OS_Windows)
155         enum libNames = "libStorm.dll";
156     else static if(Derelict_OS_Mac)
157         enum libNames = "libStorm.dylib";
158     else static if(Derelict_OS_Posix)
159         enum libNames = "libStorm.so";
160     else
161 		static assert(0, "Need to implement StormLib libNames for this operating system.");