]>
Commit | Line | Data |
---|---|---|
9b2ade70 JF |
1 | #import <CoreFoundation/CFData.h> |
2 | #import <CoreGraphics/CGImage.h> | |
3 | #import <Foundation/Foundation.h> | |
4 | #import <UIKit/UIImage-UIImageInternal.h> | |
5 | ||
6 | #include <stdint.h> | |
7 | #include <stdlib.h> | |
8 | ||
9 | #define _trace() NSLog(@"_trace():%s:%u", __FILE__, __LINE__) | |
10 | ||
11 | extern "C" CGImageRef UIGetScreenImage(); | |
12 | extern "C" NSData *UIImagePNGRepresentation(UIImage *); | |
13 | extern "C" NSData *UIImageJPEGRepresentation(UIImage *); | |
14 | ||
15 | int main(int argc, char *argv[]) { | |
16 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
17 | ||
18 | CGImageRef screen = UIGetScreenImage(); | |
19 | UIImage *image = [UIImage imageWithCGImage:screen]; | |
20 | NSData *png = UIImagePNGRepresentation(image); | |
21 | CFRelease(screen); | |
22 | ||
23 | NSString *dcim = [NSString stringWithFormat:@"%@/Media/DCIM", NSHomeDirectory()]; | |
24 | NSString *apple = [NSString stringWithFormat:@"%@/999APPLE", dcim]; | |
25 | ||
26 | NSFileManager *manager = [NSFileManager defaultManager]; | |
27 | BOOL directory; | |
28 | ||
29 | if (![manager fileExistsAtPath:apple isDirectory:&directory]) { | |
30 | if (![manager | |
31 | createDirectoryAtPath:apple | |
32 | withIntermediateDirectories:YES | |
33 | attributes:nil | |
34 | error:NULL | |
35 | ]) { | |
36 | NSLog(@"%@ does not exist and cannot be created", apple); | |
37 | return 1; | |
38 | } | |
39 | } else if (!directory) { | |
40 | NSLog(@"%@ exists and is not a directory", apple); | |
41 | return 1; | |
42 | } | |
43 | ||
44 | bool taken = false; | |
45 | ||
21202e03 | 46 | for (unsigned i(0); i != 100 && !taken; ++i) { |
9b2ade70 JF |
47 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
48 | ||
21202e03 JF |
49 | for (unsigned j(0); j != 100 && !taken; ++j) { |
50 | unsigned index = i * 100 + j; | |
51 | if (index == 0) | |
52 | continue; | |
9b2ade70 JF |
53 | |
54 | NSString *file = [NSString stringWithFormat:@"%@/IMG_%04u.PNG", apple, index]; | |
55 | ||
56 | if (![manager fileExistsAtPath:file isDirectory:&directory]) { | |
57 | [png writeToFile:file atomically:YES]; | |
58 | ||
59 | NSString *thm = [NSString stringWithFormat:@"%@/IMG_%04u.THM", apple, index]; | |
60 | UIImage *thumb = [image _imageScaledToSize:CGSizeMake(55.0f, 55.0f) interpolationQuality:1]; | |
61 | NSData *jpeg = UIImageJPEGRepresentation(thumb); | |
62 | [jpeg writeToFile:thm atomically:YES]; | |
63 | ||
64 | NSString *poster = [NSString stringWithFormat:@"%@/.MISC/PosterImage.jpg", dcim, index]; | |
65 | [jpeg writeToFile:poster atomically:YES]; | |
66 | ||
67 | CFNotificationCenterPostNotification( | |
68 | CFNotificationCenterGetDarwinNotifyCenter(), | |
69 | (CFStringRef) @"PictureWasTakenNotification", | |
70 | NULL, NULL, YES | |
71 | ); | |
72 | ||
73 | taken = true; | |
21202e03 JF |
74 | |
75 | NSLog(@"DONE: %@", file); | |
9b2ade70 JF |
76 | } |
77 | } | |
78 | ||
79 | [pool release]; | |
80 | } | |
81 | ||
82 | if (!taken) { | |
21202e03 | 83 | NSLog(@"%@ is too full", apple); |
9b2ade70 JF |
84 | return 1; |
85 | } | |
86 | ||
87 | [pool release]; | |
88 | return 0; | |
89 | } |