Rev 37 | Rev 62 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | toby | 1 | /* |
18 | toby | 2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
37 | toby | 3 | Copyright (C) 2003-6 Toby Thain, toby@telegraphics.com.au |
2 | toby | 4 | |
5 | This program is free software; you can redistribute it and/or modify |
||
6 | it under the terms of the GNU General Public License as published by |
||
7 | the Free Software Foundation; either version 2 of the License, or |
||
8 | (at your option) any later version. |
||
9 | |||
10 | This program is distributed in the hope that it will be useful, |
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
13 | GNU General Public License for more details. |
||
14 | |||
15 | You should have received a copy of the GNU General Public License |
||
16 | along with this program; if not, write to the Free Software |
||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
18 | */ |
||
19 | |||
20 | #include "ff.h" |
||
21 | |||
22 | #include "file_compat.h" |
||
23 | |||
24 | #include <string.h> |
||
25 | |||
35 | toby | 26 | static int parm_id; |
27 | |||
28 | // see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/findresource.asp |
||
29 | static BOOL CALLBACK enumnames(HMODULE hModule,LPCTSTR lpszType,LPTSTR lpszName,LONG_PTR lParam){ |
||
30 | |||
31 | if(IS_INTRESOURCE(lpszName)) |
||
37 | toby | 32 | parm_id = (int)lpszName; |
35 | toby | 33 | return false; // we only want the first one |
34 | } |
||
35 | |||
2 | toby | 36 | Boolean readPARMresource(HMODULE hm,char **reason){ |
37 | Boolean res = false; |
||
38 | HRSRC resinfo; |
||
39 | HANDLE h; |
||
40 | Ptr pparm; |
||
35 | toby | 41 | |
42 | parm_id = PARM_ID; |
||
43 | EnumResourceNames(hm,"PARM",enumnames,0); |
||
44 | |||
45 | // load first PARM resource |
||
46 | if( (resinfo = FindResource(hm,MAKEINTRESOURCE(parm_id),"PARM")) |
||
47 | && (h = LoadResource(hm,resinfo)) |
||
48 | && (pparm = LockResource(h)) ) |
||
45 | toby | 49 | res = readPARM(pparm,&gdata->parm,reason,1 /*Windows format resource*/); |
2 | toby | 50 | |
51 | return res; |
||
52 | } |
||
53 | |||
54 | // see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/loadlibraryex.asp |
||
55 | |||
56 | Boolean loadfile(StandardFileReply *sfr,char **reason){ |
||
57 | Boolean readok = false; |
||
58 | HMODULE hm; |
||
59 | |||
60 | sfr->sfFile.name[*sfr->sfFile.name+1] = 0; // add terminating null |
||
61 | |||
62 | if(sfr->nFileExtension){ |
||
63 | if(!strcasecmp((char*)sfr->sfFile.name + 1 + sfr->nFileExtension,"8bf")){ |
||
23 | toby | 64 | if( (hm = LoadLibraryEx((char*)sfr->sfFile.name+1,NULL,LOAD_LIBRARY_AS_DATAFILE)) ){ |
2 | toby | 65 | if(readPARMresource(hm,reason)){ |
66 | if(gdata->parm.iProtected) |
||
67 | *reason = ("The filter is protected."); |
||
68 | else |
||
69 | readok = gdata->parmloaded = true; |
||
70 | }else *reason = ("It is not a standalone filter made by Filter Factory/Filter Foundry."); |
||
71 | FreeLibrary(hm); |
||
72 | }else{ |
||
73 | *reason = "Could not open file (LoadLibrary failed)."; |
||
74 | dbglasterror("LoadLibrary"); |
||
75 | } |
||
76 | }else{ |
||
23 | toby | 77 | if( (readok = readfile(sfr,reason)) ) |
2 | toby | 78 | gdata->parmloaded = false; |
79 | } |
||
80 | } |
||
81 | |||
82 | return readok; |
||
83 | } |