Subversion Repositories filter_foundry

Rev

Rev 2 | Rev 23 | 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
2 toby 3
    Copyright (C) 2003-5 Toby Thain, toby@telegraphics.com.au
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
#include "compat_string.h"
24
 
25
//#include "UpdateResource.h"
26
 
27
extern HANDLE hDllInstance;
28
 
29
Boolean doresources(HMODULE srcmod,char *dstname);
30
 
31
void dbglasterror(char *func){
32
        char s[0x100];
33
        strcpy(s,func);
34
        strcat(s," failed: ");
35
        FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),0,s+strlen(s),0x100,NULL );
36
        DBG(s);
37
}
38
 
39
/*
40
BOOL CALLBACK enumfunc(HMODULE hModule,LPCTSTR lpszType,LPCTSTR lpszName,WORD wIDLanguage,LONG lParam){
41
        char s[0x100];
42
        sprintf(s,"EnumResourceLanguages callback: module=%#x type=%s name=%s lang=%d",
43
                hModule,lpszType,lpszName,wIDLanguage);
44
        dbg(s);
45
        return TRUE;
46
}
47
*/
48
 
49
Boolean doresources(HMODULE srcmod,char *dstname){
50
        OSErr e = noErr;
51
        int i;
52
 
53
        HRSRC datarsrc,piplrsrc,aetersrc;
54
        HANDLE datah,aeteh,hpipl,hupdate;
55
        Ptr newpipl = NULL,newaete = NULL,datap,aetep;
56
        PARM_T *pparm = NULL;
57
 
58
        PIPropertyList *pipl;
59
        short srcrn,dstrn;
60
        Handle h;
61
        long piplsize,aetesize,titlesize,catsize,*lp,origsize;
62
        Str255 title;
63
        char s[0x100];
64
 
65
        Boolean discard = true;
66
 
67
//      if(!EnumResourceLanguages(srcmod,"PiPL",MAKEINTRESOURCE(16000),enumfunc,0)) 
68
//              dbglasterror("EnumResourceLanguages");
69
 
70
        if(hupdate = BeginUpdateResource(dstname,false)){
71
                DBG("BeginUpdateResource OK");
72
                if( (datarsrc = FindResource(srcmod,MAKEINTRESOURCE(16000),RT_RCDATA))
73
                        && (datah = LoadResource(srcmod,datarsrc))
74
                        && (datap = LockResource(datah))
75
                        && (aetersrc = FindResource(srcmod,MAKEINTRESOURCE(16000),"AETE"))
76
                        && (aeteh = LoadResource(srcmod,aetersrc))
77
                        && (aetep = LockResource(aeteh))
78
                ){
79
                        DBG("loaded DATA, PiPL");
80
 
81
                        PLstrcpy(title,gdata->parm.title);
82
                        if(gdata->parm.popDialog)
83
                                PLstrcat(title,(StringPtr)"\003...");
84
 
85
                        origsize = SizeofResource(srcmod,datarsrc);
86
                        aetesize = SizeofResource(srcmod,aetersrc);
87
 
88
                        if( (newpipl = malloc(origsize+0x300))
89
                         && (newaete = malloc(aetesize+0x100))
90
                         && (pparm = malloc(sizeof(PARM_T))) ){
91
 
92
                                /* add user-specified title and category to new PiPL */
93
                                memcpy(newpipl,datap,origsize);
94
                                /* note that Windows PiPLs have 2 byte version datum in front
95
                                   that isn't reflected in struct definition or Mac resource template: */
96
 
97
                                piplsize = fixpipl((PIPropertyList*)(newpipl+2),origsize-2,title) + 2;
98
//sprintf(s,"origsize=%d titlesize=%d catsize=%d piplsize=%d",origsize,titlesize,catsize,piplsize);dbg(s);
99
 
100
                                /* copy old aete data to new block */
101
                                /* Windows 'aete' also has 2 byte version prefix */
102
                                memcpy(newaete,aetep,aetesize);
103
 
104
                                aetesize = fixaete((unsigned char*)newaete+2,aetesize-2,gdata->parm.title) + 2;
105
 
106
                                /* set up the PARM resource with saved parameters */
107
                                memcpy(pparm,&gdata->parm,sizeof(PARM_T));
108
 
109
                                /* convert to C strings for Windows PARM resource */
110
                                myp2cstr(pparm->category);
111
                                myp2cstr(pparm->title);
112
                                myp2cstr(pparm->copyright);
113
                                myp2cstr(pparm->author);
114
                                for(i=0;i<4;++i)
115
                                        myp2cstr(pparm->map[i]);
116
                                for(i=0;i<8;++i)
117
                                        myp2cstr(pparm->ctl[i]);
118
 
119
                                if( UpdateResource(hupdate,"PIPL" /* note: caps!! */,MAKEINTRESOURCE(16000),
120
                                                                   MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),newpipl,piplsize)
121
                                 && UpdateResource(hupdate,"AETE" /* note: caps!! */,MAKEINTRESOURCE(16000),
122
                                                                   MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),newaete,aetesize)
123
                                 && UpdateResource(hupdate,"PARM",MAKEINTRESOURCE(PARM_ID),
124
                                                                   MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),pparm,sizeof(PARM_T)) )
125
                                        discard = false;
126
                                else
127
                                        dbglasterror("UpdateResource");
128
 
129
                        }
130
 
131
                }else dbglasterror("Find-, Load- or LockResource");
132
 
133
                if(!EndUpdateResource(hupdate,discard))
134
                        dbglasterror("EndUpdateResource");     
135
 
136
                if(pparm) free(pparm);
137
                if(newpipl) free(newpipl);
138
                if(newaete) free(newaete);
139
        }else
140
                dbglasterror("BeginUpdateResource");
141
        return !discard;
142
}
143
 
144
OSErr make_standalone(StandardFileReply *sfr){
145
        Boolean res;
146
        char dstname[0x100],srcname[MAX_PATH+1];
147
 
148
        //FSpDelete(&sfr->sfFile);
149
        myp2cstrcpy(dstname,sfr->sfFile.name);
150
        res = GetModuleFileName(hDllInstance,srcname,MAX_PATH)
151
                && CopyFile(srcname,dstname,false)
152
                && doresources(hDllInstance,dstname);
153
 
154
        if(!res)
155
                alertuser("Could not create standalone plugin.","");
156
 
157
        return res ? ioErr : noErr;
158
}