Old 17th October 2011, 20:59   #1
Lloigor
Junior Member
 
Join Date: Oct 2011
Posts: 9
Thumbs up Time difference between two files - ${FileTimeDiff}

I thought maybe this can be useful to some.. works great for me.

PHP Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 
Get the difference between two file times
;; P1 :iFile name A.
;; 
P2 :iFile name B.
;; 
P3 :oNumber of seconds between the two filescan be negative of positive
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
!
define FileTimeDiff "!insertmacro _FileTimeDiff"
!macro _FileTimeDiff _File1_ _File2_ _Diff_
   Push 
$0  ;; File Search Handle File Time (UTC) (100 ns unit64bit int)
   
Push $3  ;; File Info (struct) / File-2 Time (UTC) (Seconds)
   
Push $4  ;; File-1 Time (UTC) (Seconds)

   
System::Call '*(i, l, l, l, i, i, i, i, &t260, &t14) i .r3'  ;; Create WIN32_FIND_DATA Struct

   
!insertmacro ___FileTimeUTCSeconds "${_File1_}"  ;; Get File1 UTC Time in Seconds
   Pop 
$4
   
!insertmacro ___FileTimeUTCSeconds "${_File2_}"  ;; Get File2 UTC Time in Seconds
   Pop 
$3
   System
::Int64Op $- $3                          ;; Calculate File Time Difference
   Pop 
$0

   _ftdexit
:
   
Pop $4
   Pop 
$3
   Exch 
$0
   Pop 
${_Diff_}
!
macroend
!macro ___FileTimeUTCSeconds _File_
   System
::Call 'kernel32::FindFirstFileA(t, i) i("${_File_}", r3) .r0'  ;; Find file info
   IntCmp 
$-1 0 0 +4  ;; if handle <= -not ok
      Push 
""
      
Pop $0
      
Goto _ftdexit     ;; do not even check the other file
;; Else (valid handle)
      
System::Call 'kernel32::FindClose(i) i(r0)'  ;; Close file search

      System
::Call '*$3(i, l, l, l, i, i, i, i, &t260, &t14) i (,,, .r0)'  ;; Get File time
      System
::Int64Op $10000000  ;; Conversion From '100 ns' >TO'1 sec' unit
!macroend

ex.: ${FileTimeDiff} "${SAVEDIR}\${FILETOCHECK}" "${BKPDIR}${BKPNUM}\${FILETOCHECK}" $0


Just began nsis scripting about a month ago, so feel free to suggest a better coding for this.
.
Lloigor is offline   Reply With Quote
Old 18th October 2011, 05:20   #2
T.Slappy
Major Dude
 
T.Slappy's Avatar
 
Join Date: Jan 2006
Location: Slovakia
Posts: 530
Send a message via ICQ to T.Slappy
Nice work!
Maybe you could add new parameter where user could choose which times to compare?
Example:
1: ftCreationTime;
2: ftLastAccessTime;
3: ftLastWriteTime;

Do not forget to add this article to wiki!

Cool looking installer with custom design: www.graphical-installer.com
I offer NSIS scripting, C/C++/C#/Delphi programming: www.unsigned.sk
Develop NSIS projects in Visual Studio 2005-2019: www.visual-installer.com
or RAD Studio 2009, 2010, XE-10.3 Rio: www.rad-installer.com
T.Slappy is offline   Reply With Quote
Old 20th October 2011, 18:09   #3
Lloigor
Junior Member
 
Join Date: Oct 2011
Posts: 9
Added.
http://nsis.sourceforge.net/FileTimeDiff
Also made it 3-modes.
Lloigor is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
difference, file, filetimediff, seconds, time

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump