FreeDiskSpace: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
No edit summary |
(Added Win95 warning) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{PageAuthor|Dr.Sweety}} | {{PageAuthor|Dr.Sweety}} | ||
<div style="border: 1px solid #404000; background-color:#f8f880; color:#000; padding:0.5em;"><b>Note: </b>This code will not work on Win95 RTM. Win95 OSR2 or WinNT4 is required.</div> | |||
== Description == | == Description == | ||
Based on the function [[CheckSpaceFree]] from [[sunjammer]] I created the following function which returns the free space (in kb) available for the path specified | Based on the function [[CheckSpaceFree]] from [[user:sunjammer|sunjammer]] I created the following function which returns the free space (in kb) available for the path specified | ||
== 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 - Path to check (can be a drive 'C:' or a full path 'C:\Windows') | ; $0 - Path to check (can be a drive 'C:' or a full path 'C:\Windows') | ||
Line 12: | Line 14: | ||
function FreeDiskSpace | function FreeDiskSpace | ||
System::Call '${sysGetDiskFreeSpaceEx}(r0,.,,. | Exch $0 | ||
System::Call '${sysGetDiskFreeSpaceEx}(r0,.,,.r0)' | |||
; convert the large integer byte values into managable kb | ; convert the large integer byte values into managable kb | ||
System::Int64Op $ | System::Int64Op $0 / 1024 | ||
Exch $0 | |||
functionend | functionend | ||
section - | section - | ||
Push '$WinDir' ; check how much free space is left for the path C:\Windows | |||
Call FreeDiskSpace | Call FreeDiskSpace | ||
Pop $1 | |||
MessageBox MB_OK "Free disk space in $0 : $1 kb" | MessageBox MB_OK "Free disk space in $0 : $1 kb" | ||
Latest revision as of 20:40, 28 September 2022
Author: Dr.Sweety (talk, contrib) |
Note: This code will not work on Win95 RTM. Win95 OSR2 or WinNT4 is required.
Description
Based on the function CheckSpaceFree from sunjammer I created the following function which returns the free space (in kb) available for the path specified
The Script
OutFile "FreeSpace.exe" !define sysGetDiskFreeSpaceEx 'kernel32::GetDiskFreeSpaceEx(t, *l, *l, *l)i' ; $0 - Path to check (can be a drive 'C:' or a full path 'C:\Windows') ; $1 - Return value, free space in kb function FreeDiskSpace Exch $0 System::Call '${sysGetDiskFreeSpaceEx}(r0,.,,.r0)' ; convert the large integer byte values into managable kb System::Int64Op $0 / 1024 Exch $0 functionend section - Push '$WinDir' ; check how much free space is left for the path C:\Windows Call FreeDiskSpace Pop $1 MessageBox MB_OK "Free disk space in $0 : $1 kb" StrCpy $2 12345 ; Free space required by you (in kb) System::Int64Op $1 > $2 ; Compare the space required and the space available Pop $3 ; Get the result ... IntCmp $3 1 okay ; ... and compare it MessageBox MB_OK "Error: Not enough disk space!" okay: MessageBox MB_OK "Enough disk space available!" sectionend