GetTime
From NSIS Wiki
Jump to navigationJump to search
| Author: Instructor (talk, contrib) |
Links
- Latest version of headers "nsh.zip"
- http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost
If a function is used without header, put the function code in your script before calling it.
The Function Description
____________________________________________________________________________
GetTime v1.3
____________________________________________________________________________
Thanks Takhir (Script "StatTest") and deguix (Function "FileModifiedDate")
Features:
1. Get local time.
2. Get file time (access, creation and modification).
Syntax:
${GetTime} "[File]" "[Option]" $var1 $var2 $var3 $var4 $var5 $var6 $var7
"[File]" ; Ignored if "L"
;
"[Option]" ; [Options]
; L Local time
; A last Access file time
; C Creation file time
; M Modification file time
;
$var1 ; Result1: day
$var2 ; Result2: month
$var3 ; Result3: year
$var4 ; Result4: day of week name
$var5 ; Result5: hour
$var6 ; Result6: minute
$var7 ; Result7: seconds
Note:
-Error flag if file isn't exist
-Error flag if syntax error
Example (Get local time):
Section ${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6 ; $0="01" day ; $1="04" month ; $2="2005" year ; $3="Friday" day of week name ; $4="16" hour ; $5="05" minute ; $6="50" seconds MessageBox MB_OK 'Date=$0/$1/$2 ($3)$\nTime=$4:$5:$6' SectionEnd
Example (Get file time):
Section ${GetTime} "$WINDIR\Explorer.exe" "C" $0 $1 $2 $3 $4 $5 $6 ; $0="12" day ; $1="10" month ; $2="2004" year ; $3="Tuesday" day of week name ; $4="2" hour ; $5="32" minute ; $6="03" seconds IfErrors 0 +2 MessageBox MB_OK "Error" IDOK +2 MessageBox MB_OK 'Date=$0/$1/$2 ($3)$\nTime=$4:$5:$6' SectionEnd
The Function Code
Function GetTime !define GetTime `!insertmacro GetTimeCall` !macro GetTimeCall _FILE _OPTION _R1 _R2 _R3 _R4 _R5 _R6 _R7 Push `${_FILE}` Push `${_OPTION}` Call GetTime Pop ${_R1} Pop ${_R2} Pop ${_R3} Pop ${_R4} Pop ${_R5} Pop ${_R6} Pop ${_R7} !macroend Exch $1 Exch Exch $0 Exch Push $2 Push $3 Push $4 Push $5 Push $6 Push $7 ClearErrors StrCmp $1 'L' gettime StrCmp $1 'A' getfile StrCmp $1 'C' getfile StrCmp $1 'M' getfile goto error getfile: IfFileExists $0 0 error System::Call '*(i,l,l,l,i,i,i,i,&t260,&t14) i .r6' System::Call 'kernel32::FindFirstFileA(t,i)i(r0,r6) .r2' System::Call 'kernel32::FindClose(i)i(r2)' gettime: System::Call '*(&i2,&i2,&i2,&i2,&i2,&i2,&i2,&i2) i .r7' StrCmp $1 'L' 0 filetime System::Call 'kernel32::GetLocalTime(i)i(r7)' goto convert filetime: System::Call '*$6(i,l,l,l,i,i,i,i,&t260,&t14)i(,.r4,.r3,.r2)' System::Free $6 StrCmp $1 'A' 0 +3 StrCpy $2 $3 goto +3 StrCmp $1 'C' 0 +2 StrCpy $2 $4 System::Call 'kernel32::FileTimeToLocalFileTime(*l,*l)i(r2,.r3)' System::Call 'kernel32::FileTimeToSystemTime(*l,i)i(r3,r7)' convert: System::Call '*$7(&i2,&i2,&i2,&i2,&i2,&i2,&i2,&i2)i\ (.r5,.r6,.r4,.r0,.r3,.r2,.r1,)' System::Free $7 IntCmp $0 9 0 0 +2 StrCpy $0 '0$0' IntCmp $1 9 0 0 +2 StrCpy $1 '0$1' IntCmp $2 9 0 0 +2 StrCpy $2 '0$2' IntCmp $6 9 0 0 +2 StrCpy $6 '0$6' StrCmp $4 0 0 +3 StrCpy $4 Sunday goto end StrCmp $4 1 0 +3 StrCpy $4 Monday goto end StrCmp $4 2 0 +3 StrCpy $4 Tuesday goto end StrCmp $4 3 0 +3 StrCpy $4 Wednesday goto end StrCmp $4 4 0 +3 StrCpy $4 Thursday goto end StrCmp $4 5 0 +3 StrCpy $4 Friday goto end StrCmp $4 6 0 error StrCpy $4 Saturday goto end error: SetErrors StrCpy $0 '' StrCpy $1 '' StrCpy $2 '' StrCpy $3 '' StrCpy $4 '' StrCpy $5 '' StrCpy $6 '' end: Pop $7 Exch $6 Exch Exch $5 Exch 2 Exch $4 Exch 3 Exch $3 Exch 4 Exch $2 Exch 5 Exch $1 Exch 6 Exch $0 FunctionEnd