Archive: Question about VPatch


Question about VPatch
When I use VPatch to patch a file, it will modified file CreationTime to LastWriteTime. I want to save the CreationTime so I search MSDN for GetFileTime and SetFileTime but not work.

My code:
FileOpen $1 "$INSTDIR\newfile.txt" r
System::Call '*(&i2, &i2) i .r0'
System::Call 'kernel32::GetFileTime(i, i, i, i) i (r1, r0,,) .r9'
vpatch::vpatchfile "$PLUGINSDIR\patch.pat" "$INSTDIR\oldfile.txt" "$INSTDIR\newfile.txt"
System::Call 'kernel32::SetFileTime(i, i, i, i) i (r1, r0,,) .r8'
System::Free $0
FileClose $1
StrCmp $8 0 +2
DetailPrint "Success!"


Try this one (as I didn't):

FileOpen $9 "$INSTDIR\newfile.txt" r
System::Call '*(i, i) i .r0'
System::Call '*(i, i) i .r1'
System::Call 'kernel32::GetFileTime(i, *l, *l, *l) i (r9, r0, r1,)'
FileClose $9

vpatch::vpatchfile "$PLUGINSDIR\patch.pat" "$INSTDIR\oldfile.txt" "$INSTDIR\newfile.txt"

FileOpen $9 "$INSTDIR\newfile.txt" r
System::Call 'kernel32::SetFileTime(i, *l, *l, *l) i (r9, r0, r1,) .r8'
System::Free $0
System::Free $1
FileClose $9

StrCmp $8 0 +2
DetailPrint "Success!"

Tested, but not work :(


try this:

FileOpen $9 "$INSTDIR\newfile.txt" r
System::Call '*(i, i) i .r0'
System::Call '*(i, i) i .r1'
System::Call 'kernel32::GetFileTime(i, *l, *l, *l) i (r9, r0, r1,)'
FileClose $9

vpatch::vpatchfile "$PLUGINSDIR\patch.pat" "$INSTDIR\oldfile.txt" "$INSTDIR\newfile.txt"

FileOpen $9 "$INSTDIR\newfile.txt" w
System::Call 'kernel32::SetFileTime(i, *l, *l, *l) i (r9, r0, r1,) .r8'
System::Free $0
System::Free $1
FileClose $9

StrCmp $8 0 +2
DetailPrint "Success!"

I modified VPatch source to save the FileTime, in vpatchdll.c header:
#include <Winbase.h>
FILETIME ftCreate, ftWrite;

and change:

result = DoPatch(hPatch, hSource, hDest);

to:

GetFileTime(hSource, &ftCreate, NULL, &ftWrite);
result = DoPatch(hPatch, hSource, hDest);
SetFileTime(hDest, &ftCreate, NULL, &ftWrite);

Comm@nder21's code I am not test, because modified the source is easy, I thinks. And the FileOpen w flags will destroy the newfile. thanks.


Modifying the source may be easy for now, but unless you submit it to Kichik for inclusion in CVS, either you are stuck with your modified version forever, with no updates or your modified version will be overwritten the next time you update NSIS.
Using the scripted method is a better solution, imo.


OK. The modified plugins in attach file.
VPatch.dll is in "NSIS\Plugins"
Readme.html is in "NSIS\Contrib\VPatch"
vpatchdll.c is in "NSIS\Contrib\VPatch\Source\Plugin"

The vpatchfile function not change, and a new function SmartPatch add to keep the file time while patch. :)