Merge pull request #2367 from ramseyjacob/transparent-proxy-file-download

Return false when the user cancels out or download fails.  Capture HT…
This commit is contained in:
Jaex 2017-03-14 20:46:40 +02:00 committed by GitHub
commit 7b0d208ef8
4 changed files with 86 additions and 2 deletions

View file

@ -438,6 +438,15 @@ internal static string DownloaderForm_ChangeProgress_Progress {
}
}
/// <summary>
/// Looks up a localized string similar to Progress: {0}.
/// </summary>
internal static string DownloaderForm_ChangeProgress_Progress___0_ {
get {
return ResourceManager.GetString("DownloaderForm_ChangeProgress_Progress___0_", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Status: {0}.
/// </summary>
@ -447,6 +456,15 @@ internal static string DownloaderForm_ChangeStatus_Status___0_ {
}
}
/// <summary>
/// Looks up a localized string similar to Download canceled..
/// </summary>
internal static string DownloaderForm_Download_Canceled {
get {
return ResourceManager.GetString("DownloaderForm_Download_Canceled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Filename: {0}.
/// </summary>
@ -483,6 +501,15 @@ internal static string DownloaderForm_fileDownloader_DownloadCompleted_Install {
}
}
/// <summary>
/// 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..
/// </summary>
internal static string DownloaderForm_ProxyDetected {
get {
return ResourceManager.GetString("DownloaderForm_ProxyDetected", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Cancel.
/// </summary>

View file

@ -986,4 +986,13 @@ Would you like to download it?</value>
<data name="ShapeType_DrawingTextBackground" xml:space="preserve">
<value>Drawing: Text (Background)</value>
</data>
<data name="DownloaderForm_ProxyDetected" xml:space="preserve">
<value>Possible proxy detected. Please open the Application Settings from the main menu and choose Proxy to enter your proxy server settings.</value>
</data>
<data name="DownloaderForm_Download_Canceled" xml:space="preserve">
<value>Download canceled.</value>
</data>
<data name="DownloaderForm_ChangeProgress_Progress___0_" xml:space="preserve">
<value>Progress: {0}</value>
</data>
</root>

View file

@ -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_);

View file

@ -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
{