Björn
(Korg Regular)
2006-02-15 02:38 PM
install-function - Logging breaks. [FIXED]

Elo again.
Been working on something that's gonna be used temp. for installation, but - I know I've done things wrong. One example of that is that in each functioncall, it's supposed to write a simple logfile, or just add a line in a existent file.
For some of the installs/uninstalls I call, it does... So, what am I doing so darn wrong here?
I'll shoot ya the code:

Code:

;******************* INSTALLS *******************
;prg_inst("key","\\searchpath",prgname,$NT or $XP, optional file, optional version on file);,$TriggerGROUP)
;INSTALLS - WITH file-ver check.
;prg_inst("regentry...\someprogram","C:\kix\someprogram.exe /Silent",someprogram,$NT,"c:\program files\someprogram\someexec.exe","6.6");,$TriggerGROUP)

;******************* UNINSTALLS *******************

prg_uninst("regentry...\someprog","uninstallstring",someprog,$NT) ;,$TriggerGROUP)
;---------------------------------
function prg_inst($prgkey,$prgpath,$prgname,$InstOS,optional $execfile,optional $execversion);,$TriggerGROUP)
dim $prgkey,$prgpath,$prgname,$execfile,$execversion,$filver,$j,$logpath,$i,$instok,$wr ;$TriggerGROUP

$logpath="C:\kix\inst_logs\" + $prgname + ".log"
'@@Error = ' + @Error ?
'@@SError = ' + @SError ?
? $logpath ?
sleep 2
$instok=0
$j=0
$i=0
if @ProductType = $InstOS
'@@Error = ' + @Error ?
'@@SError = ' + @SError ?
?"prodtype"
sleep 1
;if INGROUP($TriggerGROUP)
if $execfile <> ""
'@@Error = ' + @Error ?
'@@SError = ' + @SError ?
$filver = GETFILEVERSION( $execfile , "ProductVersion" )
$filver ?; - Installed file-version
$execversion ?; - fileversion set in func
if $execversion > $filver ; if fileversion set in func is higher then installed file-version,
$j=1 ; j equals 1
else
$j=0 ; j equals 0
endif
endif
If NOT keyexist($prgkey) AND $j=0
"Installing $prgname, please hold.(no key, and j=0)" ?
shell $prgpath
? $prgpath ?
'@@Error = ' + @Error ?
'@@SError = ' + @SError ?
if keyexist($prgkey)
$instok=1

else
'@@Error = ' + @Error ?
'@@SError = ' + @SError ?
endif
endif

if $instok=1
$Handle=FreeFileHandle()

if $Handle > 0
Open($Handle ,$logpath, 5 )
$wr=WriteLine($Handle,"Program installed on: "+ @WKSTA +" at "+@TIME+" on "+@DATE+@CRLF)
$wr=close($Handle)

else

'@@Error = ' + @Error ?
'@@SError = ' + @SError ?

endif
endif

endif

endfunction

;---------------------------------

;prg_uninst - For uninstallation

function prg_uninst($prgkey,$prgpath,$prgname,$instOS);,TriggerGROUP)
dim $prgkey, $prgpath, $prgname,$deletekey,$unlogpath,$ij,$wr ;$TriggerGROUP

$ij=0
$unlogpath="C:\kix\uninst_logs\" + $prgname + ".log"
? $unlogpath ?
if @ProductType = $InstOS AND keyexist($prgkey)
;If INGROUP($TriggerGROUP)
?"Uninstalling $prgname, please hold." ?
shell $prgpath
sleep 1

if keyexist($prgkey)
$deletekey = DELTREE($prgkey)
if @error = 0
$ij=1
endif

if not $deletekey = 0
'@@Error = ' + @Error ?
'@@SError = ' + @SError ?
? "Error occured when trying to delete key!"
endif

else
$ij=1

endif

;endif

