Click here to Skip to main content
12,697,779 members (27,089 online)
Click here to Skip to main content
Add your own
alternative version

Stats

21.8K views
445 downloads
23 bookmarked
Posted

Listing and Working with Files in Archives

, 22 Jun 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
This article describes how to use CAKE3, which is a wrapper component for many archiver DLLs,
Screenshot - Cakcmd.gif

Introduction

This article describes how to use CAKE3, which is a wrapper component for many archiver DLLs, including SharpZipLib(Zip), Sqx Archiver(Sqx), XacRett(Wide range), Unlha(Lha,Lzh), Unarj(Arj), 7-zip32(7z), Unace(ace), Unrar(rar) archives.

Background

There are some zip/unzip solutions for C#, but I need more archive types support. I believe that there will be no native support for most other archives types anytime soon, so the only method is to call Win32 DLLs...

Using the Code

All archive operations can be done via the main unit: Cakdir3, you should create a new instance of Cakdir3 if you wanted to access a new archive.

You should download the archiver DLLs first, detailed path can be found in Dlls.txt.

You can view the help file here.

Listing Files

Cakdir3 c3 = new Cakdir3(archiveName);
c3.OnMessage += new MessageEventHandler(OnMessage);
c3.List(mask);
                                    
foreach (ContentType ct in c3.Archive_Contents)
  Console.WriteLine(ct.fileName);

//Utils.GetSmallFileIcon - Return small file icon of a file (exist or not).
//Utils.GetLargeFileIcon - Return large file icon of a file (exist or not).

Testing Files

Cakdir3 c3 = new Cakdir3(archiveName);
c3.OnMessage += new MessageEventHandler(OnMessage);
c3.Test();

Compressing Files

Cakdir3 c3 = new Cakdir3(archiveName);
c3.OnMessage += new MessageEventHandler(OnMessage);
c3.AddOptions.addFile = new string[] { "C:\file2Add" }
c3.Add(); //Use c3.AddToFolder if you want to add to specific folder in archive.

Decompressing Files

Cakdir3 c3 = new Cakdir3(archiveName);
c3.OnMessage += new MessageEventHandler(OnMessage);
c3.ExtractOptions.extractFolder = "c:\path2extract";
c3.ExtractOptions.extractItem = new string[] { "*" };
c3.Extract();

Deleting Files

Cakdir3 c3 = new Cakdir3(archiveName);
c3.OnMessage += new MessageEventHandler(OnMessage);
c3.DeleteOptions.deleteFile = new string[] { "/file2del" };
c3.Delete();  

Points of Interest

I wrote this component for my next freeware archiver. I don't know what other use can be made of this. Drop me an email if you find one.

History

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author


You may also be interested in...

Comments and Discussions

 
QuestionSome issues with Cake Pin
guardian6536-Oct-07 5:22
memberguardian6536-Oct-07 5:22 
Its been a couple of months with no comments here, but I'll bite Smile | :)

It was hard finding something that would support so many archives out of the boat; especially one using one common interface. Alas, I have one major show stopping issue:

GetStream()

It makes temp files in my burried in my temp directory. I normally wouldn't care but for some reason I can't clear it out using Disk Cleanup and have to do it manually. Secondly, it appears when making these temp files it chokes on files with Unicode characters or brackets ([, ]) and other "special" characters, causing it throw an exeception. This happens if either the archive name has those characters or the files within the archive itself.

Is it possible to use a MemoryStream instead? Would it take a rewrite of Cake3? Are the libraries at fault? (It looks like Unrar.dll wouldn't give you the uncompressed bytes)

AnswerRe: Some issues with Cake Pin
Leung Yat Chun8-Oct-07 0:25
memberLeung Yat Chun8-Oct-07 0:25 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 23 Jun 2007
Article Copyright 2007 by Leung Yat Chun
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid