Archive: vpatch example script?


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? :igor:


Have you tried the readme and the NSI scripts that come with VPatch? Any specific problems you are having?


Oh I didn't see that it came with a script. Sory about the post. It's confusing right now but I'll play around with it for a couple of hours and if I can't get it I'll post my problem here. Tnx for the quick response ;)


From the readme included:

Step 1. Start the interface (VPatchGUI.exe).

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:

; 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

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.

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.
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.
Let me know where exactly you have problems if you have any.

Can vpatch patch more than one file at a time? If so could some one plz post a full script that shows how to do it. I have been playing with nsis but its still confuseing.


Yes you can patch multiple files, if you insert multiple lines like:

!insertmacro PatchFile patchdata.pat $INSTDIR\default.ini $INSTDIR\~default.tmp
!insertmacro PatchFile patchdata.pat $INSTDIR\file2.ini $INSTDIR\~default.tmp

As long as you include the patch information for the files you want to patch in the GUI, then you can use the same data file to patch multiple files.


Ahh ok cool stuff. I'll see if I can figure out where to stick that in the script.


Ok. Well I tryed this script but it errors at the !include line.

;NSIS script for HNet Patch created by Atomic GUI for NSIS

; Show gradient background
BGGradient 8080C0 0000FF FFFFFF

; Title of this installation
Name "HNet Patch"

; Do a CRC check when initializing setup
CRCCheck On

; Output filename
Outfile "HNet Patch.exe"

!include c:\program files\vpatch\patchlib.nsi

; The default installation folder
InstallDir "$PROGRAMFILES\ultima online 2d"
; Uninstall info registry location
InstallDirRegKey HKLM "SOFTWARE\HNet Patch" "Install_Dir"

; Folder selection prompt
DirText "Please select an installation folder."

; Section Default
Section "Default" Default
!insertmacro PatchFile patchdata.pat $INSTDIR\Staidx0.mul $INSTDIR\Staidx0.mul.bak
!insertmacro PatchFile patchdata.pat $INSTDIR\Statics0.mul $INSTDIR\Statics0.mul.bak

SectionIn 1

SectionEnd

Section -post
SectionEnd

; This emptily named section will always run
Section ""
WriteRegStr HKLM "SOFTWARE\HNet Patch" "Install_Dir" "$INSTDIR"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\HNet Patch" "DisplayName" "HNet Patch (remove only)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\HNet Patch" "UninstallString" '"$INSTDIR\uninst.exe"'

SetOutPath $INSTDIR
WriteUninstaller "uninst.exe"
SectionEnd

; Uninstall section here...
UninstallText "This will uninstall HNet Patch. Press NEXT to continue."
Section "Uninstall"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\HNet Patch"
Delete "$INSTDIR\uninst.exe"
RmDir "$INSTDIR"
SectionEnd


Please attach large scripts next time. From this script the include line was the only thing that matters any way...

Your problem is that you didn't quote the path and it has spaces in it so !include thinks it gets 2 paramaters (exactly what the error said) when it should get 1.


ahh got it I should have caught that lol.


ok I fixed that and now it says this:

File: "PatchData.pat" [compress] 174274/350497 bytes
Invalid command: vpatch::vpatchfile
Error in macro PatchFile on macroline 3
Error in script "C:\Documents and Settings\hcker2000.HCKER2000\Desktop\tst.nsi" on line 27 -- aborting creation process


Did you put VPatch.dll in your Plugins directory? If not, you should do that or use:
!addplugindir "C:\Path\To\Vpatch.dll\without\file\name"


ok got that fixed and it compiles now. Now when I install and show the details it says this.

Output folder: C:\yada\yada\yada\temp (this is actualy pointing to the temp dir I just didnt want to type it out)
Extract PatchData.pat
Unable to open patch file


Try it with this PatchLib and make sure you specify full path as SOURCEFILE and TEMPFILE:

!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

Hmm... InitPluginsDir is a command I didn't know about yet. Which could explain the problems.


You only need InitPluginsDir if you are using $PLUGINSDIR before any plug-in command was called. I don't have the original script anymore but if I recall correctly you extracted the patch to $TEMP so InitPluginsDir wasn't needed. Using $PLUGINSDIR just makes it easier because you don't need to worry about deleting the file.