We are working on converting the wiki to a static website controlled by markdown files in https://github.com/nsis-community. You can already see there how plug-ins will be posted. The end-user interface will still be a website but with a fresh coat of paint. Come meet us at Discord to talk about it.

File size, permissions and times

From NSIS Wiki
Jump to navigationJump to search
Author: Takhir (talk, contrib)


Description

Required: System plug-in.

Script extracts and displays following file parameters using stat() API call: type - file or directory, r/w permissions, size and creation/modification times.

The Script

  !define TEST_NAME "stat"
  !define APP_NAME "${TEST_NAME} test"
  !define FILE_NAME "${TEST_NAME}.nsi"
 
Name "${APP_NAME}"
OutFile "${APP_NAME}.exe"
 
Function Stat
 
;        DWORD st_dev;
;        WORD st_ino;
;        WORD st_mode;
;        WORD st_nlink;
;        WORD st_uid;
;        WORD st_gid;
;        WORD spacer;
;        DWORD st_rdev;
;        INT st_size;
;        DWORD st_atime;
;        DWORD st_mtime;
;        DWORD st_ctime;
!define stSTAT '(i,&i2,&i2,&i2,&i2,&i2,&i2,i,i,i,i,i) i'
 
   System::Call '*${stSTAT} .r0' ; allocates memory for STAT struct and writes address to $0
   System::Call 'msvcrt.dll::_stat(t "$EXEDIR\${FILE_NAME}", i r0) i .r1'
;   MessageBox MB_OK "_stat returned $1"
   IntCmp $1 -1 exit
   System::Call "*$0${stSTAT}(,,.r1,,,,,,.r2,.r3,.r4,.r5)"
;   MessageBox MB_OK "st_mode=$1, st_size=$2, st_atime=$3, st_mtime=$4, st_ctime=$5"
   System::Call 'msvcrt.dll::ctime(*i r3) t .r3'
   System::Call 'msvcrt.dll::ctime(*i r4) t .r4'
   System::Call 'msvcrt.dll::ctime(*i r5) t .r5'
   StrCpy $6 "File"
   IntOp $7 $1 & 0040000
   IntCmp $7 0 isfile
   StrCpy $6 "Directory"
isfile:
   StrCpy $8 "Read only"
   IntOp $7 $1 & 0000200
   IntCmp $7 0 rdonly
   StrCpy $8 "Write permitted"
rdonly:
exit:
   System::Free $0 ; free allocated memory
 
FunctionEnd
 
Section "Dummy Section" SecDummy
 
  Call Stat
  MessageBox MB_OK "Name=${FILE_NAME}$\nType=$6$\nAccess=$8$\nSize=$2 bytes$\nAccess time=$3Modify time=$4Creation time=$5"
 
sectionend

See also: To see how to change permissions AccessControl plug-in