if $ij=1
$Handle=FreeFileHandle()
if $Handle > 0
Open($Handle,$unlogpath , 5 )
$wr=WriteLine($Handle,"Program uninstalled on: "+ @WKSTA +" at "+@TIME+" on "+@DATE+@CRLF)
$wr=close($Handle)
endif
endif

endif

Endfunction




edit1: added close(3)
edit2: currently using
'@@Error = ' + @Error ?
'@@SError = ' + @SError ?
Edit3:
Finally working!
The bugg was my if-statements that tied a knot on a variable, and for some reason the statements returned false. - Fixed.
Added FreeFileHandle() to get rid of any mixups with already open filenumbers.


Gargoyle
(MM club member)
2006-02-15 04:58 PM
Re: install-function - Logging breaks.

You keep trying to open the file, and with your conditional it would be not true as it will see the file as allready open and thow an error back.

Either open the file at the beginning, or close the file within the function call.


Stanley
(Starting to like KiXtart)
2006-02-15 04:59 PM
Re: install-function - Logging breaks.

WriteLine(3,"Program installed on: + @WKSTA | @TIME | @DATE | @CRLF")
Should be
WriteLine(3,"Program installed on: "+ @WKSTA +" at "+@TIME+" on "+@DATE+@CRLF)
Otherwise you may call down the wrath of the STRING POLICE.
Seriously though Macros and Variables should never be inside strings. This can cause hard to trace errors.
Also you should close any open files after you are done with them.
IE CLOSE(3)


Mart
(KiX Supporter)
2006-02-15 09:08 PM
Re: install-function - Logging breaks.

The first section (INSTALLS) will never run because just above that you set $install to 0. So checking if $install equals 1 will always be false so the stuff after the if $install = 1 will never run.

Björn
(Korg Regular)
2006-02-16 08:43 AM
Re: install-function - Logging breaks.

Hehe, I know. That's just for my own amusement so I don't have to outcomment each section when I test.

Björn
(Korg Regular)
2006-02-16 08:51 AM
Re: install-function - Logging breaks.

Thanks =)
I don't want the Police on my back yet ;P


Björn
(Korg Regular)
2006-02-16 08:52 AM
Re: install-function - Logging breaks.

So, my changes should now make the big difference between working and not working now?

Stanley
(Starting to like KiXtart)
2006-02-16 03:03 PM
Re: install-function - Logging breaks.

Your third parameter in the function calls are not quoted.
Also liberally sprinkling the script with
? @ERROR+" "+@SERROR
May indicate where it is breaking.


Richard H.Administrator
(KiX Supporter)
2006-02-16 03:22 PM
Re: install-function - Logging breaks.

Quote:

? @ERROR+" "+@SERROR
May indicate where it is breaking




That won't work as expected. @ERROR returns a long, which will make the expression numeric. As a result you won't ever see the value of @SERROR.

Either explicitly cast the return value to a string, or coerce it:
Code:
CStr(@ERROR)+" "+@SERROR+@CRLF ; Explicit.
"["+@ERROR+"] "+@SERROR+@CRLF ; Coerced.



Stanley
(Starting to like KiXtart)
2006-02-16 04:42 PM
Re: install-function - Logging breaks.

Or
? @ERROR
? @SERROR


Les
(KiX Master)
2006-02-16 05:10 PM
Re: install-function - Logging breaks.

'@@Error = ' + @Error ?
'@@SError = ' + @SError ?


Björn
(Korg Regular)
2006-02-17 09:55 AM
Re: install-function - Logging breaks.

hmm, not to sound to stupid, but does it need to be?

I've sprayed some
Code:

'@@Error = ' + @Error ?
'@@SError = ' + @SError ?



And going to deal with the output later on today (got my ... hands full with other things right now)


Björn
(Korg Regular)
2006-02-24 10:59 AM
Re: install-function - Logging breaks.

Seems like I've found the errors in my coding.
Now I just need to go thro it again to check that it accually does what I want ;P