From b54ad35f20a1028257c5aa261e29c78c2a566f27 Mon Sep 17 00:00:00 2001 From: NixxO Date: Wed, 31 Jul 2024 21:42:29 +0300 Subject: [PATCH] 0.4.0-dev2 Fixed an issue with the progress bar (it was not shown correctly) Using the new progress bar style Signed-off-by: nixxoq --- sources/Applications.cs | 6 +++--- sources/Helper.cs | 33 ++++++++++++++++++--------------- sources/Updater.cs | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/sources/Applications.cs b/sources/Applications.cs index 352b58d..4930a0c 100644 --- a/sources/Applications.cs +++ b/sources/Applications.cs @@ -35,11 +35,11 @@ private static string UpdateApplicationList(bool isNeedUpdate = false) return File.ReadAllText(ApplicationsListPath); } - + private static bool IsNeedUpdate() { // true - need update; false - up to date or not exist - + var res = CurlWrapper.GetFileContent(ApplicationDb); var filesize = long.Parse(res); @@ -130,7 +130,7 @@ private static ProgramDetails FindApplicationInCategory(string appName, List= 0 && lastProgress != line) { lastProgress = line; - DisplayProgress(filename, progress, stopwatch); + DisplayProgress(progress, stopwatch); } else if (line.Contains("Could not resolve host")) { @@ -289,13 +289,15 @@ public static void DownloadFile(string url, string filename) private static float ParseProgress(string line) { - var match = Regex.Match(line, @"(\d+\.\d+)%"); - if (match.Success && float.TryParse(match.Groups[1].Value, out var progress)) return progress; + var match = Regex.Match(line, @"(\d+[\.,]?\d*)%\s*"); + + if (match.Success && float.TryParse(match.Groups[1].Value.Replace(",", "."), NumberStyles.Float, + CultureInfo.InvariantCulture, out var progress)) return progress; return -1; } - private static void DisplayProgress(string filename, float progress, Stopwatch stopwatch) + private static void DisplayProgress(float progress, Stopwatch stopwatch) { if (progress <= 0 || stopwatch.Elapsed.TotalSeconds <= 0) return; @@ -306,17 +308,18 @@ private static void DisplayProgress(string filename, float progress, Stopwatch s ? TimeSpan.FromSeconds(remainingSeconds) : TimeSpan.MaxValue; - var animationChar = AnimationChars[_animationIndex++ % AnimationChars.Length]; - var originalCursorTop = Console.CursorTop; - var originalCursorLeft = Console.CursorLeft; - - Console.SetCursorPosition(0, originalCursorTop); - Console.Write( - $@"{animationChar} Downloading {filename} -{progress:0.00}% completed | {remainingTime:hh\:mm\:ss} remaining"); + var progressChars = (int)(ProgressBarWidth * (progress / 100.0)); + var progressBar = new string('#', progressChars) + new string('-', ProgressBarWidth - progressChars); + + var progressText = + $"\r[{progressBar}] {progress:0.00}% | {speed:0.00} MB/s | {remainingTime:hh\\:mm\\:ss} remaining"; - Console.SetCursorPosition(originalCursorLeft, originalCursorTop); + Console.Write(progressText); + // if (!string.IsNullOrEmpty(filename)) + // { + // Console.WriteLine($" | {filename}"); + // } } } } \ No newline at end of file diff --git a/sources/Updater.cs b/sources/Updater.cs index 57b0ba8..f62e410 100644 --- a/sources/Updater.cs +++ b/sources/Updater.cs @@ -9,7 +9,7 @@ namespace xp_apps.sources { public abstract class Updater { - public const string ProgramVersion = "0.4.0-dev1"; + public const string ProgramVersion = "0.4.0-dev2"; private const string LatestReleaseVersion = "http://data.nixxoq.xyz/xp-apps/data.json"; public const string LatestReleaseZip = "https://github.com/nixxoq/xp-apps/releases/latest/download/xp-apps.zip";