/* This file is part of "psdrecover", a File Format plugin for Adobe Photoshop Copyright (C) 2007-2011 Toby Thain, toby@telegraphics.com.au This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "psdrecover.h" #include "PIAbout.h" #include "PIBufferSuite.h" #include "entry.h" // must come after Photoshop includes #include "ui.h" enum{ // In fact, Photoshop's Buffer Suite is used, so this value is only nominal. MAX_MEM = 2L<<20 }; // psdparse global options int verbose = 0, quiet = 0, rsrc = 1 /* needed to extract resolution */, print_rsrc = 0, resdump = 0, extra = 0, makedirs = 0, numbered = 0, \ help = 0, split = 0, writepng = 0, writelist = 0, writexml = 0, \ xmlout = 0, unicode_filenames = 0; long maxData; char *pngdir = ""; PSBufferSuite1 *sPSBuffer; int allocs; DLLEXPORT MACPASCAL void PluginMain(short selector, FormatRecordPtr pb, intptr_t *data, short *result){ OSErr e = noErr; EnterCodeResource(); /* Perform the requested operation */ if(selector == formatSelectorAbout){ DoAbout((AboutRecordPtr)pb); } else{ e = pb->sSPBasic->AcquireSuite(kPSBufferSuite, kPSBufferSuiteVersion1, (const void**)&sPSBuffer); if(!e){ switch (selector){ //case formatSelectorEstimatePrepare: //case formatSelectorWritePrepare: case formatSelectorReadPrepare: #if defined(WANT_LARGE_FILES) && defined(MAC_ENV) && !defined(MACMACHO) && ! TARGET_CPU_68K /* Check for large file support. We do this every time the plugin is used, and make no assumption as to whether Photoshop opened the file with HFS calls or HFS+ Fork calls (FSGetForkPosition will return noErr in the latter case). */ { SInt64 pos; has_forks = host_has_forks() && noErr == FSGetForkPosition(pb->dataFork, &pos); } #endif maxData = pb->maxData / 2; if(maxData > MAX_MEM) maxData = MAX_MEM; pb->maxData = maxData; break; case formatSelectorReadStart: allocs = 0; e = read_start(pb, data); break; case formatSelectorReadContinue: e = read_continue(pb, data); break; case formatSelectorReadFinish: e = read_finish(pb, data); if(allocs){ char s[0x100]; sprintf(s, "Mismatched allocations! %d", allocs); dbg(s); } break; // no Options or Estimate phase, since we don't write /* case formatSelectorOptionsPrepare: pb->maxData = 0; // no buffers are allocated in Options break; case formatSelectorOptionsStart: pb->data = 0; case formatSelectorOptionsContinue: case formatSelectorOptionsFinish: case formatSelectorEstimateStart: case formatSelectorEstimateContinue: case formatSelectorEstimateFinish: break; case formatSelectorWriteStart: e = write_start(pb,data); break; case formatSelectorWriteContinue: e = write_continue(pb,data); break; case formatSelectorWriteFinish: e = write_finish(pb,data); break; */ case formatSelectorFilterFile: e = noErr; break; default: e = formatBadParameters; } pb->sSPBasic->ReleaseSuite(kPSBufferSuite, kPSBufferSuiteVersion1); } } *result = e; ExitCodeResource(); }