OSDN Git Service

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