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


C++ StringPairArray::containsKey方法代码示例

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


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

示例1: downloadFile

bool Updater::downloadFile(const URL& url, const File& file, int64 resume)
{
    String headers;

    if (resume > 0) {
        headers = String("Range: bytes=") + String(resume) + String("-\r\n");
    }
    else if (file.exists()) {
        if (!file.deleteFile()) {
            return false;
        }
    }

    StringPairArray responseHeaders;
    int statusCode;
    ScopedPointer<InputStream> inputStream(url.createInputStream(false, nullptr, nullptr, headers, 5000, &responseHeaders, &statusCode));
    if (inputStream == nullptr) {
        return false;
    }

    if (resume <= 0 && statusCode != 200) {
        return false;
    }
    else if (resume > 0 && statusCode != 206) {
        return false;
    }

    ScopedPointer<FileOutputStream> outputStream(file.createOutputStream());
    if (outputStream == nullptr || outputStream->failedToOpen()) {
        return false;
    }

    int64 length = -1;
    if (responseHeaders.containsKey("Content-Length")) {
        length = responseHeaders["Content-Length"].getLargeIntValue();
    }

    int64 pos = 0;
    int64 last_pos = pos;
    double start_time = Time::getMillisecondCounterHiRes();
    double last_time = start_time;
    double now;

    int samples[DOWNLOAD_SAMPLES];
    int num_samples = 0;
    int next_sample = 0;
    int bytes_per_second;

    while (!inputStream->isExhausted() && !Thread::getCurrentThread()->threadShouldExit()) {
        char buf[0x8000];
        int size = inputStream->read(buf, sizeof(buf));
        outputStream->write(buf, size);
        pos += size;

        now = Time::getMillisecondCounterHiRes();
        if (now - last_time >= DOWNLOAD_UPDATE_INTERVAL) {
            last_time = now;
            if (length > 0) {
                updater->setTaskPercent((double)pos / length);
            }

            samples[next_sample++] = (int)(pos - last_pos);
            last_pos = pos;
            if (next_sample >= DOWNLOAD_SAMPLES) {
                next_sample = 0;
            }
            if (num_samples < DOWNLOAD_SAMPLES) {
                num_samples++;
            }
            int64 accumulator = 0;
            for (int i = 0; i < num_samples; i++) {
                accumulator += samples[i];
            }
            bytes_per_second = (int)(accumulator / (num_samples * ((double)DOWNLOAD_UPDATE_INTERVAL / 1000)));

            String message(String("Downloading ") + file.getFileName() + String(" at "));
            if (bytes_per_second >= 1024 * 1024) {
                message += String((double)bytes_per_second / 1024 / 1024, 2) + String(" MB/s");
            }
            else if (bytes_per_second >= 1024) {
                message += String((double)bytes_per_second / 1024, 2) + String(" KB/s");
            }
            else {
                message += String(bytes_per_second) + String(" bytes/s");
            }
            updater->setStatusText(message);
        }
    }

    if (pos < length) {
        return false;
    }

    now = Time::getMillisecondCounterHiRes();
    bytes_per_second = (int)(pos / ((now - start_time) / 1000));
    updater->setTaskPercent(1);

    String message(String("Completed download of ") + file.getFileName() + String(" at "));
    if (bytes_per_second >= 1024 * 1024) {
        message += String((double)bytes_per_second / 1024 / 1024, 2) + String(" MB/s");
//.........这里部分代码省略.........
开发者ID:Foe-of-Eternity,项目名称:tremulous-launcher,代码行数:101,代码来源:Updater.cpp


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