From b0793fdd8776ee1a15393d946a821d7661d49e28 Mon Sep 17 00:00:00 2001 From: ChildhoodAndy Date: Fri, 10 Jan 2014 14:51:58 +0800 Subject: [PATCH] fix bug about invalid "write debug log to file" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复:mac版Player在禁用"Show Debug Console"后, "Write Debug Log to File"无效,见 [Issue #221](https://github.com/dualface/quick-cocos2d-x/issues/221#issuecomment-32004473) --- player/proj.mac/AppController.mm | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/player/proj.mac/AppController.mm b/player/proj.mac/AppController.mm index 4b037f172..4bf170ab3 100644 --- a/player/proj.mac/AppController.mm +++ b/player/proj.mac/AppController.mm @@ -133,11 +133,14 @@ - (void) openConsoleWindow consoleController = [[ConsoleWindowController alloc] initWithWindowNibName:@"ConsoleWindow"]; } [consoleController.window orderFrontRegardless]; +} +- (void) startWriteDebugLog +{ //set console pipe pipe = [NSPipe pipe] ; pipeReadHandle = [pipe fileHandleForReading] ; - + int outfd = [[pipe fileHandleForWriting] fileDescriptor]; if (dup2(outfd, fileno(stderr)) != fileno(stderr) || dup2(outfd, fileno(stdout)) != fileno(stdout)) { @@ -226,6 +229,11 @@ - (void) startup { [self openConsoleWindow]; } + + if(projectConfig.isWriteDebugLogToFile() || projectConfig.isShowConsole()) + { + [self startWriteDebugLog]; + } app = new AppDelegate(); bridge = new AppControllerBridge(self); @@ -501,11 +509,15 @@ - (void)handleNotification:(NSNotification *)note NSData *data = [[note userInfo] objectForKey:NSFileHandleNotificationDataItem]; NSString *str = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; //show log to console - [consoleController trace:str]; - if(fileHandle!=nil){ + if(projectConfig.isShowConsole()) + { + [consoleController trace:str]; + } + //write log to file + if(fileHandle!=nil) + { [fileHandle writeData:[str dataUsingEncoding:NSUTF8StringEncoding]]; } - } - (void) closeDebugLogFile