Archive: ini hierarchy, string comparison and such.


ini hierarchy, string comparison and such.
  wondering how i might modify my install script to do a simple string comparison to add a new line in a an ini file. i'm braincramped right now, and can't seem to figure it out. here's my problem:

i write a line to an existing section of my UT2003.ini file. there are preceding lines of the same type (key). in order to preserve hiearchical dependance, my key needs to be at the end; i.e;

[Engine.GameEngine]
CacheSizeMegs=32
UseSound=True
ServerActors=IpDrv.MasterServerUplink
ServerActors=UWeb.WebServer
ServerPackages=Fire
ServerPackages=Editor
ServerPackages=TeamSymbols_UT2003
ServerPackages=MyPackage **

** new line ( ServerPackages=MyPackage ) needs to be written under the preceding entries (rather than at the top, where it is defaulting to)

how might i do that?
i know i've got to use push, pop and exch, but i'm at a loss in finding examples i can understand.

thanks in advance.


nm. found it.
  FileOpen $0 "file.txt" r
GetTempFileName $R0
FileOpen $1 $R0 w
loop:
FileRead $0 $2
IfErrors done
StrCmp $2 "line to replace$\r$\n" 0 +3
FileWrite $1 "replacement of line$\r$\n"
Goto loop
FileWrite $1 $2
Goto loop

done:
FileClose $0
FileClose $1
Delete "file.txt"
CopyFiles /SILENT $R0 "file.txt"
Delete $R0


hi. ok. that works, but now i want to first check if the line isn't already there. can't seem tot wrap my mind around that, however...

could i get some help with this please?
i'd found this: http://205.188.244.9/showthread.php?s=&postid=630801
however, now i need to possibly ignore/write over an ini value...
my script:


Section ""
FileOpen $0 "$INSTDIR\System\UT2003.ini" r
GetTempFileName $R0
FileOpen $1 $R0 w
loop:
FileRead $0 $2
IfErrors done
StrCmp $2 "MainMenuClass=XInterface.UT2MainMenu$\r$\n" 0 +3
FileWrite $1 "ServerPackages=MyPackage$\r$\nMainMenuClass=XInterface.UT2MainMenu$\r$\n"
Goto loop
FileWrite $1 $2
Goto loop
done:
FileClose $0
FileClose $1
Delete "$INSTDIR\System\UT2003.ini"
CopyFiles /SILENT $R0 "$INSTDIR\System\UT2003.ini"
Delete $R0
WriteINIStr "$INSTDIR\System\UT2003.ini" "MyPackage.MyPackageTab_IA" "LastGoalScore" "8"
SectionEnd

Use:


ClearErrors

FileOpen$0 "file" "r"
>loop:
FileRead $0 $1
IfErrors done
StrCmp$1 "some line$\r$\n" 0 loop
StrCpy$2 1
done
: FileClose $0
>
If $2's value is "1" after this peice of code, the line was found in the file.

i still don't get it.

the nifty little piece of code you wrote there checks if the line is there... you say if $2's value is "1" after this peice of code...

i still have to *check* if that's true.. right?
so there's code left to add there.. something like:

StrCmp $2 1 blah
blah:
OtherThingToDo

am i correct?


also, the code i'm using above (the rather longish block of code which you formatted so nicely! :) makes my installer hesitate and jump while reporting its progress. it also reports some worrisome details like "deleted: yourini.ini"

is there a more elegant way to do what i'm trying to do? like something more compact that doesn't generate all these temp file that need to be cleaned up? essentially, i want to test if:
"ServerPackages=MyPackage$\r$\n"
exists. if not, then add it in *above* this line:
"MainMenuClass=XInterface.UT2MainMenu$\r$\n"

thank you kichik!!


this is what i have now, and it's not working :(

; write the ini file!
Section ""

ClearErrors

FileOpen $0 "$INSTDIR\System\UT2003.ini" "r"
testloop:
FileRead $0 $1
IfErrors checkdone
StrCmp $1 "ServerPackages=MyPackage$\r$\n" 0 testloop
StrCpy $2 1
checkdone: FileClose $0

StrCmp $2 "1" finish WriteNewIniLine

WriteNewIniLine:
ClearErrors

FileOpen $0 "$INSTDIR\System\UT2003.ini" "r"
GetTempFileName $R0
FileOpen $1 $R0 w
loop:
FileRead $0 $2
IfErrors done
StrCmp $2 "MainMenuClass=XInterface.UT2MainMenu$\r$\n" 0 +3
FileWrite $1 "ServerPackages=MyPackage$\r$\nMainMenuClass=XInterface.UT2MainMenu$\r$\n"
Goto loop
FileWrite $1 $2
Goto loop
done:
FileClose $0
FileClose $1
Delete "$INSTDIR\System\UT2003.ini"
CopyFiles /SILENT $R0 "$INSTDIR\System\UT2003.ini"
Delete $R0

finish:
WriteINIStr "$INSTDIR\System\UT2003.ini" "TeamFreeze.MyPackageTab_IA" "LastGoalScore" "8"
SectionEnd


To make the progress indicator ignore those commands put them in a function and call that function from the section. To hide the output use SetDetailsPrint.

What do you mean by not working? Do you mean it prints those delete messages and jumps the progress bar or is it something else?


what i mean by not working is that the above code will write the line even if (and i don't know that above code is correctly checking/comparing) it finds the line i'm searching for.

unreal tournament re-uses ini variables.
so i've got many lines of "Serverpackages=SomePackage" in my ini.
however, if you look in my code above i'm checking for the existance of:
Serverpackages=MyPackage
and i was trying to get the script to skip to the next label if it found that line. unfortunately, it writes it anyway and so i end up with two entries of the same line in my ini:
Serverpackages=MyPackage
Serverpackages=MyPackage

btw, how would i silently call the function that contains the code?


SetDetailsPrint none
Call FunctionName
SetDetailsPrint both

I will look at the code again tomorrow because right now I can't see anything wrong with it (2 AM here, I sure have missed something ;) )...


great. can't wait to hear back on that!


sorry, the above works fine
  thanks again!


Great! Good luck with your mod/map, send us a link when the installer is ready :D


Team Freeze 2003
  http://www.badgergoose.com/teamfreeze/index.html


I don't have UT2003 so I can't test it, but I did notice two things: it doesn't check if you have UT2003 and it doesn't delete the readme on uninstall.