Download demo project - 30 Kb
Download source files - 20 Kb
Introduction
Recently I faced myself with a problem that I think is very common among developers: patching a
software release.
There are many tools for doing this, even freeware, but I wanted something similar to the LiveUpdate
of a well-known software.
Since all patching software I found is not free-source, I started writing my patch algorithm without
good results: the patch file it generated is almost the same size of the original file.
I started asking around for help, but none can get me out of trouble. Then an help arrived:
Blake Miller told me to look in the Platform SDK. I looked and I found a very-not documented
set of APIs for creating and applying patches.
The problems and the solutions
The only documentation to the APIs is in a file called PatchApi.h. This set of function isn't
very complex so I understand without problems what each function does (apart from the flags, if someone
know something more, please tell me).
The problem is that there is an import library only for the patch creation routines
(CreatePatch
and CreatePatchEx
) and not for patch applying functions.
So I tried creating one without success.
The only solution I found was to dynamically load the DLLs implementig the API. This is not so bad:
you can ship the patch program without the patch creation DLL.
You may have noted that I wrote DLLs (plural). This is true: there are two DLLs implementig this API:
mspatchc.dll
(creation) and mspatcha.dll
(apply). I've not included these
DLLs in the zips (I don't know if I can redistribute them). You can find the creation dll in the
Platform SDK and the apply dll comes with MSIE 5.01 (maybe with other MS products, I looked on MSDN
and found only IE carrying this).
The last step
I finally got it working so I wrote a simple COM dll implementing the logic of patching.
The object is very simple: it has 3 properties, 4 methods and 1 event.
Properties
SourceFile
: The old file name or the file to patch.
DestinationFile
: The new file name or the patched file to generate.
PatchFile
: Is the patch file name to be created or applyed.
Methods
CreatePatch
: Creates the patch file.
TestPatch
: Tests the patch file
ApplyPatch
: Applies the patch file
GetFileSignature
: Returns a unique (?) file signature
Events
OnProgress
: Called during processing.
Final notes
It compiles under UNICODE, but it's not well tested.
The included demo is written in Visual Basic. To get it to work, you first need to register the
UnPatcher DLL by doing:
regsvr32 UnPatcher.dll