/
GifsicleWorker.m
42 lines (29 loc) · 1.25 KB
/
GifsicleWorker.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
#import "GifsicleWorker.h"
#import "../File.h"
@implementation GifsicleWorker
@synthesize interlace;
-(NSInteger)settingsIdentifier {
return interlace;
}
-(BOOL)runWithTempPath:(NSURL *)temp {
NSMutableArray *args = [NSMutableArray arrayWithObjects:@"-o",temp.path,
interlace ? @"--interlace" : @"--no-interlace",
@"-O3",
@"--careful",/* needed for Safari/Preview decoding bug */
@"--no-comments",@"--no-names",@"--same-delay",@"--same-loopcount",@"--no-warnings",
@"--",file.filePathOptimized.path,nil];
if (![self sandBoxedTaskForKey:@"Gifsicle" bundleName:@"gifsicle" arguments:args]) {
return NO;
}
NSFileHandle *devnull = [NSFileHandle fileHandleWithNullDevice];
[task setStandardInput: devnull];
[task setStandardError: devnull];
[task setStandardOutput: devnull];
[self launchTask];
[task waitUntilExit];
[devnull closeFile];
if ([task terminationStatus]) return NO;
NSUInteger fileSizeOptimized = [File fileByteSize:temp];
return [file setFilePathOptimized:temp size:fileSizeOptimized toolName:interlace ? @"Gifsicle interlaced" : @"Gifsicle"];
}
@end