Example #1
0
        public void BeginSilentDownload()
        {
            if (DownloadStatus == UpdateDownloadStatus.None || DownloadStatus == UpdateDownloadStatus.Failed)
            {
                DownloadStatus = UpdateDownloadStatus.InProgress;

                try{
                    Directory.CreateDirectory(installerFolder);
                }catch (Exception e) {
                    DownloadError  = e;
                    DownloadStatus = UpdateDownloadStatus.Failed;
                    return;
                }

                if (string.IsNullOrEmpty(downloadUrl))
                {
                    DownloadError  = new UriFormatException("Could not determine URL of the update installer");
                    DownloadStatus = UpdateDownloadStatus.Failed;
                    return;
                }

                currentDownload = BrowserUtils.DownloadFileAsync(downloadUrl, InstallerPath, () => {
                    DownloadStatus  = UpdateDownloadStatus.Done;
                    currentDownload = null;
                }, e => {
                    DownloadError   = e;
                    DownloadStatus  = UpdateDownloadStatus.Failed;
                    currentDownload = null;
                });
            }
        }
Example #2
0
        public virtual bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
        {
            switch ((int)commandId)
            {
            case MenuOpenLinkUrl:
                BrowserUtils.OpenExternalBrowser(parameters.LinkUrl);
                break;

            case MenuCopyLinkUrl:
                SetClipboardText(string.IsNullOrEmpty(TweetDeckBridge.LastRightClickedLink) ? parameters.UnfilteredLinkUrl : TweetDeckBridge.LastRightClickedLink);
                break;

            case MenuOpenImage:
                BrowserUtils.OpenExternalBrowser(parameters.SourceUrl);
                break;

            case MenuSaveImage:
                string fileName  = GetImageFileName(parameters.SourceUrl);
                string extension = Path.GetExtension(fileName);
                string saveTarget;

                using (SaveFileDialog dialog = new SaveFileDialog {
                    AutoUpgradeEnabled = true,
                    OverwritePrompt = true,
                    Title = "Save image",
                    FileName = fileName,
                    Filter = "Image (" + (string.IsNullOrEmpty(extension) ? "unknown" : extension) + ")|*.*"
                }){
                    saveTarget = dialog.ShowDialog() == DialogResult.OK ? dialog.FileName : null;
                }

                if (saveTarget != null)
                {
                    BrowserUtils.DownloadFileAsync(parameters.SourceUrl, saveTarget, null, ex => {
                        MessageBox.Show("An error occurred while downloading the image: " + ex.Message, Program.BrandName + " Has Failed :(", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    });
                }

                break;

            case MenuCopyImageUrl:
                SetClipboardText(parameters.SourceUrl);
                break;

            case MenuCopyUsername:
                Match match = RegexTwitterAccount.Match(parameters.UnfilteredLinkUrl);
                SetClipboardText(match.Success ? match.Groups[1].Value : parameters.UnfilteredLinkUrl);
                break;

                #if DEBUG
            case MenuOpenDevTools:
                browserControl.ShowDevTools();
                break;
                #endif
            }

            return(false);
        }
Example #3
0
        public void BeginSilentDownload()
        {
            if (WindowsUtils.FileExistsAndNotEmpty(InstallerPath))
            {
                DownloadStatus = UpdateDownloadStatus.Done;
                return;
            }

            if (DownloadStatus == UpdateDownloadStatus.None || DownloadStatus == UpdateDownloadStatus.Failed)
            {
                DownloadStatus = UpdateDownloadStatus.InProgress;

                if (string.IsNullOrEmpty(downloadUrl))
                {
                    DownloadError  = new InvalidDataException("Missing installer asset.");
                    DownloadStatus = UpdateDownloadStatus.AssetMissing;
                    return;
                }

                try{
                    Directory.CreateDirectory(installerFolder);
                }catch (Exception e) {
                    DownloadError  = e;
                    DownloadStatus = UpdateDownloadStatus.Failed;
                    return;
                }

                currentDownload = BrowserUtils.DownloadFileAsync(downloadUrl, InstallerPath, null, () => {
                    DownloadStatus  = UpdateDownloadStatus.Done;
                    currentDownload = null;
                }, e => {
                    DownloadError   = e;
                    DownloadStatus  = UpdateDownloadStatus.Failed;
                    currentDownload = null;
                });
            }
        }
Example #4
0
        public virtual bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
        {
            switch (commandId)
            {
            case MenuOpenLinkUrl:
                OpenBrowser(browserControl.AsControl(), IsLink ? ContextInfo.Value : parameters.LinkUrl);
                break;

            case MenuCopyLinkUrl:
                SetClipboardText(browserControl.AsControl(), IsLink ? ContextInfo.Value : parameters.UnfilteredLinkUrl);
                break;

            case MenuCopyUsername:
                Match match = TwitterUtils.RegexAccount.Match(parameters.UnfilteredLinkUrl);
                SetClipboardText(browserControl.AsControl(), match.Success ? match.Groups[1].Value : parameters.UnfilteredLinkUrl);
                break;

            case MenuOpenMediaUrl:
                OpenBrowser(browserControl.AsControl(), TwitterUtils.GetMediaLink(GetMediaLink(parameters), ImageQuality));
                break;

            case MenuCopyMediaUrl:
                SetClipboardText(browserControl.AsControl(), TwitterUtils.GetMediaLink(GetMediaLink(parameters), ImageQuality));
                break;

            case MenuViewImage:
                string url  = GetMediaLink(parameters);
                string file = Path.Combine(BrowserCache.CacheFolder, TwitterUtils.GetImageFileName(url));

                void ViewFile()
                {
                    string ext = Path.GetExtension(file);

                    if (TwitterUtils.ValidImageExtensions.Contains(ext))
                    {
                        WindowsUtils.OpenAssociatedProgram(file);
                    }
                    else
                    {
                        FormMessage.Error("Image Download", "Invalid file extension " + ext, FormMessage.OK);
                    }
                }

                if (File.Exists(file))
                {
                    ViewFile();
                }
                else
                {
                    BrowserUtils.DownloadFileAsync(TwitterUtils.GetMediaLink(url, ImageQuality), file, ViewFile, ex => {
                        FormMessage.Error("Image Download", "An error occurred while downloading the image: " + ex.Message, FormMessage.OK);
                    });
                }

                break;

            case MenuSaveMedia:
                if (IsVideo)
                {
                    TwitterUtils.DownloadVideo(GetMediaLink(parameters), lastHighlightedTweetAuthors.LastOrDefault());
                }
                else
                {
                    TwitterUtils.DownloadImage(GetMediaLink(parameters), lastHighlightedTweetAuthors.LastOrDefault(), ImageQuality);
                }

                break;

            case MenuSaveTweetImages:
                TwitterUtils.DownloadImages(lastHighlightedTweetImageList, lastHighlightedTweetAuthors.LastOrDefault(), ImageQuality);
                break;

            case MenuOpenDevTools:
                browserControl.ShowDevTools();
                break;
            }

            return(false);
        }