Subversion Repositories filter_foundry

Rev

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