Added Download Ammount

This commit is contained in:
JacobTech 2024-11-15 00:44:25 -05:00
parent 35dc3f9aa3
commit 58586278d2

View File

@ -63,15 +63,16 @@ public class NewUpdater : FPSWindow
}); });
fi.PixelHeight = (uint)WallDistance; fi.PixelHeight = (uint)WallDistance;
Controls.Add(Total_Downloaded = new(fi) TotalProgress.Controls.Add(Total_Downloaded = new(fi)
{ {
Text = "D", Color = Color4.Black,
Location = new((int)FloatToInt(-0.9381188f), (int)FloatToInt(0.149797574f + 0.14f, true)) Text = "Downloading ...."
}); });
Total_Downloaded.Location = new(cf.Scale(5), (TotalProgress.Size.Y - Total_Downloaded.Size.Y) / 2);
Controls.Add(Transfer_Speed = new(fi) Controls.Add(Transfer_Speed = new(fi)
{ {
Text = "abcdefghijklmnopqrstuvwxyz", 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); int gap = cf.Scale(10);
@ -84,7 +85,7 @@ public class NewUpdater : FPSWindow
Color = Color4.Black, Color = Color4.Black,
Text = "Downloading ...." 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) Controls.Add(temp = new(ProgressbarTexture)
{ {
Location = new(WallDistance, cf.Scale(70) + (TotalProgress.Size.Y * (i + 1)) + (gap * (i + 1))), 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 ulong last;
private string end = "";
private void Speed_Elapsed(object? sender, System.Timers.ElapsedEventArgs e) private void Speed_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
{ {
@ -119,9 +121,12 @@ public class NewUpdater : FPSWindow
last = TotalProgress.ProgressValue; last = TotalProgress.ProgressValue;
speeds.Add(BytesPertenthSec * 2); speeds.Add(BytesPertenthSec * 2);
if (speeds.Count > 25) speeds.RemoveAt(0); 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) 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}"); $"https://{Handler.Domain}/Updater/GetSize?directory={Argumets.RemoteDirectory}{Argumets.UriBranch}{Argumets.UriSeflContaind}{Argumets.UriPlatform}{Argumets.UriVersion}");
max_pre.Wait(); max_pre.Wait();
TotalProgress.MaxProgressValue = ulong.Parse(max_pre.Result); TotalProgress.MaxProgressValue = ulong.Parse(max_pre.Result);
end = Downloaded_Amount_Neat(TotalProgress.MaxProgressValue);
files_pre.Wait(); files_pre.Wait();
string[] files = files_pre.Result.Split('\n'); string[] files = files_pre.Result.Split('\n');
Queue<int> IndexesWaiting = new(); Queue<int> IndexesWaiting = new();
@ -288,7 +294,6 @@ public class NewUpdater : FPSWindow
#region Neat #region Neat
private string Download_Speed_Neat(double Number) private string Download_Speed_Neat(double Number)
{ {
Debug.WriteLine($"a: {Number}");
ConfigFileSize cfs = cf.Format.DownloadSpeed; ConfigFileSize cfs = cf.Format.DownloadSpeed;
string Size = SizeName(Number, cfs); string Size = SizeName(Number, cfs);
int bytes = 1024; 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; int Exponet = 0;
ConfigFileSize cfs = cf.Format.DownloadAmount; ConfigFileSize cfs = cf.Format.DownloadAmount;
@ -331,7 +341,7 @@ public class NewUpdater : FPSWindow
else if (Size.ToLower().StartsWith('k')) Exponet = 1; else if (Size.ToLower().StartsWith('k')) Exponet = 1;
Number = Math.Round(Number / Math.Pow(bytes, Exponet), 2, MidpointRounding.ToEven); Number = Math.Round(Number / Math.Pow(bytes, Exponet), 2, MidpointRounding.ToEven);
if (cfs == ConfigFileSize.MebiBit || cfs == ConfigFileSize.MegaBit) Number *= 8; if (cfs == ConfigFileSize.MebiBit || cfs == ConfigFileSize.MegaBit) Number *= 8;
string text = Old_Text.Remove(0, Old_Text.IndexOf(' ')); string text = "";
if (!Number.ToString().Contains('.')) if (!Number.ToString().Contains('.'))
{ {
text = $"{Number}.00{Size}{text}"; 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}"; text = Number.ToString().Remove(0, Number.ToString().IndexOf('.')).Length != 1 ? $"{Number}{Size}{text}" : $"{Number}0{Size}{text}";
} }
return 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) private static string SizeName(double Number, ConfigFileSize format)
{ {
string Size; string Size;