Round disk size to nearest decimal place in NSIS.

huangapple go评论47阅读模式
英文:

NSIS round disk size to nearest decimal place

问题

以下代码返回系统驱动器的大小(以GB为单位):

```nsi
!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

如何将大小四舍五入到最接近的1或2个小数位,就像在内置目录页面中看到的那样?我尝试了intop但它只返回0。我不理解Math::Script插件,它是否可以使用?


<details>
<summary>英文:</summary>

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

```nsi
!include logiclib.nsh
section
  system::call &#39;kernel32::GetDiskFreeSpaceEx(t&quot;$windir&quot;, *l.r0, *l, *l)&#39;
  size:
    ${if} $0 u&gt; 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

答案1

得分: 0

这似乎更像是一个数学问题而不是一个NSIS问题,但这里有一个简单的解决方案:

!include logiclib.nsh
Section
    System::Call 'KERNEL32::GetDiskFreeSpaceEx(t"$windir", *l.r0, *l, *l)'
    StrCpy $1 00
size:
    StrCpy $1 $1 2 ; 一个简单的“四舍五入”方式
    ${If} $0 U> 1024
        System::Int64Op $0 % 1024
        Pop $1
        System::Int64Op $0 / 1024
        Pop $0
        Goto size
    ${EndIf}
    DetailPrint $0.$1
SectionEnd
英文:

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

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

huangapple
  • 本文由 发表于 2023年5月15日 05:32:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76249777.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定