コード例 #1
0
ファイル: downloader.cpp プロジェクト: WPN-XM/WPN-XM
void Downloader::processFtpDirs()
{
    if(ftpDirsProcessed())
        return;

    openInternet();

    if(!ftpDirs.empty())
    {
        updateStatus(msg("Getting file information..."));
        processMessages();

        for(list<FtpDir *>::iterator i = ftpDirs.begin(); i != ftpDirs.end(); i++)
        {
            FtpDir *f = *i;

            if(f->processed)
                continue;

            if(f->selected(components))
            {
                if(scanFtpDir(f))
                    f->processed = true;
            }
        }
    }
    
    if(ftpDirsProcessed())
        clearFtpDirs();
}
コード例 #2
0
ファイル: downloader.cpp プロジェクト: darnyte/WPN-XM
DWORDLONG Downloader::getFileSizes()
{
	if(files.empty())
		return 0;

	updateStatus(msg("Initializing..."));

	if(!openInternet())
	{
		storeError();
		return FILE_SIZE_UNKNOWN;
	}

	filesSize = 0;

	updateStatus(msg("Getting file information..."));
	bool sizeUnknown = false;

    for(map<tstring, NetFile *>::iterator i = files.begin(); i != files.end(); i++)
    {
        NetFile *file = i->second;

		if(downloadCancelled)
			break;

		if(file->size == FILE_SIZE_UNKNOWN)
		{
			try
			{
				file->size = file->url.getSize(internet);
			}
			catch(exception &e)
			{
				updateStatus(msg(e.what()));
				storeError(msg(e.what()));
				closeInternet();
				return OPERATION_STOPPED;
			}
		}

		if(!(file->size == FILE_SIZE_UNKNOWN))
			filesSize += file->size;
		else
			sizeUnknown = true;
    }

	closeInternet();

	if(sizeUnknown)
		filesSize = FILE_SIZE_UNKNOWN;

	return filesSize;
}
コード例 #3
0
ファイル: HTTPParser.cpp プロジェクト: openxtra/hotspot-sdk
bool CHTTPParser::HTTPGet(LPCTSTR pstrServer, LPCTSTR pstrObjectName, CString& rString)
{
	bool bReturn = false;

	// are we already connected
	bReturn = IsInternetAvailable();

	if(!bReturn)
	{
		// no, then try and connect
		bReturn = openInternet();
	}

	if(bReturn == true)
	{
		HINTERNET hConnect = InternetConnect(m_hSession, pstrServer, 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);

		if(hConnect != NULL)
		{
			HINTERNET hFile = NULL;
			hFile = HttpOpenRequest(hConnect, _T("GET"), pstrObjectName, HTTP_VERSION, NULL, NULL, INTERNET_FLAG_EXISTING_CONNECT, 1);

			if(hFile != NULL)
			{
				if(HttpSendRequest(hFile, NULL, 0, NULL, 0))
				{
					readString(rString, hFile);
				}
				else
				{
					bReturn = false;
				}

				InternetCloseHandle(hFile);
			}
			else
			{
				bReturn = false;
			}
			InternetCloseHandle(hConnect);
		}
		else
		{
			bReturn = false;
		}
	}

	return bReturn;
}
コード例 #4
0
ファイル: downloader.cpp プロジェクト: darnyte/WPN-XM
bool Downloader::downloadFiles()
{
	if(files.empty())
		return true;

	setMarquee(true);

	if(getFileSizes() == OPERATION_STOPPED)
	{
		setMarquee(false);
		return false;
	}

	if(!openInternet())
	{
		storeError();
		setMarquee(false);
		return false;
	}

	sizeTimeTimer.start(500);
	updateStatus(msg("Starting download..."));

	if(!(filesSize == FILE_SIZE_UNKNOWN))
		setMarquee(false);

    for(map<tstring, NetFile *>::iterator i = files.begin(); i != files.end(); i++)
    {
        NetFile *file = i->second;

		if(downloadCancelled)
			break;

		if(!file->downloaded)
			if(!downloadFile(file))
			{
				closeInternet();
				return false;
			}
			else
				downloadedFilesSize += file->bytesDownloaded;
    }

	closeInternet();
	return true;
}
コード例 #5
0
ファイル: downloader.cpp プロジェクト: WPN-XM/WPN-XM
bool Downloader::downloadFiles(bool useComponents)
{
    if(ownMsgLoop)
        downloadCancelled = false;

    if(files.empty() && ftpDirs.empty())
        return true;

    setMarquee(true);

    processFtpDirs();

    if(getFileSizes() == OPERATION_STOPPED)
    {
        TRACE(_T("OPERATION_STOPPED"));
        setMarquee(false);
        return false;
    }

    TRACE(_T("filesSize: %d"), (DWORD)filesSize);

    if(!openInternet())
    {
        storeError();
        setMarquee(false);
        return false;
    }

    sizeTimeTimer.start(500);
    updateStatus(msg("Starting download..."));
    TRACE(_T("Starting file download cycle..."));

    if(!(filesSize == FILE_SIZE_UNKNOWN))
        setMarquee(false);

    processMessages();

    for(map<tstring, NetFile *>::iterator i = files.begin(); i != files.end(); i++)
    {
        NetFile *file = i->second;

        if(downloadCancelled)
            break;

        if(useComponents)
            if(!file->selected(components))
                continue;

        if(!file->downloaded)
        {
            // If mirror was used in getFileSizes() function, check mirror first:
            if(file->mirrorUsed.length())
            {
                NetFile newFile(file->mirrorUsed, file->name, file->size);

                if(downloadFile(&newFile))
                {
                    file->downloaded = newFile.downloaded;
                    file->bytesDownloaded = newFile.bytesDownloaded;
                    downloadedFilesSize += file->bytesDownloaded;
                    continue;
                }
            }

            if(!downloadFile(file))
            {
                TRACE(_T("File was not downloaded."));

                if(checkMirrors(i->first, true))
                    downloadedFilesSize += file->bytesDownloaded;
                else
                {
                    if(stopOnError)
                    {
                        closeInternet();
                        return false;
                    }
                    else
                    {
                        TRACE(_T("Ignoring file %s"), file->name.c_str());
                    }
                }
            }
            else
                downloadedFilesSize += file->bytesDownloaded;
        }

        processMessages();
    }

    closeInternet();
    return filesDownloaded();
}
コード例 #6
0
ファイル: downloader.cpp プロジェクト: WPN-XM/WPN-XM
DWORDLONG Downloader::getFileSizes(bool useComponents)
{
    if(ownMsgLoop)
        downloadCancelled = false;

    if(files.empty())
        return 0;

    updateStatus(msg("Initializing..."));
    processMessages();

    if(!openInternet())
    {
        storeError();
        return FILE_SIZE_UNKNOWN;
    }

    filesSize = 0;
    bool sizeUnknown = false;

    for(map<tstring, NetFile *>::iterator i = files.begin(); i != files.end(); i++)
    {
        updateStatus(msg("Getting file information..."));
        processMessages();

        NetFile *file = i->second;

        if(downloadCancelled)
            break;

        if(useComponents)
            if(!file->selected(components))
                continue;

        if(file->size == FILE_SIZE_UNKNOWN)
        {
            try
            {
                try
                {
                    updateFileName(file);
                    processMessages();
                    file->size = file->url.getSize(internet);
                }
                catch(HTTPError &e)
                {
                    updateStatus(msg(e.what()));
                    //TODO: if allowContinue==0 & error code == file not found - stop.
                }
                
                if(file->size == FILE_SIZE_UNKNOWN)
                    checkMirrors(i->first, false);
            }
            catch(FatalNetworkError &e)
            {
                updateStatus(msg(e.what()));
                storeError(msg(e.what()));
                closeInternet();
                return OPERATION_STOPPED;
            }
        }

        if(!(file->size == FILE_SIZE_UNKNOWN))
            filesSize += file->size;
        else
            sizeUnknown = true;
    }

    closeInternet();

    if(sizeUnknown && !filesSize)
        filesSize = FILE_SIZE_UNKNOWN; //TODO: if only part of files has unknown size - ???

#ifdef _DEBUG
    TRACE(_T("getFileSizes result:"));

    for(map<tstring, NetFile *>::iterator i = files.begin(); i != files.end(); i++)
    {
        NetFile *file = i->second;
        TRACE(_T("    %s: %s"), file->getShortName().c_str(), (file->size == FILE_SIZE_UNKNOWN) ? _T("Unknown") : itotstr((DWORD)file->size).c_str()); 
    }
#endif

    return filesSize;
}
コード例 #7
0
ファイル: HTTPParser.cpp プロジェクト: openxtra/hotspot-sdk
CHTTPParser::CHTTPParser(void)
: m_bIsConnected(false)
, m_hSession(NULL)
{
	openInternet();
}