Exemplo n.º 1
0
        private void DownloadTempImage(string url, Action <string> process)
        {
            string?staticFileName = TwitterUrls.GetImageFileName(url);
            string file           = Path.Combine(browserComponent.CacheFolder, staticFileName ?? Path.GetRandomFileName());

            if (staticFileName != null && FileUtils.FileExistsAndNotEmpty(file))
            {
                process(file);
            }
            else
            {
                void OnSuccess()
                {
                    process(file);
                }
Exemplo n.º 2
0
        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);
                });
            }
        }
Exemplo n.º 3
0
        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)
            {