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 List<string> CheckQueueRecovery()
\r
379 string tempPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"HandBrake\");
\r
380 List<string> queueFiles = new List<string>();
\r
382 DirectoryInfo info = new DirectoryInfo(tempPath);
\r
383 FileInfo[] logFiles = info.GetFiles("*.xml");
\r
384 foreach (FileInfo file in logFiles)
\r
386 if (!file.Name.Contains("hb_queue_recovery"))
\r
389 using (FileStream strm = new FileStream(Path.Combine(file.DirectoryName, file.Name), FileMode.Open, FileAccess.Read))
\r
391 List<Job> list = Ser.Deserialize(strm) as List<Job>;
\r
394 if (list.Count != 0)
\r
396 queueFiles.Add(file.Name);
\r
406 return new List<string>(); // Keep quiet about the error.
\r
411 /// Checks if this HandBrake is running multiple instances
\r
413 /// <returns>True if the UI has another instance running</returns>
\r
414 public static bool IsMultiInstance
\r
418 return Process.GetProcessesByName("HandBrake").Length > 0 ? true : false;
\r
423 /// Clear all the encode log files.
\r
425 public static void ClearLogs()
\r
427 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
\r
428 if (Directory.Exists(logDir))
\r
430 DirectoryInfo info = new DirectoryInfo(logDir);
\r
431 FileInfo[] logFiles = info.GetFiles("*.txt");
\r
432 foreach (FileInfo file in logFiles)
\r
434 if (!file.Name.Contains("last_scan_log") && !file.Name.Contains("last_encode_log"))
\r
435 File.Delete(file.FullName);
\r
441 /// Clear old log files x days in the past
\r
443 public static void ClearOldLogs()
\r
445 string logDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\HandBrake\\logs";
\r
446 if (Directory.Exists(logDir))
\r
448 DirectoryInfo info = new DirectoryInfo(logDir);
\r
449 FileInfo[] logFiles = info.GetFiles("*.txt");
\r
451 foreach (FileInfo file in logFiles)
\r
453 if (file.LastWriteTime < DateTime.Now.AddDays(-30))
\r
455 if (!file.Name.Contains("last_scan_log.txt") && !file.Name.Contains("last_encode_log.txt"))
\r
456 File.Delete(file.FullName);
\r
463 /// Begins checking for an update to HandBrake.
\r
465 /// <param name="callback">The method that will be called when the check is finished.</param>
\r
466 /// <param name="debug">Whether or not to execute this in debug mode.</param>
\r
467 public static void BeginCheckForUpdates(AsyncCallback callback, bool debug)
\r
469 ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
\r
473 // Is this a stable or unstable build?
\r
475 Properties.Settings.Default.hb_build.ToString()
\r
477 ? Properties.Settings.Default.
\r
479 : Properties.Settings.Default.appcast;
\r
481 // Initialize variables
\r
482 WebRequest request = WebRequest.Create(url);
\r
483 WebResponse response = request.GetResponse();
\r
484 AppcastReader reader = new AppcastReader();
\r
486 // Get the data, convert it to a string, and parse it into the AppcastReader
\r
488 new StreamReader(response.GetResponseStream())
\r
491 // Further parse the information
\r
492 string build = reader.Build;
\r
494 int latest = int.Parse(build);
\r
495 int current = Properties.Settings.Default.hb_build;
\r
496 int skip = Properties.Settings.Default.skipversion;
\r
498 // If the user wanted to skip this version, don't report the update
\r
499 if (latest == skip)
\r
501 UpdateCheckInformation info =
\r
502 new UpdateCheckInformation
\r
504 NewVersionAvailable = false,
\r
505 BuildInformation = null
\r
507 callback(new UpdateCheckResult(debug, info));
\r
511 // Set when the last update was
\r
512 Properties.Settings.Default.lastUpdateCheckDate =
\r
514 Properties.Settings.Default.Save();
\r
516 UpdateCheckInformation info2 =
\r
517 new UpdateCheckInformation
\r
519 NewVersionAvailable = latest > current,
\r
520 BuildInformation = reader
\r
522 callback(new UpdateCheckResult(debug, info2));
\r
524 catch (Exception exc)
\r
526 callback(new UpdateCheckResult(debug, new UpdateCheckInformation { Error = exc }));
\r
532 /// End Check for Updates
\r
534 /// <param name="result">
\r
538 /// Update Check information
\r
540 public static UpdateCheckInformation EndCheckForUpdates(IAsyncResult result)
\r
542 UpdateCheckResult checkResult = (UpdateCheckResult)result;
\r
543 return checkResult.Result;
\r
547 /// Map languages and their iso639_2 value into a IDictionary
\r
549 /// <returns>A Dictionary containing the language and iso code</returns>
\r
550 public static IDictionary<string, string> MapLanguages()
\r
552 IDictionary<string, string> languageMap = new Dictionary<string, string>
\r
556 {"Abkhazian", "abk"},
\r
557 {"Afrikaans", "afr"},
\r
559 {"Albanian", "sqi"},
\r
560 {"Amharic", "amh"},
\r
561 {"Arabic", "ara"},
\r
562 {"Aragonese", "arg"},
\r
563 {"Armenian", "hye"},
\r
564 {"Assamese", "asm"},
\r
565 {"Avaric", "ava"},
\r
566 {"Avestan", "ave"},
\r
567 {"Aymara", "aym"},
\r
568 {"Azerbaijani", "aze"},
\r
569 {"Bashkir", "bak"},
\r
570 {"Bambara", "bam"},
\r
571 {"Basque", "eus"},
\r
572 {"Belarusian", "bel"},
\r
573 {"Bengali", "ben"},
\r
574 {"Bihari", "bih"},
\r
575 {"Bislama", "bis"},
\r
576 {"Bosnian", "bos"},
\r
577 {"Breton", "bre"},
\r
578 {"Bulgarian", "bul"},
\r
579 {"Burmese", "mya"},
\r
580 {"Catalan", "cat"},
\r
581 {"Chamorro", "cha"},
\r
582 {"Chechen", "che"},
\r
583 {"Chinese", "zho"},
\r
584 {"Church Slavic", "chu"},
\r
585 {"Chuvash", "chv"},
\r
586 {"Cornish", "cor"},
\r
587 {"Corsican", "cos"},
\r
591 {"Divehi", "div"},
\r
592 {"Nederlands", "nld"},
\r
593 {"Dzongkha", "dzo"},
\r
594 {"English", "eng"},
\r
595 {"Esperanto", "epo"},
\r
596 {"Estonian", "est"},
\r
598 {"Faroese", "fao"},
\r
599 {"Fijian", "fij"},
\r
601 {"Francais", "fra"},
\r
602 {"Western Frisian", "fry"},
\r
604 {"Georgian", "kat"},
\r
605 {"Deutsch", "deu"},
\r
606 {"Gaelic (Scots)", "gla"},
\r
608 {"Galician", "glg"},
\r
610 {"Greek Modern", "ell"},
\r
611 {"Guarani", "grn"},
\r
612 {"Gujarati", "guj"},
\r
613 {"Haitian", "hat"},
\r
615 {"Hebrew", "heb"},
\r
616 {"Herero", "her"},
\r
618 {"Hiri Motu", "hmo"},
\r
619 {"Magyar", "hun"},
\r
621 {"Islenska", "isl"},
\r
623 {"Sichuan Yi", "iii"},
\r
624 {"Inuktitut", "iku"},
\r
625 {"Interlingue", "ile"},
\r
626 {"Interlingua", "ina"},
\r
627 {"Indonesian", "ind"},
\r
628 {"Inupiaq", "ipk"},
\r
629 {"Italiano", "ita"},
\r
630 {"Javanese", "jav"},
\r
631 {"Japanese", "jpn"},
\r
632 {"Kalaallisut", "kal"},
\r
633 {"Kannada", "kan"},
\r
634 {"Kashmiri", "kas"},
\r
635 {"Kanuri", "kau"},
\r
636 {"Kazakh", "kaz"},
\r
637 {"Central Khmer", "khm"},
\r
638 {"Kikuyu", "kik"},
\r
639 {"Kinyarwanda", "kin"},
\r
640 {"Kirghiz", "kir"},
\r
643 {"Korean", "kor"},
\r
644 {"Kuanyama", "kua"},
\r
645 {"Kurdish", "kur"},
\r
648 {"Latvian", "lav"},
\r
649 {"Limburgan", "lim"},
\r
650 {"Lingala", "lin"},
\r
651 {"Lithuanian", "lit"},
\r
652 {"Luxembourgish", "ltz"},
\r
653 {"Luba-Katanga", "lub"},
\r
655 {"Macedonian", "mkd"},
\r
656 {"Marshallese", "mah"},
\r
657 {"Malayalam", "mal"},
\r
659 {"Marathi", "mar"},
\r
661 {"Malagasy", "mlg"},
\r
662 {"Maltese", "mlt"},
\r
663 {"Moldavian", "mol"},
\r
664 {"Mongolian", "mon"},
\r
666 {"Navajo", "nav"},
\r
667 {"Ndebele, South", "nbl"},
\r
668 {"Ndebele, North", "nde"},
\r
669 {"Ndonga", "ndo"},
\r
670 {"Nepali", "nep"},
\r
671 {"Norwegian Nynorsk", "nno"},
\r
672 {"Norwegian Bokmål", "nob"},
\r
674 {"Chichewa; Nyanja", "nya"},
\r
675 {"Occitan", "oci"},
\r
676 {"Ojibwa", "oji"},
\r
679 {"Ossetian", "oss"},
\r
680 {"Panjabi", "pan"},
\r
681 {"Persian", "fas"},
\r
683 {"Polish", "pol"},
\r
684 {"Portugues", "por"},
\r
685 {"Pushto", "pus"},
\r
686 {"Quechua", "que"},
\r
687 {"Romansh", "roh"},
\r
688 {"Romanian", "ron"},
\r
690 {"Russian", "rus"},
\r
692 {"Sanskrit", "san"},
\r
693 {"Serbian", "srp"},
\r
694 {"Hrvatski", "hrv"},
\r
695 {"Sinhala", "sin"},
\r
696 {"Slovak", "slk"},
\r
697 {"Slovenian", "slv"},
\r
698 {"Northern Sami", "sme"},
\r
699 {"Samoan", "smo"},
\r
701 {"Sindhi", "snd"},
\r
702 {"Somali", "som"},
\r
703 {"Sotho Southern", "sot"},
\r
704 {"Espanol", "spa"},
\r
705 {"Sardinian", "srd"},
\r
707 {"Sundanese", "sun"},
\r
708 {"Swahili", "swa"},
\r
709 {"Svenska", "swe"},
\r
710 {"Tahitian", "tah"},
\r
713 {"Telugu", "tel"},
\r
715 {"Tagalog", "tgl"},
\r
717 {"Tibetan", "bod"},
\r
718 {"Tigrinya", "tir"},
\r
720 {"Tswana", "tsn"},
\r
721 {"Tsonga", "tso"},
\r
722 {"Turkmen", "tuk"},
\r
723 {"Turkish", "tur"},
\r
725 {"Uighur", "uig"},
\r
726 {"Ukrainian", "ukr"},
\r
730 {"Vietnamese", "vie"},
\r
731 {"Volapük", "vol"},
\r
733 {"Walloon", "wln"},
\r
736 {"Yiddish", "yid"},
\r
737 {"Yoruba", "yor"},
\r
738 {"Zhuang", "zha"},
\r
741 return languageMap;
\r
745 /// Get a list of available DVD drives which are ready and contain DVD content.
\r
747 /// <returns>A List of Drives with their details</returns>
\r
748 public static List<DriveInformation> GetDrives()
\r
750 List<DriveInformation> drives = new List<DriveInformation>();
\r
751 DriveInfo[] theCollectionOfDrives = DriveInfo.GetDrives();
\r
753 foreach (DriveInfo curDrive in theCollectionOfDrives)
\r
755 if (curDrive.DriveType == DriveType.CDRom && curDrive.IsReady &&
\r
756 File.Exists(curDrive.RootDirectory + "VIDEO_TS\\VIDEO_TS.IFO"))
\r
758 drives.Add(new DriveInformation
\r
761 VolumeLabel = curDrive.VolumeLabel,
\r
762 RootDirectory = curDrive.RootDirectory + "VIDEO_TS"
\r
771 /// Change a string to Title Case/
\r
773 /// <param name="input">
\r
777 /// A string in title case.
\r
779 public static string TitleCase(string input)
\r
781 string[] tokens = input.Split(' ');
\r
782 StringBuilder sb = new StringBuilder(input.Length);
\r
783 foreach (string s in tokens)
\r
785 sb.Append(s[0].ToString().ToUpper());
\r
786 sb.Append(s.Substring(1).ToLower());
\r
790 return sb.ToString().Trim();
\r
794 /// Show the Exception Window
\r
796 /// <param name="shortError">
\r
797 /// The short error.
\r
799 /// <param name="longError">
\r
800 /// The long error.
\r
802 public static void ShowExceptiowWindow(string shortError, string longError)
\r
804 frmExceptionWindow exceptionWindow = new frmExceptionWindow();
\r
805 exceptionWindow.Setup(shortError, longError);
\r
806 exceptionWindow.Show();
\r
810 /// Get The Source from the CLI Query
\r
812 /// <param name="query">Full CLI Query</param>
\r
813 /// <returns>The Source Path</returns>
\r
814 public static string GetSourceFromQuery(string query)
\r
816 int startIndex = query.IndexOf("-i \"");
\r
817 if (startIndex != -1)
\r
819 string input = query.Substring(startIndex).Replace("-i \"", string.Empty).Trim();
\r
821 int closeIndex = input.IndexOf('"');
\r
823 return closeIndex == -1 ? "Unknown" : input.Substring(0, closeIndex);
\r
830 /// Get the Destination from the CLI Query
\r
832 /// <param name="query">Full CLI Query</param>
\r
833 /// <returns>The Destination path</returns>
\r
834 public static string GetDestinationFromQuery(string query)
\r
836 int startIndex = query.IndexOf("-o \"");
\r
837 if (startIndex != -1)
\r
839 string output = query.Substring(startIndex).Replace("-o \"", string.Empty).Trim();
\r
841 int closeIndex = output.IndexOf('"');
\r
843 return closeIndex == -1 ? "Unknown" : output.Substring(0, closeIndex);
\r