Subversion Repositories filter_foundry

Rev

Rev 85 | Rev 106 | 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
85 toby 3
    Copyright (C) 2003-7 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
62 toby 29
static BOOL CALLBACK enumnames(HMODULE hModule,LPCTSTR lpszType,
30
                                                           LPTSTR lpszName,LONG_PTR lParam)
31
{
35 toby 32
        if(IS_INTRESOURCE(lpszName))
37 toby 33
                parm_id = (int)lpszName;
35 toby 34
        return false; // we only want the first one
35
}
36
 
87 toby 37
Boolean readPARMresource(HMODULE hm,char **reason,int readobfusc){
2 toby 38
        HRSRC resinfo;
39
        HANDLE h;
40
        Ptr pparm;
87 toby 41
        int res = false;
35 toby 42
 
43
        parm_id = PARM_ID;
44
        EnumResourceNames(hm,"PARM",enumnames,0);
45
 
46
        // load first PARM resource
87 toby 47
        if( (resinfo = FindResource(hm,MAKEINTRESOURCE(parm_id),"PARM")) ){
48
                if( (h = LoadResource(hm,resinfo)) && (pparm = LockResource(h)) )
49
                        res = readPARM(pparm,&gdata->parm,reason,1 /*Windows format resource*/);
50
        }else if( readobfusc && (resinfo = FindResource(hm,MAKEINTRESOURCE(OBFUSCDATA_ID),RT_RCDATA)) ){
51
                if( (h = LoadResource(hm,resinfo)) && (pparm = LockResource(h)) ){
85 toby 52
                        obfusc(pparm,SizeofResource(hm,resinfo));
87 toby 53
                        res = readPARM(pparm,&gdata->parm,reason,1);
85 toby 54
                }
55
        }
87 toby 56
        return res;
2 toby 57
}
58
 
59
// see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/loadlibraryex.asp
60
 
61
Boolean loadfile(StandardFileReply *sfr,char **reason){
62
        Boolean readok = false;
63
        HMODULE hm;
64
 
65
        sfr->sfFile.name[*sfr->sfFile.name+1] = 0; // add terminating null
66
 
67
        if(sfr->nFileExtension){
68
                if(!strcasecmp((char*)sfr->sfFile.name + 1 + sfr->nFileExtension,"8bf")){
23 toby 69
                        if( (hm = LoadLibraryEx((char*)sfr->sfFile.name+1,NULL,LOAD_LIBRARY_AS_DATAFILE)) ){
87 toby 70
                                if(readPARMresource(hm,reason,0)){
2 toby 71
                                        if(gdata->parm.iProtected)
85 toby 72
                                                *reason = "The filter is protected.";
2 toby 73
                                        else
74
                                                readok = gdata->parmloaded = true;
85 toby 75
                                }else
76
                                        *reason = "It is not a standalone filter made by Filter Factory/Filter Foundry.";
2 toby 77
                                FreeLibrary(hm);
78
                        }else{
79
                                *reason = "Could not open file (LoadLibrary failed).";
80
                                dbglasterror("LoadLibrary");
81
                        }
82
                }else{
23 toby 83
                        if( (readok = readfile(sfr,reason)) )
2 toby 84
                                gdata->parmloaded = false;
85
                }
86
        }
87
 
88
        return readok;
89
}