Click here to Skip to main content
6,305,776 members and growing! (18,375 online)
Email Password   helpLost your password?
Web Development » Applications & Tools » Tools with source code     Intermediate

Patch: WTL application for creating patches and patching files

By SGarratt

WTL application for creating patches and patching files
VC6Win2K, WinXP, WTL, Dev
Posted:5 Mar 2002
Views:48,900
Bookmarked:15 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
7 votes for this article.
Popularity: 3.06 Rating: 3.63 out of 5
1 vote, 25.0%
1

2

3
1 vote, 25.0%
4
2 votes, 50.0%
5

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

About the Author

SGarratt


Member
Brit living in USA
C++ Windows/Unix developer

Occupation: Web Developer
Location: United States United States

Other popular Applications & Tools articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 10 of 10 (Total in Forum: 10) (Refresh)FirstPrevNext
GeneralNot working... PinmembereAi216:37 17 Oct '04  
GeneralRe: Not working... PinmemberSGarratt4:52 20 Oct '04  
GeneralRe: Not working... PinmemberSGarratt4:53 20 Oct '04  
GeneralRe: Not working... PinmemberAlexEvans20:27 22 Jan '06  
GeneralRe: Not working... PinmemberNOELPG3017:32 10 Jul '06  
GeneralRe: Not working... Pinmemberdcsoft7:53 18 Dec '08  
GeneralNeat PinmemberMcGarrah17:06 27 Mar '02  
GeneralRe: Neat PinmemberSGarratt5:17 28 Mar '02  
GeneralRe: Neat PinmemberMcGarrah8:04 28 Mar '02  
GeneralRe: Neat PinmemberNOELPG3018:06 10 Jul '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 5 Mar 2002
Editor: Smitha Vijayan
Copyright 2002 by SGarratt
Everything else Copyright © CodeProject, 1999-2009
Web12 | Advertise on the Code Project