Rev 47 | Rev 85 | 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 |
45 | 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 | |||
45 | toby | 22 | #include <Endian.h> |
23 | |||
2 | toby | 24 | #include "file_compat.h" |
25 | |||
45 | toby | 26 | Boolean readmacplugin(StandardFileReply *sfr,char **reason); |
27 | Boolean read8bfplugin(StandardFileReply *sfr,char **reason); |
||
28 | |||
2 | toby | 29 | Boolean readPARMresource(HMODULE hm,char **reason){ |
30 | Boolean res = false; |
||
23 | toby | 31 | Handle h = Get1Resource(PARM_TYPE,PARM_ID); |
32 | if(h){ |
||
2 | toby | 33 | HLock(h); |
45 | toby | 34 | res = readPARM(*h, &gdata->parm, reason, 0 /*Mac format resource*/); |
2 | toby | 35 | ReleaseResource(h); |
36 | } |
||
37 | return res; |
||
38 | } |
||
39 | |||
45 | toby | 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 |
||
47 | toby | 70 | // This signature is observed in Filter Factory standalones. |
45 | toby | 71 | for( count /= 4 ; count >= PARM_SIZE/4 ; --count, ++q ) |
47 | toby | 72 | if( EndianS32_LtoN(q[0]) == PARM_SIZE && EndianS32_LtoN(q[1]) == 1 |
62 | toby | 73 | && (res = readPARM((char*)q, &gdata->parm, reason, 1 /*Windows format resource*/)) ) |
74 | { |
||
45 | toby | 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 | |||
2 | toby | 91 | Boolean loadfile(StandardFileReply *sfr,char **reason){ |
92 | Boolean readok = false; |
||
93 | FInfo fndrInfo; |
||
94 | |||
45 | toby | 95 | if(!FSpGetFInfo(&sfr->sfFile,&fndrInfo)){ |
96 | // first try to read text parameters (AFS, TXT) |
||
97 | if( (readok = readfile(sfr,reason)) ) |
||
98 | gdata->parmloaded = false; |
||
99 | // then try plugin formats (Mac first, then Windows .8bf DLL) |
||
100 | else if( (readok = readmacplugin(sfr,reason) || read8bfplugin(sfr,reason)) ){ |
||
101 | if(gdata->parm.iProtected){ |
||
102 | *reason = "The filter is protected."; |
||
103 | return false; |
||
104 | }else |
||
105 | gdata->parmloaded = true; |
||
106 | }else *reason = "It is not a text parameter (AFS) file, nor a standalone Mac/PC filter made by Filter Factory/Filter Foundry."; |
||
107 | } |
||
2 | toby | 108 | |
109 | return readok; |
||
110 | } |