MMFFEdit.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:9k
- {========================================================================}
- {= (c) 1995-98 SwiftSoft Ronald Dittrich =}
- {========================================================================}
- {= All Rights Reserved =}
- {========================================================================}
- {= D 01099 Dresden = Tel.: +0351-8012255 =}
- {= Loewenstr.7a = info@swiftsoft.de =}
- {========================================================================}
- {= Actual versions on http://www.swiftsoft.de/mmtools.html =}
- {========================================================================}
- {= This code is for reference purposes only and may not be copied or =}
- {= distributed in any format electronic or otherwise except one copy =}
- {= for backup purposes. =}
- {= =}
- {= No Delphi Component Kit or Component individually or in a collection=}
- {= subclassed or otherwise from the code in this unit, or associated =}
- {= .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed =}
- {= without express permission from SwiftSoft. =}
- {= =}
- {= For more licence informations please refer to the associated =}
- {= HelpFile. =}
- {========================================================================}
- {= $Date: 1/29/98 - 5:41:42 PM $ =}
- {========================================================================}
- unit MMFFEdit;
- {$I COMPILER.INC}
- interface
- uses
- Windows,
- Messages,
- SysUtils,
- Classes,
- Graphics,
- Controls,
- Forms,
- Dialogs,
- StdCtrls,
- ComCtrls,
- MMObj,
- MMUtils,
- MMFFile,
- ExtCtrls
- {$IFDEF DELPHI4}
- ,ImgList
- {$ENDIF}
- ;
- type
- {-- TMMFFileDlg ------------------------------------------------}
- TMMFFileDlg = class(TForm)
- FileOpenDialog: TOpenDialog;
- Small: TImageList;
- FileSaveDialog: TSaveDialog;
- ListView: TListView;
- Label1: TLabel;
- lblFile: TLabel;
- Label3: TLabel;
- lblMaxFiles: TLabel;
- Label2: TLabel;
- lblFiles: TLabel;
- AddBtn: TButton;
- DelBtn: TButton;
- ExtractBtn: TButton;
- OKBtn: TButton;
- FastFile: TMMFastFile;
- procedure ListViewEnter(Sender: TObject);
- procedure ListViewExit(Sender: TObject);
- procedure ListViewChange(Sender: TObject; Item: TListItem; Change: TItemChange);
- procedure FastFileChange(Sender: TObject);
- procedure AddBtnClick(Sender: TObject);
- procedure DelBtnClick(Sender: TObject);
- procedure ListViewEdited(Sender: TObject; Item: TListItem; var S: string);
- procedure ExtractBtnClick(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- private
- FTitle : string;
- UpdateView: Boolean;
- procedure UpdateListView;
- procedure SetTitle(aValue: string);
- public
- property Title: string read FTitle write SetTitle;
- end;
- {-- TMMFastFileDialog -------------------------------------------------------}
- TMMFastFileDialog = class(TMMNonVisualComponent)
- private
- FSource : TMMFastFile;
- FTitle : string;
- procedure SetSource(aSource: TMMFastFile);
- protected
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- public
- constructor Create(AOwner: TComponent); override;
- function Execute: Boolean;
- published
- property Source: TMMFastFile read FSource write SetSource;
- property Title: string read FTitle write FTitle;
- end;
- var
- MMFFileDlg: TMMFFileDlg;
- implementation
- {$R *.DFM}
- {$R MMFFILE.D32}
- uses Consts, FileCtrl;
- {== TMMFastFileEditDlg ==================================================}
- procedure TMMFFileDlg.FormCreate(Sender: TObject);
- begin
- FTitle := Caption;
- Small.ResourceLoad(rtBitmap,'BM_FASTFILE',clWhite);
- end;
- {-- TMMFastFileEditDlg --------------------------------------------------}
- procedure TMMFFileDlg.FormShow(Sender: TObject);
- begin
- {$IFDEF BUILD_ACTIVEX}
- FastFile.Left := -50;
- {$ENDIF}
- UpdateView := True;
- if FastFile.FileName <> '' then
- begin
- FastFile.Init;
- AddBtn.Enabled := True;
- lblFile.Caption := MinimizeName(FastFile.FileName,
- lblFile.Canvas, lblFile.Width);
- lblMaxFiles.Caption := IntToStr(FastFile.MaxFiles);
- end;
- FileOpenDialog.Filter := {$IFDEF DELPHI3}SDefaultFilter{$ELSE}LoadStr(SDefaultFilter){$ENDIF};
- FileSaveDialog.Filter := {$IFDEF DELPHI3}SDefaultFilter{$ELSE}LoadStr(SDefaultFilter){$ENDIF};
- UpdateListView;
- end;
- {-- TMMFastFileEditDlg --------------------------------------------------}
- procedure TMMFFileDlg.SetTitle(aValue: string);
- begin
- Caption := aValue;
- end;
- {-- TMMFastFileEditDlg --------------------------------------------------}
- procedure TMMFFileDlg.ListViewEnter(Sender: TObject);
- begin
- with ListView do
- if (Items.Count > 0) and (Selected = nil) then
- begin
- Selected := Items[0];
- ItemFocused := Selected;
- end;
- OKBtn.Default := False;
- end;
- {-- TMMFastFileEditDlg --------------------------------------------------}
- procedure TMMFFileDlg.ListViewExit(Sender: TObject);
- begin
- OKBtn.Default := True;
- end;
- {-- TMMFastFileEditDlg --------------------------------------------------}
- procedure TMMFFileDlg.UpdateListView;
- var
- i: Integer;
- begin
- if not UpdateView then exit;
- ListView.Items.Clear;
- for i := 0 to FastFile.Count-1 do
- with FastFile, ListView.Items.Add do
- begin
- Caption := FileEntries[i].Name;
- SubItems.Add(Format('%d KB', [Max(FileEntries[i].Size div 1024,1)]));
- SubItems.Add(Format('%.7x', [FileEntries[i].Offset]));
- end;
- lblFiles.Caption := IntToStr(FastFile.Count);
- end;
- {-- TMMFastFileEditDlg --------------------------------------------------}
- procedure TMMFFileDlg.ListViewChange(Sender: TObject; Item: TListItem; Change: TItemChange);
- begin
- DelBtn.Enabled := ListView.Selected <> nil;
- ExtractBtn.Enabled := DelBtn.Enabled;
- end;
- {-- TMMFastFileEditDlg --------------------------------------------------}
- procedure TMMFFileDlg.FastFileChange(Sender: TObject);
- begin
- UpdateListView;
- end;
- {-- TMMFastFileEditDlg --------------------------------------------------}
- procedure TMMFFileDlg.AddBtnClick(Sender: TObject);
- begin
- if FileOpenDialog.Execute then
- FastFile.AddFile(FileOpenDialog.FileName);
- end;
- {-- TMMFastFileEditDlg --------------------------------------------------}
- procedure TMMFFileDlg.DelBtnClick(Sender: TObject);
- begin
- if (ListView.Selected <> nil) then
- FastFile.RemoveFile(ListView.Selected.Caption);
- end;
- {-- TMMFastFileEditDlg --------------------------------------------------}
- procedure TMMFFileDlg.ListViewEdited(Sender: TObject; Item: TListItem; var S: string);
- begin
- UpdateView := False;
- FastFile.RenameFile(Item.Caption,S);
- UpdateView := True;
- end;
- {-- TMMFastFileEditDlg --------------------------------------------------}
- procedure TMMFFileDlg.ExtractBtnClick(Sender: TObject);
- begin
- if (ListView.Selected <> nil) then
- begin
- FileSaveDialog.FileName := ListView.Selected.Caption;
- if FileSaveDialog.Execute then
- FastFile.ExtractFile(ListView.Selected.Caption, FileSaveDialog.FileName);
- end;
- end;
- {== TMMFastFileDialog ===================================================}
- constructor TMMFastFileDialog.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- FTitle := 'FastFile-Editor';
- FSource := nil;
- ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
- if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
- end;
- {-- TMMFastFileDialog ---------------------------------------------------}
- procedure TMMFastFileDialog.SetSource(aSource: TMMFastFile);
- begin
- if Longint(aSource) = Longint(Self) then exit;
- if (aSource is TMMFastFile) or (aSource = nil) then
- begin
- if (FSource <> aSource) then
- begin
- FSource := aSource;
- end;
- end;
- end;
- {-- TMMFastFileDialog ---------------------------------------------------}
- procedure TMMFastFileDialog.Notification(AComponent: TComponent; Operation: TOperation);
- begin
- inherited Notification(AComponent, Operation);
- if (Operation = opRemove) and (AComponent = FSource) then
- FSource := nil;
- end;
- {-- TMMFastFileDialog --------------------------------------------------}
- function TMMFastFileDialog.Execute: Boolean;
- begin
- Result := False;
- if assigned(FSource) then
- begin
- MMFFileDlg := TMMFFileDlg.Create(Application);
- try
- MMFFileDlg.FastFile.FileName := FSource.FileName;
- MMFFileDlg.Title := FTitle;
- Result := (MMFFileDlg.ShowModal = mrOK);
- finally
- MMFFileDlg.Free;
- end;
- end;
- end;
- end.