Rev 23 | Rev 47 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 23 | Rev 45 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* |
1 | /* |
2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
3 | Copyright (C) 2003-5 Toby Thain, toby@telegraphics.com.au |
3 | Copyright (C) 2003-6 Toby Thain, toby@telegraphics.com.au |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify |
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 |
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 |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
Line 17... | Line 17... | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ |
18 | */ |
19 | 19 | ||
20 | #include "ff.h" |
20 | #include "ff.h" |
21 | 21 | ||
- | 22 | #include <Endian.h> |
|
- | 23 | ||
22 | #include "file_compat.h" |
24 | #include "file_compat.h" |
23 | 25 | ||
- | 26 | Boolean readmacplugin(StandardFileReply *sfr,char **reason); |
|
- | 27 | Boolean read8bfplugin(StandardFileReply *sfr,char **reason); |
|
- | 28 | ||
24 | Boolean readPARMresource(HMODULE hm,char **reason){ |
29 | Boolean readPARMresource(HMODULE hm,char **reason){ |
25 | Boolean res = false; |
30 | Boolean res = false; |
26 | Handle h = Get1Resource(PARM_TYPE,PARM_ID); |
31 | Handle h = Get1Resource(PARM_TYPE,PARM_ID); |
27 | if(h){ |
32 | if(h){ |
28 | HLock(h); |
33 | HLock(h); |
29 | res = readPARM(*h,&gdata->parm,reason); |
34 | res = readPARM(*h, &gdata->parm, reason, 0 /*Mac format resource*/); |
30 | ReleaseResource(h); |
35 | ReleaseResource(h); |
31 | } |
36 | } |
32 | return res; |
37 | return res; |
33 | } |
38 | } |
34 | 39 | ||
- | 40 | Boolean readmacplugin(StandardFileReply *sfr,char **reason){ |
|
- | 41 | Boolean res = false; |
|
- | 42 | short rrn = FSpOpenResFile(&sfr->sfFile,fsRdPerm); |
|
- | 43 | ||
- | 44 | if( rrn != -1 ){ |
|
- | 45 | if(readPARMresource(NULL,reason)) |
|
- | 46 | res = true; |
|
- | 47 | CloseResFile(rrn); |
|
- | 48 | }else |
|
- | 49 | *reason = "Could not open file."; |
|
- | 50 | return res; |
|
- | 51 | } |
|
- | 52 | ||
- | 53 | Boolean read8bfplugin(StandardFileReply *sfr,char **reason){ |
|
- | 54 | unsigned char magic[2]; |
|
- | 55 | long count; |
|
- | 56 | Handle h; |
|
- | 57 | Boolean res = false; |
|
- | 58 | short refnum; |
|
- | 59 | int i; |
|
- | 60 | ||
- | 61 | if( ! FSpOpenDF(&sfr->sfFile,fsRdPerm,&refnum) ){ |
|
- | 62 | // check DOS EXE magic number |
|
- | 63 | count = 2; |
|
- | 64 | if(!FSRead(refnum,&count,magic) && magic[0]=='M' && magic[1]=='Z'){ |
|
- | 65 | if(!GetEOF(refnum,&count) && count < 256L<<10){ // sanity check file size < 256K |
|
- | 66 | if( (h = readfileintohandle(refnum)) ){ |
|
- | 67 | long *q = (long*)PILOCKHANDLE(h,false); |
|
- | 68 | ||
- | 69 | // look for signature at start of valid PARM resource |
|
- | 70 | // The 0x68200000 (= PARM_SIZE as BigEndian, see PARM.h) |
|
- | 71 | // is observed in Filter Factory standalones. |
|
- | 72 | for( count /= 4 ; count >= PARM_SIZE/4 ; --count, ++q ) |
|
- | 73 | if( q[0] == 0x68200000 && q[1] == 0x01000000 |
|
- | 74 | && (res = readPARM((char*)q, &gdata->parm, reason, 1 /*Windows format resource*/)) ){ |
|
- | 75 | // these are the only numeric fields we *have* to swap |
|
- | 76 | // all the rest are flags which (if we're careful) will work in either ordering |
|
- | 77 | for(i=0;i<8;++i) |
|
- | 78 | slider[i] = EndianS32_LtoN(slider[i]); |
|
- | 79 | } |
|
- | 80 | ||
- | 81 | PIDISPOSEHANDLE(h); |
|
- | 82 | } |
|
- | 83 | } |
|
- | 84 | } // else no point in proceeding |
|
- | 85 | FSClose(refnum); |
|
- | 86 | }else |
|
- | 87 | *reason = "Could not open file."; |
|
- | 88 | return res; |
|
- | 89 | } |
|
- | 90 | ||
35 | Boolean loadfile(StandardFileReply *sfr,char **reason){ |
91 | Boolean loadfile(StandardFileReply *sfr,char **reason){ |
36 | Boolean readok = false; |
92 | Boolean readok = false; |
37 | FInfo fndrInfo; |
93 | FInfo fndrInfo; |
38 | short rrn; |
- | |
39 | 94 | ||
40 | if(!FSpGetFInfo(&sfr->sfFile,&fndrInfo)) |
95 | if(!FSpGetFInfo(&sfr->sfFile,&fndrInfo)){ |
41 | switch(fndrInfo.fdType){ |
96 | // first try to read text parameters (AFS, TXT) |
42 | case TEXT_FILETYPE: |
- | |
43 | if( (readok = readfile(sfr,reason)) ) |
97 | if( (readok = readfile(sfr,reason)) ) |
44 | gdata->parmloaded = false; |
98 | gdata->parmloaded = false; |
45 | break; |
- | |
46 | case PS_FILTER_FILETYPE: |
- | |
47 | if( (rrn = FSpOpenResFile(&sfr->sfFile,fsRdPerm)) != -1 ){ |
99 | // then try plugin formats (Mac first, then Windows .8bf DLL) |
48 | if(readPARMresource(NULL,reason)){ |
100 | else if( (readok = readmacplugin(sfr,reason) || read8bfplugin(sfr,reason)) ){ |
49 | if(gdata->parm.iProtected) |
101 | if(gdata->parm.iProtected){ |
50 | *reason = ("The filter is protected."); |
102 | *reason = "The filter is protected."; |
- | 103 | return false; |
|
51 | else |
104 | }else |
52 | readok = gdata->parmloaded = true; |
105 | gdata->parmloaded = true; |
53 | }else *reason = ("It is not a standalone filter made by Filter Factory/Filter Foundry."); |
106 | }else *reason = "It is not a text parameter (AFS) file, nor a standalone Mac/PC filter made by Filter Factory/Filter Foundry."; |
54 | CloseResFile(rrn); |
- | |
55 | }else *reason = "Could not open file."; |
- | |
56 | break; |
- | |
57 | } |
107 | } |
58 | 108 | ||
59 | return readok; |
109 | return readok; |
60 | } |
110 | } |