Разработка файловой оболочки

Информация - Компьютеры, программирование

Другие материалы по предмету Компьютеры, программирование

FindForm.Refresh;

FindFile;

FindForm.FileWasFind.Sorted:=True;

FindForm.FileWasFind.Refresh;

FindForm.StatusFind.Panels[1].Text:=;

end;

 

procedure TFindForm.CBFindMaskDropDown(Sender: TObject);

begin

InitFileMask;

end;

 

procedure TFindForm.RBCurDirClick(Sender: TObject);

begin

WhereFind;

end;

 

procedure TFindForm.RBCurDriveClick(Sender: TObject);

begin

WhereFind

end;

 

procedure TFindForm.RBAllDrivesClick(Sender: TObject);

begin

WhereFind;

end;

 

procedure TFindForm.ExitSearchClick(Sender: TObject);

begin

FindForm.Close;

end;

 

procedure TFindForm.CBAdvSearchClick(Sender: TObject);

begin

if CBAdvSearch.Checked then

begin

Table.ActivePage:=Advanced Search;

end;

end;

 

procedure TFindForm.MenuPopup(Sender: TObject);

var i:integer;

begin

for i:=0 to FindForm.FileWasFind.Items.Count-1 do

If FindForm.FileWasFind.Selected[i] then

begin

FindForm.Run1.Enabled:=True;

FindForm.GoTo1.Enabled:=True;

Break;

end

else

begin

FindForm.Run1.Enabled:=False;

FindForm.GoTo1.Enabled:=False;

end;

end;

 

procedure TFindForm.Run1Click(Sender: TObject);

//Запуск файла из формы поиска

Var

i:integer;

begin

For i:=0 to FindForm.FileWasFind.Items.Count-1 do

if FindForm.FileWasFind.Selected[i] then

begin

ExecuteFile(FindForm.FileWasFind.Items[i],,,SW_SHOW);

break;

end;

FindForm.Close;

end;

 

Procedure GoToFile;

// Преход в главную форму к месту расположения найденного файла

Var

i,j:integer;

Dir,FileName:string;

begin

for i:=0 to FindForm.FileWasFind.Items.Count-1 do

begin

if FindForm.FileWasFind.Selected[i] then

begin

FileName:=ExtractFileName(FindForm.FileWasFind.Items[i]);

FindForm.Close;

Dir:=FindForm.FileWasFind.Items[i];

for j:=Length(Dir) downTo 0 do

begin

if Dir[j]=\ then

begin

Dir[j+1]:=#0;

break;

end;

end;

MainForm.Directory.SetDrive(Dir[1]);

MainForm.Directory.Expand(1);

MainForm.Directory.SetDirectory(Dir);

MainForm.Directory.BuildTree;

MainForm.FileList.Refresh;

for j:=0 to MainForm.FileList.Items.Count-1 do

begin

if MainForm.FileList.Items[j]=FileName then

begin

MainForm.FileList.Selected[j]:=True;

MainForm.FileList.Refresh;

break;

end;

end;

break

end

end;

end;

 

procedure TFindForm.GoTo1Click(Sender: TObject);

begin

GotoFile;

end;

 

procedure TFindForm.B2Click(Sender: TObject);

begin

GotoFile;

end;

 

procedure TFindForm.B1Click(Sender: TObject);

begin

Run1Click(Sender);

end;

 

procedure TFindForm.Timer1Timer(Sender: TObject);

begin

if FileWasFind.SelCount<=0 then

begin

B1.Enabled:=False;

B2.Enabled:=False;

end

else

begin

B1.Enabled:=True;

B2.Enabled:=True;

end;

end;

 

procedure TFindForm.FormClose(Sender: TObject; var Action: TCloseAction);

begin

Timer1.Enabled:=False;

end;

end.

 

 

 

 

 

 

 

Изменённый стандартный модульunit

 

FmxUtils; //Изменённый стандартный модуль

// Внесйнные изменения отмечены "{}"

 

interface

 

uses SysUtils, Windows, Classes, Consts;

 

type

EInvalidDest = class(EStreamError);

EFCantMove = class(EStreamError);

procedure CopyFile(const FileName, DestName: string);

procedure MoveFile(const FileName, DestName: string);

function GetFileSize(const FileName: string): LongInt;

function FileDateTime(const FileName: string): TDateTime;

function HasAttr(const FileName: string; Attr: Word): Boolean;

