OSDN Git Service

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