From 12a2b935bd924ae6e40684d8cc2a16c5c6360d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20N=C3=B8rfjand=20Stengaard?= Date: Thu, 1 Dec 2022 21:41:08 +0100 Subject: [PATCH] Fix rdb init size using percentage --- src/Hst.Imager.Core/Commands/RdbInitCommand.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Hst.Imager.Core/Commands/RdbInitCommand.cs b/src/Hst.Imager.Core/Commands/RdbInitCommand.cs index 0d15cd1..ee79984 100644 --- a/src/Hst.Imager.Core/Commands/RdbInitCommand.cs +++ b/src/Hst.Imager.Core/Commands/RdbInitCommand.cs @@ -81,14 +81,15 @@ public override async Task Execute(CancellationToken token) var defaultName = media.IsPhysicalDrive ? media.Model : Path.GetFileNameWithoutExtension(media.Model); var diskSize = stream.Length; + var rigidDiskBlockSize = diskSize.ResolveSize(size); + OnDebugMessage($"Disk size '{diskSize.FormatBytes()}' ({diskSize} bytes)"); var rigidDiskBlock = diskGeometry != null ? CreateFromDiskGeometry(diskGeometry) - : RigidDiskBlock.Create(Convert.ToInt64(size.Value == 0 ? stream.Length : size.Value) - .ResolveSize(size)); + : RigidDiskBlock.Create(rigidDiskBlockSize); - if (rigidDiskBlock.DiskSize > diskSize) + if (rigidDiskBlock.DiskSize > stream.Length) { return new Result(new Error($"Invalid Rigid Disk Block size '{rigidDiskBlock.DiskSize}' is larger than disk size '{diskSize}'")); }