Break on
Dim $sGolfScoreUDF, $bGolfScore, $sKiXgolfUDF, $sKiXGolfUDF, $sOutputFile
Dim $sTitle, $iRC, $sKiXGolfScrEngVer
Dim $sStartTimeDate, $sEndTimeDate, $sRunTime
Dim $iKiXGolfScore[3], $sOutput, $sResult
Dim $cpuTime,$ProcessorTimeSpent,$ConsColor
Dim $asTests, $sOutput, $sINIFile, $sTestResult, $sTest
Dim $iTests, $iPass, $iFail, $asInput
$sTitle='Fragmentation'
$iRC=SetTitle('KiXtart Golf: '+$sTitle)
$iRC=SetOption('Explicit','on')
$iRC=SetOption('NoVarsInStrings','on')
$iRC=SetOption('WrapAtEOL','on')
$iRC=SetOption('CaseSensitivity','on')
CLS
$ConsColor = @COLOR
$sGolfScoreUDF=@scriptdir+'\'+'kixgolf3.udf'
If Exist($sGolfScoreUDF)
Call $sGolfScoreUDF
$bGolfScore=1
Else
$bGolfScore=0
EndIf
$sKiXGolfScrEngVer = '3.0.3'
$sKiXGolfUDF=@scriptdir+'\kixgolf_fragmentation.udf'
Call $sKiXGolfUDF
$sOutputFile=@scriptdir+'\'+Left(@scriptname,InStrRev(@scriptname,'.'))+'txt'
$iRC=RedirectOutput($sOutputFile,1)
? '[code]'
$iRC=RedirectOutput('')
$sINIFile=@scriptdir+'\'+Left(@scriptname,InStrRev(@scriptname,'.'))+'ini'
$asTests=Split(ReadProfileString($sINIFile,'',''),Chr(10))
$iTests=Ubound($asTests)
ReDim preserve $asTests[$iTests-1]
$iPass=0
$iFail=0
$sStartTimeDate=@DATE+' '+@TIME+'.'+Right('000'+@MSECS,3)
$cpuTime = processorTime()
For Each $sTest in $asTests
$asInput=Split(ReadProfileString($sINIFile,$sTest,'In'),',')
$sOutput=''+ReadProfileString($sINIFile,$sTest,'Out')
? $sTest " "
$sTestResult=''+F($asInput)
If $sTestResult=$sOutput
"passed"
$iPass=$iPass+1
Else
Color R/N
"FAILED "
Color $ConsColor
"(should be:" $sOutput ", but was: " $sTestResult ")"
$iFail=$iFail+1
EndIf
Next
$sEndTimeDate=@DATE+' '+@TIME+'.'+Right('000'+@MSECS,3)
$ProcessorTimeSpent = processorTime(,,$cpuTime)
$sRunTime=datetimediff($sStartTimeDate, $sEndTimeDate)
If $bGolfScore
$iKiXGolfScore=KiXGolf($sKiXGolfUDF)
Else
$iKixGolfScore=''
EndIf
$sOutput=''
$sOutput=$sOutput+@CRLF+'KiXtart Engine'
$sOutput=$sOutput+@CRLF+'KiXtart Version = '+@KIX+' (' + @SCRIPTEXE + ')'
$sOutput=$sOutput+@CRLF+'KiXGolf Script = '+@SCRIPTNAME
$sOutput=$sOutput+@CRLF+' '
$sOutput=$sOutput+@CRLF+'Computer'
$sOutput=$sOutput+@CRLF+'OS = '+@PRODUCTTYPE
$sOutput=$sOutput+@CRLF+'CPU = '+@CPU
$sOutput=$sOutput+@CRLF+'Speed = '+@MHZ+' MHz'
$sOutput=$sOutput+@CRLF+'Memory = '+(Round(Cdbl(MemorySize(0))/2)*2)+' MB'
$sOutput=$sOutput+@CRLF+' '
$sOutput=$sOutput+@CRLF+'KiXGolf Scoring Engine'
$sOutput=$sOutput+@CRLF+'Scoring Engine = '+$sKiXGolfScrEngVer
$sOutput=$sOutput+@CRLF+' '
$sOutput=$sOutput+@CRLF+'KiXGolf Score'
$sOutput=$sOutput+@CRLF+'Tournament = '+$sTitle
$sOutput=$sOutput+@CRLF+'Processing Start = '+$sStartTimeDate
$sOutput=$sOutput+@CRLF+'Processing End = '+$sEndTimeDate
$sOutput=$sOutput+@CRLF+'Duration = '+$sRunTime
$sOutput=$sOutput+@CRLF+'Used Processor Time = '+serialtime($ProcessorTimeSpent)
$sOutput=$sOutput+@CRLF+'# Tests Run = '+$iTests
$sOutput=$sOutput+@CRLF+'# Tests Passed = '+$iPass
$sOutput=$sOutput+@CRLF+'# Tests Failed = '+$iFail
$sOutput=$sOutput+@CRLF+'Result = '+IIf($iPass = $iTests,'passed','FAILED')
$sOutput=$sOutput+@CRLF+'KiXGolf Score = '+$iKiXGolfScore
$sOutput=$sOutput+@CRLF+' '
$sOutput=$sOutput+@CRLF+'Thank you for participating in KiXtart Golf!'
$iRC=RedirectOutput($sOutputFile,0)
? $sOutput+@CRLF+'[/code]'
$iRC=RedirectOutput('')
? $sOutput
If @SCRIPTEXE='WKIX32.EXE'
? 'Press any key to continue...'
Get $iRC
EndIf
Exit 0
Function datetimediff($time1,$time2)
Dim $date1, $date2, $datediff, $timediff
$datetimediff=''
If Not InStr($time1,' ')
Select
Case InStr($time1,'/')
$time1=$time1+' 00:00:00.000'
Case InStr($time1,':')
$time1=@DATE+' '+$time1
Case 1
Exit 87
EndSelect
EndIf
If Not InStr($time2,' ')
Select
Case InStr($time2,'/')
$time2=$time2+' '+@TIME+'.'+Right('000'+@MSECS,3)
Case InStr($time2,':')
$time2=@DATE+' '+$time2
Case 1
$time2=@DATE+' '+@TIME+'.'+Right('000'+@MSECS,3)
EndSelect
EndIf
$time1=Split($time1,' ')
$date1=$time1[0]
$time1=$time1[1]
$time2=Split($time2,' ')
$date2=$time2[0]
$time2=$time2[1]
$datediff=serialdate($date2)-serialdate($date1)
$timediff=serialtime($time2)-serialtime($time1)
If $timediff=>86400
$timediff=$timediff-86400
$datediff=$datediff+1
EndIf
$datediff=serialdate(serialdate('0000/00/00')+$datediff-1)
$timediff=serialtime($timediff)
$datetimediff=$datediff+' '+$timediff
Exit 0
EndFunction
Function serialdate($ExpD)
Dim $z,$h,$a,$b,$c,$y,$m,$d
If InStr($ExpD,'/')
$ExpD=Split($ExpD,'/')
$y=Val($ExpD[0])
$m=Val($ExpD[1])
$d=Val($ExpD[2])
If $m<3
$m=$m+12
$y=$y-1
EndIf
$SerialDate=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306
Else
$z=0+$ExpD+306
$h=100*$z-25
$a=$h/3652425
$b=$a-$a/4
$y=(100*$b+$h)/36525
$c=$b+$z-365*$y-$y/4
$m=(5*$c+456)/153
$d=$c-(153*$m-457)/5
If $m>12
$y=$y+1
$m=$m-12
EndIf
$SerialDate=Right('0000'+$y,4)+'/'+Right('00'+$m,2)+'/'+Right('00'+$d,2)
EndIf
EndFunction
Function serialtime($strtime)
Dim $hours, $minutes, $seconds, $milliseconds
If InStr($strtime,':')
$strtime=Split($strtime,':')
Select
Case Ubound($strtime)<3
ReDim preserve $strtime[3]
If InStr($strtime[2],'.')
$strtime[3]=Right($strtime[2],Len($strtime[2])-InStr($strtime[2],'.'))
$strtime[2]=Left($strtime[2],InStr($strtime[2],'.')-1)
Else
$strtime[3]=0
EndIf
Case Ubound($strtime)>3
$serialtime=-1
Exit 87
EndSelect
$hours=Val($strtime[0])
If $hours<0 Or $hours>23
$serialtime=-1
Exit 87
EndIf
$minutes=Val($strtime[1])
If $minutes<0 Or $minutes>59
$serialtime=-1
Exit 87
EndIf
$seconds=Val($strtime[2])
If $seconds<0 Or $seconds>59
$serialtime=-1
Exit 87
EndIf
$milliseconds=Cdbl($strtime[3])
If $milliseconds<0 Or $milliseconds>999
$serialtime=-1
Exit 87
EndIf
$serialtime=0.0+($hours*3600)+($minutes*60)+($seconds)+($milliseconds/1000)
Else
$strtime=Val(Cdbl($strtime)*1000)
If $strtime<=86400000 And $strtime>=0
$hours=$strtime/3600/1000
$strtime=$strtime-($hours*3600*1000)
$hours=Right('00'+$hours,2)
$minutes=$strtime/60/1000
$strtime=$strtime-($minutes*60*1000)
$minutes=Right('00'+$minutes,2)
$seconds=$strtime/1000
$strtime=$strtime-($seconds*1000)
$seconds=Right('00'+$seconds,2)
$milliseconds=Left($strtime,3)
$milliseconds=Right('000'+$milliseconds,3)
$serialtime=$hours+':'+$minutes+':'+$seconds+'.'+$milliseconds
Else
$serialtime='-1'
Exit 87
EndIf
EndIf
EndFunction
Function numberformat($number,$digits)
Dim $comma
$comma=ReadValue('HKEY_CURRENT_USER\Control Panel\International','sDecimal')
$digits=Val($digits)
If $digits<0
$digits=0
EndIf
$number=''+Round(Cdbl($number),$digits)
If Not InStr($number,$comma)
$number=$number+$comma
EndIf
$number=Split($number,$comma)
If $digits=0
$numberformat=$number[0]
Return
EndIf
While Len($number[1])<$digits
$number[1]=$number[1]+'0'
Loop
$number=Join($number,$comma)
$numberformat=$number
EndFunction
Function ProcessorTime(optional $pid, $machine, $differ)
Dim $objItem
If VarType($pid) = 0 $pid = @pid EndIf
If VarType($machine) = 0 $machine = "." EndIf
For Each $objItem in GetObject("winmgmts:\\" + $machine + "\root\cimv2").ExecQuery("Select * from Win32_Process where processID = " + $pid,,48)
$processorTime = (0.0 + $objItem.KernelModeTime + $objItem.UserModeTime)/10000000
Next
If VarType($differ) $processorTime = $processorTime - $differ EndIf
EndFunction
Function atrim($array)
Dim $element, $maxelements, $arraydim, $rc, $a
Select
Case Ubound($array,1)=-1
$array=Trim($array)
Case Ubound($array,2)=-1
$maxelements=Val(Ubound($array))
For $element=0 to $maxelements
$array[$element]=Trim($array[$element])
Next
Case Ubound($array,27)=-1
$arraydim=0
Do
$arraydim=$arraydim+1
Until Ubound($array,$arraydim)=-1
$arraydim=$arraydim-1
If $arraydim<=26
Dim $cmd, $vars
$vars='$sub_a'
For $a=2 to $arraydim
$vars=$vars+', $sub_'+Chr($a+96)
Next
$cmd='dim '+$vars+@CRLF
For $a=1 to $arraydim
$cmd=$cmd+'for $sub_'+Chr($a+96)+'=0 to ubound($array,'+$a+')'+@CRLF
Next
$cmd=$cmd+'$array['+$vars+']=trim($array['+$vars+'])'+@CRLF
For $a=1 to $arraydim
$cmd=$cmd+'next'+@CRLF
Next
$rc=Execute($cmd)
EndIf
Case 1
EndSelect
$atrim=$array
EndFunction