/
main.m
52 lines (44 loc) · 1.74 KB
/
main.m
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
//
// main.m
// icon-extract
//
// Created by Peter Hosey on 2011-10-29.
// Copyright (c) 2011 Peter Hosey. All rights reserved.
//
#import "PRHExtractIconsFromFileOperation.h"
int main (int argc, char **argv) {
@autoreleasepool {
NSOperationQueue *queue = [NSOperationQueue mainQueue];
NSFileManager *mgr = [NSFileManager new];
NSString *cwdPath = nil;
NSEnumerator *argsEnum = [[[NSProcessInfo processInfo] arguments] objectEnumerator];
[argsEnum nextObject]; //Drop the executable name/path on the floor
NSString *arg;
for (arg in argsEnum) {
if (![arg isAbsolutePath]) {
if (!cwdPath)
cwdPath = [mgr currentDirectoryPath];
arg = [cwdPath stringByAppendingPathComponent:arg];
}
NSURL *sourceURL = [NSURL fileURLWithPath:arg];
NSString *sourceFilename = [sourceURL lastPathComponent];
NSString *sourceBaseFilename = [sourceFilename stringByDeletingPathExtension];
NSURL *destinationURL = [[sourceURL URLByDeletingLastPathComponent] URLByAppendingPathComponent:[NSString stringWithFormat:@"%@-icons.out", sourceBaseFilename] isDirectory:YES];
NSError *error = nil;
if (![mgr createDirectoryAtURL:destinationURL withIntermediateDirectories:NO attributes:nil error:&error]) {
if (([error domain] == NSCocoaErrorDomain) && ([error code] == NSFileWriteFileExistsError))
/*That's cool.*/;
else {
NSLog(@"Couldn't create output directory at %@: %@", destinationURL, error);
continue;
}
}
PRHExtractIconsFromFileOperation *op = [PRHExtractIconsFromFileOperation new];
op.sourceURL = sourceURL;
op.destinationDirectoryURL = destinationURL;
[queue addOperation:op];
}
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}
return EXIT_SUCCESS;
}