-
Notifications
You must be signed in to change notification settings - Fork 3
/
MCCCommonHeader.h
74 lines (66 loc) · 3.38 KB
/
MCCCommonHeader.h
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
//
// MCCMailAbstractor.h
// MailCommonCode
//
// Created by Scott Little on 14/6/13.
// Copyright (c) 2013 Little Known Software. All rights reserved.
//
// This requires a few levels of rewriting to get the desired results.
#define _MCC_CONCAT_2(c,d) c ## d
#define _MCC_CONCAT(a,b) _MCC_CONCAT_2(a,b)
#ifndef MCC_PLUGIN_PREFIX
#define MCC_PLUGIN_PREFIX MCC
#endif
#define MCC_PREFIXED_NAME(symbol) _MCC_CONCAT(MCC_PLUGIN_PREFIX,symbol)
#define MCC_PREFIXED_CONSTANT(symbol) _MCC_CONCAT(_MCC_CONCAT(k, MCC_PLUGIN_PREFIX),symbol)
#define MCC_SUFFIXED_NAME(symbol) _MCC_CONCAT(symbol, _MCC_CONCAT(_, MCC_PLUGIN_PREFIX) )
#define _MCC_AS_STR(a) #a
#define _MCC_CONCAT_AS_STR(a, b) _MCC_AS_STR( a ## b )
#define _MCC_NS_STR(a) @a
#define MCC_NSSTRING(a, b) _MCC_NS_STR(_MCC_CONCAT_AS_STR(a, b))
// ARC compatibility
#if __has_feature(objc_arc)
#define MCC_RETAIN(x)
#define MCC_RELEASE(x)
#define MCC_AUTORELEASE(x)
#define MCC_DEALLOC()
#define MCC_WEAK weak
#define MCC_WEAK_BLOCK __weak
#else
#define MCC_RETAIN(x) ([(x) retain])
#define MCC_RELEASE(x) ([(x) release])
#define MCC_AUTORELEASE(x) ([(x) autorelease])
#define MCC_DEALLOC() ([super dealloc])
#define MCC_WEAK assign
#define MCC_WEAK_BLOCK __block
#endif
#define MCCLogMailVersion() \
do { \
SEL commonMailInfoKey = NSSelectorFromString(@"CommonMailInfoKey"); \
NSString *mailVersionInfo = objc_getAssociatedObject(NSApp,commonMailInfoKey); \
if (!mailVersionInfo) { \
NSDictionary *OSVersionDictionary = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; \
NSString *OSBuild = [OSVersionDictionary objectForKey:@"ProductBuildVersion"]; \
NSString *OSVersion = [OSVersionDictionary objectForKey:@"ProductVersion"]; \
NSMutableString *mailVersionInformation = [NSMutableString stringWithFormat:@"\n\t\tLoaded Mail Version %@ (%@)\n\t\tOS X Version %@ (%@)", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"],[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"], OSVersion,OSBuild]; \
[mailVersionInformation appendFormat:@"\n\t\tInstalled Bundles:"]; \
NSArray *pathsToSearch = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask|NSLocalDomainMask|NSSystemDomainMask, YES); \
NSFileManager *fm = [NSFileManager defaultManager]; \
for (NSString *pathToSeach in pathsToSearch) { \
NSString *mailLibraryPath =[pathToSeach stringByAppendingPathComponent:@"Mail"]; \
NSString *bundles = [mailLibraryPath stringByAppendingPathComponent:@"Bundles"]; \
NSError *fmError = nil; \
NSArray *dirContents = [fm contentsOfDirectoryAtPath:bundles error:&fmError]; \
for (NSString *bundlePath in dirContents) { \
if ([bundlePath hasSuffix:@"mailbundle"]) { \
NSString *fullPath = [[bundles stringByAppendingPathComponent:bundlePath] stringByResolvingSymlinksInPath]; \
NSString *infoPlistPath = [fullPath stringByAppendingPathComponent:@"Contents/info.plist"]; \
NSDictionary *infoDict = [NSDictionary dictionaryWithContentsOfFile:infoPlistPath]; \
[mailVersionInformation appendFormat:@"\n\t\t\t%@ [%@ (%@)]", fullPath, [infoDict objectForKey:@"CFBundleShortVersionString"], [infoDict objectForKey:@"CFBundleVersion"]]; \
} \
} \
} \
NSLog (@"%@", mailVersionInformation); \
objc_setAssociatedObject(NSApp, commonMailInfoKey, mailVersionInformation, OBJC_ASSOCIATION_RETAIN); \
} \
} while (NO);