diff options
Diffstat (limited to 'macosx/HBOutputFileWriter.m')
-rw-r--r-- | macosx/HBOutputFileWriter.m | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/macosx/HBOutputFileWriter.m b/macosx/HBOutputFileWriter.m new file mode 100644 index 000000000..f01293f12 --- /dev/null +++ b/macosx/HBOutputFileWriter.m @@ -0,0 +1,69 @@ +/* HBOutputFileWriter.m $ + + This file is part of the HandBrake source code. + Homepage: <http://handbrake.fr/>. + It may be used under the terms of the GNU General Public License. */ + +#import "HBOutputFileWriter.h" +#import "HBUtilities.h" + +@implementation HBOutputFileWriter +{ + FILE *f; +} + +- (instancetype)initWithFileURL:(NSURL *)url; +{ + self = [super init]; + if (self) + { + _url = [url copy]; + f = fopen(url.fileSystemRepresentation, "w"); + f = freopen(NULL, "a", f); + + [self writeHeaderForReason:@"Session"]; + } + + return self; +} + +- (void)dealloc +{ + fclose(f); + [_url release]; + [super dealloc]; +} + +- (void)writeHeaderForReason:(NSString *)reason +{ + [self write:[NSString stringWithFormat:@"HandBrake Activity Log for %@: %@\n%@\n", + reason, + [[NSDate date] descriptionWithCalendarFormat:nil timeZone:nil locale:nil], + [HBUtilities handBrakeVersion]]]; +} + +- (void)write:(NSString *)text +{ + fprintf(f, "%s", text.UTF8String); + fflush(f); +} + +- (void)stdoutRedirect:(NSString *)text +{ + [self write:text]; +} + +- (void)stderrRedirect:(NSString *)text +{ + [self write:text]; +} + +- (void)clear +{ + f = freopen(NULL, "w", f); + f = freopen(NULL, "a", f); + + [self writeHeaderForReason:@"Session (Cleared)"]; +} + +@end |