Search code examples
nsis

NSIS round disk size to nearest decimal place


The following code returns the size of the system drive in GB:

!include logiclib.nsh
section
  system::call 'kernel32::GetDiskFreeSpaceEx(t"$windir", *l.r0, *l, *l)'
  size:
    ${if} $0 u> 1024
      system::int64op $0 / 1024
      pop $0
      goto size
    ${endif}
  detailprint $0
sectionend

How do i get the size rounded to the nearest 1 or 2 decimal places, as seen using the built-in directory page? i tried intop but it just returns 0. i don't understand the Math::Script plug-in, if it can be used


Solution

  • This is perhaps more of a math question than a NSIS question but here is simple solution:

    !include logiclib.nsh
    Section
        System::Call 'KERNEL32::GetDiskFreeSpaceEx(t"$windir", *l.r0, *l, *l)'
        StrCpy $1 00
    size:
        StrCpy $1 $1 2 ; A lazy way to "round"
        ${If} $0 U> 1024
            System::Int64op $0 % 1024
            Pop $1
            System::Int64op $0 / 1024
            Pop $0
            Goto size
        ${EndIf}
        DetailPrint $0.$1
    SectionEnd