-
Notifications
You must be signed in to change notification settings - Fork 7
/
Console.m
102 lines (84 loc) · 2.57 KB
/
Console.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// Console.m
// mac-screen-recorder
//
// Created by Daniel Dixon on 3/20/10.
//
#import "Console.h"
@implementation Console
-(Console*)initWithArgc:(int)argc withArgv:(char*[])argv
{
BOOL captureAudio = YES;
if (self = [super init]) {
NSLog(@"Mac Screen Recorder");
NSLog(@"requires Snow Leopard, Mac OS 10.6)");
if (argc < 2 || argv[argc-1][0] == '-') {
// If an error occurs here, send a [self release] message and return nil.
NSLog(@"ERROR: Please specify a proper output file as the only parameter (ex: './mac-screen-recorder movie.mov')");
[self release];
return nil;
} else {
NSLog(@"Please type a command (i.e. 'help'):");
}
// Find an parameters passed in via command line
int i;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i],"-noaudio") == 0) {
captureAudio = NO;
}
}
// Get the path and name of the output file
mOutputFilePath = [[[NSString alloc] initWithCString: argv[argc-1]] autorelease];
mRecorder = [[ScreenRecorder alloc] init:captureAudio];
if(mRecorder == nil) {
[self release];
return nil;
}
}
return self;
}
// Called when user hits return
- (void)dataAvailable:(NSNotification *)notification
{
//Get the available data
NSData *data = [[notification object] availableData]; //This will be the latest line of input
//Convert it to a string
NSString *dataString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
//Process the data, in this case, we just log it
//NSLog(@"%@ = %@", dataString, data);
if([dataString isEqualToString:@"start\n"]) {
[mRecorder startRecording:mOutputFilePath];
NSLog(@"Starting recording...");
}
else if([dataString isEqualToString:@"stop\n"]) {
[mRecorder stopRecording];
NSLog(@"Stopping recording...");
}
else if([dataString isEqualToString:@"help\n"]) {
NSLog(@"Usage (type one of the following commands):");
NSLog(@" start - Start recording the screen");
NSLog(@" stop - Stop recording the screen");
NSLog(@" help - Print this information");
NSLog(@" quit - Quit the screen recorder");
}
else if(![dataString isEqualToString:@"quit\n"]) {
[mRecorder stopRecording];
NSLog(@"Unknown command: '%s' \n",dataString);
}
// Wait for new input or exit?
if ([dataString isEqualToString:@"quit\n"]) {
NSLog(@"Goodbye");
[NSApp terminate:self];
[dataString release];
} else {
//Clean up the string
[dataString release];
//the waitFor... method only works once, so reregister.
[[notification object] waitForDataInBackgroundAndNotify];
}
}
- (void)dealloc {
[mRecorder release];
[super dealloc];
}
@end