GetTimeStamp: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (moved Function GetTimeStamp to GetTimeStamp: Rename)
 
(2 intermediate revisions by the same user not shown)
Line 5: Line 5:
=== Example ===
=== Example ===
<highlight-nsis>
<highlight-nsis>
Call GetTimeStamp
${TimeStamp} $0
Pop $0
DetailPrint "TimeStamp=$0"
DetailPrint "TimeStamp=$0"
</highlight-nsis>
</highlight-nsis>
Line 12: Line 11:
== Function Source ==
== Function Source ==
<highlight-nsis>
<highlight-nsis>
Function GetTimeStamp
### TimeStamp
      
!ifndef TimeStamp
    !define TimeStamp "!insertmacro _TimeStamp"
    !macro _TimeStamp FormatedString
        !ifdef __UNINSTALL__
            Call un.__TimeStamp
        !else
            Call __TimeStamp
        !endif
        Pop ${FormatedString}
    !macroend
 
!macro __TimeStamp UN
Function ${UN}__TimeStamp
     ClearErrors
     ## Store the needed Registers on the stack
     ## Store the needed Registers on the stack
         Push $0 ; Stack $0
         Push $0 ; Stack $0
Line 23: Line 35:
         Push $6 ; Stack $6 $5 $4 $3 $2 $1 $0
         Push $6 ; Stack $6 $5 $4 $3 $2 $1 $0
         Push $7 ; Stack $7 $6 $5 $4 $3 $2 $1 $0
         Push $7 ; Stack $7 $6 $5 $4 $3 $2 $1 $0
         Push $8 ; Stack $8 $7 $6 $5 $4 $3 $2 $1 $0
         ;Push $8 ; Stack $8 $7 $6 $5 $4 $3 $2 $1 $0
   
     ## Call System API to get the current system Time
     ## Call System API to get the current system Time
         System::Alloc 16
         System::Alloc 16
         Pop $0
         Pop $0
         System::Call 'kernel32::GetLocalTime(i) i(r0)'
         System::Call 'kernel32::GetLocalTime(i) i(r0)'
         System::Call '*$0(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2)i (.r1, .r2, .r3, .r4, .r5, .r6, .r7, .r8)'
         System::Call '*$0(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2)i (.r1, .r2, n, .r3, .r4, .r5, .r6, .r7)'
         System::Free $0
         System::Free $0
   
       
        IntFmt $2 "%02i" $2
        IntFmt $3 "%02i" $3
        IntFmt $4 "%02i" $4
        IntFmt $5 "%02i" $5
        IntFmt $6 "%02i" $6
       
     ## Generate Timestamp
     ## Generate Timestamp
         StrCpy $0 $1$2$4$5$6$7.$8
         ;StrCpy $0 "YEAR=$1$\nMONTH=$2$\nDAY=$3$\nHOUR=$4$\nMINUITES=$5$\nSECONDS=$6$\nMS$7"
   
        StrCpy $0 "$1$2$3$4$5$6.$7"
     ## Restore the Registers and add Timestamp to the Stack
     ## Restore the Registers and add Timestamp to the Stack
         Pop $8  ; Stack $7 $6 $5 $4 $3 $2 $1 $0
         ;Pop $8  ; Stack $7 $6 $5 $4 $3 $2 $1 $0
         Pop $7  ; Stack $6 $5 $4 $3 $2 $1 $0
         Pop $7  ; Stack $6 $5 $4 $3 $2 $1 $0
         Pop $6  ; Stack $5 $4 $3 $2 $1 $0
         Pop $6  ; Stack $5 $4 $3 $2 $1 $0
Line 44: Line 63:
         Pop $2  ; Stack $1 $0
         Pop $2  ; Stack $1 $0
         Pop $1  ; Stack $0
         Pop $1  ; Stack $0
         Push $0 ; Stack ${TimeStamp} $0
         Exch $0 ; Stack ${TimeStamp}
        Exch    ; Stack $0 ${TimeStamp}
   
        Pop $0 ; Stack ${TimeStamp}
   
FunctionEnd
FunctionEnd
!macroend
!insertmacro __TimeStamp ""
!insertmacro __TimeStamp "un."
!endif
###########
</highlight-nsis>
</highlight-nsis>

Latest revision as of 22:19, 12 June 2009

Usage

Format

  • YYYYMMDDHHmmSS.xxxx

Example

${TimeStamp} $0
DetailPrint "TimeStamp=$0"

Function Source

### TimeStamp
!ifndef TimeStamp
    !define TimeStamp "!insertmacro _TimeStamp"
    !macro _TimeStamp FormatedString
        !ifdef __UNINSTALL__
            Call un.__TimeStamp
        !else
            Call __TimeStamp
        !endif
        Pop ${FormatedString}
    !macroend
 
!macro __TimeStamp UN
Function ${UN}__TimeStamp
    ClearErrors
    ## Store the needed Registers on the stack
        Push $0 ; Stack $0
        Push $1 ; Stack $1 $0
        Push $2 ; Stack $2 $1 $0
        Push $3 ; Stack $3 $2 $1 $0
        Push $4 ; Stack $4 $3 $2 $1 $0
        Push $5 ; Stack $5 $4 $3 $2 $1 $0
        Push $6 ; Stack $6 $5 $4 $3 $2 $1 $0
        Push $7 ; Stack $7 $6 $5 $4 $3 $2 $1 $0
        ;Push $8 ; Stack $8 $7 $6 $5 $4 $3 $2 $1 $0
 
    ## Call System API to get the current system Time
        System::Alloc 16
        Pop $0
        System::Call 'kernel32::GetLocalTime(i) i(r0)'
        System::Call '*$0(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2)i (.r1, .r2, n, .r3, .r4, .r5, .r6, .r7)'
        System::Free $0
 
        IntFmt $2 "%02i" $2
        IntFmt $3 "%02i" $3
        IntFmt $4 "%02i" $4
        IntFmt $5 "%02i" $5
        IntFmt $6 "%02i" $6
 
    ## Generate Timestamp
        ;StrCpy $0 "YEAR=$1$\nMONTH=$2$\nDAY=$3$\nHOUR=$4$\nMINUITES=$5$\nSECONDS=$6$\nMS$7"
        StrCpy $0 "$1$2$3$4$5$6.$7"
 
    ## Restore the Registers and add Timestamp to the Stack
        ;Pop $8  ; Stack $7 $6 $5 $4 $3 $2 $1 $0
        Pop $7  ; Stack $6 $5 $4 $3 $2 $1 $0
        Pop $6  ; Stack $5 $4 $3 $2 $1 $0
        Pop $5  ; Stack $4 $3 $2 $1 $0
        Pop $4  ; Stack $3 $2 $1 $0
        Pop $3  ; Stack $2 $1 $0
        Pop $2  ; Stack $1 $0
        Pop $1  ; Stack $0
        Exch $0 ; Stack ${TimeStamp}
 
FunctionEnd
!macroend
!insertmacro __TimeStamp ""
!insertmacro __TimeStamp "un."
!endif
###########