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