Subversion Repositories filter_foundry

Rev

Rev 18 | 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-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 "ff.h"
  21.  
  22. #include "file_compat.h"
  23.  
  24. #include <string.h>
  25.  
  26. Boolean readPARMresource(HMODULE hm,char **reason){
  27.         Boolean res = false;
  28.         HRSRC resinfo;
  29.         HANDLE h;
  30.         Ptr pparm;
  31.  
  32.         if( (resinfo = FindResource(hm,MAKEINTRESOURCE(PARM_ID),"PARM"))
  33.                                                 && (h = LoadResource(hm,resinfo))
  34.                                                 && (pparm = LockResource(h)) ){
  35.                 res = readPARM(pparm,&gdata->parm,reason);
  36.         }
  37.         return res;
  38. }
  39.  
  40. // see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/loadlibraryex.asp
  41.  
  42. Boolean loadfile(StandardFileReply *sfr,char **reason){
  43.         Boolean readok = false;
  44.         HANDLE h;
  45.         HMODULE hm;
  46.  
  47.         sfr->sfFile.name[*sfr->sfFile.name+1] = 0; // add terminating null
  48.  
  49.         if(sfr->nFileExtension){
  50.                 if(!strcasecmp((char*)sfr->sfFile.name + 1 + sfr->nFileExtension,"8bf")){
  51.                         if( hm = LoadLibraryEx((char*)sfr->sfFile.name+1,NULL,LOAD_LIBRARY_AS_DATAFILE) ){
  52.                                 if(readPARMresource(hm,reason)){
  53.                                         if(gdata->parm.iProtected)
  54.                                                 *reason = ("The filter is protected.");
  55.                                         else
  56.                                                 readok = gdata->parmloaded = true;
  57.                                 }else *reason = ("It is not a standalone filter made by Filter Factory/Filter Foundry.");
  58.                                 FreeLibrary(hm);
  59.                         }else{
  60.                                 *reason = "Could not open file (LoadLibrary failed).";
  61.                                 dbglasterror("LoadLibrary");
  62.                         }
  63.                 }else{
  64.                         if(readok = readfile(sfr,reason))
  65.                                 gdata->parmloaded = false;
  66.                 }
  67.         }
  68.  
  69.         return readok;
  70. }
  71.