Skip to content

Commit

Permalink
0.4.0-dev2
Browse files Browse the repository at this point in the history
Fixed an issue with the progress bar (it was not shown correctly)
Using the new progress bar style

Signed-off-by: nixxoq <[email protected]>
  • Loading branch information
nixxoq committed Jul 31, 2024
1 parent f89d482 commit b54ad35
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
6 changes: 3 additions & 3 deletions sources/Applications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -130,7 +130,7 @@ private static ProgramDetails FindApplicationInCategory(string appName, List<Pro
public static void InstallApplication(string appName, bool isForce)
{
Console.Clear();

var applicationDetails = FindApplication(appName);
if (applicationDetails == null)
{
Expand Down
33 changes: 18 additions & 15 deletions sources/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -122,8 +123,7 @@ public static string[] GetCommandArgs()

public abstract class CurlWrapper
{
private static readonly char[] AnimationChars = { '|', '/', '-', '\\' };
private static int _animationIndex;
private const int ProgressBarWidth = 30;
private static readonly string Curl = GetCurl(Helper.GetCommandArgs());

private static string GetArgValue(string[] args, string key)
Expand Down Expand Up @@ -248,7 +248,7 @@ public static void DownloadFile(string url, string filename)
if (progress >= 0 && lastProgress != line)
{
lastProgress = line;
DisplayProgress(filename, progress, stopwatch);
DisplayProgress(progress, stopwatch);
}
else if (line.Contains("Could not resolve host"))
{
Expand Down Expand Up @@ -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;

Expand All @@ -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}");
// }
}
}
}
2 changes: 1 addition & 1 deletion sources/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit b54ad35

Please sign in to comment.