Page 1 of 2 12>
Topic Options
#135753 - 2005-03-16 03:08 PM How do I make the ReadProfileString jump over...
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Hi out there gurus,

How do I make the ReadProfileString jump over the invalid part of an ini file? I dont want to modify the ini file!

The ini file contains SW product data:

[117410EA-BEBF-36A3-5C0C-4DD136A22BCA]
SWName=WinAmp
Version=5.0
File=\\AppSrv\SWdisp\Winamp.msi
.
.
.
and so on

Suddenly a line key is empty:

[]
SWName=AcrobatReader
Version=6.0
File=\\AppSrv\SWdisp\AcroB.msi

I want ReadProfileString to jump over this part and continue to next product key in the ini file.

How to define code? sample please
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#135754 - 2005-03-16 03:16 PM Re: How do I make the ReadProfileString jump over...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I don't understand what's the problem.
ini-files don't get readen like that.
they are read per section.
if you don't wanna read... hmm.
ok, problems may occure if it indeed is zerolength. as that is exactly the same thing that matches "all the sections"

zero length section is illegal and indeed should break the ini totally.
_________________________
!

download KiXnet

Top
#135755 - 2005-03-17 12:20 AM Re: How do I make the ReadProfileString jump over...
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Okey, let me restate:

Here is a content of target ini file:

[117410EA-BEBF-36A3-5C0C-4DD136A22BCA]
SWName=WinAmp
Version=5.0
File=\\AppSrv\SWdisp\Winamp.msi

[345410EB-AFCF-16C3-6B1C-7BD234C22CA]
SWName=WinRar
Version=3.4
File=\\AppSrv\SWdisp\Wrar.msi

[] <------- here comes the problem
SWName=AcrobatReader
Version=6.0
File=\\AppSrv\SWdisp\AcroB.msi

[154236AC-CBFF-56A3-7A1B-3CC134B12AA]
SWName=MS AntiSpyware
Version=1
File=\\AppSrv\SWdisp\MsAsw.msi

ReadProfileString will read the first 2 section. fine no problem.
Section 3 has an invalid/empty product key []. Here everything ends, which is normal cause the returned value is zero.
As result everything after section 3 will not be listed as I want.
What Im trying to do is to simply jump over the invalid section 3 and make ReadProfileString to continue on section 4, which contains valid data.
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#135756 - 2005-03-17 12:34 AM Re: How do I make the ReadProfileString jump over...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
While you cannot enum the sections beyond the illegal one, if you provide the section name for any beyond, you can still enum or read keys.

Is it that you don't know the section names and you need to enum all of them? There are some UDFs posted that should be able to do that for you.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135757 - 2005-03-17 12:47 AM Re: How do I make the ReadProfileString jump over...
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Unfortunately I don't know the section names beyond. I try find a UDF, but still not found any which I could get ideas from... Will do more searches...
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#135758 - 2005-03-17 12:54 AM Re: How do I make the ReadProfileString jump over...
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I know there was at least one UDF posted that used ReadLine() to process an INI file, but I think it either got deleted or moved to scripts after it was critiqued for not using ReadProfileString().

That said, there is no reason why you cannot basically do the same or similar. I would start by using the ReadFile() UDF, http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=83675 to read the INI file into an array and then either process it that way or fix the illegal section and write it out to a temporary file so that ReadProfileString() can be used on it.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135759 - 2005-03-17 04:41 AM Re: How do I make the ReadProfileString jump over...
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You should rather have the .INI file or the generating program fixed so that no illegally formatted .INI files are being generated in the first place.
_________________________
There are two types of vessels, submarines and targets.

Top
#135760 - 2005-03-17 09:47 AM Re: How do I make the ReadProfileString jump over...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I vote for that too.
_________________________
!

download KiXnet

Top
#135761 - 2005-03-17 01:31 PM Re: How do I make the ReadProfileString jump over...
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Me 2 ... But I dont have rights or required access to do that. The responsible will fix this on next update, which I dont want to wait that long...

I do know which section is invalid. shouldnt it be easy to use If state to jump over that part?
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#135762 - 2005-03-17 02:37 PM Re: How do I make the ReadProfileString jump over...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
there is no jump stuff in the ini-definition.
there is no lines either.
ini has strict format and mostly because of that, it's liked so much.

you could simply do a replace on it:
Code:
 
$=open(1,mytext.ini)
$=open(2,mytext_fixed.ini,5)
do
if "[]"=$line ;if line has nothing more than [] in it, it must be the break point, fix it.
$line="[_bad_]"
endif
$=writeline(2,$line+@crlf)
$line=readline(1)
until @error



