X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=macosx%2FHBOutputPanelController.m;h=5ce02ad2d3903c1da8305a73c2d8b265db3508b1;hb=1c9c75d452c8d15ee972b4c4612763f9b95b1790;hp=f5af6d49a7c530b8f279503d4ee4460e95d793bc;hpb=ef7f472111f27ffede17caf2654538bd19db3944;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/macosx/HBOutputPanelController.m b/macosx/HBOutputPanelController.m index f5af6d49..5ce02ad2 100644 --- a/macosx/HBOutputPanelController.m +++ b/macosx/HBOutputPanelController.m @@ -60,7 +60,6 @@ /* We overwrite the existing output log with the date for starters the output log to start fresh with the new session */ /* Use the current date and time for the new output log header */ NSString *startOutputLogString = [NSString stringWithFormat: @"HandBrake Activity Log for Session (Cleared): %@\n\n", [[NSDate date] descriptionWithCalendarFormat:nil timeZone:nil locale:nil]]; - [startOutputLogString writeToFile:outputLogFile atomically:YES encoding:NSUTF8StringEncoding error:NULL]; [[HBOutputRedirect stderrRedirect] addListener:self]; @@ -70,6 +69,8 @@ [[textView layoutManager] replaceTextStorage:outputTextStorage]; [[textView enclosingScrollView] setLineScroll:10]; [[textView enclosingScrollView] setPageScroll:20]; + + encodeLogOn = NO; } return self; } @@ -90,10 +91,72 @@ */ - (IBAction)showOutputPanel:(id)sender { + if ([[self window] isVisible]) + { + [[self window] close]; + } + else + { [textView scrollRangeToVisible:NSMakeRange([outputTextStorage length], 0)]; [self showWindow:sender]; [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"OutputPanelIsOpen"]; + } +} + +- (void) startEncodeLog:(NSString *) logPath +{ + encodeLogOn = YES; + NSString *outputFileForEncode = logPath ; + /* Since the destination path matches the extension of the output file, replace the + * output movie extension and replace it with ".txt" + */ + NSFileManager * fileManager = [NSFileManager defaultManager]; + /* Establish the log file location to write to */ + /* We are initially using a .txt file as opposed to a .log file since it will open by + * default with the users text editor instead of the .log default Console.app, should + * create less confusion for less experienced users when we ask them to paste the log for support + */ + /* We need to get the current time in YY-MM-DD HH-MM-SS format to put at the beginning of the name of the log file */ + time_t _now = time( NULL ); + struct tm * now = localtime( &_now ); + NSString *dateForLogTitle = [NSString stringWithFormat:@"%02d-%02d-%02d %02d-%02d-%02d",now->tm_year + 1900, now->tm_mon + 1, now->tm_mday,now->tm_hour, now->tm_min, now->tm_sec]; + + /* Assemble the new log file name as YY-MM-DD HH-MM-SS mymoviename.txt */ + NSString *outputDateFileName = [NSString stringWithFormat:@"%@ %@.txt",[[outputFileForEncode lastPathComponent] stringByDeletingPathExtension],dateForLogTitle]; + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"EncodeLogLocation"]) // if we are putting it in the same directory with the movie + { + + outputLogFileForEncode = [[NSString stringWithFormat:@"%@/%@",[outputFileForEncode stringByDeletingLastPathComponent],outputDateFileName] retain]; + } + else // if we are putting it in the default ~/Libraries/Application Support/HandBrake/EncodeLogs logs directory + { + NSString *libraryDir = [NSSearchPathForDirectoriesInDomains( NSLibraryDirectory, + NSUserDomainMask, + YES ) objectAtIndex:0]; + NSString *encodeLogDirectory = [[[libraryDir stringByAppendingPathComponent:@"Application Support"] stringByAppendingPathComponent:@"HandBrake"] stringByAppendingPathComponent:@"EncodeLogs"]; + if( ![[NSFileManager defaultManager] fileExistsAtPath:encodeLogDirectory] ) + { + [[NSFileManager defaultManager] createDirectoryAtPath:encodeLogDirectory + withIntermediateDirectories:NO + attributes:nil + error:nil]; + } + outputLogFileForEncode = [[NSString stringWithFormat:@"%@/%@",encodeLogDirectory,outputDateFileName] retain]; + } + [fileManager createFileAtPath:outputLogFileForEncode contents:nil attributes:nil]; + + /* Similar to the regular activity log, we print a header containing the date and time of the encode as well as what directory it was encoded to */ + NSString *versionStringFull = [[NSString stringWithFormat: @"Handbrake Version: %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)\n\n", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]]; + NSString *startOutputLogString = [NSString stringWithFormat: @"HandBrake Activity Log for %@: %@\n%@",outputFileForEncode, [[NSDate date] descriptionWithCalendarFormat:nil timeZone:nil locale:nil],versionStringFull]; + [startOutputLogString writeToFile:outputLogFileForEncode atomically:YES encoding:NSUTF8StringEncoding error:NULL]; + + +} + +- (void) endEncodeLog +{ + encodeLogOn = NO; } /** @@ -120,7 +183,12 @@ fprintf(f, "%s", [text UTF8String]); fclose(f); - + if (encodeLogOn == YES && outputLogFileForEncode != nil) + { + FILE *e = fopen([outputLogFileForEncode UTF8String], "a"); + fprintf(e, "%s", [text UTF8String]); + fclose(e); + } /* Below uses Objective-C to write to the file, though it is slow and uses * more memory than the c function above. For now, leaving this in here * just in case and commented out. @@ -149,11 +217,11 @@ { [outputTextStorage deleteCharactersInRange:NSMakeRange(0, [outputTextStorage length])]; /* We want to rewrite the app version info to the top of the activity window so it is always present */ - NSString *versionStringFull = [[NSString stringWithFormat: @"Handbrake Version: %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleGetInfoString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]]; + NSString *versionStringFull = [[NSString stringWithFormat: @"Handbrake Version: %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)\n\n", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]]; time_t _now = time( NULL ); struct tm * now = localtime( &_now ); fprintf(stderr, "[%02d:%02d:%02d] macgui: %s\n", now->tm_hour, now->tm_min, now->tm_sec, [versionStringFull UTF8String]); - + } /** @@ -178,6 +246,29 @@ [myScript release]; } +/** + * Opens the activity log txt file in users default editor. + */ +- (IBAction)openEncodeLogDirectory:(id)sender +{ + /* Opens the activity window log file in the users default text editor */ + NSString *libraryDir = [NSSearchPathForDirectoriesInDomains( NSLibraryDirectory, + NSUserDomainMask, + YES ) objectAtIndex:0]; + NSString *encodeLogDirectory = [[[libraryDir stringByAppendingPathComponent:@"Application Support"] stringByAppendingPathComponent:@"HandBrake"] stringByAppendingPathComponent:@"EncodeLogs"]; + if( ![[NSFileManager defaultManager] fileExistsAtPath:encodeLogDirectory] ) + { + [[NSFileManager defaultManager] createDirectoryAtPath:encodeLogDirectory + withIntermediateDirectories:NO + attributes:nil + error:nil]; + } + + NSAppleScript *myScript = [[NSAppleScript alloc] initWithSource: [NSString stringWithFormat: @"%@%@%@", @"tell application \"Finder\" to open (POSIX file \"", encodeLogDirectory, @"\")"]]; + [myScript executeAndReturnError: nil]; + [myScript release]; +} + - (IBAction)clearActivityLogFile:(id)sender { /* We overwrite the existing output log with the new date and time header */ @@ -186,7 +277,7 @@ [startOutputLogString writeToFile:outputLogFile atomically:NO encoding:NSUTF8StringEncoding error:NULL]; /* We want to rewrite the app version info to the top of the activity window so it is always present */ - NSString *versionStringFull = [[NSString stringWithFormat: @"macgui: Handbrake Version: %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleGetInfoString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]]; + NSString *versionStringFull = [[NSString stringWithFormat: @"macgui: Handbrake Version: %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)\n\n", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]]; [versionStringFull writeToFile:outputLogFile atomically:NO encoding:NSUTF8StringEncoding error:NULL]; }