Archive: VPatch--Patch Directly


VPatch--Patch Directly
I found VPatch can only path the source file to a new file.
I want to patch the source file directly and create a backup of it.

Here is the my code of vpatchdll.c:


static char source[1024];
static char dest[1024];
static char exename[1024];
HANDLE hPatch, hSource, hDest;
int result;

//added by Shao Hao - update source file directly and create a backup to dst file.
popstring(exename);
if (!lstrcmpi(exename, "/replace")) { // replace mode
popstring(exename);
popstring(dest);
popstring(source);

if (!MoveFile(dest, source))
return;
}
else { // normal patching
popstring(source);
popstring(dest);
}

hPatch = CreateFile(exename, GENERIC_READ, FILE_SHARE_READ, NULL,
...


use the new vpatch like this:

vpatch::vpatchfile /REPLACE "$PLUGINSDIR\patch.pat" "$INSTDIR\oldfile.txt" "$INSTDIR\backup.txt"


Have a Fun:)

If the backup file exist, MoveFile function will failue and installer will do nothing.


No! Please do not do it like this!!! :rolleyes:

Instead, download the VPatch 3 release candidate (RC5a) and use the VPatchFile macro in VPatchLib.nsh. :)
Or even better, look at the new example.nsi and documentation :D
This provides the functionality you want but does it in NSIS and only replaces the file when the patching was succesfull.

RC5a can be downloaded from: http://www.tibed.net/files/vpatch3releasecandidate.zip
and will be posted on:
http://www.tibed.net/vpatch
in the near future.

Note: the newer NSIS plug-in (v3) is not yet included with NSIS so if you make patches with v3 be sure to compile the NSIS plug-in yourself as well. The macro library is safe to use.