2016-07-05 194 views

回答

2

您可以使用!system命令在編譯時執行外部工具。該外部工具/腳本應該生成包含安裝和卸載說明的包含文件。

您還可以使用NSIS的飛行產生的指令,但是當你把所有的它在一個腳本這是一個有點亂:

; Generate some files for this example: 
!system 'mkdir "$%temp%\testdir\subdir\sub2\sub3"' 
!appendfile "$%temp%\testdir\file1.txt" "" 
!appendfile "$%temp%\testdir\subdir\file2.txt" "" 
!appendfile "$%temp%\testdir\subdir\sub2\file3.txt" "" 
!appendfile "$%temp%\testdir\subdir\sub2\sub3\file4.txt" "" 



!macro GENFILELIST_Enum SourceDir InstDir 
Push "${SourceDir}" 
Push "${InstDir}" 
Call GENFILELIST_Enum 
!macroend 

### Start editing here ### 

!macro GeneratePages 
OutFile "test.exe" 
Name "Test" 
RequestExecutionLevel admin 
InstallDir "$ProgramFiles\MyTestApp" 

Page Directory 
Page InstFiles 
UninstPage UninstConfirm 
UninstPage InstFiles 
!macroend 

!macro GENFILELIST 
!insertmacro GENFILELIST_Enum "$%temp%\testdir" "" ; Files to install 
!macroend 

!macro GenerateInstallSections FileInstructions 
Section 
SetOutPath $InstDir 
!include "${FileInstructions}" 
WriteUninstaller "$InstDir\Uninst.exe" 
SectionEnd 
!macroend 

!macro GenerateUninstallSections FileInstructions 
Section Uninstall 
SetOutPath $InstDir 
!include "${FileInstructions}" 
SetOutPath $Temp 
Delete "$InstDir\Uninst.exe" 
RmDir $InstDir 
SectionEnd 
!macroend 

### Stop editing here ### 


!ifndef GENFILELIST_IN 
!tempfile GENFILELISTAPP 
!tempfile GENFILELIST_IN 
!tempfile GENFILELIST_UN 
!appendfile "${GENFILELIST_IN}" '!define GENFILELIST_UN "${GENFILELIST_UN}"$\n' 
!appendfile "${GENFILELIST_IN}" 'OutFile "${GENFILELISTAPP}"$\n' 
!system '"${NSISDIR}/makensis" "/DGENFILELIST_IN=${GENFILELIST_IN}" "${__FILE__}"' = 0 
!system '"${GENFILELISTAPP}" /S' = 0 
!delfile "${GENFILELISTAPP}" 
!insertmacro GeneratePages 
!insertmacro GenerateInstallSections "${GENFILELIST_IN}" 
!insertmacro GenerateUninstallSections "${GENFILELIST_UN}" 
!delfile "${GENFILELIST_IN}" 
!delfile "${GENFILELIST_UN}" 
!else 
!include LogicLib.nsh 
!include "${GENFILELIST_IN}" 
!delfile "${GENFILELIST_IN}" 
!macro GENFILELIST_Append file string tmpvar 
FileOpen ${tmpvar} "${file}" a 
FileSeek ${tmpvar} 0 END 
FileWrite ${tmpvar} '${string}' 
FileClose ${tmpvar} 
!macroend 
!define DOLLAR "$$" 
Function GENFILELIST_Enum 
System::Store S 
Pop $9 ; Relative path 
Pop $8 ; Base path 
${IfThen} $9 == "" ${|} StrCpy $9 "${DOLLAR}OutDir" ${|} 
FindFirst $0 $1 "$8\*" 
loop: 
StrCmp $1 "" stop 
    StrCmp $1 "." next 
    StrCmp $1 ".." next 
    StrCpy $3 $1 
    ${If} ${FileExists} "$8\$1\*" 
     !insertmacro GENFILELIST_Append "${GENFILELIST_IN}" 'SetOutPath "${DOLLAR}OutDir\$1"$\n' $2 
     Push $8\$1 
     Push $9\$1 
     Call GENFILELIST_Enum 
    ${Else} 
     !insertmacro GENFILELIST_Append "${GENFILELIST_IN}" 'File "$8\$1"$\n' $2 
     !insertmacro GENFILELIST_Append "${GENFILELIST_UN}" 'Delete "$9\$1"$\n' $2 
    ${EndIf} 
    next: 
    FindNext $0 $1 
    Goto loop 
stop: 
FindClose $0 
!insertmacro GENFILELIST_Append "${GENFILELIST_UN}" 'RmDir "$9"$\n' $2 
System::Store L 
FunctionEnd 
RequestExecutionLevel user 
Section 
!insertmacro GENFILELIST 
SectionEnd 
!endif 
+0

所以結果是幾乎相同的,因爲它是對於我上面提到的腳本。 –