1. Computing & Technology

Discuss in my forum

How to Create a Stub Program to support Self-Extracting Archives

STUB - Full Source Code

By , About.com Guide

How to Create a Stub Program to support Self-Extracting Archives

Here's the full source code to a sample STUB program. Download the heavily documented version.

~~~~~~~~~~~~~~~~~~~~~~~~~
program SelfStub;
{$DEFINE BuildingStub}

uses
   AbArcTyp,
   AbUnzPrc,
   AbUtils,
   AbZipTyp,
   Dialogs,
   SysUtils;

type
   THelper = class
   public
     procedure UnzipProc(Sender : TObject; Item : TAbArchiveItem; const NewName : string) ;
   end;

var
   ZipArchive : TAbZipArchive;
   Helper : THelper;
   PWord: string;
   Entered: Boolean;

procedure THelper.UnzipProc(Sender : TObject; Item : TAbArchiveItem; const NewName : string) ;
begin
   if (Item.IsEncrypted) and (Entered = False) then
     begin
       PWord := InputBox('PCB Zip-Archive Is Password Protected', 'Archive created by PCB Zip' + #13#10 + #13#10 + 'Enter password:' + #13#10 + #13#10 + 'NOTE that PCB Zip ASSUMES that all files were' + #13#10 + 'archived with the same password!!!','') ;
       Entered := True;
     end;
   ZipArchive.Password := PWord;
   AbUnzip(Sender, TAbZipItem(Item), NewName) ;
end;

begin //program starts here
   Entered := False;
   PWord := '';
   ZipArchive := TAbZipArchive.Create(ParamStr(0), fmOpenRead or fmShareDenyNone) ;
   ChDir(ExtractFilePath(ParamStr(0))) ;

   Helper := THelper.Create;
   try
     ZipArchive.Load;
     ZipArchive.ExtractHelper := Helper.UnzipProc;
     ZipArchive.ExtractFiles('*.*') ;
   finally
     Helper.Free;
     ZipArchive.Free;
   end;
end.
~~~~~~~~~~~~~~~~~~~~~~~~~

Related Searches zip archive source code

©2012 About.com. All rights reserved.

A part of The New York Times Company.