- NSIS Discussion
- File versions help
Archive: File versions help
Afrow UK
25th May 2003 11:56 UTC
File versions help
I'm going to have to use GetFileTime to do this...
I have jeff.wal in 1>C:\textures
I also have jeff.wal in 2>C:\temp\textures
If jeff.wal in dir1 is newer than jeff.wal in dir2, then I want to copy jeff.wal across to update jeff.wal in dir2.
Is this possible with GetFileTime?
All I currently can do is if GetFileTime of jeff.wal in dir1 is different to GetFileTime of jeff.wal in dir2 (StrCmp), then copy across.
The problem is, jeff.wal in dir2 may be newer than jeff.wal in dir1, therefore the old file will overwrite the newer one.
-Stu
deguix
25th May 2003 12:41 UTC
Yes, you have only to compare the first DWORD given of the C:\textures one with the first of the C:\temp\textures one jeff.wal, if the result is equal, compare second of the DWORD give with each one. So will be like this:
[EDIT]
# $0 is "C:\\Textures\\jeff.wal", $1 is "C:\\Temp\\Textures\\jeff.wal" (results of the custom page)
# Get File Times in two 32-bits DWORDs
>GetFileTime $0 $R0 $R1
GetFileTime$1 $R2 $R3
># Now compare
>IntCmp $R2 $R0 0 Old New
>IntCmp $R3 $R1 Same Old New
># Put the codes here
>Old: ;If the first file is new than the second
CopyFiles$1 $0
Goto EndComparation
>New: ;If the second file is new than the first
CopyFiles$0 $1
Goto EndComparation
Same
: ;If the two are equal (nothing to do here)
>EndComparation: ;The end of the comparation, put normal codes here
>
[/EDIT]
kichik
25th May 2003 14:18 UTC
Comparing the first DWORD is not enough. The first DWORD can only contain 2^32 which is around 430,000 seconds which is only 120 hours.
Comparing the two DWRODs as shown in this example is a lot better. Two DWORDs give you a resulotion of 58494241 years.
Afrow UK
25th May 2003 14:20 UTC
If file 2 is newer than file 1, then I don't want to copy file 2 over file 1
I'll just replace
IntCmp $R2 $R0 0 Old New
IntCmp $R3 $R1 Same Old New
with
IntCmp $R2 $R0 0 Old 0
IntCmp $R3 $R1 Same Old Same
And remove the new copy bit
-Stu
Afrow UK
25th May 2003 14:22 UTC
But how would I go about changing that script that Kichik has shown me - I don't want to use GetFileTime local.
What script shall I use?
-Stu
kichik
25th May 2003 14:25 UTC
GetFileTimeLocal and GetFileTime return the same values, therefor you can just change GetFileTimeLocal to GetFileTime.
deguix
25th May 2003 14:47 UTC
Kichik, I compare the two DWORDs.
AfrowUK, if is new, I will don't want to compare the second DWORD, because it is not needed. Only if the first DWORD of the two files are equal.
And to fix the code:
[EDIT]Ops, don't need the goto[/EDIT]
# I want to detect only if the file 1 is new to overwrite the 2.
# $0 is "C:\Textures\jeff.wal", $1 is "C:\Temp\Textures\jeff.wal" (results of the custom page)
# Get File Times in two 32-bits DWORDs
>GetFileTime $0 $R0 $R1
GetFileTime$1 $R2 $R3
># Now compare
>IntCmp $R0 $R2 0 EndComparation +2
IntCmp $R1 $R3 EndComparation EndComparation 0
># If is new
>CopyFiles $0 $1
EndComparation
: ;The end of the comparation, put normal codes here
>
I don't put the IntCmpU because these DWORDs can be negative.
kichik
25th May 2003 14:50 UTC
Right, sorry, my bad.
Afrow UK
25th May 2003 15:15 UTC
Well, here it is then!
# Copy
StrCmp ${INPUT_DIR2} "" skipcopy2
IfFileExists "${INPUT_DIR1}\env\$2*" 0 skipcopy2
FindFirst $R1 $R2 "${INPUT_DIR2}\env\$2*"
IfErrors errorcopy2
DetailPrint "File env\$7$R2"
IfFileExists "${OUTPUT_DIR}\env\$7$R2" 0 copyfile2_1
GetFileTime "${INPUT_DIR2}\env\$7$R2" $R0 $R1
GetFileTime "${OUTPUT_DIR}\env\$7$R2" $R2 $R3
IntCmp $R0 $R2 0 copyloop2 +2
IntCmp $R1 $R3 copyloop2 copyloop2 0
Delete "${OUTPUT_DIR}\env\$7$R2"
copyfile2_1:
CopyFiles "${INPUT_DIR2}\env\$7$R2" "${OUTPUT_DIR}\env\$7$R2"
copyloop2:
FindNext $R1 $R2
IfErrors donecopy2
DetailPrint "File env\$7$R2"
IfFileExists "${OUTPUT_DIR}\env\$7$R2" 0 copyfile2_2
GetFileTime "${INPUT_DIR2}\env\$7$R2" $R0 $R1
GetFileTime "${OUTPUT_DIR}\env\$7$R2" $R2 $R3
IntCmp $R0 $R2 0 copyloop2 +2
IntCmp $R1 $R3 copyloop2 copyloop2 0
Delete "${OUTPUT_DIR}\env\$7$R2"
copyfile2_2:
CopyFiles "${INPUT_DIR2}\env\$7$R2" "${OUTPUT_DIR}\env\$7$R2"
Goto copyloop2
donecopy2:
ClearErrors
FindClose $R1
Goto skipcopy2
errorcopy2:
FindClose $R1
DetailPrint "Error: No $2 in ${INPUT_DIR2}"
skipcopy2:
-Stu :o