Archive: How to use the with nsisPatchGen generated files


How to use the with nsisPatchGen generated files
  Hi @ all.

I was in the search of a tool that I could use to easily compare my old project with a updated one and create an patch. So I came over nsisPatchGen.
Now I managed to run this tool and I got a directory with a complete div of my project. There are all the files "filename.txt.pat" with the div between the files.
I guess I need to write an installer for my patch now that includes the created *.nsh file and there I have to call the functions. But what´s the right way of doing that?
The main problem is how do I use the ${PATCH_INSTALL_ROOT} and ${PATCH_SOURCE_ROOT} variables? Especially if there are no registry entries for the the stuff I want to patch.
What is you suggestion what is the best way to go? And please keep in mind that I just started to learn how to use the NSIS installer.
Thank you I´m looking forward to hearing from you!


As far as I know, nsisPatchGen should generate both the patch files and the script to install them. Make sure you haven't missed a script file in there.


I tried it and like I said it created the patch files and a header file with the required functions to patch my project.
In this generated header file is a macro (!macro NSISPGPatchFile PATCHDATA SOURCEFILE TEMPFILE) and there are 5 functions:
Function patchDirectoriesAdded
Function patchDirectoriesRemoved
Function patchFilesAdded
Function patchFilesRemoved
Function patchFilesModified
Because I don´t add or remove directories the first to are not necessary.

In the function patchFilesAdded are two lines for every file that is added.


patchFilesAdded

SetOutPath "${PATCH_INSTALL_ROOT}\d"
File "${PATCH_SOURCE_ROOT}\d\L0M.xml"
>.
.
.
>FunctionEnd
>
The next function removes a file:

patchFilesRemoved

Delete "${PATCH_INSTALL_ROOT}\Z.exe"
>FunctionEnd
>
And the last one uses the macro with every changed file:

patchFilesModified

InitPluginsDir

;Patching "d\RW.xml" using patch file "d\RW.xml.pat"
DetailPrint "Patching ${PATCH_INSTALL_ROOT}\d\RW.xml"
!insertmacro NSISPGPatchFile "${PATCH_FILES_ROOT}\d\RW.xml.pat" "${PATCH_INSTALL_ROOT}\d\RW.xml" "RW.xml.tmp"
>.
.
.
>FunctionEnd
>
The used macro uses VPatch to patch my files.

macro NSISPGPatchFile PATCHDATA SOURCEFILE TEMPFILE

InitPluginsDir
File "/oname=$PLUGINSDIR\${TEMPFILE}.patchFile" "${PATCHDATA}"
vpatch::vpatchfile "$PLUGINSDIR\${TEMPFILE}.patchFile" "${SOURCEFILE}" "${TEMPFILE}"
Pop $1
DetailPrint$1
StrCpy$1 $1 2
StrCmp$1 "OK" +2
SetErrors
IfFileExists"${TEMPFILE}" +1 +3
Delete "${SOURCEFILE}"
Rename /REBOOTOK "${TEMPFILE}" "${SOURCEFILE}"
Delete "$PLUGINSDIR\${TEMPFILE}.patchFile"
>!macroend
>
That´s everything I get. Now if I create an installer and try to include this file I get the error message:

!include: error in script: "Z.nsh" on line 24
Error in script "C:\...\Z.nsi" on line 26 -- aborting creation process

Line 24 is:
SetOutPath "${PATCH_INSTALL_ROOT}\d"
The error is that ${PATCH_INSTALL_ROOT} is unknown. To avoid that error I can create defines for
${PATCH_INSTALL_ROOT}
${PATCH_SOURCE_ROOT}
${PATCH_FILES_ROOT}
in the header file but I need on different computers different paths.
The source and the patch files should be included in the installer and so the path should be clear. The install path should be the path that my project is already installed in. But how can I do that? Thank you.

From the Readme.txt:

The calling script must define the following variables _before_ calling any
of the patch functions:

The location of <directory2> on the source machine, e.g.

!define PATCH_SOURCE_ROOT "newVersion"

The location of the *.pat patch files on the source machine (as defined by the optional <patch output directory> command line parameter), e.g.

!define PATCH_FILES_ROOT "patchFiles"

The directory to which the files will be installed, e.g.

!define PATCH_INSTALL_ROOT $INSTDIR
So you define PATCH_SOURCE_ROOT and PATCH_FILES_ROOT to be the appropriate directories on your machine. These defines are only used when creating the installer, so don't matter when the installer is run.

$INSTDIR is a special NSIS define which means the installation directory on the users machine. If you don't store the installation directory in the registry then you will have to let the user pick the installation directory. See the general NSIS help for this.