function ExecuteFile(const FileName, Params, DefaultDir: string;

ShowCmd: Integer): THandle;

{} Var AllReadByteFile:Real;

{} SizeAllCopy:Longint;

implementation

 

uses Forms, ShellAPI, UProgressForm, UMainForm_, UNotTrivial,UMainForm;

 

const

SInvalidDest = Destination %s does not exist;

SFCantMove = Cannot move file %s;

 

procedure CopyFile(const FileName, DestName: TFileName);

var

FileSizeProgress,ReadByteFile:Real;

CopyBuffer: Pointer; { buffer for copying }

BytesCopied: Longint;

Source, Dest: Integer; { handles }

Destination: TFileName; { holder for expanded destination name }

const

ChunkSize: Longint = 8192; { copy in 8K chunks }

begin

Destination := ExpandFileName(DestName); { expand the destination path }

if HasAttr(Destination, faDirectory) then { if destination is a directory... }

Destination := Destination + ExtractFileName(FileName); { ...clone file name }

GetMem(CopyBuffer, ChunkSize); { allocate the buffer }

try

Source := FileOpen(FileName, fmShareDenyWrite); { open source file }

if Source < 0 then raise EFOpenError.CreateFmt(SFOpenError, [FileName]);

try

Dest := FileCreate(Destination); { create output file; overwrite existing }

if Dest < 0 then raise EFCreateError.CreateFmt(SFCreateError, [Destination]);

try

//Ведение статистики в форме прогресса копирования

{} If MainForm.CMFileList.Items.Count=0 then

{} SizeAllCopy:=GetSizeAllFiles(MainForm.TempCopyMove);

{} ProgressForm.ProgresCopy.Progress:=0;

{} ProgressForm.Total.Caption:=FormatSize(IntToStr(SizeAllCopy));

{} FileSizeProgress:=GetFileSize(FileName);

{} ProgressForm.LFrom.Caption:=FileName;

{} ProgressForm.LFileSize.Caption:=FormatSize(IntToStr(GetFileSize(FileName)));

{} ProgressForm.LTo.Caption:=Destination;

{} ProgressForm.Update;

{} ReadByteFile:=0;

repeat

BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk }

{} if ChunkSize>GetFileSize(FileName)then

{} ReadByteFile:=ReadByteFile+GetFileSize(FileName)

{} else

{} ReadByteFile:=ReadByteFile+ChunkSize;

{} ProgressForm.LREadyWrite.Caption:=FormatSize(FloatToStr(ReadByteFile));

{} ProgressForm.Update;

{} ProgressForm.ProgresCopy.Progress:=FloatToInt(((100*ReadByteFile)/(FileSizeProgress+1)));

{End Paste}

if BytesCopied > 0 then { if we read anything... }

FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }

{} ProgressForm.ProgresCopy.Repaint;

{} ProgressForm.AllProgresCopy.Repaint;

until BytesCopied < ChunkSize; { until we run out of chunks }

{} AllReadByteFile:=AllReadByteFile+GetFileSize(FileName);

{} ProgressForm.Ready.Caption:=FormatSize(FloatToStr(AllReadByteFile));

{} ProgressForm.AllProgresCopy.Progress:=FloatToInt(((100*(AllReadByteFile)/(SizeAllCopy+1))));

{} ProgressForm.ProgresCopy.Progress:=100;

finally

FileClose(Dest); { close the destination file }

end;

finally

FileClose(Source); { close the source file }

end;

finally

FreeMem(CopyBuffer, ChunkSize); { free the buffer }

end;

end;

 

 

{ MoveFile procedure }

{

Moves the file passed in FileName to the directory specified in DestDir.

Tries to just rename the file. If that fails, try to copy the file and

delete the original.

 

Raises an exception if the source file is read-only, and therefore cannot

be deleted/moved.

}

 

procedure MoveFile(const FileName, DestName: string);

var

Destination: string;

begin

Destination := ExpandFileName(DestName); { expand the destination path }

if not RenameFile(FileName, Destination) then { try just renaming }

begin

CopyFile(FileName, Destination); { copy it over to destination...}

DelOneFile(FileName,All);

end;

end;

 

{ GetFileSize function }

{

Returns the size of the named file without opening the file. If the file

doesnt exist, returns -1.

}

 

function GetFileSize(const FileName: string): LongInt;

var

SearchRec: TSearchRec;

begin

if FindFir