PepiMK
24th September 2003 08:51 UTC
Where is SetFileTime?
I need to update the filetime of a file that is already installed (and will not be updated) during my installation.
Now I found GetFileTime in the NSIS documentation, but not one word on any SetFileTime :(
I could add that function to the source somehow most probably, but would like to hear first if there are any existing solutions for this? Thanks :)
kichik
24th September 2003 10:58 UTC
There is no built in command for that. If you want to change the modified time to the current time you can use this little script:
FileOpen $0 "C:\path\to\file" a
FileSeek $0 0 SET
FileReadByte $0 $1
FileSeek $0 0 SET
FileWriteByte $0 $1
FileClose $0
If you want to set it to another time you can use the System.dll plug-in and call SetFileTime directly.
PepiMK
24th September 2003 12:44 UTC
No, I need a specific date - that of the installer.
So I tried:
FileOpen $0 $EXEDIR\myinstaller.exe a
System::Call 'kernel32::GetFileTime(i, i, i, i) v (.r0, .r1, .r2, .r3)'
FileClose $0
FileOpen $0 $INSTDIR\mydatefile.zip a
System::Call 'kernel32::SetFileTime(i, *i, *i, *i) v (.r0, .r1, .r2, .r3)'
FileClose $0
Actually I would have to set a special date instead of the one from the installer, but if it doesn't even work this way, I'll have to look for some other way to go avoid this :(
kichik
24th September 2003 13:06 UTC
There are a few problems in that script:
- The installers name can be changed. You should process $CMDLINE or use GetModuleFileName to get the installer's name.
- GetFileTime requires pointers but you've passed on simple integers.
- Both GetFileTime and SetFileTime require pointers to FILETIME structures which is not the same size as an integer.
- The first parameter in both GetFileTime is for input not for output and therefore that dot before r0 is not supposed to be there.
- SetFileTime requires input, not output so the same dot position applies from the last point applies here too.
- Your installer is in use when running, you can't open it with append more, only read.
Here's a working script:
FileOpen $0 $EXEDIR\bla.exe r
System::Call 'kernel32::GetFileTime(i, *l, *l, *l) i (r0, .r1, .r2, .r3)'
FileClose $0
FileOpen $0 $EXEDIR\uninst.exe a
System::Call 'kernel32::SetFileTime(i, *l, *l, *l) i (r0, r1, r2, r3)'
FileClose $0
PepiMK
25th September 2003 12:54 UTC
Ok, I admit, I didn't fully understand System:Call (obviously) ;)
Thanks a lot for the working script!
TomWolle
22nd June 2008 14:03 UTC
Is it possible to do that during script compile time?
EDIT: nvm I found my answer