📄 findcarrier.pas
字号:
unit findcarrier;
interface
uses
SysUtils, Classes
,CarrierFile, BMPReplace, ASCIIReplace, ASCIIInsert, PDFInsert,
MultiLang
{$IFDEF CLX}
, QForms, QStdCtrls, QControls, QDialogs
{$ELSE}
, Forms, StdCtrls, FileCtrl, Controls
{$ENDIF}
;
type
TForm4 = class(TForm)
Button2: TButton;
Button3: TButton;
Button1: TButton;
Edit1: TEdit;
Memo1: TMemo;
Button4: TButton;
ListBox1: TListBox;
Label1: TLabel;
ComboBox1: TComboBox;
Button5: TButton;
CheckBox1: TCheckBox;
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
FilesFound: TStrings;
FileSize: TStrings;
quit: Boolean;
procedure ProcessDirectory(Dir, Mask: String);
public
Filename: String;
SpaceNeeded: Longint;
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
procedure TForm4.Button3Click(Sender: TObject);
begin
quit:=true;
Filename:='undefined';
Close;
end;
procedure TForm4.Button2Click(Sender: TObject);
begin
if ListBox1.ItemIndex<0 then Filename:='undefined'
else FileName:=ListBox1.Items.Strings[ListBox1.ItemIndex];
Close;
end;
procedure TForm4.Button1Click(Sender: TObject);
var
Caption: String;
Result: String;
Start: WideString;
begin
Caption:=ml.GetCodeString('findcarrier',1);
Start:='/';
SelectDirectory(Caption,Start,Result);
Edit1.Text:=Result;
end;
procedure TForm4.FormShow(Sender: TObject);
begin
ListBox1.Items.Clear;
ComboBox1.ItemIndex:=0;
quit:=false;
end;
procedure TForm4.ProcessDirectory(Dir, Mask: String);
var
fsr: TSearchRec;
myCarrier: TCarrierFile;
myBMP: TBMPReplace;
myPDF: TPDFInsert;
myASC: TASCIIReplace;
myTXT: TASCIIInsert;
rep: Integer;
i: Integer;
Meth: Integer;
sp: Longint;
oMask: String;
mh: Integer;
begin
if quit then exit;
oMask:=Mask;
if Mask='*.*' then rep:=4 else rep:=1;
i:=0;
while i<rep do begin
if Mask='*.ASC' then begin
Mask:='*.TXT';
Meth:=0;
end
else Meth:=1;
if rep=4 then begin
if i=0 then Mask:='*.BMP';
if i=1 then Mask:='*.TXT';
if i=2 then Mask:='*.HTM';
if i=3 then Mask:='*.PDF';
end;
if Dir[Length(Dir)]='/' then Dir:=Copy(Dir,1,Length(Dir)-1);
if (FindFirst(Dir+'/*.*',faAnyFile,fsr)=0) And (CheckBox1.Checked) then begin
if ((fsr.Attr and faDirectory)<>0) and (fsr.Name<>'.') and (fsr.Name<>'..') then ProcessDirectory(Dir+'/'+fsr.Name,oMask);
while FindNext(fsr)=0 do begin
Application.ProcessMessages;
for mh:=1 to 10 do Application.HandleMessage;
if ((fsr.Attr and faDirectory)<>0) and (fsr.Name<>'.') and (fsr.Name<>'..') then ProcessDirectory(Dir+'/'+fsr.Name,oMask);
if quit then exit;
end;
end;
FindClose(fsr);
if (FindFirst(Dir+'/'+Mask,faAnyFile,fsr)=0) and not(quit) then begin
Application.ProcessMessages;
for mh:=1 to 10 do Application.HandleMessage;
myCarrier:=TCarrierFile.Create;
myCarrier.LoadFromFile(Dir+'/'+fsr.Name);
if Mask='*.BMP' then begin
myCarrier.SetFileType('BMP',0);
myBMP:=TBMPReplace.Create;
myBMP.CreateFromCarrierFile(myCarrier);
if myBMP.isUsable='OK' then begin
sp:=myBMP.GetAvailSize;
if sp>(SpaceNeeded+4) then begin
FilesFound.Add(Dir+'/'+fsr.Name);
FileSize.Add(InttoStr(sp));
// adding to list box
Listbox1.Items.Add(Dir+'/'+fsr.Name);
Application.ProcessMessages;
end;
end;
myBMP.Free;
end;
if (Mask='*.TXT') and (Meth=0) then begin
myCarrier.SetFileType('ASC',0);
myASC:=TASCIIReplace.Create;
myASC.CreateFromCarrierFile(myCarrier);
if myASC.isUsable='OK' then begin
sp:=myASC.GetAvailSize;
if sp>(SpaceNeeded+4) then begin
FilesFound.Add(Dir+'/'+fsr.Name);
FileSize.Add(InttoStr(sp));
// adding to list box
Listbox1.Items.Add(Dir+'/'+fsr.Name);
Application.ProcessMessages;
end;
end;
myASC.Free;
end;
if (Mask='*.TXT') or (Mask='*.HTM') then begin
myCarrier.SetFileType('TXT',0);
myTXT:=TASCIIInsert.Create;
myTXT.CreateFromCarrierFile(myCarrier);
if myTXT.isUsable='OK' then begin
sp:=myTXT.GetAvailSize;
if sp>(SpaceNeeded+4) then begin
FilesFound.Add(Dir+'/'+fsr.Name);
FileSize.Add(InttoStr(sp));
// adding to list box
Listbox1.Items.Add(Dir+'/'+fsr.Name);
Application.ProcessMessages;
end;
end;
myTXT.Free;
end;
if Mask='*.PDF' then begin
myCarrier.SetFileType('PDF',0);
myPDF:=TPDFInsert.Create;
myPDF.CreateFromCarrierFile(myCarrier);
if myPDF.isUsable='OK' then begin
sp:=myPDF.GetAvailSize;
if sp>(SpaceNeeded+4) then begin
FilesFound.Add(Dir+'/'+fsr.Name);
FileSize.Add(InttoStr(sp));
// adding to list box
Listbox1.Items.Add(Dir+'/'+fsr.Name);
Application.ProcessMessages;
end;
end;
myPDF.Free;
end;
myCarrier.Free;
while (FindNext(fsr)=0) and not(quit) do begin
Application.ProcessMessages;
for mh:=1 to 10 do Application.HandleMessage;
if quit then exit;
myCarrier:=TCarrierFile.Create;
myCarrier.LoadFromFile(Dir+'/'+fsr.Name);
if Mask='*.BMP' then begin
myCarrier.SetFileType('BMP',0);
myBMP:=TBMPReplace.Create;
myBMP.CreateFromCarrierFile(myCarrier);
if myBMP.isUsable='OK' then begin
sp:=myBMP.GetAvailSize;
if sp>(SpaceNeeded+4) then begin
FilesFound.Add(Dir+'/'+fsr.Name);
FileSize.Add(InttoStr(sp));
// adding to list box
Listbox1.Items.Add(Dir+'/'+fsr.Name);
Application.ProcessMessages;
end;
end;
myBMP.Free;
end;
if (Mask='*.TXT') and (Meth=0) then begin
myCarrier.SetFileType('ASC',0);
myASC:=TASCIIReplace.Create;
myASC.CreateFromCarrierFile(myCarrier);
if myASC.isUsable='OK' then begin
sp:=myASC.GetAvailSize;
if sp>(SpaceNeeded+4) then begin
FilesFound.Add(Dir+'/'+fsr.Name);
FileSize.Add(InttoStr(sp));
// adding to list box
Listbox1.Items.Add(Dir+'/'+fsr.Name);
Application.ProcessMessages;
end;
end;
myASC.Free;
end;
if (Mask='*.TXT') or (Mask='*.HTM') then begin
myCarrier.SetFileType('TXT',0);
myTXT:=TASCIIInsert.Create;
myTXT.CreateFromCarrierFile(myCarrier);
if myTXT.isUsable='OK' then begin
sp:=myTXT.GetAvailSize;
if sp>(SpaceNeeded+4) then begin
FilesFound.Add(Dir+'/'+fsr.Name);
FileSize.Add(InttoStr(sp));
// adding to list box
Listbox1.Items.Add(Dir+'/'+fsr.Name);
Application.ProcessMessages;
end;
end;
myTXT.Free;
end;
if Mask='*.PDF' then begin
myCarrier.SetFileType('PDF',0);
myPDF:=TPDFInsert.Create;
myPDF.CreateFromCarrierFile(myCarrier);
if myPDF.isUsable='OK' then begin
sp:=myPDF.GetAvailSize;
if sp>(SpaceNeeded+4) then begin
FilesFound.Add(Dir+'/'+fsr.Name);
FileSize.Add(InttoStr(sp));
// adding to list box
Listbox1.Items.Add(Dir+'/'+fsr.Name);
Application.ProcessMessages;
end;
end;
myPDF.Free;
end;
myCarrier.Free;
end;
end;
FindClose(fsr);
Inc(i);
end;
end;
procedure TForm4.Button4Click(Sender: TObject);
var
Mask: String;
min: Longint;
midx: Integer;
i,j: Integer;
n: Longint;
begin
Cursor:=crHourGlass;
Button1.Cursor:=crHourGlass;
Button2.Cursor:=crHourGlass;
Button3.Cursor:=crHourGlass;
Button4.Cursor:=crHourGlass;
Edit1.Cursor:=crHourGlass;
ListBox1.Cursor:=crHourGlass;
Memo1.Cursor:=crHourGlass;
ComboBox1.Cursor:=crHourGlass;
Label1.Cursor:=crHourGlass;
FilesFound:=TStringList.Create;
FileSize:=TStringList.Create;
FilesFound.Clear;
FileSize.Clear;
ListBox1.Items.Clear;
case ComboBox1.ItemIndex of
0: Mask:='*.*';
1: Mask:='*.BMP';
2: Mask:='*.ASC';
3: Mask:='*.TXT';
4: Mask:='*.HTM';
end;
ProcessDirectory(Edit1.Text,Mask);
// sorting
ListBox1.Items.Clear;
for i:=0 to FilesFound.Count-1 do begin
min:=2000000000;
n:=0;
midx:=0;
for j:=0 to FilesFound.Count-1 do begin
n:=StrToInt(FileSize.Strings[j]);
if min>n then begin
min:=n;
midx:=j;
end;
end;
ListBox1.Items.Add(FilesFound.Strings[midx]);
FilesFound.Delete(midx);
FileSize.Delete(midx);
end;
//
FilesFound.Free;
FileSize.Free;
Cursor:=crDefault;
Button1.Cursor:=crDefault;
Button2.Cursor:=crDefault;
Button3.Cursor:=crDefault;
Button4.Cursor:=crDefault;
Edit1.Cursor:=crDefault;
ListBox1.Cursor:=crDefault;
Memo1.Cursor:=crDefault;
ComboBox1.Cursor:=crDefault;
Label1.Cursor:=crDefault;
end;
procedure TForm4.FormCreate(Sender: TObject);
begin
Form4.Caption:=ml.GetComponentString('findcarrier.Form4.Caption');
Button1.Caption:=ml.GetComponentString('findcarrier.Button1.Caption');
Button2.Caption:=ml.GetComponentString('findcarrier.Button2.Caption');
Button3.Caption:=ml.GetComponentString('findcarrier.Button3.Caption');
Button4.Caption:=ml.GetComponentString('findcarrier.Button4.Caption');
Button5.Caption:=ml.GetComponentString('findcarrier.Button5.Caption');
ml.GetComponentStringList('findcarrier.ComboBox1.Items',ComboBox1.Items);
Edit1.Text:=ml.GetComponentString('findcarrier.Edit1.Text');
Label1.Caption:=ml.GetComponentString('findcarrier.Label1.Caption');
ml.GetComponentStringList('findcarrier.Memo1.Lines',Memo1.Lines);
end;
procedure TForm4.Button5Click(Sender: TObject);
begin
{$IFDEF CLX}
Application.HelpSystem.ShowContextHelp(900,Application.HelpFile);
{$ELSE}
Application.HelpContext(900);
{$ENDIF}
end;
procedure TForm4.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose:=True;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -