File Modified Date and Time: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Created page.)
 
m (FF: use <highlight-nsis> instead of a list. Added "Page author" line.)
Line 8: Line 8:
== Function call: ==
== Function call: ==


*'''Push''' ''"[path/]file.ext"'' ;File or folder
<highlight-nsis>
*'''Call''' ''FileModifiedDate''
Push "[path/]file.ext" ;File or folder
*'''Pop''' ''"$var1"'' ;Variable (for year)
Call FileModifiedDate
*'''Pop''' ''"$var2"'' ;Variable (for month)
Pop "$var1" ;Variable (for year)
*'''Pop''' ''"$var3"'' ;Variable (for day)
Pop "$var2" ;Variable (for month)
*'''Pop''' ''"$var4"'' ;Variable (for day of week name)
Pop "$var3" ;Variable (for day)
*'''Pop''' ''"$var5"'' ;Variable (for hour)
Pop "$var4" ;Variable (for day of week name)
*'''Pop''' ''"$var6"'' ;Variable (for minute)
Pop "$var5" ;Variable (for hour)
*'''Pop''' ''"$var7"'' ;Variable (for seconds)
Pop "$var6" ;Variable (for minute)
Pop "$var7" ;Variable (for seconds)
</highlight-nsis>


== The function: ==
== The function: ==
 
<highlight-nsis>
<highlight-nsis>;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; Superseded by    : GetTime function.
; Superseded by    : GetTime function.
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
Line 159: Line 161:
   Exch 6
   Exch 6


FunctionEnd</highlight-nsis>
FunctionEnd
</highlight-nsis>
 
Page author: [[User:deguix|deguix]]

Revision as of 19:59, 29 April 2005

Description

Superseded by: GetTime function.
Required: System Plugin.

This function returns a file or folder modified date and time.

Function call:

Push "[path/]file.ext" ;File or folder
Call FileModifiedDate
Pop "$var1" ;Variable (for year)
Pop "$var2" ;Variable (for month)
Pop "$var3" ;Variable (for day)
Pop "$var4" ;Variable (for day of week name)
Pop "$var5" ;Variable (for hour)
Pop "$var6" ;Variable (for minute)
Pop "$var7" ;Variable (for seconds)

The function:

;----------------------------------------------------------------------------
; Superseded by     : GetTime function.
;----------------------------------------------------------------------------
; Title             : File modified date and time
; Short Name        : FileModifiedDate
; Last Changed      : 21/Feb/2005
; Code Type         : Function
; Code Sub-Type     : Normal
;----------------------------------------------------------------------------
; Required          : System plugin.
; Description       : Returns a file or folder modified date and time.
;----------------------------------------------------------------------------
; Function Call     : Push "[path/]file.ext"
;                       File or folder to get modified date and time.
;
;                     Call FileModifiedDate
;
;                     Pop "$Variable1"
;                       Year.
;
;                     Pop "$Variable2"
;                       Month.
;
;                     Pop "$Variable3"
;                       Day.
;
;                     Pop "$Variable4"
;                       Day of the week name.
;
;                     Pop "$Variable5"
;                       Hour.
;
;                     Pop "$Variable6"
;                       Minute.
;
;                     Pop "$Variable7"
;                       Second.
;----------------------------------------------------------------------------
; Author            : Diego Pedroso
; Author Reg. Name  : deguix
;----------------------------------------------------------------------------
 
Function FileModifiedDate
 
  # Prepare variables
  Exch $0
  Push $1
  Push $2
  Push $3
  Push $4
  Push $5
  Push $6
  Push $7
  Push $R0
 
  # Original System Example (with no dependencies)
 
  ; create WIN32_FIND_DATA struct
  System::Call '*(i, l, l, l, i, i, i, i, &t260, &t14) i .r2'
 
  ; Find file info
  System::Call 'kernel32::FindFirstFileA(t, i) i(r0, r2) .r3'
 
  ; ok?
  IntCmp $3 -1 sgfst_exit
 
    ; close file search
    System::Call 'kernel32::FindClose(i) i(r3)'
 
    ; Create systemtime struct for local time
    System::Call '*(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2) i .R0'
 
    ; Get File time
    System::Call '*$2(i, l, l, l, i, i, i, i, &t260, &t14) i (,,, .r3)'
 
    ; Convert file time (UTC) to local file time
    System::Call 'kernel32::FileTimeToLocalFileTime(*l, *l) i(r3, .r1)'
 
    ; Convert file time to system time
    System::Call 'kernel32::FileTimeToSystemTime(*l, i) i(r1, R0)'
 
    sgfst_exit:
 
  System::Call '*$R0(&i2, &i2, &i2, &i2, &i2, &i2, &i2, &i2)i \
  (.r4, .r5, .r3, .r6, .r2, .r1, .r0,)'
 
  # Day of week: convert to name
  StrCmp $3 0 0 +3
    StrCpy $3 Sunday
      Goto WeekNameEnd
  StrCmp $3 1 0 +3
    StrCpy $3 Monday
      Goto WeekNameEnd
  StrCmp $3 2 0 +3
    StrCpy $3 Tuesday
      Goto WeekNameEnd
  StrCmp $3 3 0 +3
    StrCpy $3 Wednesday
      Goto WeekNameEnd
  StrCmp $3 4 0 +3
    StrCpy $3 Thursday
      Goto WeekNameEnd
  StrCmp $3 5 0 +3
    StrCpy $3 Friday
      Goto WeekNameEnd
  StrCmp $3 6 0 +2
    StrCpy $3 Saturday
  WeekNameEnd:
 
  # Minute: convert to 2 digits format
	IntCmp $1 9 0 0 +2
	  StrCpy $1 '0$1'
 
  # Second: convert to 2 digits format
	IntCmp $0 9 0 0 +2
	  StrCpy $0 '0$0'
 
  # Return to user
  Pop $R0
  Exch $6
  Exch
  Exch $5
  Exch
  Exch 2
  Exch $4
  Exch 2
  Exch 3
  Exch $3
  Exch 3
  Exch 4
  Exch $2
  Exch 4
  Exch 5
  Exch $1
  Exch 5
  Exch 6
  Exch $0
  Exch 6
 
FunctionEnd

Page author: deguix