-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSMFComplexProcessDropShadowControl.m
67 lines (56 loc) · 1.48 KB
/
SMFComplexProcessDropShadowControl.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// SMFComplexProcessDropShadowControl.m
// SMFramework
//
// Created by Thomas Cool on 2/28/11.
// Copyright 2011 Thomas Cool. All rights reserved.
//
#import "SMFComplexProcessDropShadowControl.h"
@interface NSObject (smfcpdsc)
-(void)process:(SMFComplexProcessDropShadowControl *)p ended:(NSString *)s;
@end
@implementation SMFComplexProcessDropShadowControl
@synthesize ap;
@synthesize returnCode;
@synthesize finished;
-(id)init
{
self=[super init];
returnCode=YES;
finished=NO;
return self;
}
-(void)controlWasActivated
{
[super controlWasActivated];
[self performSelectorInBackground:@selector(runProcess) withObject:nil];
}
-(void)dealloc
{
self.ap=nil;
[super dealloc];
}
-(int)runProcess
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
char line[200];
FILE* fp = popen([ap UTF8String], "r");
// NSMutableArray *lines = [[NSMutableArray alloc]init];
if (fp)
{
while (fgets(line, sizeof line, fp))
{
NSString *s = [NSString stringWithCString:line encoding:NSUTF8StringEncoding];
// NSLog(@"s: %@",s);
[self performSelectorOnMainThread:@selector(appendToText:) withObject:[s stringByAppendingString:@"\n"] waitUntilDone:YES];
}
}
returnCode = pclose(fp);
finished =YES;
if ([self.delegate respondsToSelector:@selector(process:ended:)]) {
[self.delegate process:self ended:ap];
}
[pool release];
return returnCode;
}
@end