OSDN Git Service

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