well, based on Instructor's functions and code posted on other topics I'm trying to compile a script that takes a given directory and builds a proper list ready to !include in install section. This could be a helper to parse the entire directory structure in the installation script. The code that I'm figuring is this:
OutFile test.exe
Name "NSIS Script Helper"
!include "FileFunc.nsh"
!insertmacro Locate
!define DirName 'D:\New_Installation'
!define FileList '$EXEDIR\Files.lst'
var TargetDir
Section
FileOpen $R1 ${FileList} w
${Locate} "${DirName}" "/L=F /M=*.*" "LocateCallBack"
FileClose $R1
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
Exec '"notepad.exe" "${FileList}"'
SectionEnd
Function LocateCallBack
StrLen $R2 '${DirName}'
StrCpy $TargetDir $R8 '' $R2
StrCmp $TargetDir '' +1 +3
FileWrite $R1 'SetOutPath "$$INSTDIR"$\r$\n'
goto +2
FileWrite $R1 'CreateDirectory "$$INSTDIR$TargetDir"$\r$\nSetOutPath "$$INSTDIR$TargetDir"$\r$\n'
FileWrite $R1 'File "$R8\$R7"$\r$\n'
Push $0
FunctionEnd
The resulting list where I really stuck is this:
SetOutPath "$INSTDIR"
File "D:\New_Installation\root.dll"
SetOutPath "$INSTDIR"
File "D:\New_Installation\rootexec.exe"
CreateDirectory "$INSTDIR\subdir"
SetOutPath "$INSTDIR\subdir"
File "D:\New_Installation\subdir\other_recourse.dll"
CreateDirectory "$INSTDIR\subdir"
SetOutPath "$INSTDIR\subdir"
File "D:\New_Installation\subdir\recourse.dll"
CreateDirectory "$INSTDIR\subdir\Folder"
SetOutPath "$INSTDIR\subdir\Folder"
File "D:\New_Installation\subdir\Folder\somedll.dll"
CreateDirectory "$INSTDIR\subdir\Folder"
SetOutPath "$INSTDIR\subdir\Folder"
File "D:\New_Installation\subdir\Folder\some_other.dll"
CreateDirectory "$INSTDIR\documents"
SetOutPath "$INSTDIR\documents"
File "D:\New_Installation\documents\help.pdf"
CreateDirectory "$INSTDIR\documents"
SetOutPath "$INSTDIR\documents"
File "D:\New_Installation\documents\more_help.html"
I can't handle how I should write the code to eliminate the repeated lines 'SetOutPath...' and 'CreateDirectory...' so the resulting list will be like this:
SetOutPath "$INSTDIR"
File "D:\New_Installation\root.dll"
File "D:\New_Installation\rootexec.exe"
CreateDirectory "$INSTDIR\subdir"
SetOutPath "$INSTDIR\subdir"
File "D:\New_Installation\subdir\other_recourse.dll"
File "D:\New_Installation\subdir\recourse.dll"
CreateDirectory "$INSTDIR\subdir\Folder"
SetOutPath "$INSTDIR\subdir\Folder"
File "D:\New_Installation\subdir\Folder\somedll.dll"
File "D:\New_Installation\subdir\Folder\some_other.dll"
CreateDirectory "$INSTDIR\documents"
SetOutPath "$INSTDIR\documents"
File "D:\New_Installation\documents\help.pdf"
File "D:\New_Installation\documents\more_help.html"
Help please!