3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.fr>.
\r
5 It may be used under the terms of the GNU General Public License. */
\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
14 using System.Runtime.InteropServices;
\r
16 namespace Handbrake.Functions
\r
21 /// CLI output is based on en-US locale,
\r
22 /// we use this CultureInfo as IFormatProvider to *.Parse() calls
\r
24 static readonly public CultureInfo Culture = new CultureInfo("en-US", false);
\r
26 Process hbProc = new Process();
\r
29 /// Execute a HandBrakeCLI process.
\r
31 /// <param name="s"></param>
\r
32 /// <param name="query">The CLI Query</param>
\r
33 public Process runCli(object s, string query)
\r
37 string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe");
\r
38 string logPath = Path.Combine(Path.GetTempPath(), "hb_encode_log.dat");
\r
40 string strCmdLine = String.Format(@" CMD /c """"{0}"" {1} 2>""{2}"" """, handbrakeCLIPath, query, logPath);
\r
42 ProcessStartInfo cliStart = new ProcessStartInfo("CMD.exe", strCmdLine);
\r
43 if (Properties.Settings.Default.cli_minimized == "Checked")
\r
44 cliStart.WindowStyle = ProcessWindowStyle.Minimized;
\r
45 hbProc = Process.Start(cliStart);
\r
47 // Set the process Priority
\r
48 switch (Properties.Settings.Default.processPriority)
\r
51 hbProc.PriorityClass = ProcessPriorityClass.RealTime;
\r
54 hbProc.PriorityClass = ProcessPriorityClass.High;
\r
56 case "Above Normal":
\r
57 hbProc.PriorityClass = ProcessPriorityClass.AboveNormal;
\r
60 hbProc.PriorityClass = ProcessPriorityClass.Normal;
\r
63 hbProc.PriorityClass = ProcessPriorityClass.Idle;
\r
66 hbProc.PriorityClass = ProcessPriorityClass.BelowNormal;
\r
70 catch (Exception exc)
\r
72 MessageBox.Show("An error occured in runCli()\n Error Information: \n\n" + exc.ToString());
\r
77 [DllImport("user32.dll")]
\r
78 public static extern void LockWorkStation();
\r
79 [DllImport("user32.dll")]
\r
80 public static extern int ExitWindowsEx(int uFlags, int dwReason);
\r
82 public void afterEncodeAction()
\r
84 // Do something whent he encode ends.
\r
85 switch (Properties.Settings.Default.CompletionOption)
\r
88 System.Diagnostics.Process.Start("Shutdown", "-s -t 60");
\r
91 ExitWindowsEx(0, 0);
\r
94 Application.SetSuspendState(PowerState.Suspend, true, true);
\r
97 Application.SetSuspendState(PowerState.Hibernate, true, true);
\r
102 case "Quit HandBrake":
\r
103 Application.Exit();
\r
111 /// Append the CLI query to the start of the log file.
\r
113 /// <param name="query"></param>
\r
114 public void addCLIQueryToLog(string query)
\r
116 string logPath = Path.Combine(Path.GetTempPath(), "hb_encode_log.dat");
\r
118 StreamReader reader = new StreamReader(File.Open(logPath, FileMode.Open, FileAccess.Read));
\r
119 String log = reader.ReadToEnd();
\r
122 StreamWriter writer = new StreamWriter(File.Create(logPath));
\r
124 writer.Write("### CLI Query: " + query + "\n\n");
\r
125 writer.Write("#########################################\n\n");
\r
126 writer.WriteLine(log);
\r
132 /// Save a copy of the log to the users desired location or a default location
\r
133 /// if this feature is enabled in options.
\r
135 /// <param name="query"></param>
\r
136 public void copyLog(string query)
\r
138 // The user may wish to do something with the log.
\r
139 if (Properties.Settings.Default.saveLog == "Checked")
\r
141 string logPath = Path.Combine(Path.GetTempPath(), "hb_encode_log.dat");
\r
142 Functions.QueryParser parsed = Functions.QueryParser.Parse(query);
\r
144 if (Properties.Settings.Default.saveLogWithVideo == "Checked")
\r
146 string[] destName = parsed.Destination.Split('\\');
\r
147 string destinationFile = "";
\r
148 for (int i = 0; i < destName.Length - 1; i++)
\r
150 destinationFile += destName[i] + "\\";
\r
153 destinationFile += DateTime.Now.ToString().Replace("/", "-").Replace(":", "-") + " " + destName[destName.Length - 1] + ".txt";
\r
155 File.Copy(logPath, destinationFile);
\r
157 else if (Properties.Settings.Default.saveLogPath != String.Empty)
\r
159 string[] destName = parsed.Destination.Split('\\');
\r
160 string dest = destName[destName.Length - 1];
\r
161 string filename = DateTime.Now.ToString().Replace("/", "-").Replace(":", "-") + " " + dest + ".txt";
\r
162 string useDefinedLogPath = Path.Combine(Properties.Settings.Default.saveLogPath, filename);
\r
164 File.Copy(logPath, useDefinedLogPath);
\r