当前位置: 首页>>代码示例>>C++>>正文


C++ Download::getCrcCalc方法代码示例

本文整理汇总了C++中Download::getCrcCalc方法的典型用法代码示例。如果您正苦于以下问题:C++ Download::getCrcCalc方法的具体用法?C++ Download::getCrcCalc怎么用?C++ Download::getCrcCalc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Download的用法示例。


在下文中一共展示了Download::getCrcCalc方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: handleEndData

/** Download finished! */
void DownloadManager::handleEndData(UserConnection* aSource) {

    dcassert(aSource->getState() == UserConnection::STATE_DONE);
    Download* d = aSource->getDownload();
    dcassert(d != NULL);

    if(d->isSet(Download::FLAG_TREE_DOWNLOAD)) {
        d->getFile()->flush();
        delete d->getFile();
        d->setFile(NULL);

        Download* old = d->getOldDownload();

        size_t bl = 1024;
        while(bl * old->getTigerTree().getLeaves().size() < old->getSize())
            bl *= 2;
        old->getTigerTree().setBlockSize(bl);
        dcassert(old->getSize() != -1);
        old->getTigerTree().setFileSize(old->getSize());

        old->getTigerTree().calcRoot();

        if(!(*old->getTTH() == old->getTigerTree().getRoot())) {
            // This tree is for a different file, remove from queue...
            fire(DownloadManagerListener::Failed(), old, STRING(INVALID_TREE));

            string target = old->getTarget();

            aSource->setDownload(NULL);
            removeDownload(old, true);

            QueueManager::getInstance()->removeSource(target, aSource->getUser(), QueueItem::Source::FLAG_BAD_TREE, false);
            checkDownloads(aSource);
            return;
        }

        d->getOldDownload()->setTreeValid(true);

        HashManager::getInstance()->addTree(old->getTarget(), old->getTigerTree());

        aSource->setDownload(d->getOldDownload());

        delete d;

        // Ok, now we can continue to the actual file...
        checkDownloads(aSource);
        return;
    }

    u_int32_t crc = 0;
    bool hasCrc = (d->getCrcCalc() != NULL);

    // First, finish writing the file (flushing the buffers and closing the file...)
    try {
        d->getFile()->flush();
        if(hasCrc)
            crc = d->getCrcCalc()->getFilter().getValue();
        delete d->getFile();
        d->setFile(NULL);
        d->setCrcCalc(NULL);

        // Check if we're anti-fragging...
        if(d->isSet(Download::FLAG_ANTI_FRAG)) {
            // Ok, rename the file to what we expect it to be...
            try {
                const string& tgt = d->getTempTarget().empty() ? d->getTarget() : d->getTempTarget();
                File::renameFile(d->getDownloadTarget(), tgt);
                d->unsetFlag(Download::FLAG_ANTI_FRAG);
            } catch(const FileException& e) {
                dcdebug("AntiFrag: %s\n", e.getError().c_str());
                // Now what?
            }
        }
    } catch(const FileException& e) {
        fire(DownloadManagerListener::Failed(), d, e.getError());
        
        aSource->setDownload(NULL);
        removeDownload(d, true);
        removeConnection(aSource);
        return;
    }
    
    dcassert(d->getPos() == d->getSize());
    dcdebug("Download finished: %s, size " I64_FMT ", downloaded " I64_FMT "\n", d->getTarget().c_str(), d->getSize(), d->getTotal());

    // Check if we have some crc:s...
    if(BOOLSETTING(SFV_CHECK)) {
        SFVReader sfv(d->getTarget());
        if(sfv.hasCRC()) {
            bool crcMatch;
            string tgt = d->getDownloadTarget();
            if(hasCrc) {
                crcMatch = (crc == sfv.getCRC());
            } else {
                // More complicated, we have to reread the file
                try {
                    
                    File ff(tgt, File::READ, File::OPEN);
                    CalcInputStream<CRC32Filter, false> f(&ff);
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:linuxdcpp,代码行数:101,代码来源:DownloadManager.cpp


注:本文中的Download::getCrcCalc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。