this way no need to tweak anything, right?
_________________________
!

download KiXnet

Top
#135763 - 2005-03-17 02:41 PM Re: How do I make the ReadProfileString jump over...
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
This little script should grab the valid section names from your ini file - not very robust but should get you going.

Code:

$yourIni = 'c:\blah.ini'
$sections =''
$ = open(1,$yourIni)
$line = trim(readline(1))
while @error = 0
if left($line,1) = '[' and len($line)>2
$sections = $sections + ',' + substr($line,2,len($line)-2)
endif
$line = trim(readline(1))
loop

$sections = substr($sections,2)
for each $section in split($sections,',')
? $section
next

_________________________
Eric

Top
#135764 - 2005-03-17 02:47 PM Re: How do I make the ReadProfileString jump over...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hehee!
my script is shorter, and it does not include word "should" and it's robust

1pt to me.
_________________________
!

download KiXnet

Top
#135765 - 2005-03-17 03:04 PM Re: How do I make the ReadProfileString jump over...
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
I'm a bit late to the party, but...

This script will return all the sections, entries and values as an array that you can enumerate.

It also returns all the bad sections and entries, including malformed sections and entries with no values.

Code:
$=SetOption("Explicit","ON")

Dim $sIniFile,$asIniCollection,$asIniItem

$sIniFile="\path\to\myinifile.ini"

$asIniCollection=EnumIni($sIniFile)
For Each $asIniItem in $asIniCollection
?
"Section: '" $asIniItem[0] "'" ?
"Key : '" $asIniItem[1] "'" ?
"Value : '" $asIniItem[2] "'" ?
Next

Function EnumIni($sIniFile)
Dim $fd,$sLine
Dim $aEntry[3]
$fd=FreeFileHandle()
If @ERROR Exit @ERROR EndIf
If Open($fd,$sIniFile) Exit @ERROR EndIf
$sLine=ReadLine($fd)
While Not @ERROR
$sLine=LTrim($sLine)
If $sLine<>"" AND Left($sLine,1)<>";"
$aEntry[1]=""
$aEntry[2]=""
If Left($sLine,1)="["
$aEntry[0]=SubStr($sLine,2,InStr($sLine+"]","]")-2)
Else
$aEntry[1]=Left($sLine,InStr($sLine+"=","=")-1)
$aEntry[2]=SubStr($sLine,Len($aEntry[1])+2)
Redim Preserve $EnumIni[UBound($EnumIni)+1]
$EnumIni[UBound($Enumini)]=$aEntry
EndIf
EndIf
$sLine=ReadLine($fd)
Loop
EndFunction


Top
#135766 - 2005-03-17 03:15 PM Re: How do I make the ReadProfileString jump over...
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
I said "should" because I don't take into account the fact that you can comment out lines (sections) in an ini file with a ";".

By the way, won't your script insert a blank line at the beginning of your new ini?
_________________________
Eric

Top
#135767 - 2005-03-17 03:21 PM Re: How do I make the ReadProfileString jump over...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
in ini file, blank is just as good as no blank.
in english, it doesn't matter.
and yes, it does.
_________________________
!

download KiXnet

Top
#135768 - 2005-03-17 03:28 PM Re: How do I make the ReadProfileString jump over...
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
I know, i was just giving you sh*%. Anyway, 1984 has plenty of options now
_________________________
Eric

Top
#135769 - 2005-03-17 04:18 PM Re: How do I make the ReadProfileString jump over...
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Oh yeah.... I played with maciep code and it works.
But now problem occers on opposite way :-)
will not work if the ini file dont have any "invalid" section.
Now lets check the Richards and Jooels code...

Fun kix is (when u know how to do!)
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#135770 - 2005-03-18 02:00 PM Re: How do I make the ReadProfileString jump over...
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Ok. i vote for Jooel code. simple and shorter.

Replaced "[_bad_]" with "" and added $=close(1) and $=close(2) to end of code.

Now Im happy...
cheers folks
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#135771 - 2005-03-18 02:57 PM Re: How do I make the ReadProfileString jump over...
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I thought also that you will change that bad part.
anyways, if there is some info in that section, it will be lost if you remove the header part...
but, if it's just a garbage insert, then that is the obvious way, ofcourse.

and thanks for choosing the golfers approach
_________________________
!

download KiXnet

Top
#135772 - 2005-03-21 02:59 PM Re: How do I make the ReadProfileString jump over...
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Sumi rockers! U R good...
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.159 seconds in which 0.116 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org