GetTime: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.) |
m (Added category links.) |
||
Line 195: | Line 195: | ||
FunctionEnd | FunctionEnd | ||
</highlight-nsis> | </highlight-nsis> | ||
[[{{ns:14}}:Disk, Path & File Functions]] |
Revision as of 22:18, 30 April 2005
Author: Instructor (talk, contrib) |
Links
- Latest version of headers "nsh.zip"
- http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost
If function used without header then put function in script before call it
The Function
/* ____________________________________________________________________________ GetTime v1.2 ____________________________________________________________________________ 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*/ ;--------------------------------------------------------------------------- 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 ClearErrors StrCmp $1 'L' gettime System::Call '*(i,l,l,l,i,i,i,i,&t260,&t14) i .r2' System::Call 'kernel32::FindFirstFileA(t,i)i(r0,r2) .r3' IntCmp $3 -1 error System::Call 'kernel32::FindClose(i)i(r3)' gettime: System::Call '*(&i2,&i2,&i2,&i2,&i2,&i2,&i2,&i2) i .r0' StrCmp $1 'L' 0 filetime System::Call 'kernel32::GetLocalTime(i)i(r0)' goto convert filetime: System::Call '*$2(i,l,l,l,i,i,i,i,&t260,&t14)i(,.r6,.r5,.r4)' StrCmp $1 'A' 0 +3 StrCpy $4 $5 goto +5 StrCmp $1 'C' 0 +3 StrCpy $4 $6 goto +2 StrCmp $1 'M' 0 error System::Call 'kernel32::FileTimeToLocalFileTime(*l,*l)i(r4,.r3)' System::Call 'kernel32::FileTimeToSystemTime(*l,i)i(r3,r0)' convert: System::Call '*$0(&i2,&i2,&i2,&i2,&i2,&i2,&i2,&i2)i\ (.r5,.r6,.r4,.r0,.r3,.r2,.r1,)' 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: StrCpy $0 '' StrCpy $1 '' StrCpy $2 '' StrCpy $3 '' StrCpy $4 '' StrCpy $5 '' StrCpy $6 '' SetErrors end: 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