FreeDiskSpace: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (→‎Description: fix broken wiki links/syntax)
(Added Win95 warning)
 
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 ==
Line 6: Line 8:
== The Script ==
== The Script ==
<highlight-nsis>OutFile "FreeSpace.exe"
<highlight-nsis>OutFile "FreeSpace.exe"
!define sysGetDiskFreeSpaceEx 'kernel32::GetDiskFreeSpaceExA(t, *l, *l, *l) i'
!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,.,,.r1)'
  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 $1 / 1024
   System::Int64Op $0 / 1024
   ; Return the free space
   Exch $0
  Pop $1
functionend
functionend


section -
section -
   StrCpy $0 'C:\Windows' ; check how much free space is left for the path C:\Windows
   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