Rev 149 | Rev 188 | 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 |
171 | dmarschall | 3 | Copyright (C) 2003-2019 Toby Thain, toby@telegraphics.com.au |
2 | toby | 4 | |
5 | This program is free software; you can redistribute it and/or modify |
||
145 | dmarschall | 6 | it under the terms of the GNU General Public License as published by |
2 | toby | 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 | |||
145 | dmarschall | 15 | You should have received a copy of the GNU General Public License |
2 | toby | 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 | |||
85 | toby | 22 | #include <Resources.h> |
45 | toby | 23 | |
2 | toby | 24 | #include "file_compat.h" |
25 | |||
87 | toby | 26 | Boolean readPARMresource(HMODULE hm,char **reason,int readobfusc){ |
2 | toby | 27 | Boolean res = false; |
85 | toby | 28 | Handle h; |
29 | |||
30 | if( !(h = Get1Resource(PARM_TYPE,PARM_ID)) |
||
87 | toby | 31 | && readobfusc |
85 | toby | 32 | && (h = Get1Resource('DATA',OBFUSCDATA_ID)) ){ |
33 | HLock(h); |
||
34 | obfusc((unsigned char*)*h,GetHandleSize(h)); |
||
35 | } |
||
23 | toby | 36 | if(h){ |
2 | toby | 37 | HLock(h); |
45 | toby | 38 | res = readPARM(*h, &gdata->parm, reason, 0 /*Mac format resource*/); |
2 | toby | 39 | ReleaseResource(h); |
40 | } |
||
41 | return res; |
||
42 | } |
||
43 | |||
85 | toby | 44 | static Boolean readmacplugin(StandardFileReply *sfr,char **reason){ |
45 | toby | 45 | Boolean res = false; |
46 | short rrn = FSpOpenResFile(&sfr->sfFile,fsRdPerm); |
||
145 | dmarschall | 47 | |
85 | toby | 48 | if(rrn != -1){ |
87 | toby | 49 | if(readPARMresource(NULL,reason,0)) |
45 | toby | 50 | res = true; |
51 | CloseResFile(rrn); |
||
52 | }else |
||
53 | *reason = "Could not open file."; |
||
54 | return res; |
||
55 | } |
||
56 | |||
2 | toby | 57 | Boolean loadfile(StandardFileReply *sfr,char **reason){ |
58 | Boolean readok = false; |
||
59 | FInfo fndrInfo; |
||
60 | |||
45 | toby | 61 | if(!FSpGetFInfo(&sfr->sfFile,&fndrInfo)){ |
145 | dmarschall | 62 | // first try to read text parameters (AFS, TXT, PFF) |
45 | toby | 63 | if( (readok = readfile(sfr,reason)) ) |
64 | gdata->parmloaded = false; |
||
147 | dmarschall | 65 | // then try plugin formats (Mac first, then Windows .8bf or .prm DLL) |
45 | toby | 66 | else if( (readok = readmacplugin(sfr,reason) || read8bfplugin(sfr,reason)) ){ |
67 | if(gdata->parm.iProtected){ |
||
68 | *reason = "The filter is protected."; |
||
69 | return false; |
||
70 | }else |
||
71 | gdata->parmloaded = true; |
||
85 | toby | 72 | }else |
73 | *reason = "It is not a text parameter (AFS) file, nor a standalone Mac/PC filter made by Filter Factory/Filter Foundry."; |
||
45 | toby | 74 | } |
2 | toby | 75 | |
76 | return readok; |
||
77 | } |