Page 1 of 1 1
Topic Options
#157255 - 2006-02-15 02:38 PM install-function - Logging breaks. [FIXED]
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
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.


Edited by ewook (2006-02-24 10:57 AM)

Top
#157256 - 2006-02-15 04:58 PM Re: install-function - Logging breaks.
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
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.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#157257 - 2006-02-15 04:59 PM Re: install-function - Logging breaks.
Stanley Offline
Starting to like KiXtart

Registered: 2004-06-03
Posts: 130
Loc: Upstate NY, USA
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)
_________________________
Taxation WITH representation isn't so hot, either!

Top
#157258 - 2006-02-15 09:08 PM Re: install-function - Logging breaks.
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#157259 - 2006-02-16 08:43 AM Re: install-function - Logging breaks.
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
Hehe, I know. That's just for my own amusement so I don't have to outcomment each section when I test.
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#157260 - 2006-02-16 08:51 AM Re: install-function - Logging breaks.
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
Thanks =)
I don't want the Police on my back yet ;P
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#157261 - 2006-02-16 08:52 AM Re: install-function - Logging breaks.
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
So, my changes should now make the big difference between working and not working now?
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#157262 - 2006-02-16 03:03 PM Re: install-function - Logging breaks.
Stanley Offline
Starting to like KiXtart

Registered: 2004-06-03
Posts: 130
Loc: Upstate NY, USA
Your third parameter in the function calls are not quoted.
Also liberally sprinkling the script with
? @ERROR+" "+@SERROR
May indicate where it is breaking.
_________________________
Taxation WITH representation isn't so hot, either!

Top
#157263 - 2006-02-16 03:22 PM Re: install-function - Logging breaks.
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.


Top
#157264 - 2006-02-16 04:42 PM Re: install-function - Logging breaks.
Stanley Offline
Starting to like KiXtart

Registered: 2004-06-03
Posts: 130
Loc: Upstate NY, USA
Or
? @ERROR
? @SERROR
_________________________
Taxation WITH representation isn't so hot, either!

Top
#157265 - 2006-02-16 05:10 PM Re: install-function - Logging breaks.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
'@@Error = ' + @Error ?
'@@SError = ' + @SError ?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#157266 - 2006-02-17 09:55 AM Re: install-function - Logging breaks.
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
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)
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#157267 - 2006-02-24 10:59 AM Re: install-function - Logging breaks.
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
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
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.065 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

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