unit UpdaterETS;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.ExtCtrls,
Vcl.StdCtrls,
Vcl.ComCtrls,
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdExplicitTLSClientServerBase, IdFTP, ShellAPI;
type
Tupdater =
class(TForm)
FortschrittNow: TLabel;
FortschrittGesamt: TLabel;
ProgressAktuell: TProgressBar;
ProgressGesamt: TProgressBar;
FileNumber: TLabel;
DownSpeed: TLabel;
FTP: TIdFTP;
procedure FTPWorkBegin(ASender: TObject; AWorkMode: TWorkMode;
AWorkCountMax: Int64);
procedure FTPWork(ASender: TObject; AWorkMode: TWorkMode;
AWorkCount: Int64);
procedure FormCreate(Sender: TObject);
private
//procedure Connect;
//procedure Disconnect;
public
{ Public declarations }
end;
type
ThUpdater =
class(TThread)
FortschrittNow: TLabel;
FortschrittGesamt: TLabel;
ProgressAktuell: TProgressBar;
ProgressGesamt: TProgressBar;
FileNumber: TLabel;
DownSpeed: TLabel;
FTP: TIdFTP;
procedure UpdateFunc;
private
procedure Connect;
procedure Disconnect;
{ Private-Deklarationen }
protected
procedure Execute;
override;
end;
var
updater: Tupdater;
versionAK, versionNeu:
string;
StartTime: TDateTime;
Size: Int64;
CurrentFile, FileCount: Integer;
UpdatingActive: Boolean = false;
implementation
{$R *.dfm}
uses UnitConnection;
function DeleteFileDir(
const AFile:
string): Boolean;
var SH: SHFILEOPSTRUCT;
begin
ZeroMemory(@SH,SizeOf(SH));
with sh
do
begin
WND:=Application.Handle;
wFunc:=FO_DELETE;
pFrom:=PChar(AFile+#0);
fFlags:=FOF_SILENT
or FOF_NOCONFIRMATION;
end;
Result:=ShFileOperation(sh)=0;
end;
procedure Thupdater.Connect;
begin
FTP.Host:=ConHost;
FTP.Username:=ConUser;
FTP.Password:=ConPass;
FTP.Connect;
FTP.ChangeDir(ConDir);
end;
procedure Thupdater.Disconnect;
begin
FTP.Disconnect;
end;
procedure Tupdater.FTPWorkBegin(ASender: TObject; AWorkMode: TWorkMode;
AWorkCountMax: Int64);
begin
StartTime:=Now;
if AWorkCountMax>0
then
begin
ProgressAktuell.Max:=AWorkCountMax;
end
else
ProgressAktuell.Max:=Size;
end;
procedure ThUpdater.UpdateFunc;
var
Update, Befehl: tstringlist;
I: Integer;
begin
CurrentFile:= i;
Size:=
FTP.Size(Befehl[1]);
FTP.Get(Befehl[1],Befehl[2],True);
ProgressGesamt.Position:=ProgressGesamt.Position+1;
end;
procedure ThUpdater.Execute;
var
Update, Befehl: tstringlist;
I: Integer;
begin
Connect;
Update:=tstringlist.Create;
Befehl:=tstringlist.Create;
CreateDir('
tmp');
FTP.Get('
updates.ini','
tmp\updates.ini',true);
Update.LoadFromFile('
version.txt');
versionAK:=Update[0];
Update.Clear;
Update.LoadFromFile('
tmp\updates.ini');
versionNeu:=Update[0];
try
//-----------------------------------------------------------------------------------------
//FileCount bestimmen
//-----------------------------------------------------------------------------------------
for i := Update.Count - 1
downto 0
do
begin
Befehl.Clear;
ExtractStrings(['
;'],[],PChar(Update[i]),Befehl);
if Befehl[0]='
get'
then inc(FileCount);
end;
//-----------------------------------------------------------------------------------------
UpdatingActive:=True;
for i := Update.Count - 1
downto 0
do
begin
Befehl.Clear;
ExtractStrings(['
;'],[],PChar(Update[i]),Befehl);
if Befehl[0]='
dir'
then CreateDir(Befehl[1]);
if Befehl[0]='
del'
then DeleteFileDir(Befehl[1]);
if Befehl[0]='
get'
then
begin
CurrentFile:= i;
Size:=
FTP.Size(Befehl[1]);
FTP.Get(Befehl[1],Befehl[2],True);
ProgressGesamt.Position:=ProgressGesamt.Position+1;
end;
end;
finally
UpdatingActive:=False;
Update.Free;
Befehl.Free;
DeleteFileDir('
tmp');
Disconnect;
end;
end;
procedure Tupdater.FormCreate(Sender: TObject);
var myTh: ThUpdater;
begin
myTh:= Thupdater.Create(True);
myTh.Resume;
end;
procedure Tupdater.FTPWork(ASender: TObject; AWorkMode: TWorkMode;
AWorkCount: Int64);
var Speed:
String;
TotalTime: TDateTime;
H,M,Sec,MS: Word;
DLTime: Double;
begin
if UpdatingActive=True
then
begin
TotalTime:= Now-StartTime;
DecodeTime(TotalTime,H,M,Sec,MS);
Sec:=Sec+M*60+H*3600;
DLTime:=Sec+MS/1000;
if DLTime>0
then
Speed:= FormatFloat('
0.00 KB/s',(AWorkCount/1024)/DLTime);
FileNumber.Caption:='
Datei: ' +IntToStr(CurrentFile)+ '
von ' +IntToStr(FileCount);
DownSpeed.Caption:= '
Geschwindigkeit: '+Speed;
ProgressAktuell.Position:=AWorkCount;
end;
end;
end.