|
|
#1 |
|
Junior Member
Join Date: Jul 2012
Posts: 8
|
Search for text in file?
hello.
just started to use NSIS, and I would like to do following: open "settings.cfg" in the $INSTDIR look for "german", if found, copy german.cfg to $INSTDIR look for "french", if found, copy french.cfg to $INSTDIR tried to play with this http://nsis.sourceforge.net/Search_for_text_in_file for a bit, but I'm totally lost (on the look for/if found part). help? thank you. |
|
|
|
|
|
#2 |
|
Major Dude
Join Date: Oct 2006
Posts: 1,841
|
You can probably use LineFind from filefunc.nsh. http://nsis.sourceforge.net/Docs/AppendixE.html#E.2.2
|
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jul 2012
Posts: 8
|
any chance of an example?
|
|
|
|
|
|
#4 |
|
Major Dude
Join Date: Oct 2006
Posts: 1,841
|
There are many usage examples in the documentation I linked.
|
|
|
|
|
|
#5 |
|
Senior Member
|
Is your config file INI based?
ReadINIStr - http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.2.10 Create cool looking Graphical Installers in NSIS: www.graphical-installer.com -see below I offer NSIS scripting, C/C++/C#/Delphi programming: www.unsigned-softworks.sk Develop NSIS projects directly in Visual Studio 2005-2012: www.unsigned-softworks.sk/visual-installer/ |
|
|
|
|
|
#6 |
|
Junior Member
Join Date: Jul 2012
Posts: 8
|
no, it's a cfg, but it's just a renamed txt file. tried to look at those examples, but it's way too complicated for me - until now, all I had to do was check for files and move them accordingly, and this is the first time I have to do something more complicated.. I was hoping for something I could just copy & paste, no luck I guess.
|
|
|
|
|
|
#7 |
|
Moderator
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
|
T.Slappy wanted to know the format of the file. 'cfg' is just a generic extension for a configuration file, whereas an INI file has a very specific format. What does the actual format/contents look like?
Stu Need an installer? http://www.afrowsoft.co.uk |
|
|
|
|
|
#8 |
|
Junior Member
Join Date: Jul 2012
Posts: 8
|
no, it's just a text file with variables. no specific format.
the plan I had was doing a text/string lookup in the file, and then using some if text/string exists function, just like I have been using IfFileExists for all the previous tasks, but I see no such thing here (with my very unskilled eye, anyway). maybe I should just make this user selectable and forget about it.. |
|
|
|
|
|
#9 | |
|
Moderator
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
|
Quote:
If there is no specific format, how can you look up a string? We cannot help you if we do not know what the format is. Stu Need an installer? http://www.afrowsoft.co.uk |
|
|
|
|
|
|
#10 |
|
Junior Member
Join Date: Jul 2012
Posts: 8
|
inst.cfg, contents:
code: the problem is, the user can have either english, german or french in the language line, and some files that have to be copied over are language specific, and the installer needs to know when german or french is used as some extra files need to be copied over (english is not a problem, it's the default language so no extra files are needed). |
|
|
|
|
|
#11 |
|
Moderator
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
|
You should be able to use ConfigRead for this (it's in the manual).
Stu Need an installer? http://www.afrowsoft.co.uk |
|
|
|
|
|
#12 |
|
Junior Member
Join Date: Jul 2012
Posts: 8
|
I'll try, thanks.
|
|
|
|
|
|
#13 |
|
Moderator
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
|
Or you can use this code:
Stucode: Need an installer? http://www.afrowsoft.co.uk |
|
|
|
|
|
#14 |
|
Junior Member
Join Date: Jul 2012
Posts: 8
|
ugh, I'm totally lost on this - can't figure your out your piece of code or what is the $var in ConfigRead supposed to do.
guess I bit off more than I can chew. |
|
|
|
|
|
#15 |
|
Moderator
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
|
$var is what it says - a variable which receives the output/value. It can be one of NSIS's built in ones ($0-$9, $R0-$R9) or one you define yourself using the Var instruction. My code uses two variables $CfgInstallPath and $CfgLanguage which would need to be defined with the Var instruction.
Stu Need an installer? http://www.afrowsoft.co.uk |
|
|
|
|
|
#16 |
|
Major Dude
Join Date: Oct 2006
Posts: 1,841
|
|
|
|
|
|
|
#17 |
|
Junior Member
Join Date: Jul 2012
Posts: 8
|
received help from a fellow forum member. adding the function he made, should anyone need something similar in the future:
Function CheckLanguage FileOpen $R0 "$INSTDIR\install.cfg" r Var /GLOBAL CfgLanguage ${DO} FileRead $R0 $R1 ${If} ${Errors} ${Break} ${EndIf} StrCpy $R2 $R1 9 ${If} $R2 == `language ` StrCpy $CfgLanguage $R1 `` 9 ${Break} ${EndIf} ${Loop} ${Switch} $CfgLanguage ${Case} 'english' File /oname=install.cfg files\English_install.cfg ${Break} ${Case} 'german' File /oname=install.cfg files\German_install.cfg ${Break} ${Default} File /oname=install.cfg files\English_install.cfg ${Break} ${EndSwitch} FunctionEnd thanks to everybody who helped.
|
|
|
|
|
|
#18 | |
|
Junior Member
Join Date: Jul 2011
Posts: 47
|
Thank You
Quote:
How hard would it be to also get line number of found string? |
|
|
|
|
|
|
#19 |
|
Major Dude
Join Date: Oct 2006
Posts: 1,841
|
Simply add a counter to the loop. Start at zero before ${Do}, then +1 just before you ${Loop}
|
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|