我最近在开放FTP更新的软件
进入FTP下载目录,有时候下载很好,有时候下载后就出现CPU100%现象,我已经忙了几天了问题还是没有解决,请高手帮帮我.! procedure FindFtpDir(Dir,ClientDir:string;Ftp:Tidftp;Li:TListItem;var FileInt,ErrFileInt:integer);
var
i,DirCount:integer;
FtpItem:TIdFTPListItem;
DirList:TStringList;
tStream:TFileStream;
begin
ClientDir:=FormatDir(ClientDir); //这是个目录后面加'\'的函数
if not DirectoryExists(ClientDir) then
ForceDirectories(ClientDir); Ftp.ChangeDir(Dir); Ftp.List(Ftp.ListResult,'*.*'); DirCount:=Ftp.DirectoryListing.Count;
try
DirList:=TStringList.Create;
for i:=0 to DirCount-1 do
begin
FtpItem:=Ftp.DirectoryListing.Items[i];
if FtpItem.FileName[1]<>'.' then
begin
if FtpItem.ItemType=ditDirectory then
begin
DirList.Add(FtpItem.FileName);
end
else
begin
Li.SubItems[4]:='['+IntToStr(FileInt+1)+'] <'+FtpItem.FileName+','+FormatSize(FtpItem.Size)+'>';
try
if FileExists(ClientDir+FtpItem.FileName) and (Fangan=0) then
begin
tStream:=TFileStream.Create(ClientDir+FtpItem.FileName,fmOpenReadWrite or fmShareDenyNone);
tStream.Position:=tStream.Size;
WenJiandaxiao:=FtpItem.Size-tStream.Size;
try
Ftp.Get(FtpItem.FileName,tStream,true);
inc(ZongDaxiao,FtpItem.Size);
finally
tStream.Free;
end;
end
else
begin
WenJiandaxiao:=FtpItem.Size;
DeleteFile(ClientDir+FtpItem.FileName+'.WxDate');
if FileExists(ClientDir+FtpItem.FileName+'.WxDate') then
begin
Inc(ErrFileInt);
Form1.RichEditText('游戏<'+Li.Caption+'> 文件<'+FtpItem.FileName+'>更新失败',clRed);
Continue;
end;
Ftp.Get(FtpItem.FileName,ClientDir+FtpItem.FileName+'.WxDate',false);
inc(ZongDaxiao,FtpItem.Size);
end;
except
Inc(ErrFileInt);
end;
end;
end;
end;
for i:=0 to DirList.Count-1 do
begin
FindFtpDir(Dir+'/'+DirList[i],ClientDir+DirList[i],Ftp,Li,FileInt,ErrFileInt);
end;
finally
DirList.Free;
end;
end;
进入FTP下载目录,有时候下载很好,有时候下载后就出现CPU100%现象,我已经忙了几天了问题还是没有解决,请高手帮帮我.! procedure FindFtpDir(Dir,ClientDir:string;Ftp:Tidftp;Li:TListItem;var FileInt,ErrFileInt:integer);
var
i,DirCount:integer;
FtpItem:TIdFTPListItem;
DirList:TStringList;
tStream:TFileStream;
begin
ClientDir:=FormatDir(ClientDir); //这是个目录后面加'\'的函数
if not DirectoryExists(ClientDir) then
ForceDirectories(ClientDir); Ftp.ChangeDir(Dir); Ftp.List(Ftp.ListResult,'*.*'); DirCount:=Ftp.DirectoryListing.Count;
try
DirList:=TStringList.Create;
for i:=0 to DirCount-1 do
begin
FtpItem:=Ftp.DirectoryListing.Items[i];
if FtpItem.FileName[1]<>'.' then
begin
if FtpItem.ItemType=ditDirectory then
begin
DirList.Add(FtpItem.FileName);
end
else
begin
Li.SubItems[4]:='['+IntToStr(FileInt+1)+'] <'+FtpItem.FileName+','+FormatSize(FtpItem.Size)+'>';
try
if FileExists(ClientDir+FtpItem.FileName) and (Fangan=0) then
begin
tStream:=TFileStream.Create(ClientDir+FtpItem.FileName,fmOpenReadWrite or fmShareDenyNone);
tStream.Position:=tStream.Size;
WenJiandaxiao:=FtpItem.Size-tStream.Size;
try
Ftp.Get(FtpItem.FileName,tStream,true);
inc(ZongDaxiao,FtpItem.Size);
finally
tStream.Free;
end;
end
else
begin
WenJiandaxiao:=FtpItem.Size;
DeleteFile(ClientDir+FtpItem.FileName+'.WxDate');
if FileExists(ClientDir+FtpItem.FileName+'.WxDate') then
begin
Inc(ErrFileInt);
Form1.RichEditText('游戏<'+Li.Caption+'> 文件<'+FtpItem.FileName+'>更新失败',clRed);
Continue;
end;
Ftp.Get(FtpItem.FileName,ClientDir+FtpItem.FileName+'.WxDate',false);
inc(ZongDaxiao,FtpItem.Size);
end;
except
Inc(ErrFileInt);
end;
end;
end;
end;
for i:=0 to DirList.Count-1 do
begin
FindFtpDir(Dir+'/'+DirList[i],ClientDir+DirList[i],Ftp,Li,FileInt,ErrFileInt);
end;
finally
DirList.Free;
end;
end;
fName:String;
fPathName:String;
fDownPathName:String;
begin
fName:=ADOQueryVoice.FieldValues['sVoice'];
fPathName:=appRootPath + '\' + fName;
fDownPathName:=appRootPath + '\tmp.mp3';
//
if not idFtp1.Connected then idFtp1.Connect(true);
if idFtp1.Connected then
begin
idFtp1.Get(fName,fDownPathName,true);
idFtp1.Disconnect;
CopyFile(PChar(fDownPathName),PChar(fPathName),false);
end
else
begin
ShowMessage('文件下载错误!');
end;