+ // last_encode_log.txt is the primary log file. Since .NET can't read this file whilst the CLI is outputing to it (Not even in read only mode),\r
+ // we'll need to make a copy of it.\r
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +\r
+ "\\HandBrake\\logs";\r
+ string logFile = Path.Combine(logDir, file);\r
+ string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");\r
+\r
+ try\r
+ {\r
+ // Make sure the application readable log file does not already exist. FileCopy fill fail if it does.\r
+ if (File.Exists(logFile2))\r
+ File.Delete(logFile2);\r
+\r
+ // Copy the log file.\r
+ if (File.Exists(logFile))\r
+ File.Copy(logFile, logFile2, true);\r
+ else\r
+ {\r
+ appendText.AppendFormat("Waiting for the log file to be generated ...\n");\r
+ Position = 0;\r
+ ClearWindowText();\r
+ PrintLogHeader();\r
+ return appendText;\r
+ }\r
+\r
+ // Start the Reader\r
+ // Only use text which continues on from the last read line\r
+ StreamReader sr = new StreamReader(logFile2);\r
+ string line;\r
+ int i = 1;\r
+ while ((line = sr.ReadLine()) != null)\r
+ {\r
+ if (i > Position)\r
+ {\r
+ appendText.AppendLine(line);\r
+ Position++;\r
+ }\r
+ i++;\r
+ }\r
+ sr.Close();\r
+ sr.Dispose();\r
+ }\r
+ catch (Exception)\r
+ {\r
+ Reset();\r
+ appendText = new StringBuilder();\r
+ appendText.AppendFormat(\r
+ "\nThe Log file is currently in use. Waiting for the log file to become accessible ...\n");\r
+ }\r