From d04650537f325447f2d9c05c523953d254563a83 Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 30 Apr 2010 19:57:05 +0000 Subject: [PATCH] WinGui: - Kill the CLI on GUI close for Scanning and fixed for encoding. - Fixed Autoname bug where it would strip all slashes out the path git-svn-id: svn://localhost/HandBrake/trunk@3279 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/Functions/Main.cs | 23 +++++++++++++---------- win/C#/Services/Scan.cs | 20 +++++++++++++++++++- win/C#/Settings.StyleCop | 5 +++++ win/C#/frmMain.cs | 45 ++++++++++++++++++++++++--------------------- win/C#/frmOptions.cs | 1 - 5 files changed, 61 insertions(+), 33 deletions(-) diff --git a/win/C#/Functions/Main.cs b/win/C#/Functions/Main.cs index cb82a4ba..80d806b4 100644 --- a/win/C#/Functions/Main.cs +++ b/win/C#/Functions/Main.cs @@ -153,6 +153,15 @@ namespace Handbrake.Functions // Get the Source Name string sourceName = mainWindow.SourceName; + // Remove any illeagal characters from the source name + foreach (char character in Path.GetInvalidFileNameChars()) + { + if (autoNamePath != null) + { + sourceName = sourceName.Replace(character.ToString(), string.Empty); + } + } + if (Properties.Settings.Default.AutoNameRemoveUnderscore) sourceName = sourceName.Replace("_", " "); @@ -208,18 +217,12 @@ namespace Handbrake.Functions else // Otherwise, use the path that is already there. { // Use the path and change the file extension to match the previous destination - autoNamePath = Path.Combine(Path.GetDirectoryName(mainWindow.text_destination.Text), destinationFilename); + autoNamePath = Path.Combine(Path.GetDirectoryName(mainWindow.text_destination.Text), + destinationFilename); if (Path.HasExtension(mainWindow.text_destination.Text)) - autoNamePath = Path.ChangeExtension(autoNamePath, Path.GetExtension(mainWindow.text_destination.Text)); - } - } - - foreach (char character in Path.GetInvalidFileNameChars()) - { - if (autoNamePath != null) - { - autoNamePath = autoNamePath.Replace(character.ToString(), string.Empty); + autoNamePath = Path.ChangeExtension(autoNamePath, + Path.GetExtension(mainWindow.text_destination.Text)); } } diff --git a/win/C#/Services/Scan.cs b/win/C#/Services/Scan.cs index abecfec2..6fd00a34 100644 --- a/win/C#/Services/Scan.cs +++ b/win/C#/Services/Scan.cs @@ -128,6 +128,24 @@ namespace Handbrake.Services } /// + /// Kill the scan + /// + public void KillScan() + { + try + { + if (hbProc != null) + hbProc.Kill(); + } + 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); + } + } + + /// /// Start a scan for a given source path and title /// /// Path to the source file @@ -193,7 +211,7 @@ namespace Handbrake.Services { Console.WriteLine("frmMain.cs - scanProcess() " + exc); } - } + } /// /// Read the log file diff --git a/win/C#/Settings.StyleCop b/win/C#/Settings.StyleCop index 90f8bc06..8d623254 100644 --- a/win/C#/Settings.StyleCop +++ b/win/C#/Settings.StyleCop @@ -150,6 +150,11 @@ False + + + False + + diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index 50a4c8ef..0b89a573 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -1783,23 +1783,13 @@ namespace Handbrake private void KillScan() { - try - { - SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted); - EnableGUI(); - ResetGUI(); + SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted); + EnableGUI(); + ResetGUI(); - if (SourceScan.ScanProcess() != null) - SourceScan.ScanProcess().Kill(); + SourceScan.KillScan(); - 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); - } + lbl_encode.Text = "Scan Cancelled!"; } private void ResetGUI() @@ -1987,9 +1977,9 @@ namespace Handbrake /// /// Handle GUI shortcuts /// - /// - /// - /// + /// Message + /// Keys + /// Bool protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == (Keys.Control | Keys.S)) @@ -2009,18 +1999,31 @@ namespace Handbrake /// /// If the queue is being processed, prompt the user to confirm application close. /// - /// + /// FormClosingEventArgs protected override void OnFormClosing(FormClosingEventArgs e) { // If currently encoding, the queue isn't paused, and there are queue items to process, prompt to confirm close. - if ((encodeQueue.IsEncoding) && (!encodeQueue.PauseRequested) && (encodeQueue.Count > 0)) + if (encodeQueue.IsEncoding) { DialogResult result = MessageBox.Show( - "HandBrake has queue items to process. Closing HandBrake will not stop the current encoding, but will stop processing the queue.\n\nDo you want to close HandBrake?", + "HandBrake has queue items to process. Closing HandBrake will stop the current encoding.\n\nDo you want to close HandBrake?", "Close HandBrake?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + if (result == DialogResult.No) e.Cancel = true; + + // Try to safely close out if we can, or kill the cli if using in-gui status + if (Settings.Default.enocdeStatusInGui) + encodeQueue.Stop(); + else + encodeQueue.SafelyClose(); + } + + if (SourceScan.IsScanning) + { + SourceScan.ScanCompleted -= new EventHandler(SourceScan_ScanCompleted); + SourceScan.KillScan(); } base.OnFormClosing(e); } diff --git a/win/C#/frmOptions.cs b/win/C#/frmOptions.cs index 1a25c9f9..26bb2646 100644 --- a/win/C#/frmOptions.cs +++ b/win/C#/frmOptions.cs @@ -104,7 +104,6 @@ namespace Handbrake else radio_foreignAndSubs.Checked = true; - // ############################# // CLI // ############################# -- 2.11.0