From 58586278d264330bd941339699d696f9aaf2cce1 Mon Sep 17 00:00:00 2001 From: JacobTech Date: Fri, 15 Nov 2024 00:44:25 -0500 Subject: [PATCH] Added Download Ammount --- Updater/NewUpdater.cs | 51 +++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/Updater/NewUpdater.cs b/Updater/NewUpdater.cs index 3b53862..b679cac 100644 --- a/Updater/NewUpdater.cs +++ b/Updater/NewUpdater.cs @@ -63,15 +63,16 @@ public class NewUpdater : FPSWindow }); fi.PixelHeight = (uint)WallDistance; - Controls.Add(Total_Downloaded = new(fi) + TotalProgress.Controls.Add(Total_Downloaded = new(fi) { - Text = "D", - Location = new((int)FloatToInt(-0.9381188f), (int)FloatToInt(0.149797574f + 0.14f, true)) + Color = Color4.Black, + Text = "Downloading ...." }); + Total_Downloaded.Location = new(cf.Scale(5), (TotalProgress.Size.Y - Total_Downloaded.Size.Y) / 2); Controls.Add(Transfer_Speed = new(fi) { Text = "abcdefghijklmnopqrstuvwxyz", - Location = new(Total_Downloaded.Location.X, (int)FloatToInt(-0.05263158f + 0.09f, true)) + Location = new(WallDistance + Total_Downloaded.Location.X, cf.Scale(5)) }); int gap = cf.Scale(10); @@ -84,7 +85,7 @@ public class NewUpdater : FPSWindow Color = Color4.Black, Text = "Downloading ...." }; - l.Location = new(cf.Scale(5), (TotalProgress.Size.Y - l.Size.Y) / 2); + l.Location = new(Total_Downloaded.Location.X, (TotalProgress.Size.Y - l.Size.Y) / 2); Controls.Add(temp = new(ProgressbarTexture) { Location = new(WallDistance, cf.Scale(70) + (TotalProgress.Size.Y * (i + 1)) + (gap * (i + 1))), @@ -110,6 +111,7 @@ public class NewUpdater : FPSWindow } private ulong last; + private string end = ""; private void Speed_Elapsed(object? sender, System.Timers.ElapsedEventArgs e) { @@ -119,9 +121,12 @@ public class NewUpdater : FPSWindow last = TotalProgress.ProgressValue; speeds.Add(BytesPertenthSec * 2); if (speeds.Count > 25) speeds.RemoveAt(0); - if (Transfer_Speed is not null && speeds.Average() != 0) Transfer_Speed.Text = Download_Speed_Neat(speeds.Average()); + if (Transfer_Speed is not null && speeds.Average() != 0) + { + Transfer_Speed.Text = Download_Speed_Neat(speeds.Average()); + Set_Downloaded_Amount_Neat(); + } } - private void Download_DoWork(object? sender, DoWorkEventArgs e) { @@ -166,6 +171,7 @@ public class NewUpdater : FPSWindow $"https://{Handler.Domain}/Updater/GetSize?directory={Argumets.RemoteDirectory}{Argumets.UriBranch}{Argumets.UriSeflContaind}{Argumets.UriPlatform}{Argumets.UriVersion}"); max_pre.Wait(); TotalProgress.MaxProgressValue = ulong.Parse(max_pre.Result); + end = Downloaded_Amount_Neat(TotalProgress.MaxProgressValue); files_pre.Wait(); string[] files = files_pre.Result.Split('\n'); Queue IndexesWaiting = new(); @@ -288,7 +294,6 @@ public class NewUpdater : FPSWindow #region Neat private string Download_Speed_Neat(double Number) { - Debug.WriteLine($"a: {Number}"); ConfigFileSize cfs = cf.Format.DownloadSpeed; string Size = SizeName(Number, cfs); int bytes = 1024; @@ -319,7 +324,12 @@ public class NewUpdater : FPSWindow } } - private string Downloaded_Amount_Neat(double Number, string Old_Text) + private void Set_Downloaded_Amount_Neat() + { + Total_Downloaded!.Text = $"Downloaded {Downloaded_Amount_Neat(TotalProgress.ProgressValue)} of {end}"; + } + + private string Downloaded_Amount_Neat(double Number) { int Exponet = 0; ConfigFileSize cfs = cf.Format.DownloadAmount; @@ -331,7 +341,7 @@ public class NewUpdater : FPSWindow else if (Size.ToLower().StartsWith('k')) Exponet = 1; Number = Math.Round(Number / Math.Pow(bytes, Exponet), 2, MidpointRounding.ToEven); if (cfs == ConfigFileSize.MebiBit || cfs == ConfigFileSize.MegaBit) Number *= 8; - string text = Old_Text.Remove(0, Old_Text.IndexOf(' ')); + string text = ""; if (!Number.ToString().Contains('.')) { text = $"{Number}.00{Size}{text}"; @@ -340,27 +350,10 @@ public class NewUpdater : FPSWindow { text = Number.ToString().Remove(0, Number.ToString().IndexOf('.')).Length != 1 ? $"{Number}{Size}{text}" : $"{Number}0{Size}{text}"; } + return text; } - - private string TotalDownloadAmountNeat(double Number) - { - string Output; - int Exponet; - ConfigFileSize cfs = cf.Format.DownloadAmount; - int bytes = 1024; - if (cfs == ConfigFileSize.MebiBit || cfs == ConfigFileSize.MebiByte) bytes = 1000; - if (Number / bytes >= 1) - if (Number / Math.Pow(bytes, 2) >= 1) - if (Number / Math.Pow(bytes, 3) >= 1) Exponet = 3; - else Exponet = 2; - else Exponet = 1; - else Exponet = 0; - if (cfs == ConfigFileSize.MebiBit || cfs == ConfigFileSize.MegaBit) Number *= 8; - Output = $"{Math.Round(Number / Math.Pow(bytes, Exponet), 2, MidpointRounding.ToEven)}{SizeName(Number, cfs)}"; - return Output; - } - + private static string SizeName(double Number, ConfigFileSize format) { string Size;