Subversion Repositories filter_foundry

Rev

Rev 2 | Rev 11 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 toby 1
/*
2
        This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
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 <plstringfuncs.h>
21
#include <ASRegistry.h>
22
 
23
#include "ff.h"
24
 
25
#include "file_compat.h"
26
 
27
// MoreFiles headers
28
#include "FileCopy.h" 
29
#include "MoreFilesExtras.h"
30
 
31
OSErr wrstr(FILEREF rn,char *s);
32
OSErr dopkginfo(FILEREF rn);
33
OSErr make_bundle(StandardFileReply *sfr, short plugvol,long plugdir,StringPtr plugname);
34
OSErr doresources(FSSpec *srcplug, short dstvol,long dstdir,StringPtr dstname);
35
OSErr make_singlefile(StandardFileReply *sfr, short plugvol,long plugdir,StringPtr plugname);
36
 
37
OSErr wrstr(FILEREF rn,char *s){
38
        long count = strlen(s);
39
        return FSWrite(rn,&count,s);
40
}
41
 
42
OSErr doresources(FSSpec *srcplug, short dstvol,long dstdir,StringPtr dstname){
43
        short srcrn,dstrn;
44
        Handle hpipl,h;
45
        long origsize,newsize;
46
        OSErr e = noErr;
47
        Str255 title;
48
 
49
        if( -1 != (srcrn = FSpOpenResFile(srcplug,fsCurPerm)) ){
50
 
51
                hpipl = Get1Resource('DATA',16000);
52
 
53
                if( -1 != (dstrn = HOpenResFile(dstvol,dstdir,dstname,fsWrPerm)) ){
54
 
55
                        /* create a new PiPL resource for the standalone plugin,
56
                           with updated title and category strings */
57
 
58
                        if(h = Get1Resource('PiPL',16000)){
59
                                RemoveResource(h);
60
 
61
                                DetachResource(hpipl);
62
 
63
                                PLstrcpy(title,gdata->parm.title);
64
                                if(gdata->parm.popDialog)
65
                                        PLstrcat(title,"\pÉ");
66
 
67
                                origsize = GetHandleSize(hpipl);
68
                                SetHandleSize(hpipl,origsize+0x300); /* some slop for fixup to work with */
69
                                HLock(hpipl);
70
                                newsize = fixpipl((PIPropertyList*) *hpipl,origsize,title);
71
                                HUnlock(hpipl);
72
                                SetHandleSize(hpipl,newsize);
73
 
74
                                AddResource(hpipl,'PiPL',16000,"\p");
75
                        }
76
 
77
                        /* do a similar trick with the terminology resource,
78
                           so the scripting system can distinguish the standalone plugin */
79
 
80
                        if(h = Get1Resource(typeAETE,AETE_ID)){
81
                                origsize = GetHandleSize(h);
82
                                SetHandleSize(h,origsize+0x100); /* slop for fixup to work with */
83
                                HLock(h);
84
                                newsize = fixaete((unsigned char*)*h,origsize,gdata->parm.title);
85
                                HUnlock(h);
86
                                SetHandleSize(h,newsize);
87
 
88
                                ChangedResource(h);
89
                        }
90
 
91
                        if( !(e = ResError()) ){
92
 
93
                                /* now add PARM resource */
94
 
95
                                if( !(e = PtrToHand(&gdata->parm,&h,sizeof(PARM_T))) ){
96
                                        AddResource(h,'PARM',PARM_ID,"\p");
97
                                        e = ResError();
98
                                }
99
                        }
100
 
101
                        CloseResFile(dstrn);
102
 
103
                }else e = ResError();
104
 
105
                CloseResFile(srcrn);
106
 
107
        }else e = ResError();
108
 
109
        return e;
110
}
111
 
112
#if 0
8 toby 113
// FIXME: The Mach-O build (for CS2/Mac) definitely will need something similar to the following!
114
// but without bothering with the MacOSClassic parts
115
 
