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
6 namespace Handbrake.Functions
\r
9 using System.Collections.Generic;
\r
10 using System.Diagnostics;
\r
14 using System.Text.RegularExpressions;
\r
15 using System.Threading;
\r
16 using System.Windows.Forms;
\r
17 using System.Xml.Serialization;
\r
19 using HandBrake.ApplicationServices.Model;
\r
20 using HandBrake.ApplicationServices.Parsing;
\r
25 /// Useful functions which various screens can use.
\r
27 public static class Main
\r
30 /// The XML Serializer
\r
32 private static readonly XmlSerializer Ser = new XmlSerializer(typeof(List<Job>));
\r
35 /// Calculate the duration of the selected title and chapters
\r
37 /// <param name="chapterStart">
\r
38 /// The chapter Start.
\r
40 /// <param name="chapterEnd">
\r
41 /// The chapter End.
\r
43 /// <param name="selectedTitle">
\r
44 /// The selected Title.
\r
47 /// The calculated duration.
\r
49 public static TimeSpan CalculateDuration(int chapterStart, int chapterEnd, Title selectedTitle)
\r
51 TimeSpan duration = TimeSpan.FromSeconds(0.0);
\r
54 if (chapterStart != 0 && chapterEnd != 0 && chapterEnd <= selectedTitle.Chapters.Count)
\r
56 for (int i = chapterStart; i <= chapterEnd; i++)
\r
57 duration += selectedTitle.Chapters[i - 1].Duration;
\r
64 /// Set's up the DataGridView on the Chapters tab (frmMain)
\r
66 /// <param name="dataChpt">
\r
67 /// The DataGridView Control
\r
69 /// <param name="chapterEnd">
\r
70 /// The chapter End.
\r
73 /// The chapter naming.
\r
75 public static DataGridView ChapterNaming(DataGridView dataChpt, string chapterEnd)
\r
77 int i = 0, finish = 0;
\r
79 if (chapterEnd != "Auto")
\r
80 int.TryParse(chapterEnd, out finish);
\r
84 int n = dataChpt.Rows.Add();
\r
85 dataChpt.Rows[n].Cells[0].Value = i + 1;
\r
86 dataChpt.Rows[n].Cells[1].Value = "Chapter " + (i + 1);
\r
87 dataChpt.Rows[n].Cells[0].ValueType = typeof(int);
\r
88 dataChpt.Rows[n].Cells[1].ValueType = typeof(string);
\r
96 /// Import a CSV file which contains Chapter Names
\r
98 /// <param name="dataChpt">
\r
99 /// The DataGridView Control
\r
101 /// <param name="filename">
\r
102 /// The filepath and name
\r
104 /// <returns>A Populated DataGridView</returns>
\r
105 public static DataGridView ImportChapterNames(DataGridView dataChpt, string filename)
\r
107 IDictionary<int, string> chapterMap = new Dictionary<int, string>();
\r
110 StreamReader sr = new StreamReader(filename);
\r
111 string csv = sr.ReadLine();
\r
112 while (csv != null)
\r
114 if (csv.Trim() != string.Empty)
\r
116 csv = csv.Replace("\\,", "<!comma!>");
\r
117 string[] contents = csv.Split(',');
\r
119 int.TryParse(contents[0], out chapter);
\r
120 chapterMap.Add(chapter, contents[1].Replace("<!comma!>", ","));
\r
122 csv = sr.ReadLine();
\r
130 foreach (DataGridViewRow item in dataChpt.Rows)
\r
133 chapterMap.TryGetValue((int)item.Cells[0].Value, out name);
\r
134 item.Cells[1].Value = name ?? "Chapter " + item.Cells[0].Value;
\r
141 /// Create a CSV file with the data from the Main Window Chapters tab
\r
143 /// <param name="mainWindow">Main Window</param>
\r
144 /// <param name="filePathName">Path to save the csv file</param>
\r
145 /// <returns>True if successful </returns>
\r
146 public static bool SaveChapterMarkersToCsv(frmMain mainWindow, string filePathName)
\r
150 string csv = string.Empty;
\r
152 foreach (DataGridViewRow row in mainWindow.data_chpt.Rows)
\r
154 csv += row.Cells[0].Value.ToString();
\r
156 csv += row.Cells[1].Value.ToString().Replace(",", "\\,");
\r
157 csv += Environment.NewLine;
\r
159 StreamWriter file = new StreamWriter(filePathName);
\r
165 catch (Exception exc)
\r
167 frmExceptionWindow exceptionWindow = new frmExceptionWindow();
\r
168 exceptionWindow.Setup("Unable to save Chapter Makrers file! \nChapter marker names will NOT be saved in your encode", exc.ToString());
\r
169 exceptionWindow.ShowDialog();
\r
175 /// Function which generates the filename and path automatically based on
\r
176 /// the Source Name, DVD title and DVD Chapters
\r
178 /// <param name="mainWindow">
\r
179 /// The main Window.
\r
182 /// The Generated FileName
\r
184 public static string AutoName(frmMain mainWindow)
\r
186 string autoNamePath = string.Empty;
\r
187 if (mainWindow.drp_dvdtitle.Text != "Automatic")
\r
189 // Get the Source Name
\r
190 string sourceName = mainWindow.SourceName;
\r
192 // Remove any illeagal characters from the source name
\r
193 foreach (char character in Path.GetInvalidFileNameChars())
\r
195 if (autoNamePath != null)
\r
197 sourceName = sourceName.Replace(character.ToString(), string.Empty);
\r
201 if (Properties.Settings.Default.AutoNameRemoveUnderscore)
\r
202 sourceName = sourceName.Replace("_", " ");
\r
204 if (Properties.Settings.Default.AutoNameTitleCase)
\r
205 sourceName = TitleCase(sourceName);
\r
207 // Get the Selected Title Number
\r
208 string[] titlesplit = mainWindow.drp_dvdtitle.Text.Split(' ');
\r
209 string dvdTitle = titlesplit[0].Replace("Automatic", string.Empty);
\r
211 // Get the Chapter Start and Chapter End Numbers
\r
212 string chapterStart = mainWindow.drop_chapterStart.Text.Replace("Auto", string.Empty);
\r
213 string chapterFinish = mainWindow.drop_chapterFinish.Text.Replace("Auto", string.Empty);
\r
214 string combinedChapterTag = chapterStart;
\r
215 if (chapterFinish != chapterStart && chapterFinish != string.Empty)
\r
216 combinedChapterTag = chapterStart + "-" + chapterFinish;
\r
218 // Get the destination filename.
\r
219 string destinationFilename;
\r
220 if (Properties.Settings.Default.autoNameFormat != string.Empty)
\r
222 destinationFilename = Properties.Settings.Default.autoNameFormat;
\r
223 destinationFilename =
\r
224 destinationFilename.Replace("{source}", sourceName).Replace("{title}", dvdTitle).Replace(
\r
225 "{chapters}", combinedChapterTag);
\r
228 destinationFilename = sourceName + "_T" + dvdTitle + "_C" + combinedChapterTag;
\r
230 // Add the appropriate file extension
\r
231 if (mainWindow.drop_format.SelectedIndex == 0)
\r
233 if (Properties.Settings.Default.useM4v || mainWindow.Check_ChapterMarkers.Checked ||
\r
234 mainWindow.AudioSettings.RequiresM4V() || mainWindow.Subtitles.RequiresM4V())
\r
235 destinationFilename += ".m4v";
\r
237 destinationFilename += ".mp4";
\r
239 else if (mainWindow.drop_format.SelectedIndex == 1)
\r
240 destinationFilename += ".mkv";
\r
242 // Now work out the path where the file will be stored.
\r
243 // First case: If the destination box doesn't already contain a path, make one.
\r
244 if (!mainWindow.text_destination.Text.Contains(Path.DirectorySeparatorChar.ToString()))
\r
246 // If there is an auto name path, use it...
\r
247 if (Properties.Settings.Default.autoNamePath.Trim() != string.Empty &&
\r
248 Properties.Settings.Default.autoNamePath.Trim() != "Click 'Browse' to set the default location")
\r
249 autoNamePath = Path.Combine(Properties.Settings.Default.autoNamePath, destinationFilename);
\r
250 else // ...otherwise, output to the source directory
\r
251 autoNamePath = null;
\r
253 else // Otherwise, use the path that is already there.
\r
255 // Use the path and change the file extension to match the previous destination
\r
256 autoNamePath = Path.Combine(Path.GetDirectoryName(mainWindow.text_destination.Text),
\r
257 destinationFilename);
\r
259 if (Path.HasExtension(mainWindow.text_destination.Text))
\r
260 autoNamePath = Path.ChangeExtension(autoNamePath,
\r
261 Path.GetExtension(mainWindow.text_destination.Text));
\r
265 return autoNamePath;
\r
269 /// Get's HandBrakes version data from the CLI.
\r
271 public static void SetCliVersionData()
\r
275 // 0 = SVN Build / Version
\r
277 DateTime lastModified = File.GetLastWriteTime("HandBrakeCLI.exe");
\r
279 if (Properties.Settings.Default.cliLastModified == lastModified && Properties.Settings.Default.hb_build != 0)
\r
282 Properties.Settings.Default.cliLastModified = lastModified;
\r
284 Process cliProcess = new Process();
\r
285 ProcessStartInfo handBrakeCli = new ProcessStartInfo("HandBrakeCLI.exe", " -u -v0")
\r
287 UseShellExecute = false,
\r
288 RedirectStandardError = true,
\r
289 RedirectStandardOutput = true,
\r
290 CreateNoWindow = true
\r
292 cliProcess.StartInfo = handBrakeCli;
\r
296 cliProcess.Start();
\r
298 // Retrieve standard output and report back to parent thread until the process is complete
\r
299 TextReader stdOutput = cliProcess.StandardError;
\r
301 while (!cliProcess.HasExited)
\r
303 line = stdOutput.ReadLine() ?? string.Empty;
\r
304 Match m = Regex.Match(line, @"HandBrake ([svnM0-9.]*) \([0-9]*\)");
\r
305 Match platform = Regex.Match(line, @"- ([A-Za-z0-9\s ]*) -");
\r
309 string data = line.Replace("(", string.Empty).Replace(")", string.Empty).Replace("HandBrake ", string.Empty);
\r
310 string[] arr = data.Split(' ');
\r
312 Properties.Settings.Default.hb_build = int.Parse(arr[1]);
\r
313 Properties.Settings.Default.hb_version = arr[0];
\r
316 if (platform.Success)
\r
318 Properties.Settings.Default.hb_platform = platform.Value.Replace("-", string.Empty).Trim();
\r
321 if (cliProcess.TotalProcessorTime.Seconds > 10) // Don't wait longer than 10 seconds.
\r
323 Process cli = Process.GetProcessById(cliProcess.Id);
\r
324 if (!cli.HasExited)
\r
331 Properties.Settings.Default.Save();
\r
333 catch (Exception e)
\r
335 frmExceptionWindow exceptionWindow = new frmExceptionWindow();
\r
336 exceptionWindow.Setup("Unable to retrieve version information from the CLI.", e.ToString());
\r
337 exceptionWindow.ShowDialog();
\r
342 /// Check to make sure that the user has an up to date version of the CLI installed.
\r
344 public static void CheckForValidCliVersion()
\r
346 // Make sure we have a recent version for svn builds
\r
347 string version = Properties.Settings.Default.hb_version;
\r
348 if (version.Contains("svn"))
\r
350 version = version.Replace("svn", string.Empty).Trim();
\r
352 int.TryParse(version, out build);
\r
353 if (build < Properties.Settings.Default.hb_min_cli)
\r
356 "It appears you are trying to use a CLI executable that is too old for this version of the HandBrake GUI.\n" +
\r
357 "Please update the HandBrakeCLI.exe to a newer build.\n\n" +
\r
358 "HandBrake build Detected: " + Properties.Settings.Default.hb_version,
\r
360 MessageBoxButtons.OK,
\r
361 MessageBoxIcon.Error);
\r
368 /// Check if the queue recovery file contains records.
\r
369 /// If it does, it means the last queue did not complete before HandBrake closed.
\r
370 /// So, return a boolean if true.
\r
373 /// True if there is a queue to recover.
\r
375 public static bool CheckQueueRecovery()
\r
379 string tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\hb_queue_recovery.xml");
\r
380 if (File.Exists(tempPath))
\r
382 using (FileStream strm = new FileStream(tempPath, FileMode.Open, FileAccess.Read))
\r
384 List<Job> list = Ser.Deserialize(strm) as List<Job>;
\r
386 if (list.Count != 0)
\r
394 return false; // Keep quiet about the error.
\r
399 /// Get the Process ID of HandBrakeCLI for the current instance.
\r
401 /// <param name="before">List of processes before the new process was started</param>
\r
402 /// <returns>Int - Process ID</returns>
\r
403 public static int GetCliProcess(Process[] before)
\r
405 // This is a bit of a cludge. Maybe someone has a better idea on how to impliment this.
\r
406 // Since we used CMD to start HandBrakeCLI, we don't get the process ID from hbProc.
\r
407 // Instead we take the processes before and after, and get the ID of HandBrakeCLI.exe
\r
408 // avoiding any previous instances of HandBrakeCLI.exe in before.
\r
409 // Kill the current process.
\r
411 DateTime startTime = DateTime.Now;
\r
414 Process[] hbProcesses = Process.GetProcessesByName("HandBrakeCLI");
\r
415 while (hbProcesses.Length == 0)
\r
417 hbProcesses = Process.GetProcessesByName("HandBrakeCLI");
\r
418 duration = DateTime.Now - startTime;
\r
419 if (duration.Seconds > 5 && hbProcesses.Length == 0)
\r
420 // Make sure we don't wait forever if the process doesn't start
\r
424 Process hbProcess = null;
\r
425 foreach (Process process in hbProcesses)
\r
427 bool found = false;
\r
428 // Check if the current CLI instance was running before we started the current one
\r
429 foreach (Process bprocess in before)
\r
431 if (process.Id == bprocess.Id)
\r
435 // If it wasn't running before, we found the process we want.
\r
438 hbProcess = process;
\r
442 if (hbProcess != null)
\r
443 return hbProcess.Id;
\r
449 /// Clear all the encode log files.
\r
451 public static void ClearLogs()
\r
453 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
\r
454 if (Directory.Exists(logDir))
\r
456 DirectoryInfo info = new DirectoryInfo(logDir);
\r
457 FileInfo[] logFiles = info.GetFiles("*.txt");
\r
458 foreach (FileInfo file in logFiles)
\r
460 if (!file.Name.Contains("last_scan_log") && !file.Name.Contains("last_encode_log") &&
\r
461 !file.Name.Contains("tmp_appReadable_log.txt"))
\r
462 File.Delete(file.FullName);
\r
468 /// Clear old log files x days in the past
\r
470 public static void ClearOldLogs()
\r
472 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
\r
473 if (Directory.Exists(logDir))
\r
475 DirectoryInfo info = new DirectoryInfo(logDir);
\r
476 FileInfo[] logFiles = info.GetFiles("*.txt");
\r
478 foreach (FileInfo file in logFiles)
\r
480 if (file.LastWriteTime < DateTime.Now.AddDays(-30))
\r
482 if (!file.Name.Contains("last_scan_log") && !file.Name.Contains("last_encode_log") &&
\r
483 !file.Name.Contains("tmp_appReadable_log.txt"))
\r
484 File.Delete(file.FullName);
\r
491 /// Begins checking for an update to HandBrake.
\r
493 /// <param name="callback">The method that will be called when the check is finished.</param>
\r
494 /// <param name="debug">Whether or not to execute this in debug mode.</param>
\r
495 public static void BeginCheckForUpdates(AsyncCallback callback, bool debug)
\r
497 ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
\r
501 // Is this a stable or unstable build?
\r
503 Properties.Settings.Default.hb_build.ToString()
\r
505 ? Properties.Settings.Default.
\r
507 : Properties.Settings.Default.appcast;
\r
509 // Initialize variables
\r
510 WebRequest request = WebRequest.Create(url);
\r
511 WebResponse response = request.GetResponse();
\r
512 AppcastReader reader = new AppcastReader();
\r
514 // Get the data, convert it to a string, and parse it into the AppcastReader
\r
516 new StreamReader(response.GetResponseStream())
\r
519 // Further parse the information
\r
520 string build = reader.Build;
\r
522 int latest = int.Parse(build);
\r
523 int current = Properties.Settings.Default.hb_build;
\r
524 int skip = Properties.Settings.Default.skipversion;
\r
526 // If the user wanted to skip this version, don't report the update
\r
527 if (latest == skip)
\r
529 UpdateCheckInformation info =
\r
530 new UpdateCheckInformation
\r
532 NewVersionAvailable = false,
\r
533 BuildInformation = null
\r
535 callback(new UpdateCheckResult(debug, info));
\r
539 // Set when the last update was
\r
540 Properties.Settings.Default.lastUpdateCheckDate =
\r
542 Properties.Settings.Default.Save();
\r
544 UpdateCheckInformation info2 =
\r
545 new UpdateCheckInformation
\r
547 NewVersionAvailable = latest > current,
\r
548 BuildInformation = reader
\r
550 callback(new UpdateCheckResult(debug, info2));
\r
552 catch (Exception exc)
\r
554 callback(new UpdateCheckResult(debug, new UpdateCheckInformation { Error = exc }));
\r
560 /// End Check for Updates
\r
562 /// <param name="result">
\r
566 /// Update Check information
\r
568 public static UpdateCheckInformation EndCheckForUpdates(IAsyncResult result)
\r
570 UpdateCheckResult checkResult = (UpdateCheckResult)result;
\r
571 return checkResult.Result;
\r
575 /// Map languages and their iso639_2 value into a IDictionary
\r
577 /// <returns>A Dictionary containing the language and iso code</returns>
\r
578 public static IDictionary<string, string> MapLanguages()
\r
580 IDictionary<string, string> languageMap = new Dictionary<string, string>
\r
584 {"Abkhazian", "abk"},
\r
585 {"Afrikaans", "afr"},
\r
587 {"Albanian", "sqi"},
\r
588 {"Amharic", "amh"},
\r
589 {"Arabic", "ara"},
\r
590 {"Aragonese", "arg"},
\r
591 {"Armenian", "hye"},
\r
592 {"Assamese", "asm"},
\r
593 {"Avaric", "ava"},
\r
594 {"Avestan", "ave"},
\r
595 {"Aymara", "aym"},
\r
596 {"Azerbaijani", "aze"},
\r
597 {"Bashkir", "bak"},
\r
598 {"Bambara", "bam"},
\r
599 {"Basque", "eus"},
\r
600 {"Belarusian", "bel"},
\r
601 {"Bengali", "ben"},
\r
602 {"Bihari", "bih"},
\r
603 {"Bislama", "bis"},
\r
604 {"Bosnian", "bos"},
\r
605 {"Breton", "bre"},
\r
606 {"Bulgarian", "bul"},
\r
607 {"Burmese", "mya"},
\r
608 {"Catalan", "cat"},
\r
609 {"Chamorro", "cha"},
\r
610 {"Chechen", "che"},
\r
611 {"Chinese", "zho"},
\r
612 {"Church Slavic", "chu"},
\r
613 {"Chuvash", "chv"},
\r
614 {"Cornish", "cor"},
\r
615 {"Corsican", "cos"},
\r
619 {"Divehi", "div"},
\r
620 {"Nederlands", "nld"},
\r
621 {"Dzongkha", "dzo"},
\r
622 {"English", "eng"},
\r
623 {"Esperanto", "epo"},
\r
624 {"Estonian", "est"},
\r
626 {"Faroese", "fao"},
\r
627 {"Fijian", "fij"},
\r
629 {"Francais", "fra"},
\r
630 {"Western Frisian", "fry"},
\r
632 {"Georgian", "kat"},
\r
633 {"Deutsch", "deu"},
\r
634 {"Gaelic (Scots)", "gla"},
\r
636 {"Galician", "glg"},
\r
638 {"Greek Modern", "ell"},
\r
639 {"Guarani", "grn"},
\r
640 {"Gujarati", "guj"},
\r
641 {"Haitian", "hat"},
\r
643 {"Hebrew", "heb"},
\r
644 {"Herero", "her"},
\r
646 {"Hiri Motu", "hmo"},
\r
647 {"Magyar", "hun"},
\r
649 {"Islenska", "isl"},
\r
651 {"Sichuan Yi", "iii"},
\r
652 {"Inuktitut", "iku"},
\r
653 {"Interlingue", "ile"},
\r
654 {"Interlingua", "ina"},
\r
655 {"Indonesian", "ind"},
\r
656 {"Inupiaq", "ipk"},
\r
657 {"Italiano", "ita"},
\r
658 {"Javanese", "jav"},
\r
659 {"Japanese", "jpn"},
\r
660 {"Kalaallisut", "kal"},
\r
661 {"Kannada", "kan"},
\r
662 {"Kashmiri", "kas"},
\r
663 {"Kanuri", "kau"},
\r
664 {"Kazakh", "kaz"},
\r
665 {"Central Khmer", "khm"},
\r
666 {"Kikuyu", "kik"},
\r
667 {"Kinyarwanda", "kin"},
\r
668 {"Kirghiz", "kir"},
\r
671 {"Korean", "kor"},
\r
672 {"Kuanyama", "kua"},
\r
673 {"Kurdish", "kur"},
\r
676 {"Latvian", "lav"},
\r
677 {"Limburgan", "lim"},
\r
678 {"Lingala", "lin"},
\r
679 {"Lithuanian", "lit"},
\r
680 {"Luxembourgish", "ltz"},
\r
681 {"Luba-Katanga", "lub"},
\r
683 {"Macedonian", "mkd"},
\r
684 {"Marshallese", "mah"},
\r
685 {"Malayalam", "mal"},
\r
687 {"Marathi", "mar"},
\r
689 {"Malagasy", "mlg"},
\r
690 {"Maltese", "mlt"},
\r
691 {"Moldavian", "mol"},
\r
692 {"Mongolian", "mon"},
\r
694 {"Navajo", "nav"},
\r
695 {"Ndebele, South", "nbl"},
\r
696 {"Ndebele, North", "nde"},
\r
697 {"Ndonga", "ndo"},
\r
698 {"Nepali", "nep"},
\r
699 {"Norwegian Nynorsk", "nno"},
\r
700 {"Norwegian Bokmål", "nob"},
\r
702 {"Chichewa; Nyanja", "nya"},
\r
703 {"Occitan", "oci"},
\r
704 {"Ojibwa", "oji"},
\r
707 {"Ossetian", "oss"},
\r
708 {"Panjabi", "pan"},
\r
709 {"Persian", "fas"},
\r
711 {"Polish", "pol"},
\r
712 {"Portugues", "por"},
\r
713 {"Pushto", "pus"},
\r
714 {"Quechua", "que"},
\r
715 {"Romansh", "roh"},
\r
716 {"Romanian", "ron"},
\r
718 {"Russian", "rus"},
\r
720 {"Sanskrit", "san"},
\r
721 {"Serbian", "srp"},
\r
722 {"Hrvatski", "hrv"},
\r
723 {"Sinhala", "sin"},
\r
724 {"Slovak", "slk"},
\r
725 {"Slovenian", "slv"},
\r
726 {"Northern Sami", "sme"},
\r
727 {"Samoan", "smo"},
\r
729 {"Sindhi", "snd"},
\r
730 {"Somali", "som"},
\r
731 {"Sotho Southern", "sot"},
\r
732 {"Espanol", "spa"},
\r
733 {"Sardinian", "srd"},
\r
735 {"Sundanese", "sun"},
\r
736 {"Swahili", "swa"},
\r
737 {"Svenska", "swe"},
\r
738 {"Tahitian", "tah"},
\r
741 {"Telugu", "tel"},
\r
743 {"Tagalog", "tgl"},
\r
745 {"Tibetan", "bod"},
\r
746 {"Tigrinya", "tir"},
\r
748 {"Tswana", "tsn"},
\r
749 {"Tsonga", "tso"},
\r
750 {"Turkmen", "tuk"},
\r
751 {"Turkish", "tur"},
\r
753 {"Uighur", "uig"},
\r
754 {"Ukrainian", "ukr"},
\r
758 {"Vietnamese", "vie"},
\r
759 {"Volapük", "vol"},
\r
761 {"Walloon", "wln"},
\r
764 {"Yiddish", "yid"},
\r
765 {"Yoruba", "yor"},
\r
766 {"Zhuang", "zha"},
\r
769 return languageMap;
\r
773 /// Get a list of available DVD drives which are ready and contain DVD content.
\r
775 /// <returns>A List of Drives with their details</returns>
\r
776 public static List<DriveInformation> GetDrives()
\r
778 List<DriveInformation> drives = new List<DriveInformation>();
\r
779 DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives();
\r
781 foreach (DriveInfo curDrive in theCollectionOfDrives)
\r
783 if (curDrive.DriveType == DriveType.CDRom && curDrive.IsReady &&
\r
784 File.Exists(curDrive.RootDirectory + "VIDEO_TS\\VIDEO_TS.IFO"))
\r
786 drives.Add(new DriveInformation
\r
789 VolumeLabel = curDrive.VolumeLabel,
\r
790 RootDirectory = curDrive.RootDirectory + "VIDEO_TS"
\r
799 /// Change a string to Title Case/
\r
801 /// <param name="input">
\r
805 /// A string in title case.
\r
807 public static string TitleCase(string input)
\r
809 string[] tokens = input.Split(' ');
\r
810 StringBuilder sb = new StringBuilder(input.Length);
\r
811 foreach (string s in tokens)
\r
813 sb.Append(s[0].ToString().ToUpper());
\r
814 sb.Append(s.Substring(1).ToLower());
\r
818 return sb.ToString().Trim();
\r
822 /// Show the Exception Window
\r
824 /// <param name="shortError">
\r
825 /// The short error.
\r
827 /// <param name="longError">
\r
828 /// The long error.
\r
830 public static void ShowExceptiowWindow(string shortError, string longError)
\r
832 frmExceptionWindow exceptionWindow = new frmExceptionWindow();
\r
833 exceptionWindow.Setup(shortError, longError);
\r
834 exceptionWindow.Show();
\r