Custom Dialog Free Space Summary of all Drives

From NSIS Wiki

Author: Red Wine (talk, contrib)


Description

The following example on how to create a custom dialog that shows a summary of target's required space and free space for all drives provided for the subject at this forum thread.

The Code

outfile 'customtest.exe'
 
!define REQUIRED '30000' ; predefined required space in MBs
 
!include 'FileFunc.nsh'
!Include 'MUI.nsh'
 
!insertmacro GetDrives
!insertmacro DriveSpace
 
!insertmacro MUI_PAGE_WELCOME
page custom CustomCreate
!insertmacro MUI_PAGE_INSTFILES
 
!insertmacro MUI_LANGUAGE "English"
 
Section -
#######
SectionEnd
 
Function CustomCreate
   Push $1 ;park value to the stack
   InstallOptions::initDialog /NOUNLOAD '$PLUGINSDIR\custom.ini'
   Pop $1 ;get dialog HWND
   ReadINIStr $2 "$PLUGINSDIR\custom.ini" "Field 1" "HWND"
   SetCtlColors $2 0x0000FF 0xFFFFFF
   CreateFont $3 "Tahoma" 7 800
   SendMessage $2 ${WM_SETFONT} $3 0
   InstallOptions::show
   Pop $1 ;get button action
   Pop $1 ;get custom.ini full path
   Pop $1 ;get back value from stack
FunctionEnd 
 
Function GetDrivesCallBack
   ${DriveSpace} "$9" "/D=F /S=M" $R0
   StrCpy $9 $9 1
   IntCmp '$R0' '${REQUIRED}' +4 +4 0
   StrCmp '$R2' 'state_ok' +3
   WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'State' 'Drive:  $9     \
   Required Space =  ${REQUIRED} Mbytes      Free Space =  $R0 Mbytes'
   StrCpy '$R2' 'state_ok'
   ReadIniStr '$R1' '$PLUGINSDIR\custom.ini' 'Field 1' 'ListItems'
   StrCmp '$R1' '' 0 addlist
   WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'ListItems' 'Drive:  $9     \
   Required Space =  ${REQUIRED} Mbytes      Free Space =  $R0 Mbytes'
   goto end
  addlist:
   WriteIniStr '$PLUGINSDIR\custom.ini' 'Field 1' 'ListItems' '$R1|Drive:  $9     \
   Required Space =  ${REQUIRED} Mbytes      Free Space =  $R0 Mbytes'
  end:
   Push $0
FunctionEnd
 
Function .onInit
   initpluginsdir
   file /oname=$PLUGINSDIR\custom.ini custom.ini
   ${GetDrives} "HDD" GetDrivesCallBack
FunctionEnd

The custom.ini

[Settings]
NumFields=1
 
[Field 1]
Type=Listbox
State=
Left=12
Right=-11
Top=12
Bottom=36
Flags=

License

This script is provided 'as-is', without any express or implied warranty. In no event will the author be held liable for any damages arising from the use of this code.

Permission is granted to anyone to use this script for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  1. The origin of this script must not be misrepresented; you must not claim that you wrote the original code. If you use this header file in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  2. Altered versions must be plainly marked as such, and must not be misrepresented as being the original script.
  3. This notice may not be removed or altered from any distribution.
Personal tools
donate
ads