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