Skip to content

Commit fe161b6

Browse files
committed
Round formatted bytes, display plus sign more often
1 parent 97bc3a4 commit fe161b6

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

FlashpointInstaller/src/Common.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public static string GetFormattedBytes(long bytes)
376376
while (--i >= 0)
377377
{
378378
double unitSize = Math.Pow(1024, i);
379-
if (bytes >= unitSize) return (Math.Floor(bytes / unitSize * 10) / 10).ToString("N1") + units[i];
379+
if (bytes >= unitSize) return (Math.Round(bytes / unitSize * 10) / 10).ToString("N1") + units[i];
380380
}
381381

382382
return "0 bytes";

FlashpointManager/src/Common.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,7 @@ public static void SyncManager()
374374
long sizeChange = component.Size - oldSize;
375375
totalSizeChange += sizeChange;
376376

377-
string displayedSize = GetFormattedBytes(sizeChange);
378-
if (displayedSize[0] != '-') displayedSize = "+" + displayedSize;
377+
string displayedSize = GetFormattedBytes(sizeChange, true);
379378

380379
var item = new ListViewItem();
381380
item.Text = component.Title;
@@ -394,7 +393,7 @@ public static void SyncManager()
394393
item.Text = component.Title;
395394
item.SubItems.Add("This component is deprecated and can be deleted.");
396395
item.SubItems.Add("");
397-
item.SubItems.Add(GetFormattedBytes(-component.Size));
396+
item.SubItems.Add(GetFormattedBytes(-component.Size, true));
398397

399398
Main.UpdateList.Items.Add(item);
400399
}
@@ -406,7 +405,7 @@ public static void SyncManager()
406405

407406
if (ComponentTracker.Outdated.Count > 0 || ComponentTracker.Deprecated.Count > 0)
408407
{
409-
Main.UpdateButton.Text += $" ({GetFormattedBytes(totalSizeChange)})";
408+
Main.UpdateButton.Text += $" ({GetFormattedBytes(totalSizeChange, true)})";
410409
Main.UpdateButton.Enabled = true;
411410
}
412411
else
@@ -604,18 +603,24 @@ void AddDependencies(string[] depends)
604603
}
605604

606605
// Formats bytes as a human-readable string
607-
public static string GetFormattedBytes(long bytes)
606+
public static string GetFormattedBytes(long bytes, bool plusSign = false)
608607
{
609608
string[] units = new[] { " bytes", "KB", "MB", "GB" };
610609
int i = units.Length;
611610

611+
string formattedBytes = "0 bytes";
612+
612613
while (--i >= 0)
613614
{
614615
double unitSize = Math.Pow(1024, i);
615-
if (Math.Abs(bytes) >= unitSize) return (Math.Floor(bytes / unitSize * 10) / 10).ToString("N1") + units[i];
616+
if (Math.Abs(bytes) >= unitSize)
617+
{
618+
formattedBytes = (Math.Round(bytes / unitSize * 10) / 10).ToString("N1") + units[i];
619+
break;
620+
}
616621
}
617622

618-
return "0 bytes";
623+
return (plusSign && !formattedBytes.StartsWith("-") ? "+" : "") + formattedBytes;
619624
}
620625

621626
// Function for errors unrelated to the component list

FlashpointManager/src/Forms/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void ComponentList_AfterCheck(object sender, TreeViewEventArgs e)
8383
? long.Parse(File.ReadLines(component.InfoFile).First().Split(' ')[1])
8484
: component.Size);
8585

86-
ChangeButton.Text = $"Apply changes ({FPM.GetFormattedBytes(FPM.ModifiedSize)})";
86+
ChangeButton.Text = $"Apply changes ({FPM.GetFormattedBytes(FPM.ModifiedSize, true)})";
8787
ChangeButton.Enabled = true;
8888
}
8989

0 commit comments

Comments
 (0)