]> git.saurik.com Git - uikittools.git/blob - uishoot.mm
Added uishoot.
[uikittools.git] / uishoot.mm
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
46 for (unsigned i(0); i != 10 && !taken; ++i) {
47 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
48
49 for (unsigned j(0); j != 1000 && !taken; ++j) {
50 unsigned index = i * 1000 + j;
51
52 NSString *file = [NSString stringWithFormat:@"%@/IMG_%04u.PNG", apple, index];
53
54 if (![manager fileExistsAtPath:file isDirectory:&directory]) {
55 [png writeToFile:file atomically:YES];
56
57 NSString *thm = [NSString stringWithFormat:@"%@/IMG_%04u.THM", apple, index];
58 UIImage *thumb = [image _imageScaledToSize:CGSizeMake(55.0f, 55.0f) interpolationQuality:1];
59 NSData *jpeg = UIImageJPEGRepresentation(thumb);
60 [jpeg writeToFile:thm atomically:YES];
61
62 NSString *poster = [NSString stringWithFormat:@"%@/.MISC/PosterImage.jpg", dcim, index];
63 [jpeg writeToFile:poster atomically:YES];
64
65 CFNotificationCenterPostNotification(
66 CFNotificationCenterGetDarwinNotifyCenter(),
67 (CFStringRef) @"PictureWasTakenNotification",
68 NULL, NULL, YES
69 );
70
71 taken = true;
72 }
73 }
74
75 [pool release];
76 }
77
78 if (!taken) {
79 NSLog(@"%@ is full", apple);
80 return 1;
81 }
82
83 [pool release];
84 return 0;
85 }