Article View: borland.public.cppbuilder.internet.web
Article #184Re: Doing an internet resuming on a file
From: CJ
Date: Thu, 01 Nov 2007 20:15
Date: Thu, 01 Nov 2007 20:15
114 lines
3795 bytes
3795 bytes
Forget about this code, I saw an example of something you did online
before. There is one part in the code that it's cashing in, I am not sure
what kind of value is supposed to be in there. Question, isn't new
FileStream
supposed to be called before you check the FileStream->Size ?????
TFileStream* FileStream;
1. if(FileName != "")
2. {
3. if(FileExists(FileName))
4. {
5. if(AcceptRanges.Pos("bytes") != 0)
6. {
7. AnsiString Range = ("Range: bytes=" + AnsiString(FileStream->Size) +
"-\r\n");
8. if(!HttpAddRequestHeaders(hFile, Range.c_str(), -1,
HTTP_ADDREQ_FLAG_ADD))
9. {
throw Exception("unable to add range header to file request");
}
bIsResuming = true;
}
------------ The full part of the code that --------------
SaveDialog = new TSaveDialog(NULL);
try
{
if(SaveDialog->Execute())
FileName = SaveDialog->FileName;
}
__finally
{
delete SaveDialog;
}
if(FileName != "")
{
if(FileExists(FileName))
{
if(AcceptRanges.Pos("bytes") != 0)
{
AnsiString Range = ("Range: bytes=" + AnsiString(FileStream->Size) +
"-\r\n");
if(!HttpAddRequestHeaders(hFile, Range.c_str(), -1,
HTTP_ADDREQ_FLAG_ADD))
{
throw Exception("unable to add range header to file request");
}
bIsResuming = true;
}
}
if(!HttpSendRequest(hFile, NULL, 0, NULL, 0))
{
throw Exception("unable to send file request to the server");
}
if(bIsResuming)
FileStream = new TFileStream(FileName, fmOpenReadWrite |
fmShareDenyWrite);
else
FileStream = new TFileStream(FileName, fmCreate);
try
{
if(bIsResuming)
{
FileStream->Seek(0, soFromEnd);
dwBytesRead = FileStream->Position;
}
else
dwBytesRead;
ProgressBar->Position = (dwBytesRead * 100 / dwBufLen);
ProgressBar->Max = dwContentLen;
while(InternetReadFile(hFile, Data, 1024, &dwBytesRead))
{
if(dwBytesRead == 0)
break;
iWritten = 0;
DataPtr = Data;
do
{
iWritten = FileStream->Write(DataPtr, dwBytesRead);
if(iWritten < 1)
throw Exception("unable to write to local file");
DataPtr += iWritten;
dwBytesRead -= iWritten;
ProgressBar->StepBy(iWritten);
Application->ProcessMessages();
}
while(dwBytesRead != 0);
}
if(FileStream->Size != dwContentLen)
throw Exception("File saved is incomplete");
}
__finally
{
delete FileStream;
}
}
}
__finally
{
if(hFile) InternetCloseHandle(hFile);
if(hConnect) InternetCloseHandle(hConnect);
if(hSession) InternetCloseHandle(hSession);
}
Technical Details
Message-ID:
<472a33c4$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<472a0628@newsgroups.borland.com> <472a1834$1@newsgroups.borland.com> <472a1f78$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,99fbc0169b784de6 X-Google-Attributes: gidfeeec,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "CJ" <cluis@yahoo.com> From: "CJ" <cluis@yahoo.com> Newsgroups: borland.public.cppbuilder.internet.web References: <472a0628@newsgroups.borland.com> <472a1834$1@newsgroups.borland.com> <472a1f78$1@newsgroups.borland.com> Subject: Re: Doing an internet resuming on a file Date: Thu, 1 Nov 2007 15:15:07 -0500 Lines: 116 Organization: none X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 98.199.212.74 Message-ID: <472a33c4$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1193948100 98.199.212.74 (1 Nov 2007 13:15:00 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail