From fe386ff3d53e836d41f2413f0599597b199b65d0 Mon Sep 17 00:00:00 2001 From: osy <50960678+osy@users.noreply.github.com> Date: Sat, 26 Nov 2022 23:20:19 -0800 Subject: [PATCH] settings: always use binary count for size formats Fixes #4396 --- Configuration/UTMAppleConfigurationDrive.swift | 2 +- Managers/UTMAppleVirtualMachine.swift | 2 +- Managers/UTMPendingVirtualMachine.swift | 6 +++--- Managers/UTMQemuVirtualMachine.swift | 2 +- Platform/Shared/VMConfigDriveDetailsView.swift | 6 +++--- Platform/Shared/VMDetailsView.swift | 2 +- Platform/Shared/VMWizardSummaryView.swift | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Configuration/UTMAppleConfigurationDrive.swift b/Configuration/UTMAppleConfigurationDrive.swift index 1ebd9fb30..0758882f1 100644 --- a/Configuration/UTMAppleConfigurationDrive.swift +++ b/Configuration/UTMAppleConfigurationDrive.swift @@ -48,7 +48,7 @@ struct UTMAppleConfigurationDrive: UTMConfigurationDrive { } else { sizeBytes = Int64(sizeMib) * Int64(bytesInMib) } - return ByteCountFormatter.string(fromByteCount: sizeBytes, countStyle: .file) + return ByteCountFormatter.string(fromByteCount: sizeBytes, countStyle: .binary) } init(newSize: Int) { diff --git a/Managers/UTMAppleVirtualMachine.swift b/Managers/UTMAppleVirtualMachine.swift index 71503b376..ab10ff6c4 100644 --- a/Managers/UTMAppleVirtualMachine.swift +++ b/Managers/UTMAppleVirtualMachine.swift @@ -48,7 +48,7 @@ import Virtualization @MainActor override var detailsSystemMemoryLabel: String { let bytesInMib = Int64(1048576) - return ByteCountFormatter.string(fromByteCount: Int64(appleConfig.system.memorySize) * bytesInMib, countStyle: .memory) + return ByteCountFormatter.string(fromByteCount: Int64(appleConfig.system.memorySize) * bytesInMib, countStyle: .binary) } override var hasSaveState: Bool { diff --git a/Managers/UTMPendingVirtualMachine.swift b/Managers/UTMPendingVirtualMachine.swift index 0d771ff0f..938ae936d 100644 --- a/Managers/UTMPendingVirtualMachine.swift +++ b/Managers/UTMPendingVirtualMachine.swift @@ -97,13 +97,13 @@ import Foundation lastDownloadSpeedUpdate = Date() let bytesPerSecond = bytesWrittenSinceLastDownloadSpeedUpdate bytesWrittenSinceLastDownloadSpeedUpdate = 0 - let bytesString = ByteCountFormatter.string(fromByteCount: bytesPerSecond, countStyle: .file) + let bytesString = ByteCountFormatter.string(fromByteCount: bytesPerSecond, countStyle: .binary) let speedFormat = NSLocalizedString("%@/s", comment: "Format string for the 'per second' part of a download speed.") estimatedDownloadSpeed = String.localizedStringWithFormat(speedFormat, bytesString) /// sizes - downloadedSize = ByteCountFormatter.string(fromByteCount: totalBytesWritten, countStyle: .file) - estimatedDownloadSize = ByteCountFormatter.string(fromByteCount: totalBytesExpectedToWrite, countStyle: .file) + downloadedSize = ByteCountFormatter.string(fromByteCount: totalBytesWritten, countStyle: .binary) + estimatedDownloadSize = ByteCountFormatter.string(fromByteCount: totalBytesExpectedToWrite, countStyle: .binary) } public func setDownloadProgress(new newBytesWritten: Int64, currentTotal totalBytesWritten: Int64, estimatedTotal totalBytesExpectedToWrite: Int64) { diff --git a/Managers/UTMQemuVirtualMachine.swift b/Managers/UTMQemuVirtualMachine.swift index 6b0ff83a4..cca412fca 100644 --- a/Managers/UTMQemuVirtualMachine.swift +++ b/Managers/UTMQemuVirtualMachine.swift @@ -44,7 +44,7 @@ public extension UTMQemuVirtualMachine { @MainActor override var detailsSystemMemoryLabel: String { let bytesInMib = Int64(1048576) - return ByteCountFormatter.string(fromByteCount: Int64(qemuConfig.system.memorySize) * bytesInMib, countStyle: .memory) + return ByteCountFormatter.string(fromByteCount: Int64(qemuConfig.system.memorySize) * bytesInMib, countStyle: .binary) } /// Check if a QEMU target is supported diff --git a/Platform/Shared/VMConfigDriveDetailsView.swift b/Platform/Shared/VMConfigDriveDetailsView.swift index caddde4b2..86211b592 100644 --- a/Platform/Shared/VMConfigDriveDetailsView.swift +++ b/Platform/Shared/VMConfigDriveDetailsView.swift @@ -78,9 +78,9 @@ struct VMConfigDriveDetailsView: View { } if let imageUrl = config.imageURL, let fileSize = data.computeSize(for: imageUrl) { - DefaultTextField("Size", text: .constant(ByteCountFormatter.string(fromByteCount: fileSize, countStyle: .file))).disabled(true) + DefaultTextField("Size", text: .constant(ByteCountFormatter.string(fromByteCount: fileSize, countStyle: .binary))).disabled(true) } else if config.sizeMib > 0 { - DefaultTextField("Size", text: .constant(ByteCountFormatter.string(fromByteCount: Int64(config.sizeMib) * bytesInMib, countStyle: .file))).disabled(true) + DefaultTextField("Size", text: .constant(ByteCountFormatter.string(fromByteCount: Int64(config.sizeMib) * bytesInMib, countStyle: .binary))).disabled(true) } #if os(macOS) @@ -160,7 +160,7 @@ private struct ResizePopoverView: View { private var sizeString: String? { if let currentSize = currentSize { - return ByteCountFormatter.string(fromByteCount: currentSize, countStyle: .file) + return ByteCountFormatter.string(fromByteCount: currentSize, countStyle: .binary) } else { return nil } diff --git a/Platform/Shared/VMDetailsView.swift b/Platform/Shared/VMDetailsView.swift index 61dd25c2d..9485ad158 100644 --- a/Platform/Shared/VMDetailsView.swift +++ b/Platform/Shared/VMDetailsView.swift @@ -32,7 +32,7 @@ struct VMDetailsView: View { private var sizeLabel: String { let size = data.computeSize(for: vm) - return ByteCountFormatter.string(fromByteCount: size, countStyle: .file) + return ByteCountFormatter.string(fromByteCount: size, countStyle: .binary) } var body: some View { diff --git a/Platform/Shared/VMWizardSummaryView.swift b/Platform/Shared/VMWizardSummaryView.swift index 023fe5d9a..6239030aa 100644 --- a/Platform/Shared/VMWizardSummaryView.swift +++ b/Platform/Shared/VMWizardSummaryView.swift @@ -29,7 +29,7 @@ struct VMWizardSummaryView: View { } } #endif - return ByteCountFormatter.string(fromByteCount: size, countStyle: .file) + return ByteCountFormatter.string(fromByteCount: size, countStyle: .binary) } var coreDescription: String { @@ -123,7 +123,7 @@ struct VMWizardSummaryView: View { TextField("Architecture", text: .constant(wizardState.systemArchitecture.prettyValue)) TextField("System", text: .constant(wizardState.systemTarget.prettyValue)) } - TextField("RAM", text: .constant(ByteCountFormatter.string(fromByteCount: Int64(wizardState.systemMemoryMib * wizardState.bytesInMib), countStyle: .memory))) + TextField("RAM", text: .constant(ByteCountFormatter.string(fromByteCount: Int64(wizardState.systemMemoryMib * wizardState.bytesInMib), countStyle: .binary))) TextField("CPU", text: .constant(coreDescription)) TextField("Storage", text: .constant(storageDescription)) if !wizardState.useAppleVirtualization && wizardState.operatingSystem == .Linux {