1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
// =================================================================================================
// Copyright 2002 Adobe Systems Incorporated
// All Rights Reserved.
//
// NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
// of the Adobe license agreement accompanying it.
// =================================================================================================
/**
* Uses the XMPFiles component API to find the main XMP Packet for a data file, serializes the XMP, and writes
* it to a human-readable log file. This is preferred over "dumb" packet scanning.
*/
#include <string>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdexcept>
#include <errno.h>
#include <cstring>
#if XMP_WinBuild
#pragma warning ( disable : 4127 ) // conditional expression is constant
#pragma warning ( disable : 4996 ) // '...' was declared deprecated
#endif
#define TXMP_STRING_TYPE std::string
#define XMP_INCLUDE_XMPFILES 1
#include "XMP.hpp"
#include "XMP.incl_cpp"
using namespace std;
static FILE * sLogFile = stdout;
// =================================================================================================
static void WriteMinorLabel ( FILE * log, const char * title )
{
fprintf ( log, "\n// " );
for ( size_t i = 0; i < strlen(title); ++i ) fprintf ( log, "-" );
fprintf ( log, "--\n// %s :\n\n", title );
fflush ( log );
} // WriteMinorLabel
// =================================================================================================
static XMP_Status DumpCallback ( void * refCon, XMP_StringPtr outStr, XMP_StringLen outLen )
{
XMP_Status status = 0;
size_t count;
FILE * outFile = static_cast < FILE * > ( refCon );
count = fwrite ( outStr, 1, outLen, outFile );
if ( count != outLen ) status = errno;
return status;
} // DumpCallback
// =================================================================================================
static void
ProcessFile ( const char * fileName )
{
bool ok;
char buffer [1000];
SXMPMeta xmpMeta;
SXMPFiles xmpFile;
XMP_FileFormat format;
XMP_OptionBits openFlags, handlerFlags;
XMP_PacketInfo xmpPacket;
sprintf ( buffer, "Dumping main XMP for %s", fileName );
WriteMinorLabel ( sLogFile, buffer );
xmpFile.OpenFile ( fileName, kXMP_UnknownFile, kXMPFiles_OpenForRead );
ok = xmpFile.GetFileInfo ( 0, &openFlags, &format, &handlerFlags );
if ( ! ok ) return;
fprintf ( sLogFile, "File info : format = \"%.4s\", handler flags = %.8X\n", &format, handlerFlags );
fflush ( sLogFile );
ok = xmpFile.GetXMP ( &xmpMeta, 0, &xmpPacket );
if ( ! ok ) return;
XMP_Int32 offset = (XMP_Int32)xmpPacket.offset;
XMP_Int32 length = xmpPacket.length;
fprintf ( sLogFile, "Packet info : offset = %d, length = %d\n", offset, length );
fflush ( sLogFile );
fprintf ( sLogFile, "\nInitial XMP from %s\n", fileName );
xmpMeta.DumpObject ( DumpCallback, sLogFile );
xmpFile.CloseFile();
} // ProcessFile
// =================================================================================================
int
main ( int argc, const char * argv [] )
{
if ( ! SXMPMeta::Initialize() ) {
printf ( "## SXMPMeta::Initialize failed!\n" );
return -1;
}
XMP_OptionBits options = 0;
#if UNIX_ENV
options |= kXMPFiles_ServerMode;
#endif
if ( ! SXMPFiles::Initialize ( options ) ) {
printf ( "## SXMPFiles::Initialize failed!\n" );
return -1;
}
for ( int i = 1; i < argc; ++i ) ProcessFile ( argv[i] );
SXMPFiles::Terminate();
SXMPMeta::Terminate();
return 0;
}
|