summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
Diffstat (limited to 'win')
-rw-r--r--win/C#/Functions/Win32.cs9
-rw-r--r--win/C#/HandBrakeCS.csproj21
-rw-r--r--win/C#/Parsing/Parser.cs4
-rw-r--r--win/C#/frmActivityWindow.Designer.cs70
-rw-r--r--win/C#/frmActivityWindow.cs265
-rw-r--r--win/C#/frmActivityWindow.resx5
-rw-r--r--win/C#/frmMain.cs148
7 files changed, 224 insertions, 298 deletions
diff --git a/win/C#/Functions/Win32.cs b/win/C#/Functions/Win32.cs
index bf0bde69c..b624a8342 100644
--- a/win/C#/Functions/Win32.cs
+++ b/win/C#/Functions/Win32.cs
@@ -1,4 +1,11 @@
-using System;
+/* win32.cs $
+
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
+
+
+using System;
using System.Runtime.InteropServices;
namespace Handbrake.Functions
diff --git a/win/C#/HandBrakeCS.csproj b/win/C#/HandBrakeCS.csproj
index a00d53034..78cbc1d59 100644
--- a/win/C#/HandBrakeCS.csproj
+++ b/win/C#/HandBrakeCS.csproj
@@ -165,12 +165,6 @@
<Compile Include="frmPreview.Designer.cs">
<DependentUpon>frmPreview.cs</DependentUpon>
</Compile>
- <Compile Include="frmActivityWindow.cs">
- <SubType>Form</SubType>
- </Compile>
- <Compile Include="frmActivityWindow.Designer.cs">
- <DependentUpon>frmActivityWindow.cs</DependentUpon>
- </Compile>
<Compile Include="frmAbout.cs">
<SubType>Form</SubType>
</Compile>
@@ -217,8 +211,15 @@
<Compile Include="Functions\PresetLoader.cs" />
<Compile Include="Functions\QueryGenerator.cs" />
<Compile Include="Functions\Main.cs" />
+ <Compile Include="Functions\Scan.cs" />
<Compile Include="Functions\UpdateCheckInformation.cs" />
<Compile Include="Functions\Win32.cs" />
+ <Compile Include="frmActivityWindow.cs">
+ <SubType>Form</SubType>
+ </Compile>
+ <Compile Include="frmActivityWindow.Designer.cs">
+ <DependentUpon>frmActivityWindow.cs</DependentUpon>
+ </Compile>
<Compile Include="Presets\Export.cs" />
<Compile Include="Presets\Import.cs" />
<Compile Include="Presets\preset.cs" />
@@ -258,10 +259,6 @@
<DependentUpon>frmPreview.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
- <EmbeddedResource Include="frmActivityWindow.resx">
- <DependentUpon>frmActivityWindow.cs</DependentUpon>
- <SubType>Designer</SubType>
- </EmbeddedResource>
<EmbeddedResource Include="frmAbout.resx">
<SubType>Designer</SubType>
<DependentUpon>frmAbout.cs</DependentUpon>
@@ -290,6 +287,10 @@
<DependentUpon>frmUpdater.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
+ <EmbeddedResource Include="frmActivityWindow.resx">
+ <DependentUpon>frmActivityWindow.cs</DependentUpon>
+ <SubType>Designer</SubType>
+ </EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
diff --git a/win/C#/Parsing/Parser.cs b/win/C#/Parsing/Parser.cs
index 9b0e6459e..b3bca0187 100644
--- a/win/C#/Parsing/Parser.cs
+++ b/win/C#/Parsing/Parser.cs
@@ -91,7 +91,7 @@ namespace Handbrake.Parsing
{
string tmp = base.ReadLine();
- m_buffer += tmp;
+ m_buffer += tmp + Environment.NewLine;
Match m = Regex.Match(tmp, "^Scanning title ([0-9]*) of ([0-9]*)");
if (OnReadLine != null)
OnReadLine(this, tmp);
@@ -106,7 +106,7 @@ namespace Handbrake.Parsing
{
string tmp = base.ReadToEnd();
- m_buffer += tmp;
+ m_buffer += tmp + Environment.NewLine;
if (OnReadToEnd != null)
OnReadToEnd(this, tmp);
diff --git a/win/C#/frmActivityWindow.Designer.cs b/win/C#/frmActivityWindow.Designer.cs
index 9d253187d..eeb5e358c 100644
--- a/win/C#/frmActivityWindow.Designer.cs
+++ b/win/C#/frmActivityWindow.Designer.cs
@@ -42,17 +42,13 @@ namespace Handbrake
this.mnu_openLogFolder = new System.Windows.Forms.ToolStripMenuItem();
this.ToolTip = new System.Windows.Forms.ToolTip(this.components);
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
- this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton();
+ this.dropDownLogSelector = new System.Windows.Forms.ToolStripDropDownButton();
this.btn_encode_log = new System.Windows.Forms.ToolStripMenuItem();
this.btn_scan_log = new System.Windows.Forms.ToolStripMenuItem();
this.btn_copy = new System.Windows.Forms.ToolStripButton();
this.panel1 = new System.Windows.Forms.Panel();
- this.statusStrip1 = new System.Windows.Forms.StatusStrip();
- this.lbl_slb = new System.Windows.Forms.ToolStripStatusLabel();
- this.txt_log = new System.Windows.Forms.ToolStripStatusLabel();
this.rightClickMenu.SuspendLayout();
this.toolStrip1.SuspendLayout();
- this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// rtf_actLog
@@ -64,7 +60,7 @@ namespace Handbrake
this.rtf_actLog.Location = new System.Drawing.Point(0, 25);
this.rtf_actLog.Name = "rtf_actLog";
this.rtf_actLog.ReadOnly = true;
- this.rtf_actLog.Size = new System.Drawing.Size(404, 530);
+ this.rtf_actLog.Size = new System.Drawing.Size(404, 552);
this.rtf_actLog.TabIndex = 29;
this.rtf_actLog.Text = "";
//
@@ -100,7 +96,7 @@ namespace Handbrake
//
this.toolStrip1.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.toolStripDropDownButton1,
+ this.dropDownLogSelector,
this.btn_copy});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
@@ -109,18 +105,18 @@ namespace Handbrake
this.toolStrip1.TabIndex = 96;
this.toolStrip1.Text = "toolStrip1";
//
- // toolStripDropDownButton1
+ // dropDownLogSelector
//
- this.toolStripDropDownButton1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
- this.toolStripDropDownButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.dropDownLogSelector.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
+ this.dropDownLogSelector.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.btn_encode_log,
this.btn_scan_log});
- this.toolStripDropDownButton1.Image = global::Handbrake.Properties.Resources.Output_Small;
- this.toolStripDropDownButton1.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
- this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
- this.toolStripDropDownButton1.Name = "toolStripDropDownButton1";
- this.toolStripDropDownButton1.Size = new System.Drawing.Size(90, 22);
- this.toolStripDropDownButton1.Text = "Select Log";
+ this.dropDownLogSelector.Image = global::Handbrake.Properties.Resources.Output_Small;
+ this.dropDownLogSelector.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None;
+ this.dropDownLogSelector.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.dropDownLogSelector.Name = "dropDownLogSelector";
+ this.dropDownLogSelector.Size = new System.Drawing.Size(90, 22);
+ this.dropDownLogSelector.Text = "Select Log";
//
// btn_encode_log
//
@@ -156,56 +152,27 @@ namespace Handbrake
this.panel1.Size = new System.Drawing.Size(404, 552);
this.panel1.TabIndex = 97;
//
- // statusStrip1
- //
- this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.lbl_slb,
- this.txt_log});
- this.statusStrip1.Location = new System.Drawing.Point(0, 555);
- this.statusStrip1.Name = "statusStrip1";
- this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 12, 0);
- this.statusStrip1.Size = new System.Drawing.Size(404, 22);
- this.statusStrip1.TabIndex = 98;
- this.statusStrip1.Text = "statusStrip1";
- //
- // lbl_slb
- //
- this.lbl_slb.BackColor = System.Drawing.Color.Transparent;
- this.lbl_slb.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.lbl_slb.Name = "lbl_slb";
- this.lbl_slb.Size = new System.Drawing.Size(85, 17);
- this.lbl_slb.Text = "Selected Log: ";
- //
- // txt_log
- //
- this.txt_log.BackColor = System.Drawing.Color.Transparent;
- this.txt_log.Name = "txt_log";
- this.txt_log.Size = new System.Drawing.Size(78, 17);
- this.txt_log.Text = "{selected log}";
- //
- // frmActivityWindow
+ // NewActivityWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ControlLight;
this.ClientSize = new System.Drawing.Size(404, 577);
this.Controls.Add(this.rtf_actLog);
- this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.panel1);
this.Controls.Add(this.toolStrip1);
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
- this.Name = "frmActivityWindow";
+ this.Name = "NewActivityWindow";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "Activity Window";
+ this.Text = "New Activity Window";
+ this.Load += new System.EventHandler(this.NewActivityWindow_Load);
this.rightClickMenu.ResumeLayout(false);
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
- this.statusStrip1.ResumeLayout(false);
- this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@@ -217,13 +184,10 @@ namespace Handbrake
internal System.Windows.Forms.ToolTip ToolTip;
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.Panel panel1;
- private System.Windows.Forms.StatusStrip statusStrip1;
- private System.Windows.Forms.ToolStripStatusLabel txt_log;
- private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton1;
+ private System.Windows.Forms.ToolStripDropDownButton dropDownLogSelector;
private System.Windows.Forms.ToolStripMenuItem btn_encode_log;
private System.Windows.Forms.ToolStripMenuItem btn_scan_log;
private System.Windows.Forms.ToolStripButton btn_copy;
- private System.Windows.Forms.ToolStripStatusLabel lbl_slb;
private System.Windows.Forms.ContextMenuStrip rightClickMenu;
private System.Windows.Forms.ToolStripMenuItem mnu_copy_log;
private System.Windows.Forms.ToolStripMenuItem mnu_openLogFolder;
diff --git a/win/C#/frmActivityWindow.cs b/win/C#/frmActivityWindow.cs
index 9f9f41128..9e261700f 100644
--- a/win/C#/frmActivityWindow.cs
+++ b/win/C#/frmActivityWindow.cs
@@ -6,6 +6,7 @@
using System;
using System.ComponentModel;
+using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
@@ -18,130 +19,113 @@ namespace Handbrake
{
public partial class frmActivityWindow : Form
{
- private delegate void setTextCallback(string text);
- private String _readFile;
- private readonly EncodeAndQueueHandler _encodeQueue;
- private int _position; // Position in the arraylist reached by the current log output in the rtf box.
- private readonly frmMain _mainWin;
- private Boolean _lastUpdate;
- private Boolean fileNotFoundQuickFix;
+ private delegate void setTextCallback(StringBuilder text);
+ private delegate void setTextClearCallback();
+ private static int _position;
+ private static string _lastMode;
+ private static string _currentMode;
- public frmActivityWindow(string file, EncodeAndQueueHandler eh, frmMain mw)
+ public frmActivityWindow()
{
InitializeComponent();
+ }
+ private void NewActivityWindow_Load(object sender, EventArgs e)
+ {
+ SetScanMode();
+ Thread monitor = new Thread(LogMonitor);
- _encodeQueue = eh;
- _mainWin = mw;
-
- fileNotFoundQuickFix = false;
-
- if (file == "last_scan_log.txt")
- SetLogView(true);
- else
- SetLogView(false);
-
- // Start a new thread which will montior and keep the log window up to date if required/
try
{
- Thread monitor = new Thread(AutoUpdate) { IsBackground = true };
monitor.Start();
}
catch (Exception exc)
{
- MessageBox.Show("startLogThread(): Exception: \n" + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show(exc.ToString());
}
}
- /// <summary>
- /// Set the view which the Log window displays.
- /// Scan = true;
- /// Encode = false;
- /// </summary>
- /// <param name="scan">Boolean. Scan = true</param>
- public void SetLogView(Boolean scan)
+ private void LogMonitor()
{
- // Reset
- _position = 0;
- rtf_actLog.Text = String.Empty;
+ while (true)
+ {
+ // Perform a reset if require.
+ // If we have switched to a different log file, we want to start from the beginning.
+ if (SetLogFile != _lastMode)
+ {
+ _position = 0;
+ ClearWindowText();
+ }
- // Print the log header
- rtf_actLog.AppendText(String.Format("### Windows GUI {1} {0} \n", Properties.Settings.Default.hb_build, Properties.Settings.Default.hb_version));
- rtf_actLog.AppendText(String.Format("### Running: {0} \n###\n", Environment.OSVersion));
- rtf_actLog.AppendText(String.Format("### CPU: {0} \n", getCpuCount()));
- rtf_actLog.AppendText(String.Format("### Ram: {0} MB \n", TotalPhysicalMemory()));
- rtf_actLog.AppendText(String.Format("### Screen: {0}x{1} \n", screenBounds().Bounds.Width, screenBounds().Bounds.Height));
- rtf_actLog.AppendText(String.Format("### Temp Dir: {0} \n", Path.GetTempPath()));
- rtf_actLog.AppendText(String.Format("### Install Dir: {0} \n", Application.StartupPath));
- rtf_actLog.AppendText(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath));
- rtf_actLog.AppendText("#########################################\n\n");
+ // Perform the window update
+ switch (SetLogFile)
+ {
+ case "last_scan_log.txt":
+ AppendWindowText(ReadFile("last_scan_log.txt"));
+ _lastMode = "last_scan_log.txt";
+ break;
+ case "last_encode_log.txt":
+ AppendWindowText(ReadFile("last_encode_log.txt"));
+ _lastMode = "last_encode_log.txt";
+ break;
+ }
- // Seutp the log file
- if (scan)
- {
- txt_log.Text = "Scan Log";
- _readFile = "last_scan_log.txt";
+ Thread.Sleep(1000);
}
- else
- {
- _readFile = "last_encode_log.txt";
- txt_log.Text = "Encode Log";
- if (_encodeQueue.isEncoding)
- if ((!_encodeQueue.LastEncode.IsEmpty) && _encodeQueue.LastEncode.Query != String.Empty)
- {
- rtf_actLog.AppendText("### CLI Query: " + _encodeQueue.LastEncode.Query + "\n");
- rtf_actLog.AppendText("### Custom Query: " + _encodeQueue.LastEncode.CustomQuery + "\n\n");
- rtf_actLog.AppendText("#########################################\n\n");
- }
- }
- _lastUpdate = false;
}
-
- private void AutoUpdate(object state)
+ private StringBuilder ReadFile(string file)
{
+ StringBuilder appendText = new StringBuilder();
+
+ // 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),
+ // we'll need to make a copy of it.
+ string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
+ string logFile = Path.Combine(logDir, file);
+ string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");
+
try
{
- _lastUpdate = false;
- UpdateTextFromThread();
- while (true)
+ // Make sure the application readable log file does not already exist. FileCopy fill fail if it does.
+ if (File.Exists(logFile2))
+ File.Delete(logFile2);
+
+ // Copy the log file.
+ if (File.Exists(logFile))
+ File.Copy(logFile, logFile2, true);
+ else
{
- if (IsHandleCreated)
- {
- if (_encodeQueue.isEncoding || _mainWin.isScanning)
- UpdateTextFromThread();
- else
- {
- // The encode may just have stoped, so, refresh the log one more time before restarting it.
- if (_lastUpdate == false)
- UpdateTextFromThread();
+ appendText.AppendFormat("Waiting for the log file to be generated ...\n");
+ _position = 0;
+ ClearWindowText();
+ return appendText;
+ }
- _lastUpdate = true; // Prevents the log window from being updated when there is no encode going.
- _position = 0; // There is no encoding, so reset the log position counter to 0 so it can be reused
- }
+ // Start the Reader
+ // Only use text which continues on from the last read line
+ StreamReader sr = new StreamReader(logFile2);
+ string line;
+ int i = 1;
+ while ((line = sr.ReadLine()) != null)
+ {
+ if (i > _position)
+ {
+ appendText.AppendLine(line);
+ _position++;
}
- Thread.Sleep(1000);
+ i++;
}
- }
- catch (Exception exc)
- {
- MessageBox.Show("AutoUpdate(): Exception: \n" + exc);
- }
- }
- private void UpdateTextFromThread()
- {
- try
- {
- String info = ReadFile();
- if (info.Contains("has exited"))
- info += "\n ############ End of Log ############## \n";
+ sr.Close();
+ sr.Dispose();
- SetText(info);
}
catch (Exception exc)
{
- MessageBox.Show("UpdateTextFromThread(): Exception: \n" + exc);
+ appendText.AppendFormat("\nERROR: The Log file could not be read. You may need to restart HandBrake! " + exc);
+ _position = 0;
+ ClearWindowText();
}
+ return appendText;
}
- private void SetText(string text)
+ private void AppendWindowText(StringBuilder text)
{
try
{
@@ -149,74 +133,73 @@ namespace Handbrake
{
if (rtf_actLog.InvokeRequired)
{
- IAsyncResult invoked = BeginInvoke(new setTextCallback(SetText), new object[] { text });
+ IAsyncResult invoked = BeginInvoke(new setTextCallback(AppendWindowText), new object[] { text });
EndInvoke(invoked);
}
else
- rtf_actLog.AppendText(text);
+ rtf_actLog.AppendText(text.ToString());
}
}
catch (Exception exc)
{
- MessageBox.Show("SetText(): Exception: \n" + exc);
+ MessageBox.Show("SetWindowText(): Exception: \n" + exc);
}
}
- private String ReadFile()
+ private void ClearWindowText()
{
- String appendText = String.Empty;
try
{
- // 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),
- // we'll need to make a copy of it.
- string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
- string logFile = Path.Combine(logDir, _readFile);
- string logFile2 = Path.Combine(logDir, "tmp_appReadable_log.txt");
-
- // Make sure the application readable log file does not already exist. FileCopy fill fail if it does.
- if (File.Exists(logFile2))
- File.Delete(logFile2);
-
- // Copy the log file.
- if (File.Exists(logFile))
- File.Copy(logFile, logFile2, true);
- else
- {
- if (fileNotFoundQuickFix)
- return "";
- fileNotFoundQuickFix = true;
- return "\n\n\nERROR: The log file could not be found. \nMaybe you cleared your system's tempory folder or maybe you just havn't run an encode yet. \nTried to find the log file in: " + logFile;
- }
-
- StreamReader sr = new StreamReader(logFile2);
- string line;
- int i = 1;
- while ((line = sr.ReadLine()) != null)
+ if (IsHandleCreated)
{
- if (i > _position)
+ if (rtf_actLog.InvokeRequired)
{
- appendText += line + Environment.NewLine;
- _position++;
+ IAsyncResult invoked = BeginInvoke(new setTextClearCallback(ClearWindowText));
+ EndInvoke(invoked);
}
- i++;
+ else
+ rtf_actLog.Clear();
}
- sr.Close();
- sr.Dispose();
-
- return appendText;
}
catch (Exception exc)
{
- return "Error in ReadFile() \n Unable to read the log file.\n You may have to restart HandBrake. Will try reading the file again in a few seconds... \n Error Information: \n\n" + exc;
+ MessageBox.Show("ClearWindowText(): Exception: \n" + exc);
}
}
- protected override void OnClosing(CancelEventArgs e)
+ public void PrintLogHeader()
{
- e.Cancel = true;
- this.Hide();
- base.OnClosing(e);
+ // Print the log header. This function will be re-implimented later. Do not delete.
+ rtf_actLog.AppendText(String.Format("### Windows GUI {1} {0} \n", Properties.Settings.Default.hb_build, Properties.Settings.Default.hb_version));
+ rtf_actLog.AppendText(String.Format("### Running: {0} \n###\n", Environment.OSVersion));
+ rtf_actLog.AppendText(String.Format("### CPU: {0} \n", getCpuCount()));
+ rtf_actLog.AppendText(String.Format("### Ram: {0} MB \n", TotalPhysicalMemory()));
+ rtf_actLog.AppendText(String.Format("### Screen: {0}x{1} \n", screenBounds().Bounds.Width, screenBounds().Bounds.Height));
+ rtf_actLog.AppendText(String.Format("### Temp Dir: {0} \n", Path.GetTempPath()));
+ rtf_actLog.AppendText(String.Format("### Install Dir: {0} \n", Application.StartupPath));
+ rtf_actLog.AppendText(String.Format("### Data Dir: {0} \n", Application.UserAppDataPath));
+ rtf_actLog.AppendText("#########################################\n\n");
}
+ #region Public
+
+ public string SetLogFile
+ {
+ get { return string.IsNullOrEmpty(_currentMode) ? "" : _currentMode; }
+ set { _currentMode = value; }
+ }
+ public void SetScanMode()
+ {
+ SetLogFile = "last_scan_log.txt";
+ this.Text = "Activity Window (Scan Log)";
+ }
+ public void SetEncodeMode()
+ {
+ SetLogFile = "last_encode_log.txt";
+ this.Text = "Activity Window (Enocde Log)";
+ }
+
+ #endregion
+
#region User Interface
private void mnu_copy_log_Click(object sender, EventArgs e)
{
@@ -243,11 +226,11 @@ namespace Handbrake
}
private void btn_scan_log_Click(object sender, EventArgs e)
{
- SetLogView(true);
+ SetScanMode();
}
private void btn_encode_log_Click(object sender, EventArgs e)
{
- SetLogView(false);
+ SetEncodeMode();
}
#endregion
@@ -288,5 +271,11 @@ namespace Handbrake
}
#endregion
+ protected override void OnClosing(CancelEventArgs e)
+ {
+ e.Cancel = true;
+ this.Hide();
+ base.OnClosing(e);
+ }
}
} \ No newline at end of file
diff --git a/win/C#/frmActivityWindow.resx b/win/C#/frmActivityWindow.resx
index 833a5194b..ab607e8cf 100644
--- a/win/C#/frmActivityWindow.resx
+++ b/win/C#/frmActivityWindow.resx
@@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="rightClickMenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
- <value>320, 17</value>
+ <value>205, 18</value>
</metadata>
<metadata name="ToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
@@ -141,9 +141,6 @@
tq1C9U1mNGd6qTvZTe2Jrry5kwNH7+z+zPf0mfZ76A/LmeTprDhiYwAAAABJRU5ErkJggg==
</value>
</data>
- <metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
- <value>204, 17</value>
- </metadata>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAYAMDAAAAEACACoDgAAZgAAACAgAAABAAgAqAgAAA4PAAAQEAAAAQAIAGgFAAC2FwAAMDAAAAEA
diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs
index f379ffd19..9763ddd3e 100644
--- a/win/C#/frmMain.cs
+++ b/win/C#/frmMain.cs
@@ -28,7 +28,6 @@ namespace Handbrake
// Globals: Mainly used for tracking. *********************************
public Title selectedTitle;
- private DVD thisDVD;
private frmQueue queueWindow;
private frmPreview qtpreview;
private frmActivityWindow ActivityWindow;
@@ -304,7 +303,7 @@ namespace Handbrake
else
{
if (fileList[0] != "")
- startScan(fileList[0]);
+ StartScan(fileList[0]);
else
UpdateSourceLabel();
}
@@ -339,7 +338,7 @@ namespace Handbrake
#region File Menu
private void mnu_killCLI_Click(object sender, EventArgs e)
{
- killScan();
+ KillScan();
}
private void mnu_exit_Click(object sender, EventArgs e)
{
@@ -356,7 +355,7 @@ namespace Handbrake
{
String file = lastAction == "scan" ? "last_scan_log.txt" : "last_encode_log.txt";
- frmActivityWindow dvdInfoWindow = new frmActivityWindow(file, encodeQueue, this);
+ frmActivityWindow dvdInfoWindow = new frmActivityWindow();
dvdInfoWindow.Show();
}
private void mnu_options_Click(object sender, EventArgs e)
@@ -740,7 +739,7 @@ namespace Handbrake
lastAction = "encode"; // Set the last action to encode - Used for activity window.
if (ActivityWindow != null)
- ActivityWindow.SetLogView(false);
+ ActivityWindow.SetEncodeMode();
}
this.Focus();
@@ -802,11 +801,13 @@ namespace Handbrake
}
private void btn_ActivityWindow_Click(object sender, EventArgs e)
{
- String file = lastAction == "scan" ? "last_scan_log.txt" : "last_encode_log.txt";
if (ActivityWindow == null)
- ActivityWindow = new frmActivityWindow(file, encodeQueue, this);
+ ActivityWindow = new frmActivityWindow();
- ActivityWindow.SetLogView(!encodeQueue.isEncoding);
+ if (encodeQueue.isEncoding)
+ ActivityWindow.SetEncodeMode();
+ else
+ ActivityWindow.SetScanMode();
ActivityWindow.Show();
}
@@ -890,7 +891,7 @@ namespace Handbrake
}
sourcePath = Path.GetFileName(file);
- startScan(file);
+ StartScan(file);
}
private void drp_dvdtitle_Click(object sender, EventArgs e)
{
@@ -1414,8 +1415,9 @@ namespace Handbrake
#region Source Scan
public Boolean isScanning { get; set; }
- private static int scanProcessID { get; set; }
- private void startScan(String filename)
+ private Scan SourceScan;
+
+ private void StartScan(String filename)
{
// Setup the GUI components for the scan.
sourcePath = filename;
@@ -1432,79 +1434,52 @@ namespace Handbrake
tb_preview.Enabled = false;
mnu_killCLI.Visible = true;
- // Start hte Scan Thread
+ // Start the Scan
try
{
- if (ActivityWindow != null)
- ActivityWindow.SetLogView(true);
+ // if (ActivityWindow != null)
+ // ActivityWindow.SetupLogViewer(true);
isScanning = true;
- ThreadPool.QueueUserWorkItem(scanProcess);
+ SourceScan = new Scan();
+ SourceScan.ScanSource(sourcePath);
+ SourceScan.ScanStatusChanged += new EventHandler(SourceScan_ScanStatusChanged);
+ SourceScan.ScanCompleted += new EventHandler(SourceScan_ScanCompleted);
}
catch (Exception exc)
{
- MessageBox.Show("frmMain.cs - startScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show("frmMain.cs - StartScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
- private void scanProcess(object state)
- {
- try
- {
- string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
- string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
- string dvdInfoPath = Path.Combine(logDir, "last_scan_log.txt");
- // Make we don't pick up a stale last_encode_log.txt (and that we have rights to the file)
- if (File.Exists(dvdInfoPath))
- File.Delete(dvdInfoPath);
-
- String dvdnav = string.Empty;
- if (Properties.Settings.Default.noDvdNav)
- dvdnav = " --no-dvdnav";
- string strCmdLine = String.Format(@"cmd /c """"{0}"" -i ""{1}"" -t0 {2} -v >""{3}"" 2>&1""", handbrakeCLIPath, sourcePath, dvdnav, dvdInfoPath);
-
- ProcessStartInfo hbParseDvd = new ProcessStartInfo("CMD.exe", strCmdLine) { WindowStyle = ProcessWindowStyle.Hidden };
-
- Boolean cleanExit = true;
- using (hbproc = Process.Start(hbParseDvd))
- {
- Process[] before = Process.GetProcesses(); // Get a list of running processes before starting.
- scanProcessID = Main.getCliProcess(before);
- hbproc.WaitForExit();
- if (hbproc.ExitCode != 0)
- cleanExit = false;
- }
-
- if (cleanExit) // If 0 exit code, CLI exited cleanly.
- {
- if (!File.Exists(dvdInfoPath))
- throw new Exception("Unable to retrieve the DVD Info. last_scan_log.txt is missing. \nExpected location of last_scan_log.txt: \n"
- + dvdInfoPath);
-
- using (StreamReader sr = new StreamReader(dvdInfoPath))
- {
- thisDVD = DVD.Parse(sr);
- sr.Close();
- sr.Dispose();
- }
+ void SourceScan_ScanStatusChanged(object sender, EventArgs e)
+ {
+ UpdateScanStatusLabel();
+ }
+ void SourceScan_ScanCompleted(object sender, EventArgs e)
+ {
+ UpdateGuiAfterScan();
+ }
- updateUIafterScan();
- }
- }
- catch (Exception exc)
+ private void UpdateScanStatusLabel()
+ {
+ if (InvokeRequired)
{
- MessageBox.Show("frmMain.cs - scanProcess() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- enableGUI();
+ BeginInvoke(new UpdateWindowHandler(UpdateScanStatusLabel));
+ return;
}
+ lbl_encode.Text = SourceScan.ScanStatus();
}
- private void updateUIafterScan()
+ private void UpdateGuiAfterScan()
{
+ if (InvokeRequired)
+ {
+ BeginInvoke(new UpdateWindowHandler(UpdateGuiAfterScan));
+ return;
+ }
+
try
{
- if (InvokeRequired)
- {
- BeginInvoke(new UpdateWindowHandler(updateUIafterScan));
- return;
- }
+ DVD thisDVD = SourceScan.SouceData();
// Setup some GUI components
drp_dvdtitle.Items.Clear();
@@ -1518,8 +1493,6 @@ namespace Handbrake
// Enable the creation of chapter markers if the file is an image of a dvd.
if (sourcePath.ToLower().Contains(".iso") || sourcePath.Contains("VIDEO_TS"))
Check_ChapterMarkers.Enabled = true;
- else if (Directory.Exists(Path.Combine(sourcePath, "VIDEO_TS")))
- Check_ChapterMarkers.Enabled = true;
else
{
Check_ChapterMarkers.Enabled = false;
@@ -1538,20 +1511,21 @@ namespace Handbrake
UpdateSourceLabel();
// Enable the GUI components and enable any disabled components
- enableGUI();
+ EnableGUI();
}
catch (Exception exc)
{
MessageBox.Show("frmMain.cs - updateUIafterScan " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- enableGUI();
+ EnableGUI();
}
}
- private void enableGUI()
+
+ private void EnableGUI()
{
try
{
if (InvokeRequired)
- BeginInvoke(new UpdateWindowHandler(enableGUI));
+ BeginInvoke(new UpdateWindowHandler(EnableGUI));
lbl_encode.Text = "Scan Completed";
foreach (Control ctrl in Controls)
ctrl.Enabled = true;
@@ -1564,33 +1538,28 @@ namespace Handbrake
}
catch (Exception exc)
{
- MessageBox.Show("frmMain.cs - enableGUI() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show("frmMain.cs - EnableGUI() " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
- private void killScan()
+ private void KillScan()
{
try
{
- enableGUI();
- resetGUI();
+ SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted);
+ EnableGUI();
+ ResetGUI();
+
+ if (SourceScan.ScanProcess() != null)
+ SourceScan.ScanProcess().Kill();
- Process[] prs = Process.GetProcesses();
- foreach (Process process in prs)
- {
- if (process.Id == scanProcessID)
- {
- process.Refresh();
- if (!process.HasExited)
- process.Kill();
- }
- }
+ lbl_encode.Text = "Scan Cancelled!";
}
catch (Exception ex)
{
MessageBox.Show("Unable to kill HandBrakeCLI.exe \nYou may need to manually kill HandBrakeCLI.exe using the Windows Task Manager if it does not close automatically within the next few minutes. \n\nError Information: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
- private void resetGUI()
+ private void ResetGUI()
{
drp_dvdtitle.Items.Clear();
drop_chapterStart.Items.Clear();
@@ -1600,7 +1569,6 @@ namespace Handbrake
PictureSettings.lbl_Aspect.Text = "Select a Title";
sourcePath = String.Empty;
text_destination.Text = String.Empty;
- thisDVD = null;
selectedTitle = null;
isScanning = false;
}