Rev 408 | Rev 536 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
259 | daniel-mar | 1 | /* |
2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
||
3 | Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au |
||
4 | Copyright (C) 2018-2021 Daniel Marschall, ViaThinkSoft |
||
5 | |||
6 | This program is free software; you can redistribute it and/or modify |
||
7 | it under the terms of the GNU General Public License as published by |
||
8 | the Free Software Foundation; either version 2 of the License, or |
||
9 | (at your option) any later version. |
||
10 | |||
11 | This program is distributed in the hope that it will be useful, |
||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | GNU General Public License for more details. |
||
15 | |||
16 | You should have received a copy of the GNU General Public License |
||
17 | along with this program; if not, write to the Free Software |
||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
19 | */ |
||
20 | |||
21 | #include "ff.h" |
||
22 | |||
23 | #include <Resources.h> |
||
24 | |||
25 | #include "file_compat.h" |
||
26 | |||
440 | daniel-mar | 27 | Boolean readPARMresource(HMODULE hm,char **reason){ |
259 | daniel-mar | 28 | Boolean res = false; |
29 | Handle h; |
||
30 | |||
440 | daniel-mar | 31 | if( (h = Get1Resource(PARM_TYPE,PARM_ID_NEW)) || |
32 | (h = Get1Resource(PARM_TYPE,PARM_ID_OLD)) ) |
||
33 | { |
||
259 | daniel-mar | 34 | HLock(h); |
271 | daniel-mar | 35 | if(GetHandleSize(h) == sizeof(PARM_T)) { |
440 | daniel-mar | 36 | res = readPARM(*h, &gdata->parm, reason, 0 /*Mac format resource*/); |
37 | gdata->obfusc = false; |
||
38 | ReleaseResource(h); |
||
39 | } else { |
||
40 | // PARM has wrong size. Should not happen |
||
41 | gdata->obfusc = false; |
||
42 | ReleaseResource(h); |
||
43 | return false; |
||
44 | } |
||
45 | } |
||
46 | else if( ((h = Get1Resource(OBFUSCDATA_TYPE_NEW,OBFUSCDATA_ID_NEW)) || |
||
47 | (h = Get1Resource(OBFUSCDATA_TYPE_OLD,OBFUSCDATA_ID_OLD))) ) |
||
48 | { |
||
49 | HLock(h); |
||
50 | if(GetHandleSize(h) == sizeof(PARM_T)) { |
||
271 | daniel-mar | 51 | deobfusc((PARM_T*)*h); |
440 | daniel-mar | 52 | res = readPARM(*h, &gdata->parm, reason, 0 /*Mac format resource*/); |
271 | daniel-mar | 53 | gdata->obfusc = true; |
440 | daniel-mar | 54 | ReleaseResource(h); |
271 | daniel-mar | 55 | } else { |
56 | // Obfuscated PARM has wrong size. Should not happen |
||
57 | gdata->obfusc = false; |
||
58 | ReleaseResource(h); |
||
59 | return false; |
||
60 | } |
||
259 | daniel-mar | 61 | } |
62 | if (!res) { |
||
63 | gdata->obfusc = false; |
||
64 | } |
||
65 | return res; |
||
66 | } |
||
67 | |||
68 | static Boolean readmacplugin(StandardFileReply *sfr,char **reason){ |
||
69 | Boolean res = false; |
||
70 | short rrn = FSpOpenResFile(&sfr->sfFile,fsRdPerm); |
||
71 | |||
72 | if(rrn != -1){ |
||
440 | daniel-mar | 73 | if(readPARMresource(NULL,reason)) |
259 | daniel-mar | 74 | res = true; |
75 | CloseResFile(rrn); |
||
76 | }else |
||
77 | *reason = "Could not open file."; |
||
78 | return res; |
||
79 | } |
||
80 | |||
81 | Boolean loadfile(StandardFileReply *sfr,char **reason){ |
||
82 | Boolean readok = false; |
||
83 | FInfo fndrInfo; |
||
84 | |||
408 | daniel-mar | 85 | // The different read-functions will return true if the resource was successfully loaded, |
86 | // or false otherwise. If *reason is set, then the answer is clearly "No". If the result |
||
87 | // is just false, it means that the program should continue with the next read-function. |
||
88 | *reason = NULL; |
||
89 | |||
259 | daniel-mar | 90 | if(FSpGetFInfo(&sfr->sfFile,&fndrInfo) == noErr){ |
91 | // first try to read text parameters (AFS, TXT, PFF) |
||
408 | daniel-mar | 92 | if (*reason == NULL) { |
93 | if (readfile_afs_pff(sfr,reason)) { |
||
94 | gdata->parmloaded = false; |
||
95 | gdata->obfusc = false; |
||
96 | return true; |
||
97 | } |
||
98 | } |
||
440 | daniel-mar | 99 | |
408 | daniel-mar | 100 | // then try "Filters Unlimited" file (FFX) |
101 | if (*reason == NULL) { |
||
102 | if (readfile_ffx(sfr,reason)) { |
||
103 | gdata->parmloaded = true; |
||
104 | gdata->obfusc = false; |
||
105 | return true; |
||
106 | } |
||
107 | } |
||
440 | daniel-mar | 108 | |
408 | daniel-mar | 109 | // then try "PluginCommander TXT" file (TXT) |
110 | if (*reason == NULL) { |
||
111 | if (readfile_picotxt(sfr,reason)) { |
||
112 | gdata->parmloaded = true; |
||
113 | gdata->obfusc = false; |
||
114 | return true; |
||
115 | } |
||
116 | } |
||
440 | daniel-mar | 117 | |
408 | daniel-mar | 118 | // Try Mac plugin resource |
119 | if (*reason == NULL) { |
||
120 | if (readmacplugin(sfr,reason)) { |
||
121 | if (gdata->parm.iProtected) { |
||
122 | *reason = "The filter is protected."; |
||
123 | } else { |
||
124 | gdata->parmloaded = true; |
||
125 | return true; |
||
126 | } |
||
127 | } |
||
128 | } |
||
440 | daniel-mar | 129 | |
408 | daniel-mar | 130 | // Try Windows resources (we need to do a binary scan) |
131 | // Note that we cannot detect obfuscated filters here! |
||
132 | if (*reason == NULL) { |
||
133 | if (readfile_8bf(sfr,reason)) { |
||
134 | if (gdata->parm.iProtected) { |
||
135 | *reason = "The filter is protected."; |
||
136 | } else { |
||
137 | gdata->parmloaded = true; |
||
138 | return true; |
||
139 | } |
||
140 | } |
||
141 | } |
||
375 | daniel-mar | 142 | |
408 | daniel-mar | 143 | // We didn't had success. If we have a clear reason, return false and the reason. |
144 | // If we don't have a clear reason, set a generic reason and return false. |
||
440 | daniel-mar | 145 | if (*reason == NULL) { |
408 | daniel-mar | 146 | *reason = "It is not a text parameter file, nor a standalone Mac/PC filter created by Filter Factory/Filter Foundry."; |
147 | } |
||
148 | return false; |
||
149 | } else { |
||
150 | *reason = "File cannot be opened"; |
||
151 | return false; |
||
259 | daniel-mar | 152 | } |
153 | } |