OSDN Git Service

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