Subversion Repositories filter_foundry

Rev

Rev 185 | Rev 189 | 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
113 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
 
113 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
 
22
#include "file_compat.h"
23
#include "compat_string.h"
113 dmarschall 24
#include "versioninfo_modify_win.h"
25
#include "version.h"
2 toby 26
 
27
extern HANDLE hDllInstance;
28
 
29
Boolean doresources(HMODULE srcmod,char *dstname);
30
 
31
void dbglasterror(char *func){
32
        char s[0x100];
62 toby 33
 
2 toby 34
        strcpy(s,func);
35
        strcat(s," failed: ");
36
        FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),0,s+strlen(s),0x100,NULL );
35 toby 37
        dbg(s);
2 toby 38
}
39
 
40
/*
41
BOOL CALLBACK enumfunc(HMODULE hModule,LPCTSTR lpszType,LPCTSTR lpszName,WORD wIDLanguage,LONG lParam){
42
        char s[0x100];
43
        sprintf(s,"EnumResourceLanguages callback: module=%#x type=%s name=%s lang=%d",
44
                hModule,lpszType,lpszName,wIDLanguage);
45
        dbg(s);
46
        return TRUE;
47
}
48
*/
49
 
50
Boolean doresources(HMODULE srcmod,char *dstname){
23 toby 51
        HRSRC datarsrc,aetersrc;
52
        HANDLE datah,aeteh,hupdate;
2 toby 53
        Ptr newpipl = NULL,newaete = NULL,datap,aetep;
54
        PARM_T *pparm = NULL;
185 dmarschall 55
        size_t piplsize,aetesize,origsize;
2 toby 56
        Str255 title;
85 toby 57
        LPCTSTR parm_type;
58
        int i,parm_id;
2 toby 59
        Boolean discard = true;
162 dmarschall 60
        LPWSTR changeRequestStr, tmp;
113 dmarschall 61
        char* soleFilename;
2 toby 62
 
162 dmarschall 63
        if (!isWin32NT()) {
64
                HMODULE hLib;
65
 
66
                hLib = LoadLibraryA("UNICOWS.DLL");
67
                if (!hLib) {
163 dmarschall 68
                        char* sysdir;
69
 
70
                        sysdir = (char*)malloc(MAX_PATH);
71
                        GetSystemDirectoryA(sysdir, MAX_PATH);
72
                        alertuser("To build standalone plugins using this version of\nWindows, you need to install UNICOWS.DLL\n\nPlease download it from the Internet\nand place it into following directory:",sysdir);
73
                        free(sysdir);
74
 
162 dmarschall 75
                        return false;
76
                } else {
77
                        FreeLibrary(hLib);
78
                }
79
        }
80
 
113 dmarschall 81
//      if(!EnumResourceLanguages(srcmod,"PiPL",MAKEINTRESOURCE(16000),enumfunc,0))
2 toby 82
//              dbglasterror("EnumResourceLanguages");
83
 
162 dmarschall 84
        if( (hupdate = _BeginUpdateResource(dstname,false)) ){
2 toby 85
                DBG("BeginUpdateResource OK");
113 dmarschall 86
                if( (datarsrc = FindResource(srcmod,MAKEINTRESOURCE(16000),RT_RCDATA))
2 toby 87
                        && (datah = LoadResource(srcmod,datarsrc))
113 dmarschall 88
                        && (datap = LockResource(datah))
89
                        && (aetersrc = FindResource(srcmod,MAKEINTRESOURCE(16000),"AETE"))
2 toby 90
                        && (aeteh = LoadResource(srcmod,aetersrc))
62 toby 91
                        && (aetep = LockResource(aeteh)) )
92
                {
2 toby 93
                        DBG("loaded DATA, PiPL");
94
 
95
                        PLstrcpy(title,gdata->parm.title);
113 dmarschall 96
                        if(gdata->parm.popDialog)
2 toby 97
                                PLstrcat(title,(StringPtr)"\003...");
98
 
99
                        origsize = SizeofResource(srcmod,datarsrc);
100
 
113 dmarschall 101
                        if( (newpipl = malloc(origsize+0x300))
184 dmarschall 102
                         && (newaete = malloc(4096))
62 toby 103
                         && (pparm = malloc(sizeof(PARM_T))) )
104
                        {
2 toby 105
                                /* add user-specified title and category to new PiPL */
106
                                memcpy(newpipl,datap,origsize);
113 dmarschall 107
                                /* note that Windows PiPLs have 2 byte version datum in front
2 toby 108
                                   that isn't reflected in struct definition or Mac resource template: */
109
                                piplsize = fixpipl((PIPropertyList*)(newpipl+2),origsize-2,title) + 2;
110
 
111
                                /* set up the PARM resource with saved parameters */
112
                                memcpy(pparm,&gdata->parm,sizeof(PARM_T));
113
 
114
                                /* convert to C strings for Windows PARM resource */
115
                                myp2cstr(pparm->category);
116
                                myp2cstr(pparm->title);
117
                                myp2cstr(pparm->copyright);
118
                                myp2cstr(pparm->author);
119
                                for(i=0;i<4;++i)
120
                                        myp2cstr(pparm->map[i]);
121
                                for(i=0;i<8;++i)
122
                                        myp2cstr(pparm->ctl[i]);
113 dmarschall 123
 
184 dmarschall 124
                                /* Generate 'aete' resource (contains names of the parameters for the "Actions" tab in Photoshop) */
125
                                aetesize = aete_generate(newaete, pparm);
126
 
85 toby 127
                                if(gdata->obfusc){
128
                                        parm_type = RT_RCDATA;
129
                                        parm_id = OBFUSCDATA_ID;
130
                                        obfusc((unsigned char*)pparm,sizeof(PARM_T));
131
                                }else{
132
                                        parm_type = "PARM";
133
                                        parm_id = PARM_ID;
134
                                }
2 toby 135
 
133 dmarschall 136
                                /* Attention: The resource we have found using FindResource() might have a different
137
                                   language than the resource we are saving (Neutral), so we might end up having
138
                                   multiple languages for the same resource. Therefore, the language "Neutral" was
186 dmarschall 139
                                   set in the Scripting.rc file for the resource AETE and PIPL.rc for the resources PIPL. */
162 dmarschall 140
                                if( _UpdateResource(hupdate,"PIPL" /* note: caps!! */,MAKEINTRESOURCE(16000),
185 dmarschall 141
                                                                   MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),newpipl,(DWORD)piplsize)
162 dmarschall 142
                                 && _UpdateResource(hupdate,"AETE" /* note: caps!! */,MAKEINTRESOURCE(16000),
185 dmarschall 143
                                                                   MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),newaete,(DWORD)aetesize)
162 dmarschall 144
                                 && _UpdateResource(hupdate,parm_type,MAKEINTRESOURCE(parm_id),
2 toby 145
                                                                   MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),pparm,sizeof(PARM_T)) )
146
                                        discard = false;
113 dmarschall 147
                                else
2 toby 148
                                        dbglasterror("UpdateResource");
113 dmarschall 149
 
150
                                if (soleFilename = strrchr(dstname, '\\')) {
151
                                    ++soleFilename;
152
                                } else {
153
                                    soleFilename = dstname;
154
                                }
155
 
156
                                // Format of argument "PCWSTR changes" is "<name>\0<value>\0<name>\0<value>\0....."
157
                                // You can CHANGE values for any given name
158
                                // You can DELETE entries by setting the value to "\b" (0x08 backspace character)
159
                                // You cannot (yet) ADD entries.
162 dmarschall 160
                                changeRequestStr = (LPWSTR)malloc(6*2*100+1);
161
 
162
                                tmp = changeRequestStr ;
163
 
164
                                tmp += mbstowcs(tmp, "Comments", 100);
165
                                tmp++;
166
                                tmp += mbstowcs(tmp, "Built using Filter Foundry " VERSION_STR, 100);
167
                                tmp++;
168
 
169
                                tmp += mbstowcs(tmp, "CompanyName", 100);
170
                                tmp++;
171
                                tmp += mbstowcs(tmp, pparm->author, 100);
172
                                tmp++;
173
 
174
                                tmp += mbstowcs(tmp, "LegalCopyright", 100);
175
                                tmp++;
176
                                tmp += mbstowcs(tmp, pparm->copyright, 100);
177
                                tmp++;
178
 
179
                                tmp += mbstowcs(tmp, "FileDescription", 100);
180
                                tmp++;
181
                                tmp += mbstowcs(tmp, pparm->title, 100);
182
                                tmp++;
183
 
184
                                tmp += mbstowcs(tmp, "OriginalFilename", 100);
185
                                tmp++;
186
                                tmp += mbstowcs(tmp, soleFilename, 100);
187
                                tmp++;
188
 
189
                                tmp += mbstowcs(tmp, "License", 100);
190
                                tmp++;
191
                                tmp += mbstowcs(tmp, "\b", 100); // \b = remove, since filter is standalone and might have its own license
192
                                tmp++;
193
 
194
                                tmp += mbstowcs(tmp, "", 1);
195
 
113 dmarschall 196
                                if (UpdateVersionInfoWithHandle(dstname, hupdate, changeRequestStr) != NOERROR) {
197
                                        alertuser("UpdateVersionInfoWithHandle failed","");
198
                                }
163 dmarschall 199
 
200
                                free(changeRequestStr);
2 toby 201
                        }
