mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-02 18:26:27 +13:00
DownloadAndUploadFile error handling
This commit is contained in:
parent
5667ffcb76
commit
442d91f6df
2 changed files with 19 additions and 6 deletions
1
ShareX/Forms/FileExistForm.Designer.cs
generated
1
ShareX/Forms/FileExistForm.Designer.cs
generated
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue