Click here to Skip to main content
15,893,487 members
Articles / Desktop Programming / Windows Forms

Listing and Working with Files in Archives

Rate me:
Please Sign up or sign in to vote.
2.86/5 (6 votes)
22 Jun 2007CPOL 32.3K   529   23  
This article describes how to use CAKE3, which is a wrapper component for many archiver DLLs,
using System;
using System.Runtime.InteropServices;

namespace AceDllWrapped
{
	/// <summary>
	/// 
	/// Functions and their structures for Ace-Dll and UnAce-Dll.
	/// 
	/// </summary>

	//--------------------------------------------------------------------------------
	//--------          Part 3: Functions supported by UNAceV2.Dll        ------------
	//--------------------------------------------------------------------------------

	//---------------------------------------------------------------------------
	//
	// UnAceV2.Dll supports the following functions:
	//
	//   ACEInitDll
	//   ACEReadArchiveData
	//   ACEList
	//   ACETest
	//   ACEExtract
	//
	// First of all - before any other function is called - the Dll has to be
	// initialized by ACEInitDll(). Using this function the application has
	// to set temporary directory, key file path, comment buffer and
	// callback function pointers.
	// (callback function pointers can be set to NULL for first-try-runs)
	//
	// See description of each function for details about their task, input and
	// output. Return codes of those functions are listed in part 3.1.
	//
	//---------------------------------------------------------------------------
	//
	// Contents:
	//   Part 3.1: UnAceV2.Dll function return codes
	//   Part 3.2: functions and parameter structures
	//
	//---------------------------------------------------------------------------


	public class UnAceFnc
	{
		public UnAceFnc() {}

		//---------------------------------------------------------------------------
		//===========---  Part 3.1: UnAceV2.Dll function return codes  ---===========
		//---------------------------------------------------------------------------

		//-----------------------------------------------------------------------
		// These error codes are returned by the UnAceV2.Dll-functions. The meanings
		// of the codes are the same, as they are for the exit codes of ACE.EXE.
		//-----------------------------------------------------------------------

		public const int ACE_ERROR_NOERROR      = 0;	// no error; operation succesful
		public const int ACE_ERROR_MEM          = 1;	// insufficient memory
		public const int ACE_ERROR_FILES        = 2;	// no files specified
		public const int ACE_ERROR_FOUND        = 3;	// specified archive not found
		public const int ACE_ERROR_FULL         = 4;	// disk full
		public const int ACE_ERROR_OPEN         = 5;	// could not open file
		public const int ACE_ERROR_READ         = 6;	// read error
		public const int ACE_ERROR_WRITE        = 7;	// write error
		public const int ACE_ERROR_CLINE        = 8;	// invalid command line
		public const int ACE_ERROR_CRC          = 9;	// CRC error
		public const int ACE_ERROR_OTHER        = 10;	// other error
		public const int ACE_ERROR_EXISTS       = 11;	// file already exists
		public const int ACE_ERROR_USER         = 255;	// user break (application returned
														// cancel code at callback function)

		//-----------------------------------------------------------------------
		// These error codes are returned by the UnAceV2.Dll-functions. They are not
		// used by ACE.EXE yet.
		//-----------------------------------------------------------------------

		public const int ACE_ERROR_PARAM      = 128;	// might be used later

		
		//---------------------------------------------------------------------------
		//============---  Part 3.2: functions and parameter structures ---==========
		//---------------------------------------------------------------------------

		//---------------------------  ACEInitDll  --------------------------------
		// Initializes ACE dynamic link library. Has to be called before any
		// other function call. May be called more than one time.
		//-------------------------------------------------------------------------

		//-----------------------------------------------------------------------
		// ACEInitDll() parameter structure.
		//-----------------------------------------------------------------------

		[StructLayout(LayoutKind.Sequential, Pack=1)]
			public struct sACEInitDllStruc
		{
			public sACEGlobalDataStruc GlobalData;
			
			[MarshalAs(UnmanagedType.ByValArray, SizeConst=64)]
			byte[] Reserved;				// has to be filled with zeroes
		}


		//-----------------------------------------------------------------------
		// ACEInitDll() function declaration.
		//-----------------------------------------------------------------------

		[DllImport("AceV2.Dll")]
		public static extern int ACEInitDll(IntPtr DllDataPtr);


		//-----------------------  ACEReadArchiveData  ----------------------------
		// Tests a file whether it is an archive or not and reads out the archive
		// data.
		//-------------------------------------------------------------------------

		//-----------------------------------------------------------------------
		// ACEReadArchiveData() parameter structure.
		//-----------------------------------------------------------------------

		[StructLayout(LayoutKind.Sequential, Pack=1)]
			public struct sACEReadArchiveDataStruc
		{
			public IntPtr ArchiveData;	// if this pointer is NULL, the file passed to
										// ACEReadArchiveData is no archive; otherwise 
										// it points to a sACEArchiveDataStruc structure 
										// that contains information about the archive

			[MarshalAs(UnmanagedType.ByValArray, SizeConst=64)]
			byte[] Reserved;				// has to be filled with zeroes
		}


		//-----------------------------------------------------------------------
		// ACEReadArchiveData() function declaration.
		//-----------------------------------------------------------------------

		[DllImport("AceV2.Dll")]
		public static extern int ACEReadArchiveData(string ArchiveName, ref sACEReadArchiveDataStruc ArchiveData);


		//----------------------------  ACEList  ----------------------------------
		// Passes the specified files in the archive to StateCallbackProc().
		//-------------------------------------------------------------------------

		//-----------------------------------------------------------------------
		// ACEList() parameter structure.
		//-----------------------------------------------------------------------

		[StructLayout(LayoutKind.Sequential, Pack=1)]
			public struct sACEListStruc
		{
			public sACEFilesStruc Files;	// specifies files to be listed; see tACEFilesStruc structure
			
			[MarshalAs(UnmanagedType.ByValArray, SizeConst=64)]
			byte[] Reserved;				// has to be filled with zeroes
		}


		//-----------------------------------------------------------------------
		// ACEList() function declaration.
		//-----------------------------------------------------------------------

		[DllImport("AceV2.Dll")]
		public static extern int ACEList(string ArchiveName, ref sACEListStruc List);


		//----------------------------  ACETest  ----------------------------------
		// Tests specified files in archive.
		//-------------------------------------------------------------------------

		//-----------------------------------------------------------------------
		// ACETest() parameter structure.
		//-----------------------------------------------------------------------

		[StructLayout(LayoutKind.Sequential, Pack=1)]
			public struct sACETestStruc
		{
			public sACEFilesStruc Files;	// specifies files to test; see tACEFilesStruc structure
			
			public string DecryptPassword;	// zero-terminated string, case-sensitive (maxlen=56)

			[MarshalAs(UnmanagedType.ByValArray, SizeConst=64)]
			byte[] Reserved;				// has to be filled with zeroes
		}


		//-----------------------------------------------------------------------
		// ACETest() function declaration.
		//-----------------------------------------------------------------------
		
		[DllImport("AceV2.Dll")]
		public static extern int ACETest(string ArchiveName, ref sACETestStruc Test);


		//---------------------------  ACEExtract  --------------------------------
		// Extracts specified  files.
		//-------------------------------------------------------------------------

		//-----------------------------------------------------------------------
		// ACEExtract() parameter structure.
		//-----------------------------------------------------------------------

		[StructLayout(LayoutKind.Sequential, Pack=1)]
			public struct sACEExtractStruc
		{
			public sACEFilesStruc Files;	// specifies files to extract; see tACEFilesStruc structure
			
			public string DestinationDir;	// directory to extract files to
					
			public int ExcludePath;         // extract files without path
			
			public string DecryptPassword;	// password for decryption (if files are encrypted);
											// zero-terminated string, case-sensitive (maxlen=56)
			
			[MarshalAs(UnmanagedType.ByValArray, SizeConst=64)]
			byte[] Reserved;				// has to be filled with zeroes
		}


		//-----------------------------------------------------------------------
		// ACEExtract() function declaration.
		//-----------------------------------------------------------------------

		[DllImport("AceV2.Dll")]
		public static extern int ACEExtract(string ArchiveName, ref sACEExtractStruc Extract);
	
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Founder
Hong Kong Hong Kong

Comments and Discussions