202
 
203
                }else dbglasterror("Find-, Load- or LockResource");
204
 
162 dmarschall 205
                if(!_EndUpdateResource(hupdate,discard))
113 dmarschall 206
                        dbglasterror("EndUpdateResource");
2 toby 207
 
208
                if(pparm) free(pparm);
209
                if(newpipl) free(newpipl);
210
                if(newaete) free(newaete);
113 dmarschall 211
        }else
2 toby 212
                dbglasterror("BeginUpdateResource");
213
        return !discard;
214
}
215
 
216
OSErr make_standalone(StandardFileReply *sfr){
217
        Boolean res;
218
        char dstname[0x100],srcname[MAX_PATH+1];
219
 
220
        //FSpDelete(&sfr->sfFile);
221
        myp2cstrcpy(dstname,sfr->sfFile.name);
222
        res = GetModuleFileName(hDllInstance,srcname,MAX_PATH)
113 dmarschall 223
                  && CopyFile(srcname,dstname,false)
62 toby 224
                  && doresources(hDllInstance,dstname);
2 toby 225
 
184 dmarschall 226
        if(!res) {
2 toby 227
                alertuser("Could not create standalone plugin.","");
184 dmarschall 228
        } else {
229
                showmessage("Filter was sucessfully created");
230
        }
2 toby 231
 
232
        return res ? ioErr : noErr;
233
}