1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
//------------------------------------------------------------------------------------------------------------------------------
Unit backup;
interface
uses
Winapi.Windows, Winapi.Messages, SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.ExtCtrls, Zip, Vcl.FileCtrl,
Vcl.ComCtrls, Vcl.CheckLst, common_Thread;
type
TBackupThread = class(TThread)
protected
procedure Execute; override;
Public
OkTerminate : boolean;
AbortRequested: boolean;
ErrorCount : integer;
CurrentFileId : integer;
Constructor Create(CreateSuspended:boolean);
End;
implementation
{$R *.dfm}
uses Ioutils,versions,common,ShlObj, ComObj, ActiveX ,config,FormDiagnostique,DateUtils;
//------------------------------------------------------------------------------------------------------------------------------
// TThreadBackup
//------------------------------------------------------------------------------------------------------------------------------
Constructor TBackupThread.Create(CreateSuspended:boolean);
Begin
inherited;
OkTerminate := false;
AbortRequested:= false;
ErrorCount := 0;
CurrentFileId := 0;
End;
//------------------------------------------------------------------------------------------------------------------------------
procedure TBackupThread.execute;
var
zip : TZipFile;
S, Msg, SrcPathAndName, NameInZip : string;
i,p : integer;
EmptyBytes: TBytes;
Begin
ErrorCount := 0;
AbortRequested:=false;
with BackupForm do
Begin
zip := TZipFile.Create;
Zip.Open(FName, zmWrite);
for i := 0 to FileList.Count-1 do
Begin
CurrentFileId := i;
S := FileList.strings[i];
p := pos('>',S);
SrcPathAndName := copy(S,1,p-1);
delete(S,1,p);
NameInZip := S;
try
if (SrcPathAndName='') then
Begin
Msg := 'Adding directory '+NameInZip;
FileDone.Add(Msg);
Zip.Add(EmptyBytes,NameInZip, zcStored); // it is a directory only, add the directory
end else
Begin
Msg := 'Adding file '+SrcPathAndName;
FileDone.Add(Msg);
Zip.Add(SrcPathAndName, NameInZip); // it is a file
end;
FileDone.Delete(FileDone.count-1);
FileDone.Add(Msg+' --> done');
except
FileDone.Delete(FileDone.count-1);
FileDone.Add('>>>>>> ERROR '+Msg);
inc(ErrorCount);
end;
if AbortRequested then break;
End;
zip.free;
End;
OkTerminate := true;
End; |
Partager