Working Installation CompletionTime function: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author and download links, and changed format of some pages.)
m (Updated author links.)
Line 1: Line 1:
{|align=right
|<small>Author: [[{{ns:2}}:Afrow UK|Afrow UK]] ([[{{ns:3}}:Afrow UK|talk]], [[{{ns:-1}}:Contributions/Afrow UK|contrib]])</small>
|}
<br style="clear:both;">
== Description ==
== Description ==
This function gets the start and finish (completion) times of the installation process.
This function gets the start and finish (completion) times of the installation process.
Line 218: Line 222:


-Stu
-Stu
Page author: [[User:Afrow UK|Afrow UK]]

Revision as of 03:06, 30 April 2005

Author: Afrow UK (talk, contrib)


Description

This function gets the start and finish (completion) times of the installation process.

This is a replacement for the old one (that used GetFileTime) which did not work correctly on an installation time of over 1 minute. This script works up to a 24 hour installation period!

This function needs testing, so if you find any problems then please PM me on the NSIS forums or email me (afrowuk@tiscali.co.uk)

Usage 1

# this goes at the start of the first section
Push start ;signifies to start counting
Push 0 ;output mode (finish only)
Call CompletionTime
Pop $0 ;current time (xx:xx:xx)
Pop $1 ;current time (xx:xx:xx)
DetailPrint "Start Time: $1"

Usage 2

# this goes at the end of the last section
Push finish ;signifies to finish & report completion time
Push 3;output mode (1=secs only|2=secs+mins only|3=all)
Call CompletionTime
Pop $0 ;completed time (x hours, x mins, x secs.)
Pop $1 ;current time (xx:xx:xx)
DetailPrint "Finish Time: $1"
DetailPrint "Completed In: $0"

The Function

Function CompletionTime
Exch $0 ;output mode
Exch
Exch $1 ;start or finish
Push $2 ;universal
Push $3 ;universal
Push $4 ;universal
Push $R0 ;temp
Push $R1 ;hours
Push $R2 ;mins
Push $R3 ;secs
 
StrCpy $R0 $0 ;store output mode
StrCpy $R1 0 ;hours
StrCpy $R2 0 ;mins
StrCpy $R3 0 ;secs
StrCpy $R4 0 ;hours (day)
 
StrCmp $1 start 0 finish
 
# save start time
System::Call '*(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2) i .r1'
System::Call 'kernel32::GetLocalTime(i) i(r1)'
System::Call '*$1(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2) \
(,,,, .r3, .r2, .r1,)'
  StrLen $4 $1
  StrCmp $4 1 0 +2
   StrCpy $1 0$1
  StrLen $4 $2
  StrCmp $4 1 0 +2
   StrCpy $2 0$2
  StrLen $4 $3
  StrCmp $4 1 0 +2
   StrCpy $3 0$3
 StrCpy $0 "$3:$2:$1"
 
  WriteINIStr "$TEMP\completiontime.tmp" "Time" "Value" "$0"
 
  Goto done2
 
finish:
# get finish time
System::Call '*(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2) i .r1'
System::Call 'kernel32::GetLocalTime(i) i(r1)'
System::Call '*$1(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2) \
(,,,, .r3, .r2, .r1,)'
  StrLen $4 $1
  StrCmp $4 1 0 +2
   StrCpy $1 0$1
  StrLen $4 $2
  StrCmp $4 1 0 +2
   StrCpy $2 0$2
  StrLen $4 $3
  StrCmp $4 1 0 +2
   StrCpy $3 0$3
 StrCpy $0 "$3:$2:$1"
 
# get start time
  ReadINIStr $1 "$TEMP\completiontime.tmp" "Time" "Value"
   StrCmp $1 "" error
 
# get hours
StrCpy $3 $1 2 -8 ;get start hour chunk
StrCpy $2 $0 2 -8 ;get finish hour chunk
 
IntCmp $2 $3 0 +3 +6
 StrCpy $R1 0
Goto +5
 IntOp $R1 60 - $3
 IntOp $R1 $2 + $3
Goto +2
 IntOp $R1 $2 - $3
 
# get minutes
StrCpy $3 $1 2 -5 ;get start minutes chunk
StrCpy $2 $0 2 -5 ;get finish minutes chunk
 
IntCmp $2 $3 0 +3 +6
 StrCpy $R2 0
Goto +5
 IntOp $R2 60 - $3
 IntOp $R2 $2 + $3
Goto +2
 IntOp $R2 $2 - $3
 
# get seconds
StrCpy $3 $1 2 -2 ;get start seconds chunk
StrCpy $2 $0 2 -2 ;get finish seconds chunk
 
IntCmp $2 $3 0 +3 +6
 StrCpy $R3 0
Goto +5
 IntOp $R3 60 - $3
 IntOp $R3 $2 + $3
Goto +2
 IntOp $R3 $2 - $3
 
# check times
StrCmp $R0 1 0 +6
 IntOp $R1 $R1 * 60 ;convert to minutes
 IntOp $R2 $R2 + $R1 ;add to minutes
 IntOp $R2 $R2 * 60 ;convert to seconds
 IntOp $R3 $R3 + $R2 ;add to seconds
Goto +4
 
StrCmp $R0 2 0 +3
 IntOp $R1 $R1 * 60 ;convert to minutes
 IntOp $R2 $R2 + $R1 ;add to minutes
 
# do hours
StrCmp $R0 2 skip_hours
StrCmp $R0 1 skip_hours
IntCmp $R1 0 +6 0 0
IntCmp $R1 1 0 +3 +3
 StrCpy $R1 "$R1 hour, "
Goto +4
 StrCpy $R1 "$R1 hours, "
Goto +2
skip_hours:
 StrCpy $R1 ""
 
# do minutes
StrCmp $R0 1 skip_minutes
IntCmp $R2 0 +6 0 0
IntCmp $R2 1 0 +3 +3
 StrCpy $R2 "$R2 minute, "
Goto +4
 StrCpy $R2 "$R2 minutes, "
Goto +2
skip_minutes:
 StrCpy $R2 ""
 
# do seconds
IntCmp $R3 0 +6 0 0
IntCmp $R3 1 0 +3 +3
 StrCpy $R3 "$R3 second. "
Goto +4
 StrCpy $R3 "$R3 seconds. "
Goto +2
 StrCpy $R3 ""
 
StrCpy $0 "$R1$R2$R3"
 
Goto done
 
error:
StrCpy $0 "Error: No installation start time found!"
 
done:
SetDetailsPrint none
 IfFileExists "$TEMP\completiontime.tmp" 0 +2
  Delete "$TEMP\completiontime.tmp"
SetDetailsPrint both
 
done2:
 Push $0 ;backup old string
System::Call '*(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2) i .r1'
System::Call 'kernel32::GetLocalTime(i) i(r1)'
System::Call '*$1(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2) \
(,,,, .r3, .r2, .r1,)'
  StrLen $4 $1
  StrCmp $4 1 0 +2
   StrCpy $1 0$1
  StrLen $4 $2
  StrCmp $4 1 0 +2
   StrCpy $2 0$2
  StrLen $4 $3
  StrCmp $4 1 0 +2
   StrCpy $3 0$3
 StrCpy $1 "$3:$2:$1"
 Pop $0 ;restore backup
 
Pop $R3
Pop $R2
Pop $R1
Pop $R0
Pop $4
Pop $3
Pop $2
Exch $1 ;current time (start and finish)
Exch
Exch $0 ;current time (start) or completion time (finish)
FunctionEnd

-Stu