Subversion Repositories filter_foundry

Rev

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