External License file: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Corrected link to System plug-in.)
No edit summary
Line 43: Line 43:
; Installer Functions
; Installer Functions


 
!define FILE_SHARE_READ 1
!define stSTAT '(i,&i2,&i2,&i2,&i2,&i2,&i2,i,i,i,i,i) i'
!define GENERIC_READ 0x80000000
 
!define OPEN_EXISTING 3
;$0 - allocated buffer pointer
!define FILE_BEGIN 0
;$1 - file size
!define FILE_END 2
;$2 - License window handle (RichEdit)
;$4 - syscall result value
 
Function fileSize
 
  System::Call '*${stSTAT} .r0' ; allocates memory for STAT struct and writes address to $0
  System::Call 'msvcrt.dll::_stat(t "$EXEDIR\${LIC_NAME}", i r0) i .r1'
  IntCmp $1 -1 exit
  System::Call "*$0${stSTAT}(,,,,,,,,.r1,,,)"
exit:
  System::Free $0 ; free allocated memory
 
FunctionEnd


Function addLicense
Function addLicense


   Call fileSize
   System::Call 'kernel32::CreateFile(t "$EXEDIR\${LIC_NAME}", i ${GENERIC_READ}, i ${FILE_SHARE_READ}, i 0, i ${OPEN_EXISTING}, i 0, i 0) i .r0'
  IfErrors exit
  System::Call 'kernel32::SetFilePointer(i r0, i 0, i 0, i ${FILE_END}) i .r1'
   IntOp $1 $1 + 1 ; for terminating zero
   IntOp $1 $1 + 1 ; for terminating zero
  FindWindow $2 "#32770" "" $HWNDPARENT
   System::Call 'kernel32::SetFilePointer(i r0, i 0, i 0, i ${FILE_BEGIN})'
  GetDlgItem $2 $2 1000
   System::Alloc $1
   System::Call 'msvcrt.dll::calloc(i $1, i 1) i .r0'
  Pop $2
   System::Call 'msvcrt.dll::_open(t "$EXEDIR\${LIC_NAME}", i 0x8000) i .r3'
   System::Call 'kernel32::ReadFile(i r0, i r2, i r1, *i .r3, i 0)'
   System::Call 'msvcrt.dll::_read(i r3, i r0, i r1) i .r4'
   System::Call 'kernel32::CloseHandle(i r0)'
   System::Call 'msvcrt.dll::_close(i r3)'
  FindWindow $0 "#32770" "" $HWNDPARENT
   SendMessage $2 ${WM_SETTEXT} 0 $0 $4
  GetDlgItem $0 $0 1000
   System::Call 'msvcrt.dll::free(i r0)'
   SendMessage $0 ${WM_SETTEXT} $0 $2
   System::Free $2
exit:


FunctionEnd
FunctionEnd

Revision as of 18:09, 20 July 2006

Author: Takhir (talk, contrib)


Description

Requires: System plug-in.

MUI License page "show" function replaces current license text (Dummy.txt added during compilation) with (runtime) License.txt file content.

The Script

;--------------------------------
; Base names definition
 
  !define LIC_NAME "License.txt"
  !define APP_NAME "License Test"
 
 
;--------------------------------
; General Attributes
 
  Name "${APP_NAME}"
  OutFile "${APP_NAME}.exe"
 
 
;--------------------------------
; Interface
 
  !include "MUI.nsh"
  !insertmacro MUI_PAGE_WELCOME
  !define MUI_PAGE_CUSTOMFUNCTION_SHOW addLicense
  !insertmacro MUI_PAGE_LICENSE Dummy.txt
  !insertmacro MUI_LANGUAGE "English"
 
 
;--------------------------------
; Installer Sections
 
Section "Dummy Section" SecDummy
 
SectionEnd
 
 
;--------------------------------
; Installer Functions
 
!define FILE_SHARE_READ 1
!define GENERIC_READ 0x80000000
!define OPEN_EXISTING 3
!define FILE_BEGIN 0
!define FILE_END 2
 
Function addLicense
 
   System::Call 'kernel32::CreateFile(t "$EXEDIR\${LIC_NAME}", i ${GENERIC_READ}, i ${FILE_SHARE_READ}, i 0, i ${OPEN_EXISTING}, i 0, i 0) i .r0'
   IfErrors exit
   System::Call 'kernel32::SetFilePointer(i r0, i 0, i 0, i ${FILE_END}) i .r1'
   IntOp $1 $1 + 1 ; for terminating zero
   System::Call 'kernel32::SetFilePointer(i r0, i 0, i 0, i ${FILE_BEGIN})'
   System::Alloc $1
   Pop $2
   System::Call 'kernel32::ReadFile(i r0, i r2, i r1, *i .r3, i 0)'
   System::Call 'kernel32::CloseHandle(i r0)'
   FindWindow $0 "#32770" "" $HWNDPARENT
   GetDlgItem $0 $0 1000
   SendMessage $0 ${WM_SETTEXT} $0 $2
   System::Free $2
exit:
 
FunctionEnd