Progress Tracking

This commit is contained in:
JacobTech 2023-10-17 16:29:33 -04:00
parent 008ea2ee02
commit b9754bc79b
4 changed files with 47 additions and 33 deletions

View File

@ -51,6 +51,9 @@ public class Config
A = 1f
}
};
if (!Directory.Exists(Program.JT)) Directory.CreateDirectory(Program.JT);
if (!Directory.Exists(Program.JT + "/Updater")) Directory.CreateDirectory(Program.JT + "/Updater" );
if (!Directory.Exists(Program.JT + "/Updater/Config")) Directory.CreateDirectory(Program.JT + "/Updater/Config");
FileStream ms = new(Program.JT + "/Updater/Config/Settings.json", FileMode.Create);
JsonSerializer.Serialize(new Utf8JsonWriter(ms),
file,

View File

@ -3,9 +3,9 @@ using System.Diagnostics;
using System.Net;
using System.Text.Json;
using GraphicsManager;
using GraphicsManager.Enums;
using GraphicsManager.Objects;
using GraphicsManager.Objects.Core;
using OpenTK.Mathematics;
using OpenTK.Windowing.Desktop;
namespace Updater;
@ -13,43 +13,48 @@ namespace Updater;
public class NewUpdater : FPSWindow
{
private readonly ConfigFile cf;
private Texture ProgressbarTexture;
private ProgressBar TotalProgress;
private Argumets Argumets;
private List<ProgressBar> ProgressThreads = new();
public FontInteraction fi;
private int WallDistance;
private readonly BackgroundWorker Download = new();
public NewUpdater(NativeWindowSettings nws, GameWindowSettings gws, Argumets args)
:base(nws, gws)
{
cf = Config.GetConfig();
Size = new(cf.Scale(Size.X), cf.Scale(Size.Y));
Argumets = args;
fi = FontInteraction.Load(FontFamily.LoadFontFamily("Noto Sans").Result);
var r = FontFamily.LoadFontFamily().Result;
FontInteraction fi = FontInteraction.Load(r);
BackgroundColor = cf.Colors.Background.ToColor4();
WallDistance = cf.Scale(16);
ProgressbarTexture = TextureManager.AddTexture(File.OpenRead("/home/jacob/Pictures/Progress.png"));
Controls.Add(TotalProgress = new ProgressBar(ProgressbarTexture)
int WallDistance = cf.Scale(15);
//Texture ProgressbarTexture = TextureManager.AddTexture(File.OpenRead("/home/jacob/Pictures/Progress.png"));
Controls.Add(TotalProgress = new ProgressBar()
{
Location = new(WallDistance, cf.Scale(70), 0),
Size = new(Size.X - WallDistance - WallDistance, cf.Scale(20)),
BackgroundColor = cf.Colors.Progress_bars.Backcolor.ToColor4(),
ProgressColor = cf.Colors.Progress_bars.Fillcolor.ToColor4(),
ProgressValue = 25,
ProgressGap = 4,
Shader = Rectangle.DefaultAlphaShader[Context],
TextureDisplay = TextureDisplay.ProgressHorizontalCenter,
ProgressGap = (uint)cf.Scale(3),
//Shader = Rectangle.DefaultAlphaShader[Context],
//TextureDisplay = TextureDisplay.ProgressHorizontalCenter,
UpdateOnDraw = true
});
TotalProgress.InnerShader = TotalProgress.Shader;
int gap = cf.Scale(15);
//TotalProgress.InnerShader = TotalProgress.Shader;
int gap = cf.Scale(10);
for (int i = 0; i < cf.Format.DownloadThreads; i++)
{
ProgressBar temp;
Size = new(Size.X, Size.Y + gap + TotalProgress.Size.Y);
Controls.Add(temp = new ProgressBar(ProgressbarTexture)
Label l = new(fi)
{
Location = new(WallDistance, cf.Scale(70) + (TotalProgress.Size.Y * (i + 1)) + (cf.Scale(15) * (i + 1)), 0),
Color = Color4.Black,
Text = "Downloading bob"
};
l.Location = new(cf.Scale(5), (int)(((TotalProgress.Size.Y - l.TrueHeight) / 2) - fi.PixelHeight + l.PostiveTrueHeight), 0);
Controls.Add(temp = new ProgressBar()
{
Location = new(WallDistance, cf.Scale(70) + (TotalProgress.Size.Y * (i + 1)) + (gap * (i + 1)), 0),
Size = TotalProgress.Size,
BackgroundColor = TotalProgress.BackgroundColor,
ProgressColor = TotalProgress.ProgressColor,
@ -57,13 +62,15 @@ public class NewUpdater : FPSWindow
ProgressGap = TotalProgress.ProgressGap,
Shader = TotalProgress.Shader,
TextureDisplay = TotalProgress.TextureDisplay,
UpdateOnDraw = true
UpdateOnDraw = true,
InnerShader = TotalProgress.InnerShader,
Tag = l
});
temp.InnerShader = TotalProgress.Shader;
temp.Controls.Add(l);
ProgressThreads.Add(temp);
}
fi.PixelHeight = (uint)cf.Scale(15);
Download.DoWork += new DoWorkEventHandler(Download_DoWork);
Download.DoWork += Download_DoWork;
Download.RunWorkerCompleted += Download_RunWorkerCompleted;
Download.WorkerReportsProgress = true;
Invoke(new Action(() => { Download.RunWorkerAsync(); }));
@ -130,11 +137,10 @@ public class NewUpdater : FPSWindow
#pragma warning restore SYSLIB0014 // Type or member is obsolete
ChangeProcessText("Getting update info");
string rem = webPre.DownloadString($"https://{Program.Domain}/Updater/Files?directory={Argumets.RemoteDirectory}{Argumets.UriBranch}{Argumets.UriSeflContaind}{Argumets.UriPlatform}{Argumets.UriVersion}");
ulong realmax;
string uri;
//string uri;
try
{
realmax = ulong.Parse(webPre.DownloadString($"https://{Program.Domain}/Updater/GetSize?directory={Argumets.RemoteDirectory}{Argumets.UriBranch}{Argumets.UriSeflContaind}{Argumets.UriPlatform}{Argumets.UriVersion}"));
ulong realmax = ulong.Parse(webPre.DownloadString($"https://{Program.Domain}/Updater/GetSize?directory={Argumets.RemoteDirectory}{Argumets.UriBranch}{Argumets.UriSeflContaind}{Argumets.UriPlatform}{Argumets.UriVersion}"));
TotalProgress.MaxProgressValue = realmax;
Console.WriteLine(TotalProgress.MaxProgressValue);
//queue.Enqueue(new Action(() => { if (Total_Downloaded is not null) Total_Downloaded.Text = TotalDownloadAmountNeat(realmax); }));
@ -155,8 +161,7 @@ public class NewUpdater : FPSWindow
#pragma warning restore SYSLIB0014 // Type or member is obsolete
if (string.IsNullOrEmpty(file)) return;
Console.WriteLine(file);
uri = $"https://{Program.Domain}/Updater/GetFileSize?directory={Argumets.RemoteDirectory}{Argumets.UriBranch}{Argumets.UriVersion}{Argumets.UriSeflContaind}{Argumets.UriPlatform}&file={file}";
string uri = $"https://{Program.Domain}/Updater/GetFileSize?directory={Argumets.RemoteDirectory}{Argumets.UriBranch}{Argumets.UriVersion}{Argumets.UriSeflContaind}{Argumets.UriPlatform}&file={file}";
Uri u = new($"https://{Program.Domain}/Updater/GetFile?directory={Argumets.RemoteDirectory}{Argumets.UriBranch}{Argumets.UriVersion}{Argumets.UriSeflContaind}{Argumets.UriPlatform}&file={file}");
Console.WriteLine(file);
Console.WriteLine(uri);
@ -217,7 +222,12 @@ public class NewUpdater : FPSWindow
TotalProgress.ProgressValue += (ulong)args.BytesReceived - pb.ProgressValue;
pb.ProgressValue = (ulong)args.BytesReceived;
};
ChangeProcessText($"Downloading {temp[^1]}");
string s = $"Downloading {temp[^1]}";
ChangeProcessText(s);
if (pb.Tag is Label l && temp[^1] == "file2.txt")
{
l.Text = s;
}
if (Argumets.Updater is null)
{
web.DownloadFileTaskAsync(u, Argumets.LocalDirectory + file).Wait();

View File

@ -45,8 +45,8 @@ void main()
{
this.Text = Text;
this.PixelHeight = PixelHeight;
this.X = FloatToInt(x, StartGUI.Width);
this.Y = FloatToInt(y, StartGUI.Height, true);
this.X = FloatToInt(x, 1);
this.Y = FloatToInt(y, 1, true);
this.Scale = scale;
this.DIR = dir;
this.Color = col;
@ -190,8 +190,8 @@ void main()
Shader.Use();
GL.Enable(EnableCap.Blend);
GL.Uniform4(2, Color);
_ = Matrix4.CreateScale(new Vector3(1f / StartGUI.Width, 1f / StartGUI.Height, 1.0f));
Matrix4 projectionM = Matrix4.CreateOrthographicOffCenter(0.0f, StartGUI.Width, StartGUI.Height, 0.0f, -1.0f, 1.0f);
_ = Matrix4.CreateScale(new Vector3(1f / 1, 1f / 1, 1.0f));
Matrix4 projectionM = Matrix4.CreateOrthographicOffCenter(0.0f, 1, 1, 0.0f, -1.0f, 1.0f);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
GL.BlendFunc(0, BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
GL.UniformMatrix4(1, false, ref projectionM);

View File

@ -13,8 +13,8 @@ namespace Updater;
public class StartGUI
{
internal static int Width = 694;
internal static int Height = 216;
//internal static int Width = 694;
//internal static int Height = 216;
public static SixLabors.ImageSharp.Image<Rgba32>? Logo { get; private set; }
static readonly NativeWindowSettings Settings = new()
{
@ -22,6 +22,7 @@ public class StartGUI
WindowBorder = WindowBorder.Fixed,
APIVersion = new Version(3, 2),
StartFocused = true,
Size = new(694, 105)
};
private static readonly GameWindowSettings GameWindowSettings = new()
@ -43,7 +44,7 @@ public class StartGUI
/// <param name="args"></param>
internal static int Main(Argumets args)
{
/*
var mmm = Monitors.GetMonitors();
if (mmm is not null && mmm.Any())
{
@ -56,8 +57,8 @@ public class StartGUI
Height = temph - 30;
// Settings.CurrentMonitor = mi.Handle;
}
Settings.Size = new Vector2i(Width, Height);
//Settings.Size = new Vector2i(Width, Height);
*/
Image<Rgba32> Logo = SixLabors.ImageSharp.Image.Load<Rgba32>(Tools.GetResourceStream(Assembly.GetExecutingAssembly(), "Updater.Resource.Logo.png"));
Logo.DangerousTryGetSinglePixelMemory(out Memory<Rgba32> m);
byte[] pixels = new byte[4 * Logo.Width * Logo.Height];