Click here to Skip to main content
Click here to Skip to main content

Patch: WTL application for creating patches and patching files

, 5 Mar 2002
Rate this:
Please Sign up or sign in to vote.
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 Smile | :)

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

Share

About the Author

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

Comments and Discussions

 
GeneralNot working... PinmembereAi217-Oct-04 15:37 
GeneralRe: Not working... PinmemberSGarratt20-Oct-04 3:52 
GeneralRe: Not working... PinmemberSGarratt20-Oct-04 3:53 
GeneralRe: Not working... PinmemberAlexEvans22-Jan-06 19:27 
GeneralRe: Not working... PinmemberNOELPG3010-Jul-06 16:32 
GeneralRe: Not working... Pinmemberdcsoft18-Dec-08 6:53 
GeneralNeat PinmemberMcGarrah27-Mar-02 16:06 
GeneralRe: Neat PinmemberSGarratt28-Mar-02 4:17 
GeneralRe: Neat PinmemberMcGarrah28-Mar-02 7:04 
GeneralRe: Neat PinmemberNOELPG3010-Jul-06 17:06 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 6 Mar 2002
Article Copyright 2002 by SGarratt
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid