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
11 using System.Globalization;
\r
15 using System.Text.RegularExpressions;
\r
16 using System.Threading;
\r
17 using System.Windows.Forms;
\r
18 using System.Xml.Serialization;
\r
23 /// Useful functions which various screens can use.
\r
25 public static class Main
\r
28 /// The XML Serializer
\r
30 private static readonly XmlSerializer Ser = new XmlSerializer(typeof(List<Job>));
\r
33 /// Calculate the duration of the selected title and chapters
\r
35 /// <param name="chapterStart">
\r
36 /// The chapter Start.
\r
38 /// <param name="chapterEnd">
\r
39 /// The chapter End.
\r
41 /// <param name="selectedTitle">
\r
42 /// The selected Title.
\r
45 /// The calculated duration.
\r
47 public static TimeSpan CalculateDuration(int chapterStart, int chapterEnd, Title selectedTitle)
\r
49 TimeSpan duration = TimeSpan.FromSeconds(0.0);
\r
52 if (chapterStart != 0 && chapterEnd != 0 && chapterEnd <= selectedTitle.Chapters.Count)
\r
54 for (int i = chapterStart; i <= chapterEnd; i++)
\r
55 duration += selectedTitle.Chapters[i - 1].Duration;
\r
62 /// Set's up the DataGridView on the Chapters tab (frmMain)
\r
64 /// <param name="dataChpt">
\r
65 /// The DataGridView Control
\r
67 /// <param name="chapterEnd">
\r
68 /// The chapter End.
\r
71 /// The chapter naming.
\r
73 public static DataGridView ChapterNaming(DataGridView dataChpt, string chapterEnd)
\r
75 int i = 0, finish = 0;
\r
77 if (chapterEnd != "Auto")
\r
78 int.TryParse(chapterEnd, out finish);
\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
94 /// Import a CSV file which contains Chapter Names
\r
96 /// <param name="dataChpt">
\r
97 /// The DataGridView Control
\r
99 /// <param name="filename">
\r
100 /// The filepath and name
\r
102 /// <returns>A Populated DataGridView</returns>
\r
103 public static DataGridView ImportChapterNames(DataGridView dataChpt, string filename)
\r
105 IDictionary<int, string> chapterMap = new Dictionary<int, string>();
\r
108 StreamReader sr = new StreamReader(filename);
\r
109 string csv = sr.ReadLine();
\r
110 while (csv != null)
\r
112 if (csv.Trim() != string.Empty)
\r
114 csv = csv.Replace("\\,", "<!comma!>");
\r
115 string[] contents = csv.Split(',');
\r
117 int.TryParse(contents[0], out chapter);
\r
118 chapterMap.Add(chapter, contents[1].Replace("<!comma!>", ","));
\r
120 csv = sr.ReadLine();
\r
128 foreach (DataGridViewRow item in dataChpt.Rows)
\r
131 chapterMap.TryGetValue((int)item.Cells[0].Value, out name);
\r
132 item.Cells[1].Value = name ?? "Chapter " + item.Cells[0].Value;
\r
139 /// Create a CSV file with the data from the Main Window Chapters tab
\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
148 string csv = string.Empty;
\r
150 foreach (DataGridViewRow row in mainWindow.data_chpt.Rows)
\r
152 csv += row.Cells[0].Value.ToString();
\r
154 csv += row.Cells[1].Value.ToString().Replace(",", "\\,");
\r
155 csv += Environment.NewLine;
\r
157 StreamWriter file = new StreamWriter(filePathName);
\r
163 catch (Exception exc)
\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
173 /// Function which generates the filename and path automatically based on
\r
174 /// the Source Name, DVD title and DVD Chapters
\r
176 /// <param name="mainWindow">
\r
177 /// The main Window.
\r
180 /// The Generated FileName
\r
182 public static string AutoName(frmMain mainWindow)
\r
184 string autoNamePath = string.Empty;
\r
185 if (mainWindow.drp_dvdtitle.Text != "Automatic")
\r
187 // Get the Source Name
\r
188 string sourceName = mainWindow.SourceName;
\r
190 // Remove any illeagal characters from the source name
\r
191 foreach (char character in Path.GetInvalidFileNameChars())
\r
193 if (autoNamePath != null)
\r
195 sourceName = sourceName.Replace(character.ToString(), string.Empty);
\r
199 if (Properties.Settings.Default.AutoNameRemoveUnderscore)
\r
200 sourceName = sourceName.Replace("_", " ");
\r
202 if (Properties.Settings.Default.AutoNameTitleCase)
\r
203 sourceName = TitleCase(sourceName);
\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
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
216 // Get the destination filename.
\r
217 string destinationFilename;
\r
218 if (Properties.Settings.Default.autoNameFormat != string.Empty)
\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
226 destinationFilename = sourceName + "_T" + dvdTitle + "_C" + combinedChapterTag;
\r
228 // Add the appropriate file extension
\r
229 if (mainWindow.drop_format.SelectedIndex == 0)
\r
231 if (Properties.Settings.Default.useM4v || mainWindow.Check_ChapterMarkers.Checked ||
\r
232 mainWindow.AudioSettings.RequiresM4V() || mainWindow.Subtitles.RequiresM4V())
\r
233 destinationFilename += ".m4v";
\r
235 destinationFilename += ".mp4";
\r
237 else if (mainWindow.drop_format.SelectedIndex == 1)
\r
238 destinationFilename += ".mkv";
\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
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
251 else // Otherwise, use the path that is already there.
\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
257 if (Path.HasExtension(mainWindow.text_destination.Text))
\r
258 autoNamePath = Path.ChangeExtension(autoNamePath,
\r
259 Path.GetExtension(mainWindow.text_destination.Text));
\r
263 return autoNamePath;
\r
267 /// Get's HandBrakes version data from the CLI.
\r
269 public static void SetCliVersionData()
\r
273 // 0 = SVN Build / Version
\r
275 DateTime lastModified = File.GetLastWriteTime("HandBrakeCLI.exe");
\r
277 if (Properties.Settings.Default.cliLastModified == lastModified && Properties.Settings.Default.hb_build != 0)
\r
280 Properties.Settings.Default.cliLastModified = lastModified;
\r
282 Process cliProcess = new Process();
\r
283 ProcessStartInfo handBrakeCli = new ProcessStartInfo("HandBrakeCLI.exe", " -u -v0")
\r
285 UseShellExecute = false,
\r
286 RedirectStandardError = true,
\r
287 RedirectStandardOutput = true,
\r
288 CreateNoWindow = true
\r
290 cliProcess.StartInfo = handBrakeCli;
\r
294 cliProcess.Start();
\r
296 // Retrieve standard output and report back to parent thread until the process is complete
\r
297 TextReader stdOutput = cliProcess.StandardError;
\r
299 while (!cliProcess.HasExited)
\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
307 string data = line.Replace("(", string.Empty).Replace(")", string.Empty).Replace("HandBrake ", string.Empty);
\r
308 string[] arr = data.Split(' ');
\r
310 Properties.Settings.Default.hb_build = int.Parse(arr[1]);
\r
311 Properties.Settings.Default.hb_version = arr[0];
\r
314 if (platform.Success)
\r
316 Properties.Settings.Default.hb_platform = platform.Value.Replace("-", string.Empty).Trim();
\r
319 if (cliProcess.TotalProcessorTime.Seconds > 10) // Don't wait longer than 10 seconds.
\r
321 Process cli = Process.GetProcessById(cliProcess.Id);
\r
322 if (!cli.HasExited)
\r
329 Properties.Settings.Default.Save();
\r
331 catch (Exception e)
\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
340 /// Check to make sure that the user has an up to date version of the CLI installed.
\r
342 public static void CheckForValidCliVersion()
\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
348 version = version.Replace("svn", string.Empty).Trim();
\r
350 int.TryParse(version, out build);
\r
351 if (build < Properties.Settings.Default.hb_min_cli)
\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
358 MessageBoxButtons.OK,
\r
359 MessageBoxIcon.Error);
\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
371 /// True if there is a queue to recover.
\r
373 public static bool CheckQueueRecovery()
\r
377 string tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\hb_queue_recovery.xml");
\r
378 if (File.Exists(tempPath))
\r
380 using (FileStream strm = new FileStream(tempPath, FileMode.Open, FileAccess.Read))
\r
382 List<Job> list = Ser.Deserialize(strm) as List<Job>;
\r
384 if (list.Count != 0)
\r
392 return false; // Keep quiet about the error.
\r
397 /// Get the Process ID of HandBrakeCLI for the current instance.
\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
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
409 DateTime startTime = DateTime.Now;
\r
412 Process[] hbProcesses = Process.GetProcessesByName("HandBrakeCLI");
\r
413 while (hbProcesses.Length == 0)
\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
422 Process hbProcess = null;
\r
423 foreach (Process process in hbProcesses)
\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
429 if (process.Id == bprocess.Id)
\r
433 // If it wasn't running before, we found the process we want.
\r
436 hbProcess = process;
\r
440 if (hbProcess != null)
\r
441 return hbProcess.Id;
\r
447 /// Clear all the encode log files.
\r
449 public static void ClearLogs()
\r
451 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
\r
452 if (Directory.Exists(logDir))
\r
454 DirectoryInfo info = new DirectoryInfo(logDir);
\r
455 FileInfo[] logFiles = info.GetFiles("*.txt");
\r
456 foreach (FileInfo file in logFiles)
\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
466 /// Clear old log files x days in the past
\r
468 public static void ClearOldLogs()
\r
470 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
\r
471 if (Directory.Exists(logDir))
\r
473 DirectoryInfo info = new DirectoryInfo(logDir);
\r
474 FileInfo[] logFiles = info.GetFiles("*.txt");
\r
476 foreach (FileInfo file in logFiles)
\r
478 if (file.LastWriteTime < DateTime.Now.AddDays(-30))
\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
489 /// Begins checking for an update to HandBrake.
\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
495 ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
\r
499 // Is this a stable or unstable build?
\r
501 Properties.Settings.Default.hb_build.ToString()
\r
503 ? Properties.Settings.Default.
\r
505 : Properties.Settings.Default.appcast;
\r
507 // Initialize variables
\r
508 WebRequest request = WebRequest.Create(url);
\r
509 WebResponse response = request.GetResponse();
\r
510 AppcastReader reader = new AppcastReader();
\r
512 // Get the data, convert it to a string, and parse it into the AppcastReader
\r
514 new StreamReader(response.GetResponseStream())
\r
517 // Further parse the information
\r
518 string build = reader.Build;
\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
524 // If the user wanted to skip this version, don't report the update
\r
525 if (latest == skip)
\r
527 UpdateCheckInformation info =
\r
528 new UpdateCheckInformation
\r
530 NewVersionAvailable = false,
\r
531 BuildInformation = null
\r
533 callback(new UpdateCheckResult(debug, info));
\r
537 // Set when the last update was
\r
538 Properties.Settings.Default.lastUpdateCheckDate =
\r
540 Properties.Settings.Default.Save();
\r
542 UpdateCheckInformation info2 =
\r
543 new UpdateCheckInformation
\r
545 NewVersionAvailable = latest > current,
\r
546 BuildInformation = reader
\r
548 callback(new UpdateCheckResult(debug, info2));
\r
550 catch (Exception exc)
\r
552 callback(new UpdateCheckResult(debug, new UpdateCheckInformation { Error = exc }));
\r
558 /// End Check for Updates
\r
560 /// <param name="result">
\r
564 /// Update Check information
\r
566 public static UpdateCheckInformation EndCheckForUpdates(IAsyncResult result)
\r
568 UpdateCheckResult checkResult = (UpdateCheckResult)result;
\r
569 return checkResult.Result;
\r
573 /// Map languages and their iso639_2 value into a IDictionary
\r
575 /// <returns>A Dictionary containing the language and iso code</returns>
\r
576 public static IDictionary<string, string> MapLanguages()
\r
578 IDictionary<string, string> languageMap = new Dictionary<string, string>
\r
582 {"Abkhazian", "abk"},
\r
583 {"Afrikaans", "afr"},
\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
617 {"Divehi", "div"},
\r
618 {"Nederlands", "nld"},
\r
619 {"Dzongkha", "dzo"},
\r
620 {"English", "eng"},
\r
621 {"Esperanto", "epo"},
\r
622 {"Estonian", "est"},
\r
624 {"Faroese", "fao"},
\r
625 {"Fijian", "fij"},
\r
627 {"Francais", "fra"},
\r
628 {"Western Frisian", "fry"},
\r
630 {"Georgian", "kat"},
\r
631 {"Deutsch", "deu"},
\r
632 {"Gaelic (Scots)", "gla"},
\r
634 {"Galician", "glg"},
\r
636 {"Greek Modern", "ell"},
\r
637 {"Guarani", "grn"},
\r
638 {"Gujarati", "guj"},
\r
639 {"Haitian", "hat"},
\r
641 {"Hebrew", "heb"},
\r
642 {"Herero", "her"},
\r
644 {"Hiri Motu", "hmo"},
\r
645 {"Magyar", "hun"},
\r
647 {"Islenska", "isl"},
\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
669 {"Korean", "kor"},
\r
670 {"Kuanyama", "kua"},
\r
671 {"Kurdish", "kur"},
\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
681 {"Macedonian", "mkd"},
\r
682 {"Marshallese", "mah"},
\r
683 {"Malayalam", "mal"},
\r
685 {"Marathi", "mar"},
\r
687 {"Malagasy", "mlg"},
\r
688 {"Maltese", "mlt"},
\r
689 {"Moldavian", "mol"},
\r
690 {"Mongolian", "mon"},
\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
700 {"Chichewa; Nyanja", "nya"},
\r
701 {"Occitan", "oci"},
\r
702 {"Ojibwa", "oji"},
\r
705 {"Ossetian", "oss"},
\r
706 {"Panjabi", "pan"},
\r
707 {"Persian", "fas"},
\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
716 {"Russian", "rus"},
\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
727 {"Sindhi", "snd"},
\r
728 {"Somali", "som"},
\r
729 {"Sotho Southern", "sot"},
\r
730 {"Espanol", "spa"},
\r
731 {"Sardinian", "srd"},
\r
733 {"Sundanese", "sun"},
\r
734 {"Swahili", "swa"},
\r
735 {"Svenska", "swe"},
\r
736 {"Tahitian", "tah"},
\r
739 {"Telugu", "tel"},
\r
741 {"Tagalog", "tgl"},
\r
743 {"Tibetan", "bod"},
\r
744 {"Tigrinya", "tir"},
\r
746 {"Tswana", "tsn"},
\r
747 {"Tsonga", "tso"},
\r
748 {"Turkmen", "tuk"},
\r
749 {"Turkish", "tur"},
\r
751 {"Uighur", "uig"},
\r
752 {"Ukrainian", "ukr"},
\r
756 {"Vietnamese", "vie"},
\r
757 {"Volapük", "vol"},
\r
759 {"Walloon", "wln"},
\r
762 {"Yiddish", "yid"},
\r
763 {"Yoruba", "yor"},
\r
764 {"Zhuang", "zha"},
\r
767 return languageMap;
\r
771 /// Get a list of available DVD drives which are ready and contain DVD content.
\r
773 /// <returns>A List of Drives with their details</returns>
\r
774 public static List<DriveInformation> GetDrives()
\r
776 List<DriveInformation> drives = new List<DriveInformation>();
\r
777 DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives();
\r
779 foreach (DriveInfo curDrive in theCollectionOfDrives)
\r
781 if (curDrive.DriveType == DriveType.CDRom && curDrive.IsReady &&
\r
782 File.Exists(curDrive.RootDirectory + "VIDEO_TS\\VIDEO_TS.IFO"))
\r
784 drives.Add(new DriveInformation
\r
787 VolumeLabel = curDrive.VolumeLabel,
\r
788 RootDirectory = curDrive.RootDirectory + "VIDEO_TS"
\r
797 /// Change a string to Title Case/
\r
799 /// <param name="input">
\r
803 /// A string in title case.
\r
805 public static string TitleCase(string input)
\r
807 string[] tokens = input.Split(' ');
\r
808 StringBuilder sb = new StringBuilder(input.Length);
\r
809 foreach (string s in tokens)
\r
811 sb.Append(s[0].ToString().ToUpper());
\r
812 sb.Append(s.Substring(1).ToLower());
\r
816 return sb.ToString().Trim();
\r
820 /// Show the Exception Window
\r
822 /// <param name="shortError">
\r
823 /// The short error.
\r
825 /// <param name="longError">
\r
826 /// The long error.
\r
828 public static void ShowExceptiowWindow(string shortError, string longError)
\r
830 frmExceptionWindow exceptionWindow = new frmExceptionWindow();
\r
831 exceptionWindow.Setup(shortError, longError);
\r
832 exceptionWindow.Show();
\r