Get Local Time as FILETIME for comparing with files
Description
The following functions show how to get the current local time in the FileTime format to enable comparison with file attributes, e.g. Creation, Last Access and Modification times of a file. The two functions rely on a SYSTEMTIME structure so you should include the following line in your script '!include "${NSISDIR}\Contrib\System\sysfunc.nsh"'
GetLocalAsFileTime
Description
The first function returns the actual FILETIME structure in two integers on the stack.
The Function
Function GetLocalAsFileTime ; Returns on the stack Low & High Integers of the FILETIME Structure of ; current local time Push $0 Push $1 Push $2 System::Call '*(stSYSTEMTIME) i .r1' System::Call '*(i, i) l .r0' System::Call 'kernel32::GetLocalTime(i) i(r1)' System::Call 'kernel32::SystemTimeToFileTime(i, l) l(r1, r0)' System::Call '*$0(i .r1, i .r2)' ; $1 contains the low order Int32 ; $2 contains the high order Int32 Push $1 Push $2 Exch 4 Exch Exch 3 Exch Exch 2 Pop $2 Pop $1 Pop $0 FunctionEnd
GetLocalAsInt64
Description
The second function goes one step further and converts the FILETIME structure into Int64 for easier manipulation.
The Function
Function GetLocalAsInt64 ; Returns on the stack Int64 of the FILETIME Structure of current local time Push $0 Push $1 Push $2 Push $3 System::Call '*(stSYSTEMTIME) i .r1' System::Call '*(i, i) l .r0' System::Call 'kernel32::GetLocalTime(i) i(r1)' System::Call 'kernel32::SystemTimeToFileTime(i, l) l(r1, r0)' System::Call '*$0(i .r1, i .r2)' ; $1 contains the low order Int32 ; $2 contains the high order Int32 System::Int64Op $2 * 4294967296 pop $3 System::Int64Op $3 + $1 Exch 4 Exch 3 Exch 2 Exch Pop $3 Pop $2 Pop $1 Pop $0 FunctionEnd
The Script
And the following script shows how to use these functions.
!include "${NSISDIR}\Contrib\System\sysfunc.nsh" ... Insert the Functions somewhere in the script ... Call GetLocalAsFileTime pop $R1 ;Now Contains the low order of FileTime pop $R2 ;Now Contains the high order of FileTime Call GetLocalAsInt64 pop $R3 ;Now Contains the Int64 of FileTime
These functions were made with a lot of help from kichik and brainsucker. Hope you find these functions of some help.
Vytautas
Page author: Vytautas