+ }
+}
+
+- (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
+ attributes: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;