Archive: get info from update.ini


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 :


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


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

_______________________________________________________

Os.ini :


[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:


[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

ah sorry never mind .. allready got it .. stupid me >_<


ok .lol .. I still got a question. Will this work?


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

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


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)


Done!

 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

cool.. thanks alot Afrow UK .. you're tha man !! :D


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


dont forget to update it in the archive too


Oh but of course :)

-Stu


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.


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