DownloadAndUploadFile error handling

This commit is contained in:
Jaex 2014-05-19 18:14:36 +03:00
parent 5667ffcb76
commit 442d91f6df
2 changed files with 19 additions and 6 deletions

View file

@ -121,6 +121,7 @@ private void InitializeComponent()
this.Name = "FileExistForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "ShareX - How to save?";
this.TopMost = true;
this.ResumeLayout(false);
this.PerformLayout();

View file

@ -334,25 +334,37 @@ public static void DownloadAndUploadFile(string url, string filename, TaskSettin
{
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
string downloadPath, uploadPath = null;
string downloadPath = null;
bool isDownloaded = false;
Helpers.AsyncJob(() =>
{
downloadPath = TaskHelpers.CheckFilePath(taskSettings.CaptureFolder, filename, taskSettings);
uploadPath = string.IsNullOrEmpty(downloadPath) ? Path.Combine(taskSettings.CaptureFolder, filename) : downloadPath;
if (!string.IsNullOrEmpty(downloadPath))
{
using (WebClient wc = new WebClient())
try
{
wc.Proxy = ProxyInfo.Current.GetWebProxy();
wc.DownloadFile(url, downloadPath);
using (WebClient wc = new WebClient())
{
wc.Proxy = ProxyInfo.Current.GetWebProxy();
wc.DownloadFile(url, downloadPath);
}
isDownloaded = true;
}
catch (Exception e)
{
MessageBox.Show("Download failed: " + e.ToString(), "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
},
() =>
{
UploadFile(uploadPath, taskSettings);
if (isDownloaded)
{
UploadFile(downloadPath, taskSettings);
}
});
}
}