L
logingyw
Unregistered / Unconfirmed
GUEST, unregistred user!
DLL:
function DownFileSize( fList:TStringList;var List:TListView ):integer;stdcall;
var
i,Total:integer;
URL:string;
node:TListItem;
begin
Total := 0;
List.Clear;
http := TIdHTTP.Create(nil);
try
for i := 0 to fList.Count - 1 do
begin
URL := hysite + ExtractFileName( fList.Strings );
http.Head( URL );
Total := Total + http.Response.ContentLength;
node := List.Items.Add;
node.Caption := ExtractFileName( fList.Strings );
if i=0 then
node.ImageIndex := 4
else
node.ImageIndex := 0;
node.SubItems.Add( '准备下载' );
node.SubItems.Add( inttostr(http.Response.ContentLength) );
end;
finally
Result := Total;
FreeAndNil( http );
end;
end;
function GetFileList( Ver, DesFilechar; var fList:TStringList ):integer;stdcall;
var f:TFileStream;
inif:TiniFile;
i, j:integer;
s, verstr, URL:string;
List:TStringList;
begin
Result := SUCCESS;
try
http := TIdHTTP.Create(nil);
try
f := TFileStream.Create( DesFile, fmCreate);
try
URL := hysite + 'update.ini';
http.Get( url, f );
except
Result := DOWNFILE_FAIL;
EXIT;
end;
finally
FreeAndNil( f );
end;
finally
FreeAndNil( http );
end;
try
List := TStringList.Create;
List.Clear;
inif := TIniFile.Create( DesFile );
if ver>=inif.ReadString('ver', 'LastVer', '2006.08.01') then
begin
Result := NONEWVER;
exit;
end;
for i := 1 to inif.ReadInteger( 'ver', 'num', 0 ) do
begin
if ver>inif.ReadString( 'ver', 'ver'+inttostr(i), '') then continue;
verstr := inif.ReadString('ver', 'ver'+inttostr(i), '');
for j := 1 to inif.ReadInteger( verstr, 'FileCount', 0) do
begin
s := inif.ReadString( verstr, 'File'+inttostr(j), '');
List.Add(s);
end;
if List.IndexOf( s )<0 then List.Add( s );
end;
if List.Count<1 then
RESULT := CONFIGFILE_ERROR;
fList.Clear;
for i:= 0 to List.Count - 1 do
fList.Add(List.Strings);
finally
FreeAndNil( List );
FreeAndNil( inif );
end;
end;
App:
procedure Tf_main.Button1Click(Sender: TObject);
var dFile:string;
n:integer;
begin
try
Button1.Enabled := False;
try
fList := TStringList.Create;
//到这里总报读地址错误
rt := GetFileList( pchar('2006.08.16'), pchar(dFile), fList);// call dll
n := DownFileSize( fList, ListView1);// call dll
Gauge1.MaxValue := n;
Label5.Caption := '成功。';
Except
Label5.Caption := '失败!!!';
end;
finally
FreeAndNil( fList );
Button1.Enabled := True;
end;
end;
function DownFileSize( fList:TStringList;var List:TListView ):integer;stdcall;
var
i,Total:integer;
URL:string;
node:TListItem;
begin
Total := 0;
List.Clear;
http := TIdHTTP.Create(nil);
try
for i := 0 to fList.Count - 1 do
begin
URL := hysite + ExtractFileName( fList.Strings );
http.Head( URL );
Total := Total + http.Response.ContentLength;
node := List.Items.Add;
node.Caption := ExtractFileName( fList.Strings );
if i=0 then
node.ImageIndex := 4
else
node.ImageIndex := 0;
node.SubItems.Add( '准备下载' );
node.SubItems.Add( inttostr(http.Response.ContentLength) );
end;
finally
Result := Total;
FreeAndNil( http );
end;
end;
function GetFileList( Ver, DesFilechar; var fList:TStringList ):integer;stdcall;
var f:TFileStream;
inif:TiniFile;
i, j:integer;
s, verstr, URL:string;
List:TStringList;
begin
Result := SUCCESS;
try
http := TIdHTTP.Create(nil);
try
f := TFileStream.Create( DesFile, fmCreate);
try
URL := hysite + 'update.ini';
http.Get( url, f );
except
Result := DOWNFILE_FAIL;
EXIT;
end;
finally
FreeAndNil( f );
end;
finally
FreeAndNil( http );
end;
try
List := TStringList.Create;
List.Clear;
inif := TIniFile.Create( DesFile );
if ver>=inif.ReadString('ver', 'LastVer', '2006.08.01') then
begin
Result := NONEWVER;
exit;
end;
for i := 1 to inif.ReadInteger( 'ver', 'num', 0 ) do
begin
if ver>inif.ReadString( 'ver', 'ver'+inttostr(i), '') then continue;
verstr := inif.ReadString('ver', 'ver'+inttostr(i), '');
for j := 1 to inif.ReadInteger( verstr, 'FileCount', 0) do
begin
s := inif.ReadString( verstr, 'File'+inttostr(j), '');
List.Add(s);
end;
if List.IndexOf( s )<0 then List.Add( s );
end;
if List.Count<1 then
RESULT := CONFIGFILE_ERROR;
fList.Clear;
for i:= 0 to List.Count - 1 do
fList.Add(List.Strings);
finally
FreeAndNil( List );
FreeAndNil( inif );
end;
end;
App:
procedure Tf_main.Button1Click(Sender: TObject);
var dFile:string;
n:integer;
begin
try
Button1.Enabled := False;
try
fList := TStringList.Create;
//到这里总报读地址错误
rt := GetFileList( pchar('2006.08.16'), pchar(dFile), fList);// call dll
n := DownFileSize( fList, ListView1);// call dll
Gauge1.MaxValue := n;
Label5.Caption := '成功。';
Except
Label5.Caption := '失败!!!';
end;
finally
FreeAndNil( fList );
Button1.Enabled := True;
end;
end;