private void setupProgressChanged(object sender, DownloadProgressChangeEventArgs e) { Game game = games[index]; game.lblStatus.Text = "Progress: " + e.ConvertDownloadedBytesToString() + "/" + e.ConvertTotalBytesToString() + " (" + e.ProgressPercentage.ToString() + "%) " + e.ConvertBytesToString(e.DownloadSpeedBytes) + "/s " + e.getTimeRemaining(); game.pbProgress.Value = (int)e.ProgressPercentage; }
private void downloadProgressChanged(object sender, DownloadProgressChangeEventArgs e) { if (JeremieLauncher.instance.index == index) { Version tempVer = new Version(NewVersion.VersionMajor, NewVersion.VersionMinor, NewVersion.VersionPatch, NewVersion.VersionBuild, true); JeremieLauncher.instance.RichPresence.State = $"Downloading {GameName} {tempVer}"; //DateTimeOffset dto = new DateTimeOffset(DateTime.UtcNow); //dto.AddSeconds(e.getTimeRemainingLong()); //JeremieLauncher.instance.RichPresence.Timestamps.EndUnixMilliseconds = (ulong) startdownloadtime + (ulong)(dto.ToUnixTimeMilliseconds()-startdownloadtime); //JeremieLauncher.instance.client.SetPresence(JeremieLauncher.instance.RichPresence); } lblStatus.Text = "Progress: " + e.ConvertDownloadedBytesToString() + "/" + e.ConvertTotalBytesToString() + " (" + e.ProgressPercentage.ToString() + "%) " + e.ConvertBytesToString(e.DownloadSpeedBytes) + "/s " + e.getTimeRemaining(); pbProgress.Value = e.ProgressPercentage; }
private async Task Start(int range) { if (!AllowedToRun) { throw new InvalidOperationException(); } /*if (!Utils.hasWriteAccessToFolder(Path.GetDirectoryName(Path.GetFullPath(Destination)))) * { * Utils.StartApplicationInAdminMode(); * return; * }*/ var request = (HttpWebRequest)WebRequest.Create(Source); request.Method = "GET"; request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"; request.AddRange(range); DownloadProgressChangeEventHandler DPGhandler = ProgressChanged; timer.Start(); string path = Path.GetDirectoryName(Destination); if (!string.IsNullOrEmpty(path)) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } } using (var response = await request.GetResponseAsync()) { using (var responseStream = response.GetResponseStream()) { using (var fs = new FileStream(Destination, (Overwrite && !Paused) ? FileMode.Create : FileMode.Append, FileAccess.Write, FileShare.ReadWrite)) { Paused = false; finished = false; if (fs.Length != ContentLength.Value || Overwrite) { while (AllowedToRun) { var buffer = new byte[ChunkSize]; var bytesRead = await responseStream.ReadAsync(buffer, 0, buffer.Length); DownloadProgressChangeEventArgs DPGea = new DownloadProgressChangeEventArgs(fs.Length + bytesRead, ContentLength.Value, DownloadSpeedBytes); if (DPGhandler != null) { DPGhandler?.Invoke(this, DPGea); } if (bytesRead == 0) { finished = true; break; } await fs.WriteAsync(buffer, 0, bytesRead); BytesWritten += bytesRead; nowBytes = fs.Length; } } await fs.FlushAsync(); } } } if (finished) { EventHandler handler = DownloadCompleted; if (handler != null) { handler?.Invoke(this, new EventArgs()); } } }