🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #185

Re: Doing an internet resuming on a file

#185
From: Remy Lebeau (TeamB)
Date: Thu, 01 Nov 2007 22:08
97 lines
3852 bytes
"CJ" <cluis@yahoo.com> wrote in message 
news:472a33c4$1@newsgroups.borland.com...

> 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.

The size of the file that was previously downloaded.

> isn't new FileStream supposed to be called before you
> check the FileStream->Size  ?????

Yes.  Here is an updated example:

    SaveDialog = new TSaveDialog(NULL);
    try
    {
        if( SaveDialog->Execute() )
            FileName = SaveDialog->FileName;
    }
    __finally
    {
        delete SaveDialog;
    }

    if( FileName != "" )
    {
        TSearchRec sr;
        if( FindFirstFile(FileName, faAnyFile, sr) )
        {
            FindClose(sr);

            if( (AcceptRanges.Pos("bytes") != 0) && (sr.Size > 0) )
            {
                AnsiString Range = ("Range: bytes=" + AnsiString(sr.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->Position = sr.Size;

            dwBytesRead = FileStream->Position;

            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;
        }
    }


Gambit 
Technical Details
Message-ID: <472a4e82$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <472a0628@newsgroups.borland.com> <472a1834$1@newsgroups.borland.com> <472a1f78$1@newsgroups.borland.com> <472a33c4$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
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.web
References: <472a0628@newsgroups.borland.com> <472a1834$1@newsgroups.borland.com> <472a1f78$1@newsgroups.borland.com> <472a33c4$1@newsgroups.borland.com>
Subject: Re: Doing an internet resuming on a file
Date: Thu, 1 Nov 2007 15:08:08 -0700
Lines: 99
Organization: Lebeau Software
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: 207.178.157.90
Message-ID: <472a4e82$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1193954946 207.178.157.90 (1 Nov 2007 15:09:06 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail