vpatch example script?
I'm geting into nsis to make patches with it. I want to use vpatch but I'm not sure how to make the install for the patch I made. Could some one help me out? 🧟
16 posts
Step 1. Start the interface (VPatchGUI.exe).Basically, the PatchLIB.NSI file included with VPatch contains a macro PatchFile to update a file. I assume you're using NSIS 2.0 in these steps. Inside the GUI you should use the "Create Patch" option to actually create your updates.
Step 2. Hit the "Add new version" button. Now, select the latest version of your file. Right after that, another file selection screen pops up. Now, select all older versions of your file (which need to be updated).
Step 3. You're set, you can add more files if you want through the "Add new version" button.
Step 4. Configuration: By default a "Block size" of 64 is configured. If you make it smaller, you will get smaller patch files. With the v2.0+ generator, you can safely set this to 16 to squeeze out even that last byte. Note that applying the patch file can get slower when using such small block sizes.
Step 5. Hit "Generate patches" from the Action menu. Your patches are now being generated.
Step 6. If you select "Create patch file" now, the program will create an PAT which contains the information needed to update all old files to new versions. Here, we'll call that file "PatchData.PAT" and we'll store it in the same folder as our NSIS script.
Note: Before you can use VPatch in NSIS 2.0, copy the VPatch.dll file to your NSIS\Plugins folder, or else NSIS won't recognize the vpatch::vpatchfile command found in the macro used below. You should also copy patchlib.nsi to a location searched by your NSIS script.
Step 7. Inside the script, you can use the following command to patch a file:
Step 8. You're done, because the macro PatchFile will automatically update the file, and rename the temporary file back to the original file if the update was succesfull.
; include somewhere at the top of your script
!include patchlib.nsi
;make sure the command is inside a section
Section Something
!insertmacro PatchFile patchdata.pat $INSTDIR\default.ini $INSTDIR\~default.tmp
SectionEnd
Note: The error flag will be set if the update failed. You should add your own handling for this case.
Note: You should choose a temporary filename which isn't used on the user PC. You could generate a unique one with GetTempFileName, however this is beyond the scope of this simple tutorial.
!macro PatchFile PATCHDATA SOURCEFILE TEMPFILE
Push $1
InitPluginsDir
File /oname=$PLUGINSDIR\patch.dat "${PATCHDATA}"
VPatch::VPatchFile $PLUGINSDIR\patch.dat "${SOURCEFILE}" "${TEMPFILE}"
Pop $1
DetailPrint $1
StrCpy $1 $1 2
StrCmp $1 "OK" ok_${SOURCEFILE}
SetErrors
"ok_${SOURCEFILE}":
IfFileExists "${TEMPFILE}" +1 "end_${SOURCEFILE}"
Delete "${SOURCEFILE}"
Rename /REBOOTOK "${TEMPFILE}" "${SOURCEFILE}"
"end_${SOURCEFILE}":
Pop $1
!macroend