OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / frmPreview.cs
index 0059ede..0951f34 100644 (file)
@@ -1,24 +1,26 @@
-using System;\r
-using System.Windows.Forms;\r
-using System.Threading;\r
-using System.Diagnostics;\r
-using System.Runtime.InteropServices;\r
-using System.IO;\r
-using Handbrake.EncodeQueue;\r
-using Handbrake.Functions;\r
-using QTOControlLib;\r
-using QTOLibrary;\r
-\r
-namespace Handbrake\r
+namespace Handbrake\r
 {\r
+    using System;\r
+    using System.Diagnostics;\r
+    using System.IO;\r
+    using System.Runtime.InteropServices;\r
+    using System.Threading;\r
+    using System.Windows.Forms;\r
+    using Functions;\r
+    using QTOControlLib;\r
+    using QTOLibrary;\r
+    using Services;\r
+\r
     public partial class frmPreview : Form\r
     {\r
-        readonly Queue Process = new Queue();\r
+        private readonly Queue Process = new Queue();\r
+\r
         private delegate void UpdateUIHandler();\r
-        String CurrentlyPlaying = "";\r
-        readonly frmMain MainWindow;\r
+\r
+        private string CurrentlyPlaying = string.Empty;\r
+        private readonly frmMain MainWindow;\r
         private Thread Player;\r
-        private readonly Boolean NoQT;\r
+        private readonly bool NoQT;\r
 \r
         public frmPreview(frmMain mw)\r
         {\r
@@ -41,20 +43,22 @@ namespace Handbrake
         }\r
 \r
         #region Encode Sample\r
+\r
         private void btn_playVLC_Click(object sender, EventArgs e)\r
         {\r
             lbl_status.Visible = true;\r
             try\r
             {\r
                 if (!NoQT)\r
-                    QTControl.URL = "";\r
+                    QTControl.URL = string.Empty;\r
 \r
                 if (File.Exists(CurrentlyPlaying))\r
                     File.Delete(CurrentlyPlaying);\r
             }\r
             catch (Exception)\r
             {\r
-                MessageBox.Show(this, "Unable to delete previous preview file. You may need to restart the application.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                MessageBox.Show(this, "Unable to delete previous preview file. You may need to restart the application.", \r
+                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
             }\r
 \r
             btn_playQT.Enabled = false;\r
@@ -62,20 +66,23 @@ namespace Handbrake
             lbl_status.Text = "Encoding Sample for (VLC) ...";\r
             int duration;\r
             int.TryParse(cb_duration.Text, out duration);\r
-            String query = QueryGenerator.GenerateCliQuery(MainWindow, 3, duration, cb_preview.Text);\r
+            string query = QueryGenerator.GenerateCliQuery(MainWindow, 3, duration, cb_preview.Text);\r
             ThreadPool.QueueUserWorkItem(ProcMonitor, query);\r
         }\r
+\r
         private void btn_playQT_Click(object sender, EventArgs e)\r
         {\r
             if (NoQT)\r
             {\r
-                MessageBox.Show(this, "It would appear QuickTime 7 is not installed or not accessible. Please (re)install QuickTime.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                MessageBox.Show(this, \r
+                                "It would appear QuickTime 7 is not installed or not accessible. Please (re)install QuickTime.", \r
+                                "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
                 return;\r
             }\r
             if (MainWindow.text_destination.Text.Contains(".mkv"))\r
             {\r
-                MessageBox.Show(this,\r
-                                "The QuickTime Control does not support MKV files, It is recommended you use VLC option instead.",\r
+                MessageBox.Show(this, \r
+                                "The QuickTime Control does not support MKV files, It is recommended you use VLC option instead.", \r
                                 "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             }\r
             else\r
@@ -83,13 +90,15 @@ namespace Handbrake
                 lbl_status.Visible = true;\r
                 try\r
                 {\r
-                    QTControl.URL = "";\r
+                    QTControl.URL = string.Empty;\r
                     if (File.Exists(CurrentlyPlaying))\r
                         File.Delete(CurrentlyPlaying);\r
                 }\r
                 catch (Exception)\r
                 {\r
-                    MessageBox.Show(this, "Unable to delete previous preview file. You may need to restart the application.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                    MessageBox.Show(this, \r
+                                    "Unable to delete previous preview file. You may need to restart the application.", \r
+                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
                 }\r
 \r
                 btn_playQT.Enabled = false;\r
@@ -97,19 +106,21 @@ namespace Handbrake
                 lbl_status.Text = "Encoding Sample for (QT) ...";\r
                 int duration;\r
                 int.TryParse(cb_duration.Text, out duration);\r
-                String query = QueryGenerator.GenerateCliQuery(MainWindow, 3, duration, cb_preview.Text);\r
+                string query = QueryGenerator.GenerateCliQuery(MainWindow, 3, duration, cb_preview.Text);\r
 \r
                 ThreadPool.QueueUserWorkItem(ProcMonitor, query);\r
             }\r
         }\r
+\r
         private void ProcMonitor(object state)\r
         {\r
             // Make sure we are not already encoding and if we are then display an error.\r
             if (Process.HbProcess != null)\r
-                MessageBox.Show(this, "Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                MessageBox.Show(this, "Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, \r
+                                MessageBoxIcon.Warning);\r
             else\r
             {\r
-                Process.CreatePreviewSample((string)state);\r
+                Process.CreatePreviewSample((string) state);\r
                 if (Process.HbProcess != null)\r
                 {\r
                     Process.HbProcess.WaitForExit();\r
@@ -118,6 +129,7 @@ namespace Handbrake
                 EncodeCompleted();\r
             }\r
         }\r
+\r
         private void EncodeCompleted()\r
         {\r
             try\r
@@ -132,13 +144,16 @@ namespace Handbrake
                 btn_playVLC.Enabled = true;\r
 \r
                 // Decide which Player to use.\r
-                String playerSelection = lbl_status.Text.Contains("QT") ? "QT" : "VLC";\r
+                string playerSelection = lbl_status.Text.Contains("QT") ? "QT" : "VLC";\r
 \r
                 lbl_status.Text = "Loading Clip ...";\r
 \r
                 // Get the sample filename\r
-                if (MainWindow.text_destination.Text != "")\r
-                    CurrentlyPlaying = MainWindow.text_destination.Text.Replace(".mp4", "_sample.mp4").Replace(".m4v", "_sample.m4v").Replace(".mkv", "_sample.mkv"); ;\r
+                if (MainWindow.text_destination.Text != string.Empty)\r
+                    CurrentlyPlaying =\r
+                        MainWindow.text_destination.Text.Replace(".mp4", "_sample.mp4").Replace(".m4v", "_sample.m4v").\r
+                            Replace(".mkv", "_sample.mkv");\r
+                ;\r
 \r
                 // Play back in QT or VLC\r
                 if (playerSelection == "QT")\r
@@ -146,13 +161,15 @@ namespace Handbrake
                 else\r
                     PlayVLC();\r
 \r
-                lbl_status.Text = "";\r
+                lbl_status.Text = string.Empty;\r
             }\r
             catch (Exception exc)\r
             {\r
-                MessageBox.Show(this, "frmPreview.cs EncodeCompleted " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+                MessageBox.Show(this, "frmPreview.cs EncodeCompleted " + exc, "Error", MessageBoxButtons.OK, \r
+                                MessageBoxIcon.Error);\r
             }\r
         }\r
+\r
         #endregion\r
 \r
         #region Playback\r
@@ -162,7 +179,7 @@ namespace Handbrake
         /// </summary>\r
         private void Play()\r
         {\r
-            Player = new Thread(OpenMovie) { IsBackground = true };\r
+            Player = new Thread(OpenMovie) {IsBackground = true};\r
             Player.Start();\r
             lbl_status.Visible = false;\r
         }\r
@@ -173,20 +190,23 @@ namespace Handbrake
         private void PlayVLC()\r
         {\r
             // Launch VLC and Play video.\r
-            if (CurrentlyPlaying != "")\r
+            if (CurrentlyPlaying != string.Empty)\r
             {\r
                 if (File.Exists(CurrentlyPlaying))\r
                 {\r
                     // Attempt to find VLC if it doesn't exist in the default set location.\r
                     string vlcPath;\r
-                    \r
-                    if (8 == IntPtr.Size || (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))\r
+\r
+                    if (8 == IntPtr.Size ||\r
+                        (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))\r
                         vlcPath = Environment.GetEnvironmentVariable("ProgramFiles(x86)");\r
                     else\r
                         vlcPath = Environment.GetEnvironmentVariable("ProgramFiles");\r
-      \r
-                    vlcPath = vlcPath != null ? vlcPath + @"\VideoLAN\VLC\vlc.exe" : @"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe";\r
-                    \r
+\r
+                    vlcPath = vlcPath != null\r
+                                  ? vlcPath + @"\VideoLAN\VLC\vlc.exe"\r
+                                  : @"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe";\r
+\r
                     if (!File.Exists(Properties.Settings.Default.VLC_Path))\r
                     {\r
                         if (File.Exists(vlcPath))\r
@@ -196,23 +216,24 @@ namespace Handbrake
                         }\r
                         else\r
                         {\r
-                            MessageBox.Show(this,\r
-                                            "Unable to detect VLC Player. \nPlease make sure VLC is installed and the directory specified in HandBrake's options is correct. (See: \"Tools Menu > Options > Picture Tab\") ",\r
+                            MessageBox.Show(this, \r
+                                            "Unable to detect VLC Player. \nPlease make sure VLC is installed and the directory specified in HandBrake's options is correct. (See: \"Tools Menu > Options > Picture Tab\") ", \r
                                             "VLC", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
                         }\r
                     }\r
 \r
                     if (File.Exists(Properties.Settings.Default.VLC_Path))\r
                     {\r
-                        String args = "\"" + CurrentlyPlaying + "\"";\r
+                        string args = "\"" + CurrentlyPlaying + "\"";\r
                         ProcessStartInfo vlc = new ProcessStartInfo(Properties.Settings.Default.VLC_Path, args);\r
                         System.Diagnostics.Process.Start(vlc);\r
                         lbl_status.Text = "VLC will now launch.";\r
                     }\r
-\r
                 }\r
                 else\r
-                    MessageBox.Show(this, "Unable to find the preview file. Either the file was deleted or the encode failed. Check the activity log for details.", "VLC", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                    MessageBox.Show(this, \r
+                                    "Unable to find the preview file. Either the file was deleted or the encode failed. Check the activity log for details.", \r
+                                    "VLC", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             }\r
             lbl_status.Visible = false;\r
         }\r
@@ -241,13 +262,18 @@ namespace Handbrake
             catch (COMException ex)\r
             {\r
                 QTUtils qtu = new QTUtils();\r
-                MessageBox.Show(this, "Unable to open movie:\n\nError Code: " + ex.ErrorCode.ToString("X") + "\nQT Error code : " + qtu.QTErrorFromErrorCode(ex.ErrorCode), "QT", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                MessageBox.Show(this, \r
+                                "Unable to open movie:\n\nError Code: " + ex.ErrorCode.ToString("X") +\r
+                                "\nQT Error code : " + qtu.QTErrorFromErrorCode(ex.ErrorCode), "QT", \r
+                                MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
             }\r
             catch (Exception ex)\r
             {\r
-                MessageBox.Show(this, "Unable to open movie:\n\n" + ex, "QT", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+                MessageBox.Show(this, "Unable to open movie:\n\n" + ex, "QT", MessageBoxButtons.OK, \r
+                                MessageBoxIcon.Warning);\r
             }\r
         }\r
+\r
         #endregion\r
     }\r
-}\r
+}
\ No newline at end of file