2 toby 116
OSErr make_bundle(StandardFileReply *sfr, short plugvol,long plugdir,StringPtr plugname){
117
        short dstvol = sfr->sfFile.vRefNum;
118
        long bundledir,contentsdir,macosdir,macoscdir;
119
        DInfo fndrInfo;
120
        OSErr e;
121
        Str255 temp;
122
        FSSpec fss,macosfss,macoscfss;
123
 
124
        if( !(e = FSpDirCreate(&sfr->sfFile,sfr->sfScript,&bundledir)) ){
125
                if(!(e = FSpGetDInfo(&sfr->sfFile,&fndrInfo)) ){
126
                        fndrInfo.frFlags |= kHasBundle;
127
                        FSpSetDInfo(&sfr->sfFile,&fndrInfo);
128
                }
129
                if( !(e = DirCreate(dstvol,bundledir,"\pContents",&contentsdir)) ){
130
                        if( !(e = DirCreate(dstvol,contentsdir,"\pMacOS",&macosdir)) ){
131
                                if( !(e = DirCreate(dstvol,contentsdir,"\pMacOSClassic",&macoscdir)) ){
132
 
133
                                        /* directories created ; now we need to copy the Info.plist file, and the two binaries */
134
 
135
                                        if( !(e = FSMakeFSSpec(plugvol,plugdir,"\p::Info.plist",&fss))
136
                                         && !(e = FileCopy(fss.vRefNum,fss.parID,fss.name, dstvol,contentsdir,NULL, NULL,NULL,0,false)) ){
137
                                                PLstrcpy(temp,"\p::MacOSClassic:");
138
                                                PLstrcat(temp,plugname);
139
                                                if( !(e = FSMakeFSSpec(plugvol,plugdir,temp,&macoscfss))
140
                                                 && !(e = FileCopy(macoscfss.vRefNum,macoscfss.parID,macoscfss.name, dstvol,macoscdir,NULL, NULL,NULL,0,false)) ){
141
                                                        PLstrcpy(temp,"\p::MacOS:");
142
                                                        PLstrcat(temp,plugname);
143
                                                        if( !(e = FSMakeFSSpec(plugvol,plugdir,temp,&macosfss))
144
                                                         && !(e = FileCopy(macosfss.vRefNum,macosfss.parID,macosfss.name, dstvol,macosdir,NULL, NULL,NULL,0,false)) ){
145
                                                                /* now we add PARM resources to each binary, and edit PiPLs */
146
                                                                doresources(&macosfss, dstvol,macosdir,plugname);
147
                                                                doresources(&macoscfss, dstvol,macoscdir,plugname);
148
                                                        }
149
                                                        else HDelete(0,macoscdir,plugname);
150
                                                }else HDelete(0,contentsdir,"\pInfo.plist");
151
                                        }
152
 
153
                                        if(e) HDelete(0,contentsdir,"\pMacOSClassic");
154
                                }
155
                                if(e) HDelete(0,contentsdir,"\pMacOS");
156
                        }
157
                        if(e) HDelete(0,bundledir,"\pContents");
158
                }
159
                if(e) FSpDelete(&sfr->sfFile);
160
        }
161
 
162
        return e;
163
}
164
#endif
165
 
166
OSErr make_singlefile(StandardFileReply *sfr, short plugvol,long plugdir,StringPtr plugname){
167
        OSErr e;
168
        FSSpec origfss;
169
 
170
        e = FSpDelete(&sfr->sfFile);
171
        if(e && e != fnfErr){
172
                alertuser("Can't replace the existing plugin. Try a different name or location.","");
173
                return userCanceledErr;
174
        }
175
 
176
        if( !(e = FileCopy(plugvol,plugdir,plugname, sfr->sfFile.vRefNum,sfr->sfFile.parID,NULL, sfr->sfFile.name,NULL,0,false))
177
        && !(e = FSMakeFSSpec(plugvol,plugdir,plugname,&origfss)) )
178
                /* now we add PARM resources, and edit PiPL */
179
                e = doresources(&origfss, sfr->sfFile.vRefNum,sfr->sfFile.parID,sfr->sfFile.name);
180
 
181
        return e;
182
}
183
 
184
OSErr make_standalone(StandardFileReply *sfr){
185
        OSErr e;
186
        short plugvol;
187
        long plugdir;
188
        Str255 plugname;
189
 
190
        if(!(e = GetFileLocation(CurResFile(),&plugvol,&plugdir,plugname)))
191
                e = make_singlefile(sfr,plugvol,plugdir,plugname); //make_bundle(sfr,plugvol,plugdir,plugname);
192
 
193
        if(e && e != userCanceledErr)
194
                alertuser("Could not create standalone plugin.","");
195
 
196
        return e;
197
}