From 96d04974daa559931ad15f3d7a237252a16cfcf1 Mon Sep 17 00:00:00 2001 From: ramseyjacob Date: Mon, 13 Mar 2017 23:29:02 -0400 Subject: [PATCH] Return false when the user cancels out or download fails. Capture HTTP 401 response during file download and print a helpful message to configure proxy. --- .../Properties/Resources.Designer.cs | 27 ++++++++++++ ShareX.HelpersLib/Properties/Resources.resx | 9 ++++ .../UpdateChecker/DownloaderForm.cs | 43 ++++++++++++++++++- ShareX/TaskHelpers.cs | 9 +++- 4 files changed, 86 insertions(+), 2 deletions(-) diff --git a/ShareX.HelpersLib/Properties/Resources.Designer.cs b/ShareX.HelpersLib/Properties/Resources.Designer.cs index 75f90b3b6..09f8dadd5 100644 --- a/ShareX.HelpersLib/Properties/Resources.Designer.cs +++ b/ShareX.HelpersLib/Properties/Resources.Designer.cs @@ -438,6 +438,15 @@ internal static string DownloaderForm_ChangeProgress_Progress { } } + /// + /// Looks up a localized string similar to Progress: {0}. + /// + internal static string DownloaderForm_ChangeProgress_Progress___0_ { + get { + return ResourceManager.GetString("DownloaderForm_ChangeProgress_Progress___0_", resourceCulture); + } + } + /// /// Looks up a localized string similar to Status: {0}. /// @@ -447,6 +456,15 @@ internal static string DownloaderForm_ChangeStatus_Status___0_ { } } + /// + /// Looks up a localized string similar to Download canceled.. + /// + internal static string DownloaderForm_Download_Canceled { + get { + return ResourceManager.GetString("DownloaderForm_Download_Canceled", resourceCulture); + } + } + /// /// Looks up a localized string similar to Filename: {0}. /// @@ -483,6 +501,15 @@ internal static string DownloaderForm_fileDownloader_DownloadCompleted_Install { } } + /// + /// Looks up a localized string similar to Possible proxy detected. Please open the Application Settings from the main menu and choose Proxy to enter your proxy server settings.. + /// + internal static string DownloaderForm_ProxyDetected { + get { + return ResourceManager.GetString("DownloaderForm_ProxyDetected", resourceCulture); + } + } + /// /// Looks up a localized string similar to Cancel. /// diff --git a/ShareX.HelpersLib/Properties/Resources.resx b/ShareX.HelpersLib/Properties/Resources.resx index 7aba3e883..5ecf1e061 100644 --- a/ShareX.HelpersLib/Properties/Resources.resx +++ b/ShareX.HelpersLib/Properties/Resources.resx @@ -986,4 +986,13 @@ Would you like to download it? Drawing: Text (Background) + + Possible proxy detected. Please open the Application Settings from the main menu and choose Proxy to enter your proxy server settings. + + + Download canceled. + + + Progress: {0} + \ No newline at end of file diff --git a/ShareX.HelpersLib/UpdateChecker/DownloaderForm.cs b/ShareX.HelpersLib/UpdateChecker/DownloaderForm.cs index a3f29e43f..0b9676cfd 100644 --- a/ShareX.HelpersLib/UpdateChecker/DownloaderForm.cs +++ b/ShareX.HelpersLib/UpdateChecker/DownloaderForm.cs @@ -196,6 +196,41 @@ private void ChangeStatus(string status) lblStatus.Text = string.Format(Resources.DownloaderForm_ChangeStatus_Status___0_, status); } + private void HandleDownloadException(Exception ex) + { + if(ex is WebException) + { + var webEx = (WebException)ex; + + if (webEx.Status == WebExceptionStatus.ProtocolError) + { + var response = webEx.Response as HttpWebResponse; + if (response != null) + { + var responseCode = (int)response.StatusCode; + + if (responseCode == 401) + { + ChangeFormForPossibleProxyDetected(); + return; + } + } + } + } + + ChangeStatus(ex.Message); + } + + private void ChangeFormForPossibleProxyDetected() + { + txtChangelog.WordWrap = true; + txtChangelog.Text = Resources.DownloaderForm_ProxyDetected; + cbShowChangelog.Checked = true; + ChangeStatus(Resources.Error); + ChangeProgressForCanceledDownload(); + UpdateFormSize(); + } + private void ChangeProgress() { if (fileDownloader != null) @@ -206,6 +241,12 @@ private void ChangeProgress() } } + private void ChangeProgressForCanceledDownload() + { + lblProgress.Text = string.Format(CultureInfo.CurrentCulture, Resources.DownloaderForm_ChangeProgress_Progress___0_, + Resources.DownloaderForm_Download_Canceled); + } + private void StartDownload() { if (!string.IsNullOrEmpty(URL) && Status == DownloaderFormStatus.Waiting) @@ -223,7 +264,7 @@ private void StartDownload() fileDownloader.DownloadStarted += (v1, v2) => ChangeStatus(Resources.DownloaderForm_StartDownload_Downloading_); fileDownloader.ProgressChanged += (v1, v2) => ChangeProgress(); fileDownloader.DownloadCompleted += fileDownloader_DownloadCompleted; - fileDownloader.ExceptionThrowed += (v1, v2) => ChangeStatus(fileDownloader.LastException.Message); + fileDownloader.ExceptionThrowed += (v1, v2) => HandleDownloadException(fileDownloader.LastException); fileDownloader.StartDownload(); ChangeStatus(Resources.DownloaderForm_StartDownload_Getting_file_size_); diff --git a/ShareX/TaskHelpers.cs b/ShareX/TaskHelpers.cs index 58da2d346..0877f9f90 100644 --- a/ShareX/TaskHelpers.cs +++ b/ShareX/TaskHelpers.cs @@ -1102,7 +1102,10 @@ public static bool CheckFFmpeg(TaskSettings taskSettings) if (MessageBox.Show(string.Format(Resources.ScreenRecordForm_StartRecording_does_not_exist, ffmpegPath), "ShareX - " + Resources.ScreenRecordForm_StartRecording_Missing + " ffmpeg.exe", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { - if (FFmpegDownloader.DownloadFFmpeg(false, DownloaderForm_InstallRequested) == DialogResult.OK) + + var downloadDialogResult = FFmpegDownloader.DownloadFFmpeg(false, DownloaderForm_InstallRequested); + + if (downloadDialogResult == DialogResult.OK) { Program.DefaultTaskSettings.CaptureSettings.FFmpegOptions.CLIPath = taskSettings.TaskSettingsReference.CaptureSettings.FFmpegOptions.CLIPath = taskSettings.CaptureSettings.FFmpegOptions.CLIPath = Program.DefaultFFmpegFilePath; @@ -1112,6 +1115,10 @@ public static bool CheckFFmpeg(TaskSettings taskSettings) taskSettings.CaptureSettings.FFmpegOptions.OverrideCLIPath = true; #endif } + else if(downloadDialogResult == DialogResult.Cancel) + { + return false; + } } else {