![]() |
Include a list during compilation
Hello,
During setup, I want to edit a number of installed files (e.g. to adjust the path inside these files). I would like the list of files to be edited to be configurable (i.e., not hardcoded in my main code, but listed in another file e.g. "editscripts.nsh"). Preferably, I want to include this list during compilation of the setup executable. With the following code, I can do this, but I wondered whether there is some simpler way. (Another way would be to have a file "editscripts.dat" that contains these filenames, and simply read this file during execution of the setup, but I prefer to have only one single execution file during setup and not a lot of datafiles on the side). ; editscripts.nsh, to be included in main code ; Function ListEditScripts ; don´t quit the next line, ; otherwise the loop won´t stop... Push "" ; The list of files to be edited: Push "myfiles\commandline.bat" Push "myfiles\commandline.config" Push "myfiles\utils\util.bat" Push "myfiles\utils\util.config" FunctionEnd Function GetNextEditScript Call ListEditScripts loop: Pop $0 MessageBox MB_OK "Var 0 is $0" StrCmp $0 "" endloop loop endloop: FunctionEnd |
Maybe this could help you (?) - put these lines to somefile.nsi (.nsh):
Push "myfiles\commandline.bat" Push "myfiles\commandline.config" Push "myfiles\utils\util.bat" Push "myfiles\utils\util.config" and replace them in ListEditScripts functions with !include 'somefile.nsi'. Something says me that this is not exactly what you want :rolleyes: |
Well, actually, that is what I do now.
The code I showed I put in "somefile.nsi" and in my main code "maincode.nsi" I do the include. But I would like the code in "somefile.nsi" to be simpler. In other words: I would like to get rid of all the 'push' bit (and the 'push "" ' bit). Thank you anyway. |
You prefer to have only one single execution file during setup and not a lot of datafiles on the side. If you !include a file to NSIS script then you don't need it during setup.
OK, no problem to get rid of all the 'push'. Then you must parse your filelist from some file. You can do this:
|
Example
!define filename 'example.txt'
name "example" outfile "example.exe" setcompressor lzma !include "logiclib.nsh" page instfiles section "" fileopen $0 ${filename} r ${do} fileread $0 $1 messagebox mb_ok $1 ${loopuntil} $1 == '' fileclose $0 sectionend |
I guess what I don´t see is how to do "Then iterate over lines of the filelist" during compilation.
When I create a custom page, e.g.: Page custom EditMyFiles and do as you suggest inside "EditMyFiles" (iterate over the filelist), this will only happen during execution time, not during compilation. Indeed, in this case, my filelist.dat can be simply: filename1 filename2 On the other hand, if I do it by means of "!include somefile.nsh", then inside somefile.nsh I cannot simply have a list of files, I have to present them there with Push "filename1" Push "filename2" |
In the code example, the fileread loop is done during execution of example.exe, not during creation of example.exe.
|
Then you should do "pre-build step" (using sed or awk) and "translate" simple filelist into the Push-filelist. And !include this new one :up:
|
Just for your info - this is my way how I "build" setups. Simple batch file:
call get_files_CD.bat echo !define VERZE_CD > DDVerze.nsi echo !define DDVERZE 'CD' >> DDVerze.nsi ..\common\get_time.exe "!define DATUM_VYROBY" >> DDVerze.nsi makensis install.nsi pause |
Ok, that´s a good idea. Instead of directly compiling the nsi code, do some sed/awk stuff first to create the necessary include files.
I might go and do just that. Many thanks for the help. |
| All times are GMT. The time now is 04:20. |
Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.