Skip to content

Commit

Permalink
settings: always use binary count for size formats
Browse files Browse the repository at this point in the history
Fixes #4396
  • Loading branch information
osy committed Nov 27, 2022
1 parent 88fad76 commit fe386ff
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Configuration/UTMAppleConfigurationDrive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Managers/UTMAppleVirtualMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions Managers/UTMPendingVirtualMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Managers/UTMQemuVirtualMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Platform/Shared/VMConfigDriveDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Platform/Shared/VMDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Platform/Shared/VMWizardSummaryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit fe386ff

Please sign in to comment.