Subversion Repositories filter_foundry

Rev

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