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