|
| 1 | +#include <CoreFoundation/CoreFoundation.h> |
| 2 | +#include <CoreServices/CoreServices.h> |
| 3 | + |
| 4 | +#include <xar/xar.h> |
| 5 | + |
| 6 | +/* ----------------------------------------------------------------------------- |
| 7 | + Step 1 |
| 8 | + Set the UTI types the importer supports |
| 9 | + |
| 10 | + Modify the CFBundleDocumentTypes entry in Info.plist to contain |
| 11 | + an array of Uniform Type Identifiers (UTI) for the LSItemContentTypes |
| 12 | + that your importer can handle |
| 13 | + |
| 14 | + ----------------------------------------------------------------------------- */ |
| 15 | + |
| 16 | +/* ----------------------------------------------------------------------------- |
| 17 | + Step 2 |
| 18 | + Implement the GetMetadataForFile function |
| 19 | + |
| 20 | + Implement the GetMetadataForFile function below to scrape the relevant |
| 21 | + metadata from your document and return it as a CFDictionary using standard keys |
| 22 | + (defined in MDItem.h) whenever possible. |
| 23 | + ----------------------------------------------------------------------------- */ |
| 24 | + |
| 25 | +/* ----------------------------------------------------------------------------- |
| 26 | + Step 3 (optional) |
| 27 | + If you have defined new attributes, update the schema.xml file |
| 28 | + |
| 29 | + Edit the schema.xml file to include the metadata keys that your importer returns. |
| 30 | + Add them to the <allattrs> and <displayattrs> elements. |
| 31 | + |
| 32 | + Add any custom types that your importer requires to the <attributes> element |
| 33 | + |
| 34 | + <attribute name="com_mycompany_metadatakey" type="CFString" multivalued="true"/> |
| 35 | + |
| 36 | + ----------------------------------------------------------------------------- */ |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +/* ----------------------------------------------------------------------------- |
| 41 | + Get metadata attributes from file |
| 42 | + |
| 43 | + This function's job is to extract useful information your file format supports |
| 44 | + and return it as a dictionary |
| 45 | + ----------------------------------------------------------------------------- */ |
| 46 | + |
| 47 | +Boolean GetMetadataForFile(void* thisInterface, |
| 48 | + CFMutableDictionaryRef attributes, |
| 49 | + CFStringRef contentTypeUTI, |
| 50 | + CFStringRef pathToFile) |
| 51 | +{ |
| 52 | + /* Pull any available metadata from the file at the specified path */ |
| 53 | + /* Return the attribute keys and attribute values in the dict */ |
| 54 | + /* Return TRUE if successful, FALSE if there was no data provided */ |
| 55 | + char cpath[PATH_MAX]; |
| 56 | + xar_t x; |
| 57 | + xar_file_t f; |
| 58 | + xar_iter_t i; |
| 59 | + CFMutableStringRef filelist; |
| 60 | + |
| 61 | + if( CFStringGetCString(pathToFile, cpath, sizeof(cpath), kCFStringEncodingUTF8) == FALSE ) |
| 62 | + return FALSE; |
| 63 | + |
| 64 | + x = xar_open(cpath, READ); |
| 65 | + if( !x ) |
| 66 | + return FALSE; |
| 67 | + |
| 68 | + i = xar_iter_new(); |
| 69 | + if( !i ) |
| 70 | + return FALSE; |
| 71 | + |
| 72 | + filelist = CFStringCreateMutable(NULL, 0); |
| 73 | + for(f = xar_file_first(x, i); f; f = xar_file_next(i)) { |
| 74 | + const char *path; |
| 75 | + path = xar_get_path(f); |
| 76 | + CFStringAppendCString(filelist, " ", kCFStringEncodingUTF8); |
| 77 | + CFStringAppendCString(filelist, path, kCFStringEncodingUTF8); |
| 78 | + } |
| 79 | + CFDictionarySetValue(attributes, kMDItemTextContent, filelist); |
| 80 | + CFDictionarySetValue(attributes, kMDItemKind, CFSTR("XAR!")); |
| 81 | + CFDictionarySetValue(attributes, kMDItemCreator, CFSTR("xar")); |
| 82 | + CFRelease(filelist); |
| 83 | + |
| 84 | + xar_close(x); |
| 85 | + return TRUE; |
| 86 | +} |
0 commit comments