diff --git a/Update/Update/MainForm.cs b/Update/Update/MainForm.cs index ae754e5..d13581f 100644 --- a/Update/Update/MainForm.cs +++ b/Update/Update/MainForm.cs @@ -6,6 +6,8 @@ using System.Drawing; using System.IO; using System.IO.Compression; using System.Linq; +using System.Net; +using System.Reflection.Emit; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -69,22 +71,37 @@ namespace Update progressBar1.Visible = true; progressBar1.Maximum = 100;//fileNameArr.Count(); progressBar1.Value = 0; - new TaskFactory().StartNew(() => + Task.Run(async() => { string tempFile = upTempPath + "\\" + Program.updateUrl.Substring(Program.updateUrl.LastIndexOf("/") + 1); - bool result = Program.DownloadFile(Program.updateUrl, tempFile); + //bool result = Program.DownloadFile(Program.updateUrl, tempFile); - while (true) + //while (true) + //{ + // Invoke(new Action(() => + // { + // progressBar1.Value = Program.progress; + // })); + // if (Program.progress == 100) + // break; + //} + + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + using (var downloadClient = new WebClient()) { - Invoke(new Action(() => + downloadClient.Proxy = null; + + downloadClient.DownloadProgressChanged += (s, args) => { - progressBar1.Value = Program.progress; - })); - if (Program.progress == 100) - break; + Invoke(new Action(() => { progressBar1.Value = args.ProgressPercentage; })); + + }; + + await downloadClient.DownloadFileTaskAsync(new Uri(Program.updateUrl), tempFile); } - if (result) + if (1 == 1) + //if (result) { ZipFile.ExtractToDirectory(tempFile, upTempPath); File.Delete(tempFile);