private static void Main() { // First of all, get the list of urls (as text or URL files) from the command line or Clipboard ReadOnlyCollection <NamedUrl> urls = UrlGetter.GetUrls(); if ((urls != null) && (urls.Count > 0)) { // Clean-up any files left over in the program's temporary directory, from previous runs // of the program. UrlConverter.CleanUpProgramTempDirectory(); try { UrlConverter.MakeLinkFiles(urls); SoundFeedback.PlaySuccess(); return; } catch (Exception) { SoundFeedback.PlayFailure(); ////System.Windows.Forms.MessageBox.Show(Ex.Message); } } SoundFeedback.PlayFailure(); }
/// <summary> /// Tries to extract the URL send to the program as text or URL file, through the command line or /// the Clipboard. /// </summary> /// <returns>The URL string, or an empty string if no valid URL in sent to the program.</returns> public static ReadOnlyCollection <NamedUrl> GetUrls() { List <NamedUrl> urls = new List <NamedUrl>(); // First try: if we have at least one command line argument, maybe they are URL or WEBSITE files. string[] commandLineArgs = Environment.GetCommandLineArgs(); if (commandLineArgs.Length >= 2) { for (int i = 1; i < commandLineArgs.Length; i++) { string argument = commandLineArgs[i]; if (!argument[0].Equals('/')) { NamedUrl url = UrlGetter.GetUrlFromUrlFile(argument); if (url != null) { urls.Add(url); } } } if (urls.Count > 0) { return(urls.AsReadOnly()); } } // Second try: determine whether the Clipboard contains one or more URL as text line(s). if (Clipboard.ContainsText()) { // Retrieve the text data from the Clipboard in Text or UnicodeText format. string clipText = Clipboard.GetText(); // Split in lines string[] potentialUrls = clipText.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (string potentialUrl in potentialUrls) { // Add the named url only if it is valid NamedUrl url = new NamedUrl(potentialUrl, string.Empty); if (!string.IsNullOrEmpty(url.Name)) { urls.Add(url); } } return(urls.AsReadOnly()); } // Third try: determine whether the Clipboard contains one or more URLs as a URL or WEBSITE files if (Clipboard.ContainsFileDropList()) { // Retrieve the file names from the Clipboard. StringCollection files = Clipboard.GetFileDropList(); if ((files != null) && (files.Count > 0)) { foreach (string file in files) { urls.Add(UrlGetter.GetUrlFromUrlFile(file)); } return(urls.AsReadOnly()); } } return(null); }