Beispiel #1
0
        private static Media?GetMedia(IContextMenuParams parameters, TweetDeckExtraContext extraContext, ImageQuality imageQuality)
        {
            var media = extraContext?.Media;

            if (media != null)
            {
                return(media);
            }

            if (parameters.TypeFlags.HasFlag(ContextMenuType.Media) && parameters.HasImageContents)
            {
                return(new Media(Media.Type.Image, TwitterUrls.GetMediaLink(parameters.SourceUrl, imageQuality)));
            }

            return(null);
        }
        private static void DownloadTempImage(string url, ImageQuality quality, Action <string> process)
        {
            string file = Path.Combine(BrowserCache.CacheFolder, TwitterUrls.GetImageFileName(url) ?? Path.GetRandomFileName());

            if (FileUtils.FileExistsAndNotEmpty(file))
            {
                process(file);
            }
            else
            {
                DownloadFileAuth(TwitterUrls.GetMediaLink(url, quality), file, () => {
                    process(file);
                }, ex => {
                    FormMessage.Error("Image Download", "An error occurred while downloading the image: " + ex.Message, FormMessage.OK);
                });
            }
        }
        public static void DownloadImages(string[] urls, string username, ImageQuality quality)
        {
            if (urls.Length == 0)
            {
                return;
            }

            string firstImageLink = TwitterUrls.GetMediaLink(urls[0], quality);
            int    qualityIndex   = firstImageLink.IndexOf(':', firstImageLink.LastIndexOf('/'));

            string filename = TwitterUrls.GetImageFileName(firstImageLink);
            string ext      = Path.GetExtension(filename); // includes dot

            using SaveFileDialog dialog = new SaveFileDialog {
                      AutoUpgradeEnabled = true,
                      OverwritePrompt    = urls.Length == 1,
                      Title    = "Save Image",
                      FileName = qualityIndex == -1 ? filename : $"{username} {Path.ChangeExtension(filename, null)} {firstImageLink.Substring(qualityIndex + 1)}".Trim() + ext,
                      Filter   = (urls.Length == 1 ? "Image" : "Images") + (string.IsNullOrEmpty(ext) ? " (unknown)|*.*" : $" (*{ext})|*{ext}")
                  };

            if (dialog.ShowDialog() == DialogResult.OK)
            {