OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Functions / CLI.cs
1 /*  CLI.cs $\r
2         \r
3            This file is part of the HandBrake source code.\r
4            Homepage: <http://handbrake.m0k.org/>.\r
5            It may be used under the terms of the GNU General Public License. */\r
6 \r
7 using System;\r
8 using System.Collections.Generic;\r
9 using System.Threading;\r
10 using System.Diagnostics;\r
11 using System.Windows.Forms;\r
12 using System.Globalization;\r
13 using System.IO;\r
14 \r
15 namespace Handbrake.Functions\r
16 {\r
17     class CLI\r
18     {\r
19         /// <summary>\r
20         /// CLI output is based on en-US locale,\r
21         /// we use this CultureInfo as IFormatProvider to *.Parse() calls\r
22         /// </summary>\r
23         static readonly public CultureInfo Culture = new CultureInfo("en-US", false);\r
24 \r
25         Process hbProc = new Process();\r
26 \r
27         public Process runCli(object s, string query, bool stderr, bool stdout, bool useShellExec, bool noWindow)\r
28         {\r
29             try\r
30             {\r
31                 string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");\r
32                 string logPath = Path.Combine(Path.GetTempPath(), "hb_encode_log.dat");\r
33 \r
34                 string strCmdLine = String.Format(@"cmd /c """"{0}"" {1} 2>""{2}"" """, handbrakeCLIPath, query, logPath);\r
35 \r
36                 ProcessStartInfo cliStart = new ProcessStartInfo("CMD.exe", strCmdLine);\r
37                 hbProc = Process.Start(cliStart);\r
38 \r
39                 // Set the process Priority \r
40                 switch (Properties.Settings.Default.processPriority)\r
41                 {\r
42                     case "Realtime":\r
43                         hbProc.PriorityClass = ProcessPriorityClass.RealTime;\r
44                         break;\r
45                     case "High":\r
46                         hbProc.PriorityClass = ProcessPriorityClass.High;\r
47                         break;\r
48                     case "Above Normal":\r
49                         hbProc.PriorityClass = ProcessPriorityClass.AboveNormal;\r
50                         break;\r
51                     case "Normal":\r
52                         hbProc.PriorityClass = ProcessPriorityClass.Normal;\r
53                         break;\r
54                     case "Low":\r
55                         hbProc.PriorityClass = ProcessPriorityClass.Idle;\r
56                         break;\r
57                     default:\r
58                         hbProc.PriorityClass = ProcessPriorityClass.BelowNormal;\r
59                         break;\r
60                 }\r
61             }\r
62             catch\r
63             {\r
64                 MessageBox.Show("Internal Software Error. Please Restart the Program");\r
65             }\r
66             return hbProc;\r
67         }\r
68     }\r
69 }\r