OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Functions / Main.cs
1 /*  Main.cs $\r
2     This file is part of the HandBrake source code.\r
3     Homepage: <http://handbrake.fr>.\r
4     It may be used under the terms of the GNU General Public License. */\r
5 \r
6 namespace Handbrake.Functions\r
7 {\r
8     using System;\r
9     using System.Collections.Generic;\r
10     using System.Diagnostics;\r
11     using System.Globalization;\r
12     using System.IO;\r
13     using System.Net;\r
14     using System.Text;\r
15     using System.Text.RegularExpressions;\r
16     using System.Threading;\r
17     using System.Windows.Forms;\r
18     using System.Xml.Serialization;\r
19     using Model;\r
20     using Parsing;\r
21 \r
22     /// <summary>\r
23     /// Useful functions which various screens can use.\r
24     /// </summary>\r
25     public static class Main\r
26     {\r
27         /// <summary>\r
28         /// The XML Serializer\r
29         /// </summary>\r
30         private static readonly XmlSerializer Ser = new XmlSerializer(typeof(List<Job>));\r
31 \r
32         /// <summary>\r
33         /// Calculate the duration of the selected title and chapters\r
34         /// </summary>\r
35         /// <param name="chapterStart">\r
36         /// The chapter Start.\r
37         /// </param>\r
38         /// <param name="chapterEnd">\r
39         /// The chapter End.\r
40         /// </param>\r
41         /// <param name="selectedTitle">\r
42         /// The selected Title.\r
43         /// </param>\r
44         /// <returns>\r
45         /// The calculated duration.\r
46         /// </returns>\r
47         public static TimeSpan CalculateDuration(int chapterStart, int chapterEnd, Title selectedTitle)\r
48         {\r
49             TimeSpan duration = TimeSpan.FromSeconds(0.0);\r
50             chapterStart++;\r
51             chapterEnd++;\r
52             if (chapterStart != 0 && chapterEnd != 0 && chapterEnd <= selectedTitle.Chapters.Count)\r
53             {\r
54                 for (int i = chapterStart; i <= chapterEnd; i++)\r
55                     duration += selectedTitle.Chapters[i - 1].Duration;\r
56             }\r
57 \r
58             return duration;\r
59         }\r
60 \r
61         /// <summary>\r
62         /// Set's up the DataGridView on the Chapters tab (frmMain)\r
63         /// </summary>\r
64         /// <param name="dataChpt">\r
65         /// The DataGridView Control\r
66         /// </param>\r
67         /// <param name="chapterEnd">\r
68         /// The chapter End.\r
69         /// </param>\r
70         /// <returns>\r
71         /// The chapter naming.\r
72         /// </returns>\r
73         public static DataGridView ChapterNaming(DataGridView dataChpt, string chapterEnd)\r
74         {\r
75             int i = 0, finish = 0;\r
76 \r
77             if (chapterEnd != "Auto")\r
78                 int.TryParse(chapterEnd, out finish);\r
79 \r
80             while (i < finish)\r
81             {\r
82                 int n = dataChpt.Rows.Add();\r
83                 dataChpt.Rows[n].Cells[0].Value = i + 1;\r
84                 dataChpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);\r
85                 dataChpt.Rows[n].Cells[0].ValueType = typeof(int);\r
86                 dataChpt.Rows[n].Cells[1].ValueType = typeof(string);\r
87                 i++;\r
88             }\r
89 \r
90             return dataChpt;\r
91         }\r
92 \r
93         /// <summary>\r
94         /// Import a CSV file which contains Chapter Names\r
95         /// </summary>\r
96         /// <param name="dataChpt">\r
97         /// The DataGridView Control\r
98         /// </param>\r
99         /// <param name="filename">\r
100         /// The filepath and name\r
101         /// </param>\r
102         /// <returns>A Populated DataGridView</returns>\r
103         public static DataGridView ImportChapterNames(DataGridView dataChpt, string filename)\r
104         {\r
105             IDictionary<int, string> chapterMap = new Dictionary<int, string>();\r
106             try\r
107             {\r
108                 StreamReader sr = new StreamReader(filename);\r
109                 string csv = sr.ReadLine();\r
110                 while (csv != null)\r
111                 {\r
112                     if (csv.Trim() != string.Empty)\r
113                     {\r
114                         csv = csv.Replace("\\,", "<!comma!>");\r
115                         string[] contents = csv.Split(',');\r
116                         int chapter;\r
117                         int.TryParse(contents[0], out chapter);\r
118                         chapterMap.Add(chapter, contents[1].Replace("<!comma!>", ","));\r
119                     }\r
120                     csv = sr.ReadLine();\r
121                 }\r
122             }\r
123             catch (Exception)\r
124             {\r
125                 return null;\r
126             }\r
127 \r
128             foreach (DataGridViewRow item in dataChpt.Rows)\r
129             {\r
130                 string name;\r
131                 chapterMap.TryGetValue((int)item.Cells[0].Value, out name);\r
132                 item.Cells[1].Value = name ?? "Chapter " + item.Cells[0].Value;\r
133             }\r
134 \r
135             return dataChpt;\r
136         }\r
137 \r
138         /// <summary>\r
139         /// Create a CSV file with the data from the Main Window Chapters tab\r
140         /// </summary>\r
141         /// <param name="mainWindow">Main Window</param>\r
142         /// <param name="filePathName">Path to save the csv file</param>\r
143         /// <returns>True if successful </returns>\r
144         public static bool SaveChapterMarkersToCsv(frmMain mainWindow, string filePathName)\r
145         {\r
146             try\r
147             {\r
148                 string csv = string.Empty;\r
149 \r
150                 foreach (DataGridViewRow row in mainWindow.data_chpt.Rows)\r
151                 {\r
152                     csv += row.Cells[0].Value.ToString();\r
153                     csv += ",";\r
154                     csv += row.Cells[1].Value.ToString().Replace(",", "\\,");\r
155                     csv += Environment.NewLine;\r
156                 }\r
157                 StreamWriter file = new StreamWriter(filePathName);\r
158                 file.Write(csv);\r
159                 file.Close();\r
160                 file.Dispose();\r
161                 return true;\r
162             }\r
163             catch (Exception exc)\r
164             {\r
165                 MessageBox.Show("Unable to save Chapter Makrers file! \nChapter marker names will NOT be saved in your encode \n\n" + exc, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
166                 return false;\r
167             }\r
168         }\r
169 \r
170         /// <summary>\r
171         /// Function which generates the filename and path automatically based on \r
172         /// the Source Name, DVD title and DVD Chapters\r
173         /// </summary>\r
174         /// <param name="mainWindow">\r
175         /// The main Window.\r
176         /// </param>\r
177         /// <returns>\r
178         /// The Generated FileName\r
179         /// </returns>\r
180         public static string AutoName(frmMain mainWindow)\r
181         {\r
182             string autoNamePath = string.Empty;\r
183             if (mainWindow.drp_dvdtitle.Text != "Automatic")\r
184             {\r
185                 // Get the Source Name \r
186                 string sourceName = mainWindow.SourceName;\r
187 \r
188                 // Remove any illeagal characters from the source name\r
189                 foreach (char character in Path.GetInvalidFileNameChars())\r
190                 {\r
191                     if (autoNamePath != null)\r
192                     {\r
193                         sourceName = sourceName.Replace(character.ToString(), string.Empty);\r
194                     }\r
195                 }\r
196 \r
197                 if (Properties.Settings.Default.AutoNameRemoveUnderscore)\r
198                     sourceName = sourceName.Replace("_", " ");\r
199 \r
200                 if (Properties.Settings.Default.AutoNameTitleCase)\r
201                     sourceName = TitleCase(sourceName);\r
202 \r
203                 // Get the Selected Title Number\r
204                 string[] titlesplit = mainWindow.drp_dvdtitle.Text.Split(' ');\r
205                 string dvdTitle = titlesplit[0].Replace("Automatic", string.Empty);\r
206 \r
207                 // Get the Chapter Start and Chapter End Numbers\r
208                 string chapterStart = mainWindow.drop_chapterStart.Text.Replace("Auto", string.Empty);\r
209                 string chapterFinish = mainWindow.drop_chapterFinish.Text.Replace("Auto", string.Empty);\r
210                 string combinedChapterTag = chapterStart;\r
211                 if (chapterFinish != chapterStart && chapterFinish != string.Empty)\r
212                     combinedChapterTag = chapterStart + "-" + chapterFinish;\r
213 \r
214                 // Get the destination filename.\r
215                 string destinationFilename;\r
216                 if (Properties.Settings.Default.autoNameFormat != string.Empty)\r
217                 {\r
218                     destinationFilename = Properties.Settings.Default.autoNameFormat;\r
219                     destinationFilename =\r
220                         destinationFilename.Replace("{source}", sourceName).Replace("{title}", dvdTitle).Replace(\r
221                             "{chapters}", combinedChapterTag);\r
222                 }\r
223                 else\r
224                     destinationFilename = sourceName + "_T" + dvdTitle + "_C" + combinedChapterTag;\r
225 \r
226                 // Add the appropriate file extension\r
227                 if (mainWindow.drop_format.SelectedIndex == 0)\r
228                 {\r
229                     if (Properties.Settings.Default.useM4v || mainWindow.Check_ChapterMarkers.Checked ||\r
230                         mainWindow.AudioSettings.RequiresM4V() || mainWindow.Subtitles.RequiresM4V())\r
231                         destinationFilename += ".m4v";\r
232                     else\r
233                         destinationFilename += ".mp4";\r
234                 }\r
235                 else if (mainWindow.drop_format.SelectedIndex == 1)\r
236                     destinationFilename += ".mkv";\r
237 \r
238                 // Now work out the path where the file will be stored.\r
239                 // First case: If the destination box doesn't already contain a path, make one.\r
240                 if (!mainWindow.text_destination.Text.Contains(Path.DirectorySeparatorChar.ToString()))\r
241                 {\r
242                     // If there is an auto name path, use it...\r
243                     if (Properties.Settings.Default.autoNamePath.Trim() != string.Empty &&\r
244                         Properties.Settings.Default.autoNamePath.Trim() != "Click 'Browse' to set the default location")\r
245                         autoNamePath = Path.Combine(Properties.Settings.Default.autoNamePath, destinationFilename);\r
246                     else // ...otherwise, output to the source directory\r
247                         autoNamePath = null;\r
248                 }\r
249                 else // Otherwise, use the path that is already there.\r
250                 {\r
251                     // Use the path and change the file extension to match the previous destination\r
252                     autoNamePath = Path.Combine(Path.GetDirectoryName(mainWindow.text_destination.Text),\r
253                                                 destinationFilename);\r
254 \r
255                     if (Path.HasExtension(mainWindow.text_destination.Text))\r
256                         autoNamePath = Path.ChangeExtension(autoNamePath,\r
257                                                             Path.GetExtension(mainWindow.text_destination.Text));\r
258                 }\r
259             }\r
260 \r
261             return autoNamePath;\r
262         }\r
263 \r
264         /// <summary>\r
265         /// Get's HandBrakes version data from the CLI.\r
266         /// </summary>\r
267         public static void SetCliVersionData()\r
268         {\r
269             string line;\r
270 \r
271             // 0 = SVN Build / Version\r
272             // 1 = Build Date\r
273             DateTime lastModified = File.GetLastWriteTime("HandBrakeCLI.exe");\r
274 \r
275             if (Properties.Settings.Default.cliLastModified == lastModified && Properties.Settings.Default.hb_build != 0)\r
276                 return;\r
277 \r
278             Properties.Settings.Default.cliLastModified = lastModified;\r
279 \r
280             Process cliProcess = new Process();\r
281             ProcessStartInfo handBrakeCli = new ProcessStartInfo("HandBrakeCLI.exe", " -u -v0")\r
282                                                 {\r
283                                                     UseShellExecute = false,\r
284                                                     RedirectStandardError = true,\r
285                                                     RedirectStandardOutput = true,\r
286                                                     CreateNoWindow = true\r
287                                                 };\r
288             cliProcess.StartInfo = handBrakeCli;\r
289 \r
290             try\r
291             {\r
292                 cliProcess.Start();\r
293 \r
294                 // Retrieve standard output and report back to parent thread until the process is complete\r
295                 TextReader stdOutput = cliProcess.StandardError;\r
296 \r
297                 while (!cliProcess.HasExited)\r
298                 {\r
299                     line = stdOutput.ReadLine() ?? string.Empty;\r
300                     Match m = Regex.Match(line, @"HandBrake ([svnM0-9.]*) \([0-9]*\)");\r
301                     Match platform = Regex.Match(line, @"- ([A-Za-z0-9\s ]*) -");\r
302 \r
303                     if (m.Success)\r
304                     {\r
305                         string data = line.Replace("(", string.Empty).Replace(")", string.Empty).Replace("HandBrake ", string.Empty);\r
306                         string[] arr = data.Split(' ');\r
307 \r
308                         Properties.Settings.Default.hb_build = int.Parse(arr[1]);\r
309                         Properties.Settings.Default.hb_version = arr[0];\r
310                     }\r
311 \r
312                     if (platform.Success)\r
313                     {\r
314                         Properties.Settings.Default.hb_platform = platform.Value.Replace("-", string.Empty).Trim();\r
315                     }\r
316 \r
317                     if (cliProcess.TotalProcessorTime.Seconds > 10) // Don't wait longer than 10 seconds.\r
318                     {\r
319                         Process cli = Process.GetProcessById(cliProcess.Id);\r
320                         if (!cli.HasExited)\r
321                         {\r
322                             cli.Kill();\r
323                         }\r
324                     }\r
325                 }\r
326 \r
327                 Properties.Settings.Default.Save();\r
328             }\r
329             catch (Exception e)\r
330             {\r
331                 MessageBox.Show("Unable to retrieve version information from the CLI. \nError:\n" + e);\r
332             }\r
333         }\r
334 \r
335         /// <summary>\r
336         /// Check to make sure that the user has an up to date version of the CLI installed.\r
337         /// </summary>\r
338         public static void CheckForValidCliVersion()\r
339         {\r
340             // Make sure we have a recent version for svn builds\r
341             string version = Properties.Settings.Default.hb_version;\r
342             if (version.Contains("svn"))\r
343             {\r
344                 version = version.Replace("svn", string.Empty).Trim();\r
345                 int build;\r
346                 int.TryParse(version, out build);\r
347                 if (build < Properties.Settings.Default.hb_min_cli)\r
348                 {\r
349                     MessageBox.Show(\r
350                         "It appears you are trying to use a CLI executable that is too old for this version of the HandBrake GUI.\n" +\r
351                         "Please update the HandBrakeCLI.exe to a newer build.\n\n" +\r
352                         "HandBrake build Detected: " + Properties.Settings.Default.hb_version,\r
353                         "Error",\r
354                         MessageBoxButtons.OK,\r
355                         MessageBoxIcon.Error);\r
356                     return;\r
357                 }\r
358             }\r
359         }\r
360 \r
361         /// <summary>\r
362         /// Check if the queue recovery file contains records.\r
363         /// If it does, it means the last queue did not complete before HandBrake closed.\r
364         /// So, return a boolean if true. \r
365         /// </summary>\r
366         /// <returns>\r
367         /// True if there is a queue to recover.\r
368         /// </returns>\r
369         public static bool CheckQueueRecovery()\r
370         {\r
371             try\r
372             {\r
373                 string tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\hb_queue_recovery.xml");\r
374                 if (File.Exists(tempPath))\r
375                 {\r
376                     using (FileStream strm = new FileStream(tempPath, FileMode.Open, FileAccess.Read))\r
377                     {\r
378                         List<Job> list = Ser.Deserialize(strm) as List<Job>;\r
379                         if (list != null)\r
380                             if (list.Count != 0)\r
381                                 return true;\r
382                     }\r
383                 }\r
384                 return false;\r
385             }\r
386             catch (Exception)\r
387             {\r
388                 return false; // Keep quiet about the error.\r
389             }\r
390         }\r
391 \r
392         /// <summary>\r
393         /// Get the Process ID of HandBrakeCLI for the current instance.\r
394         /// </summary>\r
395         /// <param name="before">List of processes before the new process was started</param>\r
396         /// <returns>Int - Process ID</returns>\r
397         public static int GetCliProcess(Process[] before)\r
398         {\r
399             // This is a bit of a cludge. Maybe someone has a better idea on how to impliment this.\r
400             // Since we used CMD to start HandBrakeCLI, we don't get the process ID from hbProc.\r
401             // Instead we take the processes before and after, and get the ID of HandBrakeCLI.exe\r
402             // avoiding any previous instances of HandBrakeCLI.exe in before.\r
403             // Kill the current process.\r
404 \r
405             DateTime startTime = DateTime.Now;\r
406             TimeSpan duration;\r
407 \r
408             Process[] hbProcesses = Process.GetProcessesByName("HandBrakeCLI");\r
409             while (hbProcesses.Length == 0)\r
410             {\r
411                 hbProcesses = Process.GetProcessesByName("HandBrakeCLI");\r
412                 duration = DateTime.Now - startTime;\r
413                 if (duration.Seconds > 5 && hbProcesses.Length == 0)\r
414                     // Make sure we don't wait forever if the process doesn't start\r
415                     return -1;\r
416             }\r
417 \r
418             Process hbProcess = null;\r
419             foreach (Process process in hbProcesses)\r
420             {\r
421                 bool found = false;\r
422                 // Check if the current CLI instance was running before we started the current one\r
423                 foreach (Process bprocess in before)\r
424                 {\r
425                     if (process.Id == bprocess.Id)\r
426                         found = true;\r
427                 }\r
428 \r
429                 // If it wasn't running before, we found the process we want.\r
430                 if (!found)\r
431                 {\r
432                     hbProcess = process;\r
433                     break;\r
434                 }\r
435             }\r
436             if (hbProcess != null)\r
437                 return hbProcess.Id;\r
438 \r
439             return -1;\r
440         }\r
441 \r
442         /// <summary>\r
443         ///  Clear all the encode log files.\r
444         /// </summary>\r
445         public static void ClearLogs()\r
446         {\r
447             string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
448             if (Directory.Exists(logDir))\r
449             {\r
450                 DirectoryInfo info = new DirectoryInfo(logDir);\r
451                 FileInfo[] logFiles = info.GetFiles("*.txt");\r
452                 foreach (FileInfo file in logFiles)\r
453                 {\r
454                     if (!file.Name.Contains("last_scan_log") && !file.Name.Contains("last_encode_log") &&\r
455                         !file.Name.Contains("tmp_appReadable_log.txt"))\r
456                         File.Delete(file.FullName);\r
457                 }\r
458             }\r
459         }\r
460 \r
461         /// <summary>\r
462         /// Clear old log files x days in the past\r
463         /// </summary>\r
464         public static void ClearOldLogs()\r
465         {\r
466             string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";\r
467             if (Directory.Exists(logDir))\r
468             {\r
469                 DirectoryInfo info = new DirectoryInfo(logDir);\r
470                 FileInfo[] logFiles = info.GetFiles("*.txt");\r
471 \r
472                 foreach (FileInfo file in logFiles)\r
473                 {\r
474                     if (file.LastWriteTime < DateTime.Now.AddDays(-30))\r
475                     {\r
476                         if (!file.Name.Contains("last_scan_log") && !file.Name.Contains("last_encode_log") &&\r
477                             !file.Name.Contains("tmp_appReadable_log.txt"))\r
478                             File.Delete(file.FullName);\r
479                     }\r
480                 }\r
481             }\r
482         }\r
483 \r
484         /// <summary>\r
485         /// Begins checking for an update to HandBrake.\r
486         /// </summary>\r
487         /// <param name="callback">The method that will be called when the check is finished.</param>\r
488         /// <param name="debug">Whether or not to execute this in debug mode.</param>\r
489         public static void BeginCheckForUpdates(AsyncCallback callback, bool debug)\r
490         {\r
491             ThreadPool.QueueUserWorkItem(new WaitCallback(delegate\r
492                                                               {\r
493                                                                   try\r
494                                                                   {\r
495                                                                       // Is this a stable or unstable build?\r
496                                                                       string url =\r
497                                                                           Properties.Settings.Default.hb_build.ToString()\r
498                                                                               .EndsWith("1")\r
499                                                                               ? Properties.Settings.Default.\r
500                                                                                     appcast_unstable\r
501                                                                               : Properties.Settings.Default.appcast;\r
502 \r
503                                                                       // Initialize variables\r
504                                                                       WebRequest request = WebRequest.Create(url);\r
505                                                                       WebResponse response = request.GetResponse();\r
506                                                                       AppcastReader reader = new AppcastReader();\r
507 \r
508                                                                       // Get the data, convert it to a string, and parse it into the AppcastReader\r
509                                                                       reader.GetInfo(\r
510                                                                           new StreamReader(response.GetResponseStream())\r
511                                                                               .ReadToEnd());\r
512 \r
513                                                                       // Further parse the information\r
514                                                                       string build = reader.Build;\r
515 \r
516                                                                       int latest = int.Parse(build);\r
517                                                                       int current = Properties.Settings.Default.hb_build;\r
518                                                                       int skip = Properties.Settings.Default.skipversion;\r
519 \r
520                                                                       // If the user wanted to skip this version, don't report the update\r
521                                                                       if (latest == skip)\r
522                                                                       {\r
523                                                                           UpdateCheckInformation info =\r
524                                                                               new UpdateCheckInformation\r
525                                                                                   {\r
526                                                                                       NewVersionAvailable = false,\r
527                                                                                       BuildInformation = null\r
528                                                                                   };\r
529                                                                           callback(new UpdateCheckResult(debug, info));\r
530                                                                           return;\r
531                                                                       }\r
532 \r
533                                                                       // Set when the last update was\r
534                                                                       Properties.Settings.Default.lastUpdateCheckDate =\r
535                                                                           DateTime.Now;\r
536                                                                       Properties.Settings.Default.Save();\r
537 \r
538                                                                       UpdateCheckInformation info2 =\r
539                                                                           new UpdateCheckInformation\r
540                                                                               {\r
541                                                                                   NewVersionAvailable = latest > current,\r
542                                                                                   BuildInformation = reader\r
543                                                                               };\r
544                                                                       callback(new UpdateCheckResult(debug, info2));\r
545                                                                   }\r
546                                                                   catch (Exception exc)\r
547                                                                   {\r
548                                                                       callback(new UpdateCheckResult(debug, new UpdateCheckInformation { Error = exc }));\r
549                                                                   }\r
550                                                               }));\r
551         }\r
552 \r
553         /// <summary>\r
554         /// End Check for Updates\r
555         /// </summary>\r
556         /// <param name="result">\r
557         /// The result.\r
558         /// </param>\r
559         /// <returns>\r
560         /// Update Check information\r
561         /// </returns>\r
562         public static UpdateCheckInformation EndCheckForUpdates(IAsyncResult result)\r
563         {\r
564             UpdateCheckResult checkResult = (UpdateCheckResult)result;\r
565             return checkResult.Result;\r
566         }\r
567 \r
568         /// <summary>\r
569         /// Map languages and their iso639_2 value into a IDictionary\r
570         /// </summary>\r
571         /// <returns>A Dictionary containing the language and iso code</returns>\r
572         public static IDictionary<string, string> MapLanguages()\r
573         {\r
574             IDictionary<string, string> languageMap = new Dictionary<string, string>\r
575                                                           {\r
576                                                               {"Any", "und"}, \r
577                                                               {"Afar", "aar"}, \r
578                                                               {"Abkhazian", "abk"}, \r
579                                                               {"Afrikaans", "afr"}, \r
580                                                               {"Akan", "aka"}, \r
581                                                               {"Albanian", "sqi"}, \r
582                                                               {"Amharic", "amh"}, \r
583                                                               {"Arabic", "ara"}, \r
584                                                               {"Aragonese", "arg"}, \r
585                                                               {"Armenian", "hye"}, \r
586                                                               {"Assamese", "asm"}, \r
587                                                               {"Avaric", "ava"}, \r
588                                                               {"Avestan", "ave"}, \r
589                                                               {"Aymara", "aym"}, \r
590                                                               {"Azerbaijani", "aze"}, \r
591                                                               {"Bashkir", "bak"}, \r
592                                                               {"Bambara", "bam"}, \r
593                                                               {"Basque", "eus"}, \r
594                                                               {"Belarusian", "bel"}, \r
595                                                               {"Bengali", "ben"}, \r
596                                                               {"Bihari", "bih"}, \r
597                                                               {"Bislama", "bis"}, \r
598                                                               {"Bosnian", "bos"}, \r
599                                                               {"Breton", "bre"}, \r
600                                                               {"Bulgarian", "bul"}, \r
601                                                               {"Burmese", "mya"}, \r
602                                                               {"Catalan", "cat"}, \r
603                                                               {"Chamorro", "cha"}, \r
604                                                               {"Chechen", "che"}, \r
605                                                               {"Chinese", "zho"}, \r
606                                                               {"Church Slavic", "chu"}, \r
607                                                               {"Chuvash", "chv"}, \r
608                                                               {"Cornish", "cor"}, \r
609                                                               {"Corsican", "cos"}, \r
610                                                               {"Cree", "cre"}, \r
611                                                               {"Czech", "ces"}, \r
612                                                               {"Dansk", "dan"}, \r
613                                                               {"Divehi", "div"}, \r
614                                                               {"Nederlands", "nld"}, \r
615                                                               {"Dzongkha", "dzo"}, \r
616                                                               {"English", "eng"}, \r
617                                                               {"Esperanto", "epo"}, \r
618                                                               {"Estonian", "est"}, \r
619                                                               {"Ewe", "ewe"}, \r
620                                                               {"Faroese", "fao"}, \r
621                                                               {"Fijian", "fij"}, \r
622                                                               {"Suomi", "fin"}, \r
623                                                               {"Francais", "fra"}, \r
624                                                               {"Western Frisian", "fry"}, \r
625                                                               {"Fulah", "ful"}, \r
626                                                               {"Georgian", "kat"}, \r
627                                                               {"Deutsch", "deu"}, \r
628                                                               {"Gaelic (Scots)", "gla"}, \r
629                                                               {"Irish", "gle"}, \r
630                                                               {"Galician", "glg"}, \r
631                                                               {"Manx", "glv"}, \r
632                                                               {"Greek Modern", "ell"}, \r
633                                                               {"Guarani", "grn"}, \r
634                                                               {"Gujarati", "guj"}, \r
635                                                               {"Haitian", "hat"}, \r
636                                                               {"Hausa", "hau"}, \r
637                                                               {"Hebrew", "heb"}, \r
638                                                               {"Herero", "her"}, \r
639                                                               {"Hindi", "hin"}, \r
640                                                               {"Hiri Motu", "hmo"}, \r
641                                                               {"Magyar", "hun"}, \r
642                                                               {"Igbo", "ibo"}, \r
643                                                               {"Islenska", "isl"}, \r
644                                                               {"Ido", "ido"}, \r
645                                                               {"Sichuan Yi", "iii"}, \r
646                                                               {"Inuktitut", "iku"}, \r
647                                                               {"Interlingue", "ile"}, \r
648                                                               {"Interlingua", "ina"}, \r
649                                                               {"Indonesian", "ind"}, \r
650                                                               {"Inupiaq", "ipk"}, \r
651                                                               {"Italiano", "ita"}, \r
652                                                               {"Javanese", "jav"}, \r
653                                                               {"Japanese", "jpn"}, \r
654                                                               {"Kalaallisut", "kal"}, \r
655                                                               {"Kannada", "kan"}, \r
656                                                               {"Kashmiri", "kas"}, \r
657                                                               {"Kanuri", "kau"}, \r
658                                                               {"Kazakh", "kaz"}, \r
659                                                               {"Central Khmer", "khm"}, \r
660                                                               {"Kikuyu", "kik"}, \r
661                                                               {"Kinyarwanda", "kin"}, \r
662                                                               {"Kirghiz", "kir"}, \r
663                                                               {"Komi", "kom"}, \r
664                                                               {"Kongo", "kon"}, \r
665                                                               {"Korean", "kor"}, \r
666                                                               {"Kuanyama", "kua"}, \r
667                                                               {"Kurdish", "kur"}, \r
668                                                               {"Lao", "lao"}, \r
669                                                               {"Latin", "lat"}, \r
670                                                               {"Latvian", "lav"}, \r
671                                                               {"Limburgan", "lim"}, \r
672                                                               {"Lingala", "lin"}, \r
673                                                               {"Lithuanian", "lit"}, \r
674                                                               {"Luxembourgish", "ltz"}, \r
675                                                               {"Luba-Katanga", "lub"}, \r
676                                                               {"Ganda", "lug"}, \r
677                                                               {"Macedonian", "mkd"}, \r
678                                                               {"Marshallese", "mah"}, \r
679                                                               {"Malayalam", "mal"}, \r
680                                                               {"Maori", "mri"}, \r
681                                                               {"Marathi", "mar"}, \r
682                                                               {"Malay", "msa"}, \r
683                                                               {"Malagasy", "mlg"}, \r
684                                                               {"Maltese", "mlt"}, \r
685                                                               {"Moldavian", "mol"}, \r
686                                                               {"Mongolian", "mon"}, \r
687                                                               {"Nauru", "nau"}, \r
688                                                               {"Navajo", "nav"}, \r
689                                                               {"Ndebele, South", "nbl"}, \r
690                                                               {"Ndebele, North", "nde"}, \r
691                                                               {"Ndonga", "ndo"}, \r
692                                                               {"Nepali", "nep"}, \r
693                                                               {"Norwegian Nynorsk", "nno"}, \r
694                                                               {"Norwegian Bokmål", "nob"}, \r
695                                                               {"Norsk", "nor"}, \r
696                                                               {"Chichewa; Nyanja", "nya"}, \r
697                                                               {"Occitan", "oci"}, \r
698                                                               {"Ojibwa", "oji"}, \r
699                                                               {"Oriya", "ori"}, \r
700                                                               {"Oromo", "orm"}, \r
701                                                               {"Ossetian", "oss"}, \r
702                                                               {"Panjabi", "pan"}, \r
703                                                               {"Persian", "fas"}, \r
704                                                               {"Pali", "pli"}, \r
705                                                               {"Polish", "pol"}, \r
706                                                               {"Portugues", "por"}, \r
707                                                               {"Pushto", "pus"}, \r
708                                                               {"Quechua", "que"}, \r
709                                                               {"Romansh", "roh"}, \r
710                                                               {"Romanian", "ron"}, \r
711                                                               {"Rundi", "run"}, \r
712                                                               {"Russian", "rus"}, \r
713                                                               {"Sango", "sag"}, \r
714                                                               {"Sanskrit", "san"}, \r
715                                                               {"Serbian", "srp"}, \r
716                                                               {"Hrvatski", "hrv"}, \r
717                                                               {"Sinhala", "sin"}, \r
718                                                               {"Slovak", "slk"}, \r
719                                                               {"Slovenian", "slv"}, \r
720                                                               {"Northern Sami", "sme"}, \r
721                                                               {"Samoan", "smo"}, \r
722                                                               {"Shona", "sna"}, \r
723                                                               {"Sindhi", "snd"}, \r
724                                                               {"Somali", "som"}, \r
725                                                               {"Sotho Southern", "sot"}, \r
726                                                               {"Espanol", "spa"}, \r
727                                                               {"Sardinian", "srd"}, \r
728                                                               {"Swati", "ssw"}, \r
729                                                               {"Sundanese", "sun"}, \r
730                                                               {"Swahili", "swa"}, \r
731                                                               {"Svenska", "swe"}, \r
732                                                               {"Tahitian", "tah"}, \r
733                                                               {"Tamil", "tam"}, \r
734                                                               {"Tatar", "tat"}, \r
735                                                               {"Telugu", "tel"}, \r
736                                                               {"Tajik", "tgk"}, \r
737                                                               {"Tagalog", "tgl"}, \r
738                                                               {"Thai", "tha"}, \r
739                                                               {"Tibetan", "bod"}, \r
740                                                               {"Tigrinya", "tir"}, \r
741                                                               {"Tonga", "ton"}, \r
742                                                               {"Tswana", "tsn"}, \r
743                                                               {"Tsonga", "tso"}, \r
744                                                               {"Turkmen", "tuk"}, \r
745                                                               {"Turkish", "tur"}, \r
746                                                               {"Twi", "twi"}, \r
747                                                               {"Uighur", "uig"}, \r
748                                                               {"Ukrainian", "ukr"}, \r
749                                                               {"Urdu", "urd"}, \r
750                                                               {"Uzbek", "uzb"}, \r
751                                                               {"Venda", "ven"}, \r
752                                                               {"Vietnamese", "vie"}, \r
753                                                               {"Volapük", "vol"}, \r
754                                                               {"Welsh", "cym"}, \r
755                                                               {"Walloon", "wln"}, \r
756                                                               {"Wolof", "wol"}, \r
757                                                               {"Xhosa", "xho"}, \r
758                                                               {"Yiddish", "yid"}, \r
759                                                               {"Yoruba", "yor"}, \r
760                                                               {"Zhuang", "zha"}, \r
761                                                               {"Zulu", "zul"}\r
762                                                           };\r
763             return languageMap;\r
764         }\r
765 \r
766         /// <summary>\r
767         /// Get a list of available DVD drives which are ready and contain DVD content.\r
768         /// </summary>\r
769         /// <returns>A List of Drives with their details</returns>\r
770         public static List<DriveInformation> GetDrives()\r
771         {\r
772             List<DriveInformation> drives = new List<DriveInformation>();\r
773             DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives();\r
774             int id = 0;\r
775             foreach (DriveInfo curDrive in theCollectionOfDrives)\r
776             {\r
777                 if (curDrive.DriveType == DriveType.CDRom && curDrive.IsReady &&\r
778                     File.Exists(curDrive.RootDirectory + "VIDEO_TS\\VIDEO_TS.IFO"))\r
779                 {\r
780                     drives.Add(new DriveInformation\r
781                                    {\r
782                                        Id = id,\r
783                                        VolumeLabel = curDrive.VolumeLabel,\r
784                                        RootDirectory = curDrive.RootDirectory + "VIDEO_TS"\r
785                                    });\r
786                     id++;\r
787                 }\r
788             }\r
789             return drives;\r
790         }\r
791 \r
792         /// <summary>\r
793         /// Change a string to Title Case/\r
794         /// </summary>\r
795         /// <param name="input">\r
796         /// The input.\r
797         /// </param>\r
798         /// <returns>\r
799         /// A string in title case.\r
800         /// </returns>\r
801         public static string TitleCase(string input)\r
802         {\r
803             string[] tokens = input.Split(' ');\r
804             StringBuilder sb = new StringBuilder(input.Length);\r
805             foreach (string s in tokens)\r
806             {\r
807                 sb.Append(s[0].ToString().ToUpper());\r
808                 sb.Append(s.Substring(1).ToLower());\r
809                 sb.Append(" ");\r
810             }\r
811 \r
812             return sb.ToString().Trim();\r
813         }\r
814     }\r
815 }