Click here to Skip to main content
15,879,535 members
Articles / Desktop Programming / WTL
Article

Patch: WTL application for creating patches and patching files

Rate me:
Please Sign up or sign in to vote.
3.75/5 (4 votes)
5 Mar 20023 min read 83.4K   935   26   10
WTL application for creating patches and patching files

Sample Image - Patch.png

Introduction

I read a posting here by Alessandro Vergani, UnPatcher: a COM object for patching files. He created a COM object that used a little known capability (providing you have the needed MS DLL's) that can create and apply delta patches to files. (Please refer to Alessandro's article on availability of the required patch creation and application DLLs).

I decided to create a WTL app that would use his component, but later decided to abandon usage of the component in favor of a direct class wrapper, so as to avoid the need to distribute and register a separate DLL, and make my utility easily distributable as a single .exe. As such, this WTL app is a measly 108K, and has minimal runtime requirements.

The application can create, test and apply patch files, which, if you don't know, are files that represent the deltas between two files so that an original file can be changed to a newer version by "patching", or applying a file that is (hopefully!) much smaller than the new version. Seeing as the two DLLs, mspatcha.dll (apply) and mspatchc.dll (create) are provided by MS, it is obvious that they use patching techniques in Windows installer.

Program overview

The app is a WTL dialog app created with the WTL wizard. Obviously you will need to install the WTL SDK to build the app, but I was nice enough to include a release exe in the zip anyway.

There is a reusable class CPatch in patcher.cpp/h that performs all the needed DLL loading/unloading and patch functions. It is pretty self explanatory. Kudos to Alessandro again, as I pasted the code from his COM component, and converted it from there.

There is an exception class, CPatchError() that is thrown in the event of any patch failures. It does the job of decoding the errors and optionally displaying a MessageBox. Obviously you will need to wrap calls to the class in try..catch.

Most of the rest of the APP is WTL boilerplate, with the obvious exception of maindlg.h, which contains all the UI code. CMainDlg is derived from CPatch. The actual patch operations are run in a separate thread so as to allow a Cancel button to interrupt the process. You will note that I used the default extension of .ptx for patch files, this was arbitrary. I don't know if ptx is a currently common extension type. FYI, the blue triangle icon is the Greek symbol for delta, meaning change.

I included a couple files, jabberwocky.txt and jabberwocky.ptx so that the apply patch functionality can be tried. After running the patch, the full text of jabberwocky will be patched in, instead of just the first verse!

The UI state is persisted to the registry, so that the UI settings on application close are reloaded on app restart. A little gold plating there :-)

My next objective is to make a patcher than can operate on the contents of two directories, similar to other commercial patch apps such as RTP. Another thing I may do is, add command line handing to this app, and/or make a console app patcher.

As Alessandro states in his posting, the mspatchc.dll (create patch) is probably not on your PC currently, but can be freely downloaded as part of the Windows installer SDK. mspatcha.dll (apply patch) should be on your PC if you have IE 5 installed.

Hope you find this interesting and useful, as I do all the great postings at this phenomenally cool site!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Brit living in USA
C++ Windows/Unix developer

Comments and Discussions

 
GeneralNot working... Pin
Member 130971717-Oct-04 15:37
Member 130971717-Oct-04 15:37 
GeneralRe: Not working... Pin
SGarratt20-Oct-04 3:52
SGarratt20-Oct-04 3:52 
GeneralRe: Not working... Pin
SGarratt20-Oct-04 3:53
SGarratt20-Oct-04 3:53 
GeneralRe: Not working... Pin
AlexEvans22-Jan-06 19:27
AlexEvans22-Jan-06 19:27 
GeneralRe: Not working... Pin
NOELPG3010-Jul-06 16:32
NOELPG3010-Jul-06 16:32 
have you installed the latest version of the mspatchc.dll file? maybe the newest version could fix the CreatePatch: problem.

I tested this app and it only works correctly under windows 2000 and windows xp. it does not work properly under windows 98 & me, even with windows installer 2.0 installed on those systems which also bundled the mspatcha.dll file.
GeneralRe: Not working... Pin
dcsoft18-Dec-08 6:53
dcsoft18-Dec-08 6:53 
GeneralNeat Pin
McGarrah27-Mar-02 16:06
McGarrah27-Mar-02 16:06 
GeneralRe: Neat Pin
SGarratt28-Mar-02 4:17
SGarratt28-Mar-02 4:17 
GeneralRe: Neat Pin
McGarrah28-Mar-02 7:04
McGarrah28-Mar-02 7:04 
GeneralRe: Neat Pin
NOELPG3010-Jul-06 17:06
NOELPG3010-Jul-06 17:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.