CheckSpaceFree: Difference between revisions
m (Added category links.) |
(Use T func) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{ | {{PageAuthor|sunjammer}} | ||
== Description == | == Description == | ||
I wrote this example for forum user cooladn. In the end it wasn't needed but someone may find it useful. It's yet another demonstration of the usefulness of the System plugin that Brainsucker wrote for NSIS. This example checks to see if a given disk has the desired amount of free space: | I wrote this example for forum user cooladn. In the end it wasn't needed but someone may find it useful. It's yet another demonstration of the usefulness of the System plugin that Brainsucker wrote for NSIS. This example checks to see if a given disk has the desired amount of free space: | ||
== Notes == | |||
Please, please, please do not CheckSpaceFree on "c:\" when you want to CheckSpaceFree on "$INSTDIR". | |||
You need to know the capacity of the volume that the specified directory is in. This may not be the volume at the "root of the drive" (e.g. "d:\") because of the use of mount points. If you don't know what mount points are then you should find out before writing installers that look at disk space. You might even use them yourself :-) In simple terms, a system could have a drive on which stuff is stored; Instead of being accessed as d:\, it could be accessed as c:\stuff. So, if I want to install your program into c:\stuff, you should CheckSpaceFree there and not abort because I don't have enough space on c:\. | |||
== The Script == | == The Script == | ||
<highlight-nsis>OutFile "FreeSpace.exe" | <highlight-nsis>OutFile "FreeSpace.exe" | ||
!define sysGetDiskFreeSpaceEx 'kernel32:: | !define sysGetDiskFreeSpaceEx 'kernel32::GetDiskFreeSpaceEx(t, *l, *l, *l) i' | ||
; $0 - space required in kb | ; $0 - space required in kb | ||
Line 23: | Line 26: | ||
System::Call '${sysGetDiskFreeSpaceEx}(r1,.,,.r2)' | System::Call '${sysGetDiskFreeSpaceEx}(r1,.,,.r2)' | ||
converttokb: | converttokb: | ||
; convert the large integer byte values into | ; convert the large integer byte values into manageable kb | ||
System::Int64Op $2 / 1024 | System::Int64Op $2 / 1024 | ||
Pop $2 | Pop $2 | ||
Line 32: | Line 35: | ||
section - | section - | ||
StrCpy $0 12345; kb | StrCpy $0 12345 ; kb you need | ||
StrCpy $1 'c:' ; check drive c: for space | StrCpy $1 'c:' ; check drive c: for space | ||
StrCpy $2 1 | |||
Call CheckSpaceFunc | Call CheckSpaceFunc | ||
IntCmp $2 1 okay | IntCmp $2 1 okay | ||
Line 40: | Line 44: | ||
sectionend</highlight-nsis> | sectionend</highlight-nsis> | ||
[[ | [[Category:System Plugin Examples]] |
Latest revision as of 12:53, 30 September 2022
Author: sunjammer (talk, contrib) |
Description
I wrote this example for forum user cooladn. In the end it wasn't needed but someone may find it useful. It's yet another demonstration of the usefulness of the System plugin that Brainsucker wrote for NSIS. This example checks to see if a given disk has the desired amount of free space:
Notes
Please, please, please do not CheckSpaceFree on "c:\" when you want to CheckSpaceFree on "$INSTDIR".
You need to know the capacity of the volume that the specified directory is in. This may not be the volume at the "root of the drive" (e.g. "d:\") because of the use of mount points. If you don't know what mount points are then you should find out before writing installers that look at disk space. You might even use them yourself :-) In simple terms, a system could have a drive on which stuff is stored; Instead of being accessed as d:\, it could be accessed as c:\stuff. So, if I want to install your program into c:\stuff, you should CheckSpaceFree there and not abort because I don't have enough space on c:\.
The Script
OutFile "FreeSpace.exe" !define sysGetDiskFreeSpaceEx 'kernel32::GetDiskFreeSpaceEx(t, *l, *l, *l) i' ; $0 - space required in kb ; $1 - path to check ; $2 - 0 = ignore quotas, 1 = obey quotas ; trashes $2 function CheckSpaceFunc IntCmp $2 0 ignorequota ; obey quota System::Call '${sysGetDiskFreeSpaceEx}(r1,.r2,,.)' goto converttokb ; ignore quota ignorequota: System::Call '${sysGetDiskFreeSpaceEx}(r1,.,,.r2)' converttokb: ; convert the large integer byte values into manageable kb System::Int64Op $2 / 1024 Pop $2 ; check space System::Int64Op $2 > $0 Pop $2 functionend section - StrCpy $0 12345 ; kb you need StrCpy $1 'c:' ; check drive c: for space StrCpy $2 1 Call CheckSpaceFunc IntCmp $2 1 okay MessageBox MB_OK "Error: Not enough disk space" okay: sectionend