Monday, December 13, 2004

I admit, I'm working in zip file compression, and I'm not even using something home made for unzipping zip files I run into. I'm using WinZip's context menu.

Well, I should talk to the past. I've made a man of myself and implemented my own "Unzip Here" context menu, which is using Xceed Zip ActiveX 5.x. Why reinvent the wheel when it works fine? Because it didn't work that fine for me.

How many times have I right-clicked on a zip file, went to the WinZip menu, stared at Extract to here and Extract to d:\someplace\somewhere\zipfilename just to find asking myself: "Does that zip file already contain paths?". If it does, I don't need to create a "zipfilename" subfolder, thus I should select the first menu item. But if it doesn't, I sure don't want all unzipped files to end up in the current folder, thus I want to select the second menu item. I end up opening the zip file just to view file paths.

That's what I just implemented. You right-click on a zip file, you click on Unzip Here, and it will automatically detect if it needs to create a subfolder (using the zip filename) or not, then unzip everything.

I won't go into the full details of how to create a Windows Shell Extension component, the sample is pretty self-explanatory, and the web is filled with tutorials. In short, you:

  • Create a new ATL COM AppWizard project (VC++ 6).
  • Add a new Simple Object with default names and attributes (make sure not to select "Free Threaded").
  • Remove references to the newly created interface, you don't need it. (I left the IDL in there instead of copying the CLSID somewhere else... I'm lazy).
  • Remove the type library from the resources and RGS file, you don't need it.
  • Implement IShellExtInit and IContextMenu interfaces (see UnzipHereExtension.cpp).
  • Add the required registry keys (see "DllRegisterServer" in UnzipHere.cpp).

The heart of the extension resides in IContextMenu::InvokeCommand. Don't forget more than one file can be selected when your context menu gets called.

While debugging, you'll often need to restart the explorer.exe in order to release usage of your DLL. Use the Task Manager's run menu to reload it. If you don't like ending a task via the Task Manager, try this: Start Menu -> Shutdown, press Ctrl-Alt-Shift and click Cancel. The explorer.exe process will end.

On my TODO list:

  • Support zip files not ending with the ZIP extension (like self-extracting zip files).
  • Implement a "Zip This" menu.
  • Add a "File already exists. Do you want to overwrite?" prompt.
  • Hide the "aborted" error on non-zip files.

Comments welcomed! Have fun!

UnzipHere.zip (21 KB)

Zip | Samples

12/13/2004 3:57:24 PM (Eastern Standard Time, UTC-05:00)  #