summaryrefslogtreecommitdiffstats
path: root/macosx/HBOutputFileWriter.m
diff options
context:
space:
mode:
authorritsuka <[email protected]>2015-02-20 07:59:38 +0000
committerritsuka <[email protected]>2015-02-20 07:59:38 +0000
commit214fed29cdc153d4c0581bc0516b258a108cef22 (patch)
tree105b8454670e28f33a721a4d0b328dc2565a2446 /macosx/HBOutputFileWriter.m
parentfea0f7fa7473a10e56d6da95f47e03ba44ad2c35 (diff)
MacGui: refactor the stderr/stdout redirect code to be more modular.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6927 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBOutputFileWriter.m')
-rw-r--r--macosx/HBOutputFileWriter.m69
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