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


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

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


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

示例1: startServerBrowser

void UTLauncher::startServerBrowser()
{
    splashTimer.singleShot(2000, this, SLOT(closeSplash()));

    if(!settings.value("StartMinimized", false).toBool()) {
        browser->show();
    } else {
        qApp->setQuitOnLastWindowClosed(false); // workaround for app not starting
    }
    browser->setMOTD(bootstrap.MOTD());
    
    auto hasEditorSupport = [=] {
        QString editorPath = bootstrap.editorExePath();
        QString projectPath = bootstrap.projectPath();
        return QFile::exists(editorPath) && QFile::exists(projectPath);
    };
    
    auto openSettings = [=](bool mandatoryEditor = false) {
        ConfigDialog dialog(settings, mandatoryEditor);
        dialog.exec();
        browser->setEditorSupport(hasEditorSupport());
        
        browser->setHideOnClose(settings.value("MinimizeToTrayOnClose").toBool());
    };
    
    connect(browser, &ServerBrowser::openServer, [=](QString url, bool spectate, bool inEditor) {

        if(inEditor) {
            QString editorPath = bootstrap.editorExePath();
            QString projectPath = bootstrap.projectPath();
            if(!editorPath.length() || !projectPath.length()) {
                openSettings(true);
                return;
            }
            QProcess::startDetached(editorPath, QStringList() << projectPath << "-GAME" << (url + (spectate?"?SpectatorOnly=1":"")) );
        } else {
            QString exePath = bootstrap.programExePath();
            if(!exePath.length()) {
                openSettings();
                return;
            }
            const auto serverEntry = browser->serverEntryFromAddress(url);
            auto launch = [=] {
                qDebug() << "Launching!!\n";
              QProcess::startDetached(exePath, QStringList()
#ifdef LAUNCH_WITH_UE4
                << "UnrealTournament"
#endif
                << (url + (spectate?"?SpectatorOnly=1":"")) 
                << "-SaveToUserDir");
            };
                        
            if(serverEntry) {
                if(bootstrap.isStockMap(serverEntry->map)) {
                    launch();
                    return;
                }
                

                QString exePath = bootstrap.programExePath();
                QFileInfo exeInfo(exePath);
                auto contentDir = QDir(exeInfo.dir());
                contentDir.cdUp();
                contentDir.cdUp();
                contentDir.cd("Content");
                auto zipFilePath = contentDir.absoluteFilePath(serverEntry->map + ".zip");
                
                if(QFile::exists(zipFilePath)) {
                    launch();
                    return;
                }

                Download mapDownload;
                mapDownload.setTarget("https://ut.rushbase.net/customcontent/Data/" + serverEntry->map + ".zip");
                QProgressDialog dialog("Downloading map: " + serverEntry->map, "Cancel", 0, 100);
                
                QFile zipFile(zipFilePath);
                zipFile.open(QIODevice::WriteOnly);
                
                int httpCode = 200;
                connect(&mapDownload, &Download::error, [&](int code) {
                    httpCode = code;
                    if(code != 200) {
                        zipFile.remove();
                        QMessageBox::critical(nullptr, "Unable to download map", QString("Got code %1 while trying to download map:<br>%2").arg(code).arg(serverEntry->map));
                    }
                });
                
                connect(&mapDownload, &Download::chunk, [&](QByteArray chunk) {
                    qDebug() << "Reading!\n";
                    zipFile.write(chunk);
                });
                connect(&mapDownload, &Download::progress, [&](double progress) {
                    dialog.setValue(100*progress);
                    if(progress == 1.0) {
                        dialog.accept();
                    }
                });
                
                
//.........这里部分代码省略.........
开发者ID:Jupiter41,项目名称:UTLauncher,代码行数:101,代码来源:utlauncher.cpp


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