Skip to content

Commit

Permalink
Improve download size estimations
Browse files Browse the repository at this point in the history
  • Loading branch information
Windows10CE committed Feb 16, 2023
1 parent 4bbf9ca commit 0645d88
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
10 changes: 8 additions & 2 deletions ThunderstoreCLI/Commands/InstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,14 @@ private static async Task<int> InstallZip(Config config, HttpClient http, GameDe

if (dependenciesToInstall.Length > 0)
{
var totalSize = MiscUtils.GetSizeString(dependenciesToInstall.Select(d => d.Versions![0].FileSize).Sum());
Write.Light($"Total estimated download size: {totalSize}");
var totalSize = dependenciesToInstall
.Where(d => !config.Cache.ContainsFile($"{d.Fullname}-{d.Versions![0].VersionNumber}.zip"))
.Select(d => d.Versions![0].FileSize)
.Sum();
if (totalSize != 0)
{
Write.Light($"Total estimated download size: {MiscUtils.GetSizeString(totalSize)}");
}

var downloadTasks = dependenciesToInstall.Select(mod =>
{
Expand Down
6 changes: 1 addition & 5 deletions ThunderstoreCLI/Commands/PublishCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,7 @@ private static void PublishPackageRequest(Config config, string uploadUuid)

using var response = await HttpClient.SendAsync(request);

try
{
response.EnsureSuccessStatusCode();
}
catch
if (!response.IsSuccessStatusCode)
{
Write.Empty();
Write.ErrorExit(await response.Content.ReadAsStringAsync());
Expand Down
5 changes: 5 additions & 0 deletions ThunderstoreCLI/Utils/DownloadCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public DownloadCache(string cacheDirectory)
}
}

public bool ContainsFile(string filename)
{
return File.Exists(Path.Combine(CacheDirectory, filename));
}

// Task instead of ValueTask here because these Tasks will be await'd multiple times (ValueTask does not allow that)
public Task<string> GetFileOrDownload(string filename, string downloadUrl)
{
Expand Down
2 changes: 1 addition & 1 deletion ThunderstoreCLI/Utils/MiscUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ public static string GetSizeString(long byteSize)
finalSize /= 1024;
suffixIndex++;
}
return $"{byteSize:F2} {suffixes[suffixIndex]}";
return $"{finalSize:F2} {suffixes[suffixIndex]}";
}
}

0 comments on commit 0645d88

Please sign in to comment.