/// </summary>\r
static readonly object fileWriterLock = new object();\r
\r
+ /// <summary>\r
+ /// The Log File Header\r
+ /// </summary>\r
+ StringBuilder header = UtilityService.CreateCliLogHeader(null);\r
+\r
#endregion\r
\r
/// <summary>\r
public Encode()\r
{\r
this.EncodeStarted += this.EncodeEncodeStarted;\r
+ this.logBuffer = new StringBuilder();\r
GrowlCommunicator.Register();\r
}\r
\r
public string ActivityLog\r
{\r
get\r
- {\r
- if (this.IsEncoding == false)\r
- {\r
- try\r
- {\r
- ReadFile(); // Read the last log file back in if it exists\r
- }\r
- catch (Exception exc)\r
- {\r
- return exc.ToString();\r
- }\r
- }\r
-\r
- return string.IsNullOrEmpty(this.logBuffer.ToString()) ? "No log data available..." : this.logBuffer.ToString();\r
+ { \r
+ return string.IsNullOrEmpty(this.logBuffer.ToString()) ? header + "No log data available..." : header + this.logBuffer.ToString();\r
}\r
}\r
\r
this.EncodeCompleted(this, new EncodeCompletedEventArgs(true, null, string.Empty));\r
}\r
\r
- /// <summary>\r
- /// Read the log file\r
- /// </summary>\r
- private void ReadFile()\r
- {\r
- logBuffer = new StringBuilder();\r
- lock (logBuffer)\r
- {\r
- // 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) + "\\HandBrake\\logs";\r
- string logFile = Path.Combine(logDir, string.Format("last_encode_log{0}.txt", Init.InstanceId));\r
- string logFile2 = Path.Combine(logDir, string.Format("tmp_appReadable_log{0}.txt", Init.InstanceId));\r
- int logFilePosition = 0;\r
-\r
- try\r
- {\r
- // Copy the log file.\r
- if (File.Exists(logFile))\r
- File.Copy(logFile, logFile2, true);\r
- else\r
- return;\r
-\r
- // Start the Reader\r
- // Only use text which continues on from the last read line\r
- using (StreamReader sr = new StreamReader(logFile2))\r
- {\r
- string line;\r
- int i = 1;\r
- while ((line = sr.ReadLine()) != null)\r
- {\r
- if (i > logFilePosition)\r
- {\r
- logBuffer.AppendLine(line);\r
- logFilePosition++;\r
- }\r
- i++;\r
- }\r
- sr.Close();\r
- }\r
- }\r
- catch (Exception exc)\r
- {\r
- logBuffer.Append(\r
- Environment.NewLine + "Unable to read Log file..." + Environment.NewLine + exc +\r
- Environment.NewLine);\r
- }\r
- }\r
- }\r
-\r
/// <summary>\r
/// Setup the logging.\r
/// </summary>\r
if (File.Exists(logFile2)) File.Delete(logFile2);\r
\r
fileWriter = new StreamWriter(logFile) { AutoFlush = true };\r
-\r
fileWriter.WriteLine(UtilityService.CreateCliLogHeader(encodeQueueTask));\r
- logBuffer.AppendLine(UtilityService.CreateCliLogHeader(encodeQueueTask));\r
}\r
catch (Exception)\r
{\r
{\r
#region Private Variables\r
\r
- /// <summary>\r
- /// A Lock object\r
- /// </summary>\r
- private static readonly object locker = new object();\r
-\r
/// <summary>\r
/// The CLI data parser\r
/// </summary>\r
private StringBuilder logBuffer;\r
\r
/// <summary>\r
- /// The line number thats been read to in the log file\r
+ /// The Process belonging to the CLI\r
/// </summary>\r
- private int logFilePosition;\r
+ private Process hbProc;\r
\r
/// <summary>\r
- /// The Process belonging to the CLI\r
+ /// The Log File Header\r
/// </summary>\r
- private Process hbProc;\r
+ StringBuilder header = UtilityService.CreateCliLogHeader(null);\r
\r
#endregion\r
\r
/// </summary>\r
public ScanService()\r
{\r
+ this.logBuffer = new StringBuilder();\r
}\r
\r
#region Events\r
{\r
get\r
{\r
- if (IsScanning)\r
- return readData.Buffer.ToString();\r
-\r
- if (logBuffer == null)\r
- {\r
- ResetLogReader(false);\r
- ReadLastScanFile();\r
- }\r
-\r
- return logBuffer != null ? logBuffer.ToString() : string.Empty;\r
+ return string.IsNullOrEmpty(this.logBuffer.ToString()) ? header + "No log data available..." : header + this.logBuffer.ToString();\r
}\r
}\r
\r
this.ScanStared(this, new EventArgs());\r
}\r
\r
- ResetLogReader(true);\r
+ logBuffer = new StringBuilder();\r
\r
string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +\r
}\r
}\r
\r
- /// <summary>\r
- /// Read the log file\r
- /// </summary>\r
- private void ReadLastScanFile()\r
- {\r
- lock (locker)\r
- {\r
- // 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, string.Format("last_scan_log{0}.txt", Init.InstanceId == 0 ? string.Empty : Init.InstanceId.ToString()));\r
- string logFile2 = Path.Combine(logDir, string.Format("tmp_appReadable_log{0}.txt", Init.InstanceId == 0 ? string.Empty : Init.InstanceId.ToString()));\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
- ResetLogReader(true);\r
- return;\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 > logFilePosition)\r
- {\r
- logBuffer.AppendLine(line);\r
- logFilePosition++;\r
- }\r
- i++;\r
- }\r
- sr.Close();\r
- sr.Dispose();\r
- }\r
- catch (Exception exc)\r
- {\r
- ResetLogReader(true);\r
- }\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Reset the Log Reader\r
- /// </summary>\r
- /// <param name="addHeader">\r
- /// The add Header.\r
- /// </param>\r
- private void ResetLogReader(bool addHeader)\r
- {\r
- logFilePosition = 0;\r
- logBuffer = new StringBuilder();\r
- if (addHeader)\r
- logBuffer.AppendLine(UtilityService.CreateCliLogHeader(null));\r
- }\r
-\r
/// <summary>\r
/// Fire an event when the scan process progresses\r
/// </summary>\r
/// <returns>\r
/// The create cli log header.\r
/// </returns>\r
- public static string CreateCliLogHeader(QueueTask encJob)\r
+ public static StringBuilder CreateCliLogHeader(QueueTask encJob)\r
{\r
StringBuilder logHeader = new StringBuilder();\r
\r
- logHeader.AppendLine(String.Format("# {0}", Init.HandBrakeGuiVersionString));\r
- logHeader.AppendLine(String.Format("# Running: {0}", Environment.OSVersion));\r
- logHeader.AppendLine(String.Format("# CPU: {0}", SystemInfo.GetCpuCount));\r
- logHeader.AppendLine(String.Format("# Ram: {0} MB", SystemInfo.TotalPhysicalMemory));\r
- logHeader.AppendLine(String.Format("# Screen: {0}x{1}", SystemInfo.ScreenBounds.Bounds.Width, SystemInfo.ScreenBounds.Bounds.Height));\r
- logHeader.AppendLine(String.Format("# Temp Dir: {0}", Path.GetTempPath()));\r
- logHeader.AppendLine(String.Format("# Install Dir: {0}", Application.StartupPath));\r
- logHeader.AppendLine(String.Format("# Data Dir: {0}\n", Application.UserAppDataPath));\r
+ logHeader.AppendLine(String.Format("{0}", Init.HandBrakeGuiVersionString));\r
+ logHeader.AppendLine(String.Format("OS: {0}", Environment.OSVersion));\r
+ logHeader.AppendLine(String.Format("CPU: {0}", SystemInfo.GetCpuCount));\r
+ logHeader.Append(String.Format("Ram: {0} MB, ", SystemInfo.TotalPhysicalMemory));\r
+ logHeader.AppendLine(String.Format("Screen: {0}x{1}", SystemInfo.ScreenBounds.Bounds.Width, SystemInfo.ScreenBounds.Bounds.Height));\r
+ logHeader.AppendLine(String.Format("Temp Dir: {0}", Path.GetTempPath()));\r
+ logHeader.AppendLine(String.Format("Install Dir: {0}", Application.StartupPath));\r
+ logHeader.AppendLine(String.Format("Data Dir: {0}\n", Application.UserAppDataPath));\r
\r
if (encJob != null)\r
{\r
- logHeader.AppendLine(String.Format("# CLI Query: {0}", encJob.Query));\r
- logHeader.AppendLine(String.Format("# User Query: {0}", encJob.CustomQuery));\r
+ logHeader.AppendLine(String.Format("CLI Query: {0}", encJob.Query));\r
+ logHeader.AppendLine(String.Format("User Query: {0}", encJob.CustomQuery));\r
}\r
logHeader.AppendLine("-------------------------------------------");\r
\r
- return logHeader.ToString();\r
+ return logHeader;\r
+ }\r
+\r
+ /// <summary>\r
+ /// Return the standard log format line of text for a given log message\r
+ /// </summary>\r
+ /// <param name="message">The Log Message</param>\r
+ /// <returns>\r
+ /// A Log Message in the format: "[hh:mm:ss] message"\r
+ /// </returns>\r
+ public static string LogLine(string message)\r
+ {\r
+ return string.Format("[{0}] {1}", DateTime.Now.TimeOfDay, message);\r
}\r
}\r
}\r
\r
[global::System.Configuration.UserScopedSettingAttribute()]\r
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]\r
- [global::System.Configuration.DefaultSettingValueAttribute("False")]\r
+ [global::System.Configuration.DefaultSettingValueAttribute("True")]\r
public bool clearOldLogs {\r
get {\r
return ((bool)(this["clearOldLogs"]));\r
<Value Profile="(Default)">10</Value>\r
</Setting>\r
<Setting Name="clearOldLogs" Type="System.Boolean" Scope="User">\r
- <Value Profile="(Default)">False</Value>\r
+ <Value Profile="(Default)">True</Value>\r
</Setting>\r
<Setting Name="showCliForInGuiEncodeStatus" Type="System.Boolean" Scope="User">\r
<Value Profile="(Default)">False</Value>\r
<value>10</value>\r
</setting>\r
<setting name="clearOldLogs" serializeAs="String">\r
- <value>False</value>\r
+ <value>True</value>\r
</setting>\r
<setting name="showCliForInGuiEncodeStatus" serializeAs="String">\r
<value>False</value>\r
this.toolStrip1 = new System.Windows.Forms.ToolStrip();\r
this.btn_copy = new System.Windows.Forms.ToolStripButton();\r
this.logSelector = new System.Windows.Forms.ToolStripComboBox();\r
+ this.btn_openLogDirectory = new System.Windows.Forms.ToolStripButton();\r
this.panel1 = new System.Windows.Forms.Panel();\r
this.rightClickMenu.SuspendLayout();\r
this.toolStrip1.SuspendLayout();\r
this.mnu_copy_log,\r
this.mnu_openLogFolder});\r
this.rightClickMenu.Name = "rightClickMenu";\r
- this.rightClickMenu.Size = new System.Drawing.Size(254, 48);\r
+ this.rightClickMenu.Size = new System.Drawing.Size(178, 48);\r
// \r
// mnu_copy_log\r
// \r
// \r
this.mnu_openLogFolder.Image = global::Handbrake.Properties.Resources.folder;\r
this.mnu_openLogFolder.Name = "mnu_openLogFolder";\r
- this.mnu_openLogFolder.Size = new System.Drawing.Size(253, 22);\r
- this.mnu_openLogFolder.Text = "Open Individual Log File Directory";\r
+ this.mnu_openLogFolder.Size = new System.Drawing.Size(177, 22);\r
+ this.mnu_openLogFolder.Text = "Open Log Directory";\r
this.mnu_openLogFolder.Click += new System.EventHandler(this.MnuOpenLogFolderClick);\r
// \r
// ToolTip\r
this.toolStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;\r
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {\r
this.btn_copy,\r
- this.logSelector});\r
+ this.logSelector,\r
+ this.btn_openLogDirectory});\r
this.toolStrip1.Location = new System.Drawing.Point(0, 0);\r
this.toolStrip1.Name = "toolStrip1";\r
this.toolStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.Professional;\r
this.btn_copy.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;\r
this.btn_copy.ImageTransparentColor = System.Drawing.Color.Magenta;\r
this.btn_copy.Name = "btn_copy";\r
- this.btn_copy.Size = new System.Drawing.Size(122, 22);\r
- this.btn_copy.Text = "Copy to clipboard";\r
+ this.btn_copy.Size = new System.Drawing.Size(55, 22);\r
+ this.btn_copy.Text = "Copy";\r
this.btn_copy.Click += new System.EventHandler(this.BtnCopyClick);\r
// \r
// logSelector\r
// \r
this.logSelector.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;\r
this.logSelector.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;\r
+ this.logSelector.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));\r
this.logSelector.Items.AddRange(new object[] {\r
"Scan Log",\r
"Encode Log"});\r
this.logSelector.Size = new System.Drawing.Size(121, 25);\r
this.logSelector.SelectedIndexChanged += new System.EventHandler(this.LogSelectorClick);\r
// \r
+ // btn_openLogDirectory\r
+ // \r
+ this.btn_openLogDirectory.Image = global::Handbrake.Properties.Resources.folder;\r
+ this.btn_openLogDirectory.ImageTransparentColor = System.Drawing.Color.Magenta;\r
+ this.btn_openLogDirectory.Name = "btn_openLogDirectory";\r
+ this.btn_openLogDirectory.Size = new System.Drawing.Size(130, 22);\r
+ this.btn_openLogDirectory.Text = "Open Log Directory";\r
+ this.btn_openLogDirectory.Click += new System.EventHandler(this.btn_openLogDirectory_Click);\r
+ // \r
// panel1\r
// \r
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;\r
private System.Windows.Forms.ToolStripMenuItem mnu_copy_log;\r
private System.Windows.Forms.ToolStripMenuItem mnu_openLogFolder;\r
private System.Windows.Forms.ToolStripComboBox logSelector;\r
+ private System.Windows.Forms.ToolStripButton btn_openLogDirectory;\r
}\r
}
\ No newline at end of file
? "Activity Window (Scan Log)"\r
: "Activity Window (Encode Log)";\r
\r
+ this.logSelector.SelectedIndex = mode == ActivityLogMode.Scan ? 0 : 1;\r
+\r
if (mode == ActivityLogMode.Scan)\r
{\r
scan.ScanCompleted += stopWindowRefresh;\r
/// The e.\r
/// </param>\r
private void MnuOpenLogFolderClick(object sender, EventArgs e)\r
+ {\r
+ btn_openLogDirectory_Click(sender, e);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Open the Log Directory\r
+ /// </summary>\r
+ /// <param name="sender">The Sender</param>\r
+ /// <param name="e">The Evennt Args</param>\r
+ private void btn_openLogDirectory_Click(object sender, EventArgs e)\r
{\r
string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
string windir = Environment.GetEnvironmentVariable("WINDIR");\r
Process prc = new Process\r
- {\r
- StartInfo =\r
- {\r
- FileName = windir + @"\explorer.exe",\r
- Arguments = logDir\r
- }\r
- };\r
+ {\r
+ StartInfo =\r
+ {\r
+ FileName = windir + @"\explorer.exe",\r
+ Arguments = logDir\r
+ }\r
+ };\r
prc.Start();\r
}\r
\r
this.Dispose();\r
base.OnClosing(e);\r
}\r
+\r
+ \r
}\r
}
\ No newline at end of file
<value>2.0</value>\r
</resheader>\r
<resheader name="reader">\r
- <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\r
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\r
</resheader>\r
<resheader name="writer">\r
- <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\r
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\r
</resheader>\r
- <metadata name="rightClickMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">\r
+ <metadata name="rightClickMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">\r
<value>205, 18</value>\r
</metadata>\r
- <metadata name="ToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">\r
+ <metadata name="ToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">\r
<value>17, 17</value>\r
</metadata>\r
- <metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">\r
+ <metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">\r
<value>105, 17</value>\r
</metadata>\r
- <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />\r
+ <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />\r
<data name="btn_copy.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">\r
<value>\r
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8\r
this.check_preventSleep.AutoSize = true;\r
this.check_preventSleep.Location = new System.Drawing.Point(73, 45);\r
this.check_preventSleep.Name = "check_preventSleep";\r
- this.check_preventSleep.Size = new System.Drawing.Size(260, 17);\r
+ this.check_preventSleep.Size = new System.Drawing.Size(266, 17);\r
this.check_preventSleep.TabIndex = 91;\r
this.check_preventSleep.Text = "Prevent the system from sleeping when encoding.";\r
this.ToolTip.SetToolTip(this.check_preventSleep, "Prevent system from sleeping during encoding.");\r
this.check_clearOldLogs.AutoSize = true;\r
this.check_clearOldLogs.Location = new System.Drawing.Point(73, 234);\r
this.check_clearOldLogs.Name = "check_clearOldLogs";\r
- this.check_clearOldLogs.Size = new System.Drawing.Size(162, 17);\r
+ this.check_clearOldLogs.Size = new System.Drawing.Size(166, 17);\r
this.check_clearOldLogs.TabIndex = 90;\r
this.check_clearOldLogs.Text = "Clear logs older than 30 days";\r
this.ToolTip.SetToolTip(this.check_clearOldLogs, "Clear logs which are older than 30 days.\r\nThis only applies to HandBrakes Applica" +\r
this.check_logsInSpecifiedLocation.AutoSize = true;\r
this.check_logsInSpecifiedLocation.Location = new System.Drawing.Point(73, 139);\r
this.check_logsInSpecifiedLocation.Name = "check_logsInSpecifiedLocation";\r
- this.check_logsInSpecifiedLocation.Size = new System.Drawing.Size(305, 17);\r
+ this.check_logsInSpecifiedLocation.Size = new System.Drawing.Size(306, 17);\r
this.check_logsInSpecifiedLocation.TabIndex = 87;\r
this.check_logsInSpecifiedLocation.Text = "Put a copy of individual encode logs in a specified location:";\r
this.ToolTip.SetToolTip(this.check_logsInSpecifiedLocation, "Place a copy of the encode log in the same folder as the encoded movie.");\r
using System.Windows.Forms;\r
\r
using HandBrake.ApplicationServices;\r
- using HandBrake.ApplicationServices.Services;\r
using HandBrake.ApplicationServices.Utilities;\r
\r
using Handbrake.Functions;\r
- using Handbrake.Model;\r
using Handbrake.Properties;\r
\r
/// <summary>\r
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);\r
if (result == DialogResult.Yes)\r
{\r
- UtilityService.ClearLogFiles(30);\r
+ UtilityService.ClearLogFiles(0);\r
MessageBox.Show(this, "HandBrake's Log file directory has been cleared!", "Notice", MessageBoxButtons.OK,\r
MessageBoxIcon.Information);\r
}\r