Subversion Repositories filter_foundry

Rev

Rev 23 | Rev 85 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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