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