private void Web_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { if (Current_Process.InvokeRequired) { Current_Process.Invoke(new Action(() => { Current_Process.Value = int.Parse(e.BytesReceived.ToString()); })); Total_Progress.Invoke(new Action(() => { Total_Progress.Value = before + int.Parse(e.BytesReceived.ToString()); })); Total_Downloaded.Invoke(new Action(() => { Total_Downloaded.Text = Downloaded_Amount_Neat(Total_Progress.Value, Total_Downloaded.Text); })); } else { Current_Process.Value = int.Parse(e.BytesReceived.ToString()); Total_Progress.Value = before + int.Parse(e.BytesReceived.ToString()); Total_Downloaded.Text = Downloaded_Amount_Neat(Total_Progress.Value, Total_Downloaded.Text); } taskbar.SetProgressValue(Total_Progress.Value, Total_Progress.Maximum); }
private void Download_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { using (WebClient web = new WebClient()) { string type = "https"; string rem = ""; int max; ChangeProcessText("Getting update info"); try { rem = web.DownloadString($"{type}://jacobtech.org/Programs/Files/{RemoteDir}"); } catch (Exception ex) { if (ex.Message == "Unable to connect to the remote server") { try { type = "http"; rem = web.DownloadString($"{type}://jacobtech.org/Programs/Files/{RemoteDir}"); } catch (Exception ex2) { MessageBox.Show(ex2.Message); } } else { MessageBox.Show(ex.Message); } } try { max = int.Parse(web.DownloadString($"{type}://jacobtech.org/Programs/GetSize/{RemoteDir}")); web.DownloadProgressChanged += Web_DownloadProgressChanged; web.DownloadFileCompleted += Web_DownloadFileCompleted; Total_Downloaded.Invoke(new Action(() => { Total_Downloaded.Text = TotalDownloadAmmountNeat(max); })); foreach (string file in rem.Split('|')) { bool good = true; while (good) { while (!web.IsBusy) { string[] split = file.Split('.'); string fill = ""; foreach (string fillll in split) { fill = fill + fillll + Uri.EscapeDataString("|"); } fill = fill.Remove(fill.Length - Uri.EscapeDataString("|").Length, Uri.EscapeDataString("|").Length); string uri = $"{type}://jacobtech.org/Programs/GetFileSize/{RemoteDir}{Uri.EscapeDataString("|")}{fill}"; fil = int.Parse(web.DownloadString(uri)); if (Current_Process.InvokeRequired) { Total_Progress.Invoke(new Action(() => { Total_Progress.Maximum = max; })); string file2 = Uri.UnescapeDataString(file); Current_Process.Invoke(new Action(() => { Current_Process.Maximum = int.Parse(web.DownloadString(uri)); })); } else { Total_Progress.Maximum = max; Current_Process.Maximum = int.Parse(web.DownloadString(uri)); } string name = file.Replace("%20", " ").Replace("%28", "(").Replace("%29", ")"); Uri u = new Uri($"{type}://jacobtech.org/Programs/{RemoteDir}/Files/{file}"); ChangeProcessText($"Downloading {name}"); web.DownloadFileAsync(u, name); good = false; break; } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }