home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hot Shareware 37
/
hot37.iso
/
FICHEROS
/
9TOOL
/
ADDZIP.ZIP
/
DELPHI
/
ZWIZ.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1998-02-01
|
21KB
|
778 lines
unit Zwiz;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, ExtCtrls, StdCtrls, Buttons, FileCtrl, azip, addzipu, addzipc;
type
TfrmWizard = class(TForm)
imgWizard: TImage;
grpStep1: TGroupBox;
lblArchiveName: TLabel;
edtArchive: TEdit;
shpLine: TShape;
btnCancel: TSpeedButton;
btnBack: TSpeedButton;
btnNext: TSpeedButton;
btnFinish: TSpeedButton;
btnBrowse: TSpeedButton;
grpStep2: TGroupBox;
grpStep3: TGroupBox;
grpStep4: TGroupBox;
grpStep5: TGroupBox;
GroupBox1: TGroupBox;
grpPassword: TGroupBox;
grpCompression: TGroupBox;
radPathNo: TRadioButton;
radPathYes: TRadioButton;
radPasswordYes: TRadioButton;
radPasswordNo: TRadioButton;
lblPassword: TLabel;
edtPassword: TEdit;
radCompressNone: TRadioButton;
radCompressMinimum: TRadioButton;
radCompressNormal: TRadioButton;
radCompressMaximum: TRadioButton;
lblFiles: TLabel;
lstFiles: TFileListBox;
dirFiles: TDirectoryListBox;
drvFiles: TDriveComboBox;
btnAdd: TSpeedButton;
btnRemove: TSpeedButton;
lstSelected: TListBox;
grpMultiDisk: TGroupBox;
radMultiNo: TRadioButton;
radMultiYes: TRadioButton;
grpLFN: TGroupBox;
radLFNYes: TRadioButton;
radLFNNo: TRadioButton;
grpComment: TGroupBox;
radCommentNo: TRadioButton;
radCommentYes: TRadioButton;
mmoComment: TMemo;
mmoSummary: TMemo;
edtHidden: TEdit;
lblInfo: TLabel;
chkSFX: TCheckBox;
procedure btnCancelClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure btnBackClick(Sender: TObject);
procedure btnNextClick(Sender: TObject);
procedure edtArchiveChange(Sender: TObject);
procedure btnFinishClick(Sender: TObject);
procedure btnAddClick(Sender: TObject);
procedure btnRemoveClick(Sender: TObject);
procedure lstFilesClick(Sender: TObject);
procedure dirFilesChange(Sender: TObject);
procedure radCommentNoClick(Sender: TObject);
procedure radCommentYesClick(Sender: TObject);
procedure radPasswordNoClick(Sender: TObject);
procedure radPasswordYesClick(Sender: TObject);
procedure btnBrowseClick(Sender: TObject);
procedure edtHiddenChange(Sender: TObject);
private
{ Private declarations }
procedure AlignGroups;
procedure HideGroup(GroupNum : Integer);
procedure ShowGroup(GroupNum : Integer);
Function CheckFloppyDrives (cFileName : String) : Boolean;
procedure DisplaySummary;
function Trim(s : string) : string;
procedure WMGetMinMaxInfo(var MSG: Tmessage); message WM_GetMinMaxInfo;
public
{ Public declarations }
procedure DOZip;
end;
{$IFDEF USE_CALLBACKS}
Type
{$IFNDEF WIN32} Short = ShortInt; {$ENDIF}
TProcessCallbackData = function (iLibrary, iMessage : Short; pInfo : PChar) : Integer;
{$IFDEF WIN32} stdcall; {$ENDIF}
function ProcessCallbackData(iLibrary, iMessage : Short; pInfo : PChar) : Integer;
{$IFDEF WIN32} stdcall; {$ENDIF} export;
{$ENDIF}
var
frmWizard: TfrmWizard;
m_iStep : Integer;
{$IFDEF WIN32}
sArchiveName : String[255];
{$ELSE}
sArchiveName : String[128];
{$ENDIF}
{$IFDEF USE_CALLBACKS}
MyCallback : TProcessCallbackData;
{$ENDIF}
Const m_cMaxSteps = 5;
implementation
{$R *.DFM}
procedure TfrmWizard.btnCancelClick(Sender: TObject);
begin
Close;
end;
procedure TfrmWizard.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TfrmWizard.FormShow(Sender: TObject);
var
I: Integer;
begin
I := addZIP_SetParentWindowHandle(frmWizard.Handle);
{$IFDEF USE_CALLBACKS}
MyCallback := ProcessCallBackData;
I := addZip_InstallCallback(@MyCallback);
{$ELSE}
I := addZIP_SetWindowHandle(edtHidden.Handle);
{$ENDIF}
addZIP_Initialise;
m_iStep := 1;
AlignGroups;
grpStep1.Visible := True;
grpStep2.Visible := False;
grpStep3.Visible := False;
grpStep4.Visible := False;
grpStep5.Visible := False;
mmoSummary.Color := clBtnFace;
end;
procedure TfrmWizard.AlignGroups;
begin
grpStep2.Top := GrpStep1.Top;
grpStep2.Left := GrpStep1.Left;
grpStep2.Width := GrpStep1.Width;
grpStep2.Height := GrpStep1.height;
grpStep3.Top := GrpStep1.Top;
grpStep3.Left := GrpStep1.Left;
grpStep3.Width := GrpStep1.Width;
grpStep3.Height := GrpStep1.height;
grpStep4.Top := GrpStep1.Top;
grpStep4.Left := GrpStep1.Left;
grpStep4.Width := GrpStep1.Width;
grpStep4.Height := GrpStep1.height;
grpStep5.Top := GrpStep1.Top;
grpStep5.Left := GrpStep1.Left;
grpStep5.Width := GrpStep1.Width;
grpStep5.Height := GrpStep1.height;
end;
procedure TfrmWizard.btnBackClick(Sender: TObject);
begin
If (m_iStep > 1) Then
begin
HideGroup(m_iStep);
If (m_iStep = m_cMaxSteps) Then
btnNext.Enabled := True;
m_iStep := m_iStep - 1;
If (m_iStep = 1) Then
btnBack.Enabled := False;
ShowGroup(m_iStep);
End;
end;
procedure TfrmWizard.HideGroup(GroupNum : Integer);
begin
case GroupNum of { which group to disable }
1 : begin
grpStep1.Visible := False
end;
2 : begin
grpStep2.Visible := False
end;
3 : begin
grpStep3.Visible := False
end;
4 : begin
grpStep4.Visible := False
end;
5 : begin
grpStep5.Visible := False
end;
end; { case }
end;
procedure TfrmWizard.ShowGroup(GroupNum : Integer);
begin
case GroupNum of { which group to disable }
1 : begin
grpStep1.Visible := True
end;
2 : begin
grpStep2.Visible := True
end;
3 : begin
grpStep3.Visible := True
end;
4 : begin
grpStep4.Visible := True
end;
5 : begin
grpStep5.Visible := True
end;
end; { case }
end;
procedure TfrmWizard.btnNextClick(Sender: TObject);
begin
If (m_iStep < m_cMaxSteps) Then
begin
HideGroup(m_iStep);
If (m_iStep = 1) Then
btnBack.Enabled := True;
If (Pos(':', edtArchive.Text) > 0) Then
begin
If CheckFloppyDrives(edtArchive.Text) = False Then
begin
grpMultiDisk.Enabled := False;
radMultiNo.Enabled := False;
radMultiYes.Enabled := False;
end
Else
begin
grpMultiDisk.Enabled := True;
radMultiNo.Enabled := True;
radMultiYes.Enabled := True;
end
end
Else
begin
grpMultiDisk.Enabled := False;
radMultiNo.Enabled := False;
radMultiYes.Enabled := False;
End
End;
m_iStep := m_iStep + 1;
If (m_iStep = m_cMaxSteps) Then
begin
btnNext.Enabled := False;
DisplaySummary;
End;
ShowGroup(m_iStep);
End;
Function TfrmWizard.CheckFloppyDrives (cFileName : String) : Boolean;
var
{$IFDEF WIN32}
pFileName : PChar;
wResult : Word;
{$ELSE}
Drive : String;
DriveNumber, wResult : Word;
{$ENDIF}
begin
CheckFloppyDrives := False;
{$IFDEF WIN32}
pFileName := StrAlloc(2);
StrPCopy(pFileName, Copy(UpperCase(cFileName), 1, 1));
wResult := GetDriveType(pFileName);
StrDispose(pFileName);
{$ELSE}
Drive := UpperCase(Copy(cFileName, 1, 1));
DriveNumber := Ord(Drive[1]) - 65; {Drive must be upper case}
wResult := Word(GetDriveType(DriveNumber));
{$ENDIF}
If wResult = DRIVE_REMOVABLE then
CheckFloppyDrives := True;
End;
procedure TfrmWizard.DisplaySummary;
var
sSummary, sResult : String;
I : Integer;
sFill : array[1..10] of Char;
begin
sFill := ' ';
mmoSummary.Clear;
sSummary := 'Compress the following ' + IntToStr(lstSelected.Items.Count) + ' file';
If (lstSelected.items.Count > 1) Then
sSummary := sSummary + 's';
If chkSFX.State = cbChecked then
begin
sResult := ChangeFileExt(edtArchive.Text, '.exe');
sSummary := sSummary + ' to the archive ' + sResult + '.';
end
Else
sSummary := sSummary + ' to the archive ' + edtArchive.Text + '.';
mmoSummary.Lines.Add(sSummary);
mmoSummary.Lines.Add('');
For I := 0 To lstSelected.items.Count - 1 do
begin
sSummary := sFill + lstSelected.Items[I];
mmoSummary.Lines.Add(sSummary);
end;
mmoSummary.Lines.Add('');
sSummary := 'Selected options ';
mmoSummary.Lines.Add(sSummary);
If (radPathYes.Checked = True) Then
sSummary := sFill + 'Full path information saved'
Else
sSummary := sFill + 'Only filenames saved';
mmoSummary.Lines.Add(sSummary);
If (radPasswordYes.Checked = True) Then
sSummary := sFill + 'Files will be encrypted'
Else
sSummary := sFill + 'Files will not be encrypted';
mmoSummary.Lines.Add(sSummary);
If (radCompressNone.Checked = True) Then
sSummary := sFill + 'Files will be stored without compression'
Else If (radCompressMinimum.Checked = True) Then
sSummary := sFill + 'Files will hame minimum compressed'
Else If (radCompressNormal.Checked = True) Then
sSummary := sFill + 'Files will have normal compression'
Else
sSummary := sFill + 'Files will have maximum compression';
mmoSummary.Lines.Add(sSummary);
If (radMultiYes.Checked = True) Then
sSummary := sFill + 'Archive may span multiple disks'
Else
sSummary := sFill + 'Archive will not span disks';
mmoSummary.Lines.Add(sSummary);
If (radLFNYes.Checked = True) Then
sSummary := sFill + 'Long filenames will be stored'
Else
sSummary := sFill + 'Short (8.3) filenames will be stored';
mmoSummary.Lines.Add(sSummary);
If (radCommentYes.Checked = True) Then
begin
sSummary := sFill + 'Archive will have a comment added';
mmoSummary.Lines.Add(sSummary);
end;
end;
procedure TfrmWizard.edtArchiveChange(Sender: TObject);
begin
If (Length(edtArchive.Text) = 0) Then
btnNext.Enabled := False
Else
btnNext.Enabled := True;
end;
{Supresses leading and trailing blanks}
function TfrmWizard.Trim(s : string) : string;
var
sLen : byte absolute s;
begin
while (sLen>0) and (s[1] in [' ',^I]) do
Delete(s,1,1);
while (sLen>0) and (s[sLen] in [' ',^I]) do
Dec(sLen);
result:=s;
end;
procedure TfrmWizard.btnFinishClick(Sender: TObject);
var
iResult : Integer;
pMsg : PChar;
begin
pMsg := StrAlloc(80);
If (grpStep5.Visible = False) Then
begin
DisplaySummary;
HideGroup(m_iStep);
ShowGroup(m_cMaxSteps);
m_iStep := m_cMaxSteps;
End;
StrCopy(pMsg, 'You are about to start creating the archive.' + #13#13 + 'Press OK to proceed, Cancel to quit.');
iResult := Application.MessageBox(pMsg, 'Zip Wizard', MB_APPLMODAL + MB_OKCANCEL + MB_ICONQUESTION);
If iResult = IDOK then
begin
sArchiveName := edtArchive.Text;
DOZIP;
end;
StrCopy(pMsg, 'Finished creating archive.');
iResult := Application.MessageBox(pMsg, 'Zip Wizard', MB_APPLMODAL + MB_OK + MB_ICONINFORMATION);
StrDispose(pMsg);
Close;
end;
procedure TfrmWizard.btnAddClick(Sender: TObject);
var
sFilename : String;
begin
sFilename := lstFiles.Filename;
lstSelected.Items.Add(LowerCase(sFilename));
If (lstSelected.items.Count = 1) Then
begin
btnNext.Enabled := True;
btnFinish.Enabled := True;
btnRemove.Enabled := True;
end;
end;
procedure TfrmWizard.btnRemoveClick(Sender: TObject);
begin
lstSelected.Items.Delete(lstSelected.ItemIndex);
If (lstSelected.Items.Count = 0) Then
begin
btnNext.Enabled := False;
btnFinish.Enabled := False;
btnRemove.Enabled := False;
End;
end;
procedure TfrmWizard.lstFilesClick(Sender: TObject);
begin
btnAdd.Enabled := True;
end;
procedure TfrmWizard.dirFilesChange(Sender: TObject);
begin
btnAdd.Enabled := False;
end;
procedure TfrmWizard.radCommentNoClick(Sender: TObject);
begin
If (radCommentNo.Checked = True) Then
mmoComment.Enabled := False;
end;
procedure TfrmWizard.radCommentYesClick(Sender: TObject);
begin
If (radCommentYes.Checked = True) Then
mmoComment.Enabled := True;
end;
procedure TfrmWizard.radPasswordNoClick(Sender: TObject);
begin
If (radPasswordNo.Checked = True) Then
begin
edtPassword.Enabled := False;
lblPassword.Enabled := False;
End;
end;
procedure TfrmWizard.radPasswordYesClick(Sender: TObject);
begin
If (radPasswordYes.Checked = True) Then
begin
edtPassword.Enabled := True;
lblPassword.Enabled := True;
End;
end;
procedure TfrmWizard.btnBrowseClick(Sender: TObject);
begin
with TOpenDialog.Create(Self) do
try
Title := 'Enter a name for a .ZIP archive';
Filename := '';
InitialDir := ExtractFilepath(Application.ExeName);
DefaultExt := '.ZIP';
Filter := 'ZIP Files (*.ZIP)|*.ZIP|All Files (*.*)|*.*';
FilterIndex := 1;
HelpContext := 0;
Options := Options + [ofPathMustExist];
if Execute then
begin
If Trim(Filename) <> '' Then
edtArchive.Text := Filename
Else
edtArchive.Text := '';
End
Else
edtArchive.Text := ''
finally
Free
end;
end;
procedure TfrmWizard.WMGetMinMaxInfo(var MSG: Tmessage);
Begin
inherited;
with PMinMaxInfo(MSG.lparam)^ do
begin
with ptMaxTrackSize do
begin
X := 504;
Y := 440;
end;
with ptMinTrackSize do
begin
X := 504;
Y := 440;
end;
end;
end;
procedure TfrmWizard.DOZip;
var
{$IFDEF WIN32}
sTempFile : String[255];
{$ELSE}
sTempFile : String[128];
{$ENDIF}
sResult : String;
pPassWord, pTempFile, pArchiveName, pFiles : PChar;
I : Integer;
begin
pFiles := StrAlloc(65526);
{$IFDEF WIN32}
pArchiveName := StrAlloc(255);
pTempFile := StrAlloc(255);
{$ELSE}
pArchiveName := StrAlloc(127);
pTempFile := StrAlloc(127);
{$ENDIF}
If chkSFX.State = cbChecked then
begin
i := addZIP_BuildSFX(True);
sResult := ChangeFileExt(sArchiveName, '.EXE');
sArchiveName := sResult;
end;
{ Set the name of the archive}
StrPCopy(pArchiveName, sArchiveName);
I := addZIP_ArchiveName(pArchiveName);
{ Create pipe-delimited list of files and call the appropriate function}
StrCopy(pFiles, '');
For I := 0 To lstSelected.Items.Count - 1 do
begin
sTempFile := Trim(lstSelected.Items[I]) + '|';
StrCopy(pTempFile, '');
StrPCopy(pTempFile, sTempFile);
StrCat(pFiles, pTempFile);
end;
I := addZIP_Include(pFiles);
If (radPathYes.Checked = True) Then
I := addZIP_SaveStructure(azSTRUCTURE_ABSOLUTE)
Else
I := addZIP_SaveStructure(azSTRUCTURE_RELATIVE);
If (radPasswordYes.Checked = True) Then
begin
pPassWord := StrAlloc(Length(edtPassword.Text) + 1);
StrPCopy(pPassWord, edtPassword.Text);
I := addZIP_Encrypt(pPassword);
StrDispose(pPassWord);
end;
If (radCompressNone.Checked = True) Then
I := addZIP_SetCompressionLevel(azCOMPRESSION_NONE)
Else If (radCompressMinimum.Checked = True) Then
I := addZIP_SetCompressionLevel(azCOMPRESSION_MINIMUM)
Else If (radCompressNormal.Checked = True) Then
I := addZIP_SetCompressionLevel(azCOMPRESSION_NORMAL)
Else
I := addZIP_SetCompressionLevel(azCOMPRESSION_MAXIMUM);
If (radMultiYes.Checked = True) Then
I := addZIP_Span(True)
Else
I := addZIP_Span(False);
If (radLFNYes.Checked = True) Then
I := addZIP_UseLFN(True)
Else
I := addZIP_UseLFN(False);
If (radCommentYes.Checked = True) Then
begin
I := addZIP_Comment(mmoComment.Lines.GetText);
end;
I := addZIP;
StrDispose(pFiles);
StrDispose(pArchiveName);
StrDispose(pTempFile);
end;
{$IFDEF USE_CALLBACKS}
function ProcessCallbackData(iLibrary, iMessage : Short; pInfo : PChar) : Integer;
{$IFDEF WIN32} stdcall; {$ENDIF}
var
cAdditem : String;
begin
With frmWizard do
Case iMessage of
AM_SEARCHING : begin
{comment}
end;
AM_ZIPCOMMENT : begin
{comment}
end;
AM_ZIPPING : begin
cAdditem := ' Zipping ' + ExtractFileName(GetCompFileName(StrPas(pInfo)));
cAdditem := cAdditem + ' - ' + GetPercentComplete(StrPas(pInfo));
lblInfo.Caption := cAdditem;
lblInfo.Update;
end;
AM_ZIPPED : begin
{comment}
end;
AM_UNZIPPING : begin
{comment}
end;
AM_UNZIPPED : begin
{comment}
end;
AM_TESTING : begin
{comment}
end;
AM_TESTED : begin
{comment}
end;
AM_DELETING : begin
{comment}
end;
AM_DELETED : begin
{comment}
end;
AM_DISKCHANGE : begin
{comment}
end;
AM_VIEW : begin
{comment}
end;
AM_ERROR : begin
{error}
end;
AM_WARNING : begin
{warning}
end;
AM_QUERYOVERWRITE : begin
{
I have set the overwrite query option to default to NO to avoid a GPF
when the replace dialog (from QuickZip) is displayed
}
{ProcessCallbackData := azOW_YES;}
{ProcessCallbackData := azOW_YES_TO_ALL;}
ProcessCallbackData := azOW_NO;
{ProcessCallbackData := azOW_NO_TO_ALL;}
end;
AM_COPYING : begin
{comment}
end;
AM_COPIED : begin
{comment}
end;
end;
end;
{$ENDIF}
procedure TfrmWizard.edtHiddenChange(Sender: TObject);
{$IFNDEF USE_CALLBACKS}
var
cAdditem : String;
iAction : Integer;
{$ENDIF}
begin
{$IFNDEF USE_CALLBACKS}
iAction := StrToInt(GetAction((edtHidden.Text)));
Case iAction of
AM_SEARCHING : begin
{comment}
end;
AM_ZIPCOMMENT : begin
{comment}
end;
AM_ZIPPING : begin
cAdditem := 'Zipping ' + GetPiece((edtHidden.Text), '|', 4);
cAdditem := cAdditem + ' - ' + GetPercentComplete((edtHidden.Text));
lblInfo.Caption := cAdditem;
lblInfo.Update;
end;
AM_ZIPPED : begin
{comment}
end;
AM_UNZIPPING : begin
{comment}
end;
AM_UNZIPPED : begin
{comment}
end;
AM_TESTING : begin
{comment}
end;
AM_TESTED : begin
{comment}
end;
AM_DELETING : begin
{comment}
end;
AM_DELETED : begin
{comment}
end;
AM_DISKCHANGE : begin
{comment}
end;
AM_VIEW : begin
{comment}
end;
AM_ERROR : begin
{error}
end;
AM_WARNING : begin
{warning}
end;
AM_QUERYOVERWRITE : begin
{comment}
end;
AM_COPYING : begin
{comment}
end;
AM_COPIED : begin
{comment}
end;
end;
{$ENDIF}
end;
end.