]>
Commit | Line | Data |
---|---|---|
a4ccf03b JF |
1 | /* UIKit Tools - command-line utilities for UIKit |
2 | * Copyright (C) 2008-2012 Jay Freeman (saurik) | |
3 | */ | |
4 | ||
5 | /* Modified BSD License {{{ */ | |
6 | /* | |
7 | * Redistribution and use in source and binary | |
8 | * forms, with or without modification, are permitted | |
9 | * provided that the following conditions are met: | |
10 | * | |
11 | * 1. Redistributions of source code must retain the | |
12 | * above copyright notice, this list of conditions | |
13 | * and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the | |
15 | * above copyright notice, this list of conditions | |
16 | * and the following disclaimer in the documentation | |
17 | * and/or other materials provided with the | |
18 | * distribution. | |
19 | * 3. The name of the author may not be used to endorse | |
20 | * or promote products derived from this software | |
21 | * without specific prior written permission. | |
22 | * | |
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' | |
24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | |
25 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE | |
28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
30 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
34 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
36 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
37 | */ | |
38 | /* }}} */ | |
39 | ||
9b2ade70 JF |
40 | #import <CoreFoundation/CFData.h> |
41 | #import <CoreGraphics/CGImage.h> | |
42 | #import <Foundation/Foundation.h> | |
43 | #import <UIKit/UIImage-UIImageInternal.h> | |
44 | ||
45 | #include <stdint.h> | |
46 | #include <stdlib.h> | |
47 | ||
48 | #define _trace() NSLog(@"_trace():%s:%u", __FILE__, __LINE__) | |
49 | ||
50 | extern "C" CGImageRef UIGetScreenImage(); | |
51 | extern "C" NSData *UIImagePNGRepresentation(UIImage *); | |
52 | extern "C" NSData *UIImageJPEGRepresentation(UIImage *); | |
53 | ||
54 | int main(int argc, char *argv[]) { | |
55 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
56 | ||
57 | CGImageRef screen = UIGetScreenImage(); | |
58 | UIImage *image = [UIImage imageWithCGImage:screen]; | |
59 | NSData *png = UIImagePNGRepresentation(image); | |
60 | CFRelease(screen); | |
61 | ||
62 | NSString *dcim = [NSString stringWithFormat:@"%@/Media/DCIM", NSHomeDirectory()]; | |
63 | NSString *apple = [NSString stringWithFormat:@"%@/999APPLE", dcim]; | |
64 | ||
65 | NSFileManager *manager = [NSFileManager defaultManager]; | |
66 | BOOL directory; | |
67 | ||
68 | if (![manager fileExistsAtPath:apple isDirectory:&directory]) { | |
69 | if (![manager | |
70 | createDirectoryAtPath:apple | |
71 | withIntermediateDirectories:YES | |
72 | attributes:nil | |
73 | error:NULL | |
74 | ]) { | |
75 | NSLog(@"%@ does not exist and cannot be created", apple); | |
76 | return 1; | |
77 | } | |
78 | } else if (!directory) { | |
79 | NSLog(@"%@ exists and is not a directory", apple); | |
80 | return 1; | |
81 | } | |
82 | ||
83 | bool taken = false; | |
84 | ||
21202e03 | 85 | for (unsigned i(0); i != 100 && !taken; ++i) { |
9b2ade70 JF |
86 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
87 | ||
21202e03 JF |
88 | for (unsigned j(0); j != 100 && !taken; ++j) { |
89 | unsigned index = i * 100 + j; | |
90 | if (index == 0) | |
91 | continue; | |
9b2ade70 JF |
92 | |
93 | NSString *file = [NSString stringWithFormat:@"%@/IMG_%04u.PNG", apple, index]; | |
94 | ||
95 | if (![manager fileExistsAtPath:file isDirectory:&directory]) { | |
96 | [png writeToFile:file atomically:YES]; | |
97 | ||
98 | NSString *thm = [NSString stringWithFormat:@"%@/IMG_%04u.THM", apple, index]; | |
99 | UIImage *thumb = [image _imageScaledToSize:CGSizeMake(55.0f, 55.0f) interpolationQuality:1]; | |
100 | NSData *jpeg = UIImageJPEGRepresentation(thumb); | |
101 | [jpeg writeToFile:thm atomically:YES]; | |
102 | ||
103 | NSString *poster = [NSString stringWithFormat:@"%@/.MISC/PosterImage.jpg", dcim, index]; | |
104 | [jpeg writeToFile:poster atomically:YES]; | |
105 | ||
106 | CFNotificationCenterPostNotification( | |
107 | CFNotificationCenterGetDarwinNotifyCenter(), | |
108 | (CFStringRef) @"PictureWasTakenNotification", | |
109 | NULL, NULL, YES | |
110 | ); | |
111 | ||
112 | taken = true; | |
21202e03 JF |
113 | |
114 | NSLog(@"DONE: %@", file); | |
9b2ade70 JF |
115 | } |
116 | } | |
117 | ||
118 | [pool release]; | |
119 | } | |
120 | ||
121 | if (!taken) { | |
21202e03 | 122 | NSLog(@"%@ is too full", apple); |
9b2ade70 JF |
123 | return 1; |
124 | } | |
125 | ||
126 | [pool release]; | |
127 | return 0; | |
128 | } |