diff --git a/Launcher/Views/MainView.axaml b/Launcher/Views/MainView.axaml
index b214db0..bf11804 100644
--- a/Launcher/Views/MainView.axaml
+++ b/Launcher/Views/MainView.axaml
@@ -51,6 +51,9 @@
+
+
+
diff --git a/Launcher/Views/MainView.axaml.cs b/Launcher/Views/MainView.axaml.cs
index 2a23ef5..a82290d 100644
--- a/Launcher/Views/MainView.axaml.cs
+++ b/Launcher/Views/MainView.axaml.cs
@@ -7,8 +7,10 @@
using Avalonia.Media.Imaging;
using Launcher.Extensions;
using Launcher.Forms;
+using LauncherGamePlugin;
using LauncherGamePlugin.Commands;
using LauncherGamePlugin.Enums;
+using LauncherGamePlugin.Extensions;
namespace Launcher.Views;
@@ -42,6 +44,7 @@ public MainView()
NotInstalledListBox.SelectionChanged += (_, _) => MonitorListBox(NotInstalledListBox);
SearchBox.KeyUp += (_, _) => ApplySearch();
OnUpdateView += GenerateNewMenuItems;
+ OnUpdateView += UpdateDriveStats;
}
public void ApplySearch()
@@ -172,4 +175,29 @@ public async void OnHidePluginSideBar()
_app.SidebarState = PluginSideBar.IsVisible;
UpdateView();
}
+
+ private void UpdateDriveStats()
+ {
+ StorageSpaceStackPanel.Children.Clear();
+ try
+ {
+ var driveInfo = new DriveInfo(_app.GameDir);
+ StorageSpaceStackPanel.Children.Add(new Label()
+ {
+ FontSize = 16,
+ Content = $"{driveInfo.Name}: {driveInfo.AvailableFreeSpace.ReadableSize()} free"
+ });
+
+ var percentage = ((driveInfo.TotalSize - driveInfo.AvailableFreeSpace) / (double)driveInfo.TotalSize) * 100;
+
+ StorageSpaceStackPanel.Children.Add(new ProgressBar()
+ {
+ Value = percentage,
+ });
+ }
+ catch (Exception e)
+ {
+ _app.Logger.Log($"Unable to fetch drive statistics: {e.Message}", LogType.Warn);
+ }
+ }
}
\ No newline at end of file
diff --git a/LauncherGamePlugin/Extensions/LongExtensions.cs b/LauncherGamePlugin/Extensions/LongExtensions.cs
index c4a857e..55ce728 100644
--- a/LauncherGamePlugin/Extensions/LongExtensions.cs
+++ b/LauncherGamePlugin/Extensions/LongExtensions.cs
@@ -2,18 +2,18 @@
public static class LongExtensions
{
- private static readonly string[] gameSizes = { "B", "KB", "MB", "GB" };
+ private static readonly string[] gameSizes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
public static string ReadableSize(this long size)
{
- int type = 0;
- double bytesLeft = size;
- while (bytesLeft >= 1024)
+ if (size <= 0)
{
- type++;
- bytesLeft /= 1024;
+ return "0 B";
}
- return $"{bytesLeft:0.00} {gameSizes[type]}";
+ var i = (int)Math.Floor(Math.Log(size, 1024));
+ var p = Math.Pow(1024, i);
+ var s = Math.Round(size / p, 2);
+ return $"{s} {gameSizes[i]}";
}
}
\ No newline at end of file
diff --git a/RemoteDownloaderPlugin/Game/GameDownload.cs b/RemoteDownloaderPlugin/Game/GameDownload.cs
index 8d34e41..495b750 100644
--- a/RemoteDownloaderPlugin/Game/GameDownload.cs
+++ b/RemoteDownloaderPlugin/Game/GameDownload.cs
@@ -136,6 +136,7 @@ private async Task DownloadPc(IApp app, PcEntry entry)
try
{
+ // TODO: Fix security vuln, zips can have backwards paths
using HttpResponseMessage response = await client.GetAsync(entry.Url, HttpCompletionOption.ResponseHeadersRead, _cts.Token);
response.EnsureSuccessStatusCode();
await using var responseStream = await response.Content.ReadAsStreamAsync();