Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 25th July 2004, 21:58   #1
VegetaSan
Senior Member
 
VegetaSan's Avatar
 
Join Date: Jan 2004
Location: The Netherlands
Posts: 260
get info from update.ini

hey. I want this function in my installer. But I dont have a clue how to do it.

What I want is that the installer needs to extract update.ini to $INSTSDIR and that it needs to merge his info with os.ini so ... for example:

_______________________________________________________

Update.ini :

code:

[Global]
Password=NSIS
Nick=NSIS_dude
Host=mgmservers



let's say that this is the contents of update.ini

_______________________________________________________

Os.ini :

code:

[Global]
Password=NSIS_is_cool
Nick=NSIS_GIRLIE
Host=source
Version=1.0



and let's say this is Os.ini
________________________________________________________


now .. when the installer is done with extracting update.ini then it needs to overwrite the contents of Os.ini with the contents that update.ini has. So after merging then Os.ini will be like this:

code:

[Global]
Password=NSIS
Nick=NSIS_dude
Host=mgmservers
Version=1.0



_______________________________________________________

ok .. now I hope someone can help me with this. thanks.


With Regards, VegetaSan

VegetaSan....
VegetaSan is offline   Reply With Quote
Old 25th July 2004, 23:34   #2
VegetaSan
Senior Member
 
VegetaSan's Avatar
 
Join Date: Jan 2004
Location: The Netherlands
Posts: 260
ah sorry never mind .. allready got it .. stupid me >_<

VegetaSan....
VegetaSan is offline   Reply With Quote
Old 26th July 2004, 10:03   #3
VegetaSan
Senior Member
 
VegetaSan's Avatar
 
Join Date: Jan 2004
Location: The Netherlands
Posts: 260
ok .lol .. I still got a question. Will this work?

code:

ReadINIStr $0 "$INSTSDIR\Update.ini" "*.*" "*.*"
WriteINIStr "$INSTSDIR\mirc.ini" "*.*" "*.*" "$0"


VegetaSan....
VegetaSan is offline   Reply With Quote
Old 26th July 2004, 14:17   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 6,950
Uhhmmm no.

I think the only way to do this would be to create a custom function to FileRead along with WriteINIStr. There's no way of using ReadINIStr to read through each key in the update.ini, so we will have to read each line using FileRead.

I will write a function now...

-Stu
Afrow UK is offline   Reply With Quote
Old 26th July 2004, 14:17   #5
atsuk
Member
 
atsuk's Avatar
 
Join Date: Jun 2003
Location: Estonia
Posts: 91
don't think so. you have to read each entry one by one into the variable, and then write them to another ini. afther all *.* is used with files. "*" means all, and dot between them is just like in file between name and extension, so *.* means all file names with all extensions

edited:
but Afrow UK managed to reply faster(Y)
atsuk is offline   Reply With Quote
Old 26th July 2004, 15:03   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 6,950
Done!

code:
Function TrimNewlines
Exch $R0
Push $R1
Push $R2
StrCpy $R1 0

loop:
IntOp $R1 $R1 - 1
StrCpy $R2 $R0 1 $R1
StrCmp $R2 "$\r" loop
StrCmp $R2 "$\n" loop

IntOp $R1 $R1 + 1
IntCmp $R1 0 no_trim_needed
StrCpy $R0 $R0 $R1

no_trim_needed:
Pop $R2
Pop $R1
Exch $R0
FunctionEnd

Function SplitFirstStrPart
Exch $R0
Push $R1
Push $R2
StrLen $R1 $R0
IntOp $R1 $R1 + 1
loop:
IntOp $R1 $R1 - 1
StrCpy $R2 $R0 1 -$R1
StrCmp $R1 0 exit0
StrCmp $R2 "=" exit1 loop ; Change " " to "\" if str=dirpath
exit0:
StrCpy $R1 ""
Goto exit2
exit1:
IntOp $R1 $R1 - 1
StrCpy $R2 $R0 "" -$R1
IntOp $R1 $R1 + 1
StrCpy $R0 $R0 -$R1
StrCpy $R1 $R2
exit2:
Pop $R2
Exch $R1 ;rest
Exch
Exch $R0 ;first
FunctionEnd

Function ReadINIFileKeys
Exch $R0 ;INI file to write
Exch
Exch $R1 ;INI file to read
Push $R2
Push $R3
Push $R4 ;uni var
Push $R5 ;uni var
Push $R6 ;last INI section

