[Setup]
AppName=My Program
AppVerName=My Program v.1.2
DefaultDirName={pf}\My Program
[Languages]
Name: ru; MessagesFile: compiler:Languages\Russian.isl
[_Code]
type
TMsg = record
hwnd: HWND;
message: UINT;
wParam: Longint;
lParam: Longint;
time: DWORD;
pt: TPoint;
end;
const
BlockSize = 65536;
PM_REMOVE = 1;
WM_QUIT = $0012;
var
Page: TInputDirWizardPage;
PB,PB2: TNewProgressBar;
L1,L2,L3:TNewStaticText;
DS,CS:Extended;
CancelBtn:TButton;
CancelOperation:boolean;
function PeekMessage(var lpMsg: TMsg; hWnd: HWND; wMsgFilterMin, wMsgFilterMax, wRemoveMsg: UINT): BOOL; external 'PeekMessageA@user32.dll stdcall';
function TranslateMessage(const lpMsg: TMsg): BOOL; external 'TranslateMessage@user32.dll stdcall';
function DispatchMessage(const lpMsg: TMsg): Longint; external 'DispatchMessageA@user32.dll stdcall';
procedure AppProcessMessage;
var
Msg: TMsg;
begin
while PeekMessage(Msg, WizardForm.Handle, 0, 0, PM_REMOVE) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
procedure CopyFile_(Source,Target: string);
var
FileSize,ElapsedSize,CopySize:LongWord;
SourceStream,TargetStream:TFileStream;
a:Extended;
begin
SourceStream:=TFileStream.Create(Source,fmOpenRead);
TargetStream:=TFileStream.Create(Target,fmCreate);
ElapsedSize:=SourceStream.Size-SourceStream.Position;
FileSize:=SourceStream.Size;
PB.Max:=100;
PB.Position:=0;
L1.Caption:=ExtractFileName(Source);
L2.Caption:='0 %';
while ElapsedSize>0 do begin
if ElapsedSize<BlockSize then CopySize:=ElapsedSize else CopySize:=BlockSize;
TargetStream.CopyFrom(SourceStream,CopySize);
ElapsedSize:=SourceStream.Size-SourceStream.Position;
a:=(ElapsedSize div FileSize)*100;
a:=100-a; //õç ÷å çäåñü çà ãëþêè, íî ïèñàòü ýòè äåéñòâèÿ â îäíó ñòðî÷êó íåëüçÿ
PB.Position:=Round(a);//SourceStream.Position;
L2.Caption:=IntToStr(PB.Position)+' %'
L2.Invalidate;
CS:=CS+BlockSize;//(1024*1024);
a:=CS*100; //òàêàÿ æå åðåñü, íàïèñàâ âñå
a:=a/DS //â îäíó ñòðîêó íè õðåíà íå ñ÷èòàåòñÿ
PB2.Position:=Round(a);//Round(CS*100/DS);
L3.Caption:=IntToStr(PB2.Position)+' %'
AppProcessMessage;
if CancelOperation then Break;
end;
//FileSetDate(TargetStream.Handle,FileGetDate(SourceStream.Handle));
//äàòó ôàéëà íàäîáû ñìåíèòü íà ñòàðóþ, äà âîçèòüñÿ ëåíü
TargetStream.Free;
SourceStream.Free;
if CancelOperation then DeleteFile(Target);
end;
procedure CopyDir(const FromDir,ToDir,FileMask:string;IncludeSubDirs:boolean);
var
FindRec:TFindRec;
sFileName,fd,td:string;
// i,j:Int64;
ii:integer;
begin
fd:=AddBackslash(FromDir);
td:=AddBackslash(ToDir);
ForceDirectories(td);
if FindFirst(fd+FileMask,FindRec) then begin
try
repeat
sFileName:=fd+FindRec.Name;
if ((FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY)=0) then CopyFile_(sFileName,td+FindRec.Name)
else
if IncludeSubDirs then
if (FindRec.Name<>'') and (FindRec.Name<>'.') and (FindRec.Name<>'..') then
CopyDir(sFileName,td+FindRec.Name,FileMask,IncludeSubDirs);
AppProcessMessage;
until not (FindNext(FindRec) and not CancelOperation);
finally
FindClose(FindRec);
end;
end;
end;
procedure GetDirSize(const Dir,FileMask:string;IncludeSubDirs:boolean);
var
FindRec:TFindRec;
sFileName,d:string;
// i:Int64;
begin
d:=AddBackslash(Dir);
if FindFirst(d+FileMask,FindRec) then begin
try
repeat
sFileName:=d+FindRec.Name;
if ((FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY)=0) then DS:=DS+4294967295*FindRec.SizeHigh+FindRec.SizeLow
else
if IncludeSubDirs then
if (FindRec.Name<>'') and (FindRec.Name<>'.') and (FindRec.Name<>'..') then GetDirSize(sFileName,FileMask,IncludeSubDirs);
AppProcessMessage;
until not (FindNext(FindRec) and not CancelOperation);
finally
FindClose(FindRec);
end;
end;
end;
procedure CancelBtnClick(Sender:TObject);
begin
CancelOperation:=True;
end;
procedure InitializeWizard();
begin
Page:=CreateInputDirPage(wpSelectTasks,'Ïðèìåð êîïèðîâàíèÿ ôàéëîâ', 'Óêàæèòå êàòàëîãè','',False,'NewFolder');
Page.Add('Îòêóäà êîïèðîâàòü');
Page.Values[0] := 'e:\1\1';//'c:\';//ExpandConstant('{userappdata}');
Page.Add('Êóäà êîïèðîâàòü');
Page.Values[1] := 'e:\1\2';//'c:\';
PB:=TNewProgressBar.Create(WizardForm);
with PB do begin
Left:=0;
Top:=130;
Width:=Page.Surface.Width;
Parent:=Page.Surface;
end;
L1:=TNewStaticText.Create(WizardForm);
with L1 do begin
Left:=0;
Top:=115;
AutoSize:=False;
Width:=Page.Surface.Width-30;
Parent:=Page.Surface;
end;
L2:=TNewStaticText.Create(WizardForm);
with L2 do begin
Left:=Page.Surface.Width-30;
Top:=115;
AutoSize:=False;
Width:=30;
//Alignment:=taRightJustify;
Parent:=Page.Surface;
end;
PB2:=TNewProgressBar.Create(WizardForm);
with PB2 do begin
Left:=0;
Top:=170;
Width:=Page.Surface.Width;
Parent:=Page.Surface;
end;
L3:=TNewStaticText.Create(WizardForm);
with L3 do begin
Left:=Page.Surface.Width-30;
Top:=155;
AutoSize:=False;
Width:=30;
//Alignment:=taRightJustify;
Parent:=Page.Surface;
end;
CancelBtn:=TButton.Create(WizardForm);
with CancelBtn do begin
Left:=Page.Surface.Width-150;
Top:=200;
Width:=150;
Parent:=Page.Surface;
Caption:='Îòìåíèòü êîïèðîâàíèå';
OnClick:=@CancelBtnClick;
end;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result:=True;
if CurPageID=Page.ID then begin
L1.Caption:='Ïîäñ÷åò ðàçìåðà "'+Page.Values[0]+'"';
L2.Caption:='';
L3.Caption:='';
DS:=0;
PB.Position:=0;
PB.Max:=100;
PB2.Position:=0;
PB2.Max:=100;
CS:=0;
CancelOperation:=False;
WizardForm.NextButton.Enabled:=False;
WizardForm.CancelButton.Enabled:=False;
WizardForm.BackButton.Enabled:=False;
GetDirSize(Page.Values[0],'*.*',True);
CopyDir(Page.Values[0],Page.Values[1],'*.*',True);
WizardForm.NextButton.Enabled:=True;
WizardForm.CancelButton.Enabled:=True;
WizardForm.BackButton.Enabled:=True;
end;
end;