FileOpen $R2 $R1 r

Loop:
FileRead $R2 $R3
IfErrors Exit

Push $R3
Call TrimNewLines
Pop $R3

StrCmp $R3 "" Loop

StrCpy $R4 $R3 "" -1
StrCmp $R4 "]" 0 +6
StrCpy $R6 $R3 -1
StrLen $R4 $R6
IntOp $R4 $R4 - 1
StrCpy $R6 $R6 "" -$R4
Goto Loop

Push $R3
Call SplitFirstStrPart
Pop $R4
Pop $R5

WriteINIStr $R0 $R6 $R4 $R5

detailprint "$R6 $R4 $R5"

Goto Loop
Exit:

FileClose $R1

Pop $R6
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0
FunctionEnd



Note that you need all three functions!

Usage:
Push "update.ini"
Push "Os.ini"
Call ReadINIFileKeys

Adding it to archive.

-Stu
Afrow UK is offline   Reply With Quote
Old 27th July 2004, 13:33   #7
VegetaSan
Senior Member
 
VegetaSan's Avatar
 
Join Date: Jan 2004
Location: The Netherlands
Posts: 260
cool.. thanks alot Afrow UK .. you're tha man !!

VegetaSan....
VegetaSan is offline   Reply With Quote
Old 27th July 2004, 15:46   #8
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 6,950
Uhm, just noticed an error in the function.

Relace FileClose $R1 with FileClose $R2

Edit: and delete
detailprint "$R6 $R4 $R5"
(left in from testing)

-Stu
Afrow UK is offline   Reply With Quote
Old 27th July 2004, 15:54   #9
VegetaSan
Senior Member
 
VegetaSan's Avatar
 
Join Date: Jan 2004
Location: The Netherlands
Posts: 260
dont forget to update it in the archive too

VegetaSan....
VegetaSan is offline   Reply With Quote
Old 27th July 2004, 18:57   #10
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 6,950
Oh but of course

-Stu
Afrow UK is offline   Reply With Quote
Old 25th March 2008, 19:15   #11
AaronLS
Senior Member
 
Join Date: Mar 2008
Posts: 129
This is a great script but I couldn't get it to blank out an ini setting. I.E. merging in:
[SomeSection]
SomeKey=

often produces:
[SomeSection]
SomeKey=SomeKey=

It also seems to do strange things with comments sometimes. For example, if a comment ended with ] I think it treats it like a section name. So I added a check for lines that start with ; and skip those.

I have added skipping of comments. I think there might still be bugs if the semicolon is preceded by leading whitespace, but there are many apps that don't allow leading spaces in ini files anyhow.

I updated the script to work with the newer versions of SplitFirstStrPart, because the version used above does not properly parse "BlankValue=", but the newer version in the wiki does parse it correctly. All that was needed was a Push "=" for SplitFirstStrPart and renaming TrimNewLines to StrTrimNewLines.

code:

Function ReadINIFileKeys
Exch $R0 ;INI file to write
Exch
Exch $R1 ;INI file to read
Push $R2
Push $R3
Push $R4 ;uni var
Push $R5 ;uni var
Push $R6 ;last INI section

FileOpen $R2 $R1 r

Loop:
FileRead $R2 $R3 ;get next line into R3
IfErrors Exit

Push $R3
Call StrTrimNewLines
Pop $R3

StrCmp $R3 "" Loop ;if blank line, skip

StrCpy $R4 $R3 1 ;get first char into R4
StrCmp $R4 ";" Loop ;check it for semicolon and skip line if so(ini comment)

StrCpy $R4 $R3 "" -1 ;get last char of line into R4
StrCmp $R4 "]" 0 +6 ;if last char is ], parse section name, else jump to parse key/value
StrCpy $R6 $R3 -1 ;get all except last char
StrLen $R4 $R6 ;get str length
IntOp $R4 $R4 - 1 ;subtract one from length
StrCpy $R6 $R6 "" -$R4 ;copy all but first char to trim leading [, placing the section name in R6
Goto Loop

Push "=" ;push delimiting char
Push $R3
Call SplitFirstStrPart
Pop $R4
Pop $R5

WriteINIStr $R0 $R6 $R4 $R5

Goto Loop
Exit:

FileClose $R2

Pop $R6
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0
FunctionEnd


"I object to doing things that computers can do." -Olin Shivers
AaronLS is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:20.