您尚未登录,请登录后浏览更多内容! 登录 | 加入最MC

QQ登录

只需一步,快速开始

 找回密码
 加入最MC

QQ登录

只需一步,快速开始

查看: 2827|回复: 1
打印 上一主题 下一主题

[C++/Qt]QGettingStarted-强大的MC启动器核心[开源][跨平台][Win/Linux/MacOS]

[复制链接]

该用户从未签到

跳转到指定楼层
楼主
发表于 2018-5-20 11:56:06 | 只看该作者 |0人打赏回帖奖励 |倒序浏览 |阅读模式
本帖最后由 lzycc234 于 2018-5-20 12:22 编辑

Github:https://github.com/BluePlumStudio/QGettingStarted
Mcbbs:http://www.mcbbs.net/thread-793857-1-1.html






BlueBerry启动器帖子地址:MCBBS:http://www.mcbbs.net/thread-781400-1-1.html

Github:https://github.com/BluePlumStudio/QGettingStarted
官网:https://blueplum.studio/
欢迎加入BluePlum Studio.,扣Qun:166987759




编译

Windows:Visual Studio 2015/Qt Creator 4.5.0|Qt 5.10.0 下编译通过
Linux:可行,但未测试。
Mac OS:可行,但未测试。

警告

因开发周期较短可能存在Bug。

开发文档

QGSDocument:https://qgsdocument.blueplum.studio使用完整功能请查阅开发文档

快速开始

使用启动核心

1.下载源码自行编译或下载已编译好的静态库:

  • 0.2.0:


    • Windows:
      地址1:https://blueplum.pipipan.com/fs/15016760-289630377
      地址2:https://blueplum.ctfile.com/fs/15016760-289630377
  • 0.1.1:


    • Windows:
      地址1
      地址2
  • Pre 2.0.0:


    • Windows:
      地址1
      地址2
  • Beta 1.4.0:


    • Windows:
      地址1
      地址2
  • Beta 1.3.0:


    • Windows:
      城通网盘1
      城通网盘2
  • Beta 1.2.0:


    • Windows:
      城通网盘1
      城通网盘2
  • Beta 1.1.0:


    • Windows:
      城通网盘1
      城通网盘2
  • Beta 1.0.0:


    • Windows:
      城通网盘1
      城通网盘2


2.将静态库,如"QGettingStarted.lib,zlib.lib",添加进工程,包含头文件"QGettingStarted.h"即可。






打赏

0

收藏

0

支持

0

反对

0

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友

该用户从未签到

沙发
 楼主| 发表于 2018-5-20 12:00:33 | 只看该作者
本帖最后由 lzycc234 于 2018-5-20 12:22 编辑

使用方法(请访问我们的开发文档Github阅读更详细的内容)
开发文档:https://qgsdocument.blueplum.studio;
Github:https://github.com/BluePlumStudio/QGettingStarted
启动游戏


  1.     QString launchCommand;
  2.     QGSLauncher launcher;
  3.     QGSGameDirectory gameDirectory(QDir("./minecraft"));
  4.     QGSLaunchOptionsBuilder launchOptionsBuilder;

  5.     launchOptionsBuilder.setJavaPath("C:/Program Files/Java/jre1.8.0_162/bin/javaw.exe");
  6.     launchOptionsBuilder.setMaxMemory(1024);
  7.     launchOptionsBuilder.setMinMemory(128);

  8.     QGSAuthInfo authInfo;
  9.     QEventLoop eventLoop;
  10.     //正版登录替换为QGSYggdrasilAccountFactory
  11.     QGSIAccount * account(QGSOfflineAccountFactory().createAccount());
  12.     QObject::connect(account, &QGSIAccount::finished, &eventLoop, &QEventLoop::quit);
  13.     QObject::connect(account, &QGSIAccount::finished, [&authInfo](QGSAuthInfo _authInfo)
  14.     {
  15.         authInfo = _authInfo;
  16.     });
  17.     /*正版登录的错误检查
  18.     QObject::connect(account, &QGSIAccount::error, [](QGSNetworkError networkError)
  19.     {
  20.         qDebug() << "QGSNetworkError:" << networkError.getCode() << networkError.getErrorString();
  21.     });
  22.     */
  23.     account->authenticate("player");
  24.     //account->authenticate("123@xxx.com","123456"); 正版登录
  25.     eventLoop.exec();

  26.     launchOptionsBuilder.setAuthInfo(authInfo);
  27.     launchOptionsBuilder.setJVMArguments("-XX:+UseG1GC -XX:-UseAdaptiveSizePolicy -XX:-OmitStackTraceInFastThrow");

  28.     launcher.generateLaunchCommand(gameDirectory.getVersion("1.11.2"), gameDirectory, launchOptionsBuilder.getLaunchOptions(), launchCommand);
复制代码

获取游戏版本列表

  1.     //下载任务工厂
  2.     QGSDownloadTaskFactory downloadTaskFactory(new QGSBMCLAPIDownloadSource);
  3.     //下载到当前目录
  4.     QGSDownloadTask * downloadTask = downloadTaskFactory.generateGameVersionInfoJsonDownloadTask(new QFile("./version_manifest.json"));
  5.     //下载进程
  6.     QObject::connect(downloadTask, &QGSDownloadTask::downloadProgress, [=](qint64 bytesReceived, qint64 bytesTotal, QGSTask * task)
  7.     {
  8.         qDebug() << "version manifest:" << bytesReceived << ";" << bytesTotal;
  9.     });
  10.     //下载完成
  11.     QObject::connect(downloadTask, &QGSDownloadTask::finished, [=](QGSTask * task)
  12.     {
  13.         qDebug() << "version manifest prase test";
  14.         QGSGameVersionInfoListFactory versionInfoFactory;
  15.         downloadTask->getTargetFile()->open(QIODevice::ReadOnly);
  16.         QGSGameVersionInfoList versionInfoList(versionInfoFactory.createGameVersionInfoList(downloadTask->getTargetFile()->readAll()));
  17.         for (int i = 0; i < versionInfoList.size(); i++)
  18.         {
  19.             qDebug() << "id:" << versionInfoList[i].getId()
  20.                 << "type:" << versionInfoList[i].getType()
  21.                 << "time:" << versionInfoList[i].getTime()
  22.                 << "releasetime:" << versionInfoList[i].getReleaseTime()
  23.                 << "url:" << versionInfoList[i].getUrl().toString();
  24.         }
  25.         downloadTask->deleteLater();
  26.     });
  27.     //下载错误
  28.     QObject::connect(downloadTask, &QGSDownloadTask::downloadError, [=](QGSNetworkError error, QGSTask * task)
  29.     {
  30.         qDebug() << "version manifest:" << "Code:" << error.getCode() << "Message:" << error.getErrorString();
  31.     });
  32.     downloadTask->start();//也可以加入线程池中,threadPoolManager->addTaskBack(downloadTask);
复制代码

获取Forge列表

  1.     QGSDownloadTaskFactory * downloadTaskFactory(new QGSDownloadTaskFactory(new QGSOfficialDownloadSource));
  2.     QGSDownloadTask * downloadTask = nullptr;

  3.     downloadTask = downloadTaskFactory->generateForgeVersionInfoJsonDownloadTask(new QFile(QString("./forge_manifest.json")), 100, 50);
  4.     QObject::connect(downloadTask, &QGSDownloadTask::downloadProgress, [=](qint64 bytesReceived, qint64 bytesTotal, QGSTask * task)
  5.     {
  6.         qDebug() << "forge version info json:" << bytesReceived << ";" << bytesTotal;
  7.     });
  8.     QObject::connect(downloadTask, &QGSDownloadTask::finished, [=](QGSTask * task)
  9.     {
  10.         qDebug() << "forge version info json finished!";
  11.         QGSForgeVersionInfoListFactory versionInfoFactory;
  12.         downloadTask->getTargetFile()->open(QIODevice::ReadOnly);
  13.         //因forge版本较多,为了照顾性能与资源,需要设置偏移量与上限。示例中:1为偏移量,1000为上限。
  14.         QGSForgeVersionInfoList versionInfoList(versionInfoFactory.createForgeVersionInfoList(downloadTask->getTargetFile()->readAll(), 1, 1000));
  15.         versionInfoList.merge(versionInfoList);
  16.         for (int i = 0; i < versionInfoList.size(); i++)
  17.         {
  18.             qDebug() << "branch" << versionInfoList[i].getBranch()
  19.                 << "build" << versionInfoList[i].getBuild()
  20.                 << "mcversion" << versionInfoList[i].getMcversion()
  21.                 << "modified" << versionInfoList[i].getModified()
  22.                 << "version" << versionInfoList[i].getVersion()
  23.                 << "_id" << versionInfoList[i].getId();

  24.         }
  25.         task->deleteLater();
  26.     });
  27.     QObject::connect(downloadTask, &QGSDownloadTask::downloadError, [=](QGSNetworkError error, QGSTask * task)
  28.     {
  29.         qDebug() << "forge version info json:" << "Code:" << error.getCode() << "Message:" << error.getErrorString();
  30.     });
  31.     downloadTask->start();//也可以加入线程池中,threadPoolManager->addTaskBack(downloadTask);
复制代码

获取LiteLoader列表

  1.     QGSDownloadTaskFactory * downloadTaskFactory(new QGSDownloadTaskFactory(new QGSOfficialDownloadSource));
  2.     QGSDownloadTask * downloadTask = nullptr;

  3.     downloadTask = downloadTaskFactory->generateLiteLoaderVersionInfoJsonDownloadTask(new QFile(QString("./liteloader_manifest.json")));
  4.     QObject::connect(downloadTask, &QGSDownloadTask::downloadProgress, [=](qint64 bytesReceived, qint64 bytesTotal, QGSTask * task)
  5.     {
  6.         qDebug() << "liteloader version info json:" << bytesReceived << ";" << bytesTotal;
  7.     });
  8.     QObject::connect(downloadTask, &QGSDownloadTask::finished, [=](QGSTask * task)
  9.     {
  10.         qDebug() << "forge version info json finished!";
  11.         QGSLiteLoaderVersionInfoListFactory versionInfoFactory;
  12.         downloadTask->getTargetFile()->open(QIODevice::ReadOnly);
  13.         QGSLiteLoaderVersionInfoList versionInfoList(versionInfoFactory.createLiteLoaderVersionInfoList(downloadTask->getTargetFile()->readAll()));
  14.         for (int i = 0; i < versionInfoList.size(); i++)
  15.         {
  16.             /*相关操作*/
  17.         }
  18.         task->deleteLater();
  19.     });
  20.     QObject::connect(downloadTask, &QGSDownloadTask::downloadError, [=](QGSNetworkError error, QGSTask * task)
  21.     {
  22.         qDebug() << "liteloader version info json:" << "Code:" << error.getCode() << "Message:" << error.getErrorString();
  23.     });
  24.     downloadTask->start();//也可以加入线程池中,threadPoolManager->addTaskBack(downloadTask);
  25. ```cpp

  26. #获取Optifine列表

  27. ```cpp
  28.     QGSDownloadTaskFactory * downloadTaskFactory(new QGSDownloadTaskFactory(new QGSOfficialDownloadSource));
  29.     QGSDownloadTask * downloadTask = nullptr;

  30.     downloadTask = downloadTaskFactory->generateOptifineVersionInfoJsonDownloadTask(new QFile(QString("./optifine_manifest.json")));
  31.     QObject::connect(downloadTask, &QGSDownloadTask::downloadProgress, [=](qint64 bytesReceived, qint64 bytesTotal, QGSTask * task)
  32.     {
  33.         qDebug() << "optifine version info json:" << bytesReceived << ";" << bytesTotal;
  34.     });
  35.     QObject::connect(downloadTask, &QGSDownloadTask::finished, [=](QGSTask * task)
  36.     {
  37.         qDebug() << "optifine version info json finished!";
  38.         QGSOptifineVersionInfoListFactory versionInfoFactory;
  39.         downloadTask->getTargetFile()->open(QIODevice::ReadOnly);
  40.         QGSOptifineVersionInfoList versionInfoList(versionInfoFactory.createOptifineVersionInfoList(downloadTask->getTargetFile()->readAll()));
  41.         for (int i = 0; i < versionInfoList.size(); i++)
  42.         {
  43.             /*相关操作*/
  44.         }
  45.         task->deleteLater();
  46.     });
  47.     QObject::connect(downloadTask, &QGSDownloadTask::downloadError, [=](QGSNetworkError error, QGSTask * task)
  48.     {
  49.         qDebug() << "optifine manifest:" << "Code:" << error.getCode() << "Message:" << error.getErrorString();
  50.     });
  51.     downloadTask->start();//也可以加入线程池中,threadPoolManager->addTaskBack(downloadTask);
复制代码

下载游戏(库、资源补全)

  1.     //"version_manifest.json"文件需要自行下载,详见"获取版本列表"
  2.     QFile manifestFile("./version_manifest.json");
  3.     manifestFile.open(QIODevice::ReadOnly);
  4.     QGSGameVersionInfoListFactory versionInfoFactory;
  5.     QGSGameVersionInfoList versionInfoList(versionInfoFactory.createGameVersionInfoList(manifestFile.readAll()));
  6.     QGSIDownloadSource * downloadSource = new QGSBMCLAPIDownloadSource;//BMCL

  7.     QGSGameVersionInfo versionInfo = versionInfoList.getVersionInfo("1.11.2");
  8.     QGSDownloadTaskFactory * downloadTaskFactory(new QGSDownloadTaskFactory(downloadSource));
  9.     //游戏目录
  10.     QGSGameDirectory * gameDirectory(new QGSGameDirectory(QDir("./.minecraft")));
  11.     //线程池。线程池数最小为8,最大为512。
  12.     QGSThreadPoolManager * threadPoolManager(new QGSThreadPoolManager(8, 512));
  13.     //建造者工厂,用于创建游戏各部分的建造者。
  14.     QGSBuilderFactory * builderFactory(new QGSBuilderFactory(threadPoolManager));
  15.     //游戏本体建造者。
  16.     QGSGameVersionBuilder * gameVersionBuilder = builderFactory->createGameVersionBuilder(versionInfo, gameDirectory, downloadTaskFactory);
  17.     //库建造者
  18.     QGSLibraryBuilder * libraryBuilder = builderFactory->createLibraryBuilder(versionInfo, gameDirectory, downloadTaskFactory);
  19.     //资源建造者
  20.     QGSAssetBuilder * assetBuilder = builderFactory->createAssetBuilder(versionInfo, gameDirectory, downloadTaskFactory);
  21.     //前一个任务发出finished()(完成)信号后即刻执行下一个任务。
  22.     gameVersionBuilder->setNextTask(libraryBuilder).setNextTask(assetBuilder);
  23.     QObject::connect(gameVersionBuilder, &QGSGameVersionBuilder::started, [=]()//建造者开始
  24.     {
  25.         qDebug() << "gameVersionBuilder started!";
  26.     });
  27.     QObject::connect(gameVersionBuilder, &QGSGameVersionBuilder::downloadTaskStarted, [=](QGSDownloadTask * task)//任务开始
  28.     {
  29.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " started!";
  30.     });
  31.     QObject::connect(gameVersionBuilder, &QGSGameVersionBuilder::downloadTaskFinished, [=](QGSDownloadTask * task)//任务完成
  32.     {
  33.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " finished!" << gameVersionBuilder->getTaskListSize() << "left!";
  34.     });
  35.     QObject::connect(gameVersionBuilder, &QGSGameVersionBuilder::downloadTaskStoped, [=](QGSDownloadTask * task)//任务暂停
  36.     {
  37.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " stoped!";
  38.     });
  39.     QObject::connect(gameVersionBuilder, &QGSGameVersionBuilder::downloadTaskCanceled, [=](QGSDownloadTask * task)//任务取消
  40.     {
  41.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " canceled!";
  42.     });
  43.     QObject::connect(gameVersionBuilder, &QGSGameVersionBuilder::downloadTaskDownloadProgress, [](qint64 bytesReceived, qint64 bytesTotal, QGSDownloadTask * task)//任务进程
  44.     {
  45.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " download progress:" << "bytes received:" << bytesReceived << "bytes total:" << bytesTotal;
  46.     });
  47.     QObject::connect(gameVersionBuilder, &QGSGameVersionBuilder::downloadTaskDownloadError, [=](QGSNetworkError error, QGSDownloadTask * task)//任务错误(同时发出downloadTaskError())
  48.     {
  49.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " download error!" << gameVersionBuilder->getTaskListSize() << "left!" << "Error code:" << error.getCode();
  50.     });
  51.     QObject::connect(gameVersionBuilder, &QGSGameVersionBuilder::downloadTaskError, [=](QGSDownloadTask * task)//任务错误
  52.     {
  53.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " error!" << gameVersionBuilder->getTaskListSize() << "left!";
  54.     });
  55.     QObject::connect(gameVersionBuilder, &QGSGameVersionBuilder::error, [=]()//建造者错误
  56.     {
  57.         qDebug() << "gameVersionBuilder error!";
  58.     });
  59.     QObject::connect(gameVersionBuilder, &QGSGameVersionBuilder::finished, [=]()//建造者完成
  60.     {
  61.         qDebug() << "gameVersionBuilder finished!";
  62.     });
  63.     //
  64.     QObject::connect(libraryBuilder, &QGSLibraryBuilder::started, [=]()
  65.     {
  66.         qDebug() << "libraryBuilder started!";
  67.     });
  68.     QObject::connect(libraryBuilder, &QGSLibraryBuilder::downloadTaskStarted, [=](QGSDownloadTask * task)
  69.     {
  70.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " started!";
  71.     });
  72.     QObject::connect(libraryBuilder, &QGSLibraryBuilder::downloadTaskFinished, [=](QGSDownloadTask * task)
  73.     {
  74.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " finished!" << libraryBuilder->getTaskListSize() << "left!";
  75.     });
  76.     QObject::connect(libraryBuilder, &QGSLibraryBuilder::downloadTaskStoped, [=](QGSDownloadTask * task)
  77.     {
  78.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " stoped!";
  79.     });
  80.     QObject::connect(libraryBuilder, &QGSLibraryBuilder::downloadTaskCanceled, [=](QGSDownloadTask * task)
  81.     {
  82.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " canceled!";
  83.     });
  84.     QObject::connect(libraryBuilder, &QGSLibraryBuilder::downloadTaskDownloadProgress, [](qint64 bytesReceived, qint64 bytesTotal, QGSDownloadTask * task)
  85.     {
  86.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " download progress:" << "bytes received:" << bytesReceived << "bytes total:" << bytesTotal;
  87.     });
  88.     QObject::connect(libraryBuilder, &QGSLibraryBuilder::downloadTaskDownloadError, [=](QGSNetworkError error, QGSDownloadTask * task)
  89.     {
  90.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " download error!" << libraryBuilder->getTaskListSize() << "left!" << "Error code:" << error.getCode();
  91.     });
  92.     QObject::connect(libraryBuilder, &QGSLibraryBuilder::downloadTaskError, [=](QGSDownloadTask * task)
  93.     {
  94.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " error!" << libraryBuilder->getTaskListSize() << "left!";
  95.     });
  96.     QObject::connect(libraryBuilder, &QGSLibraryBuilder::error, [=]()
  97.     {
  98.         qDebug() << "libraryBuilder error!";
  99.     });
  100.     QObject::connect(libraryBuilder, &QGSLibraryBuilder::finished, [=]()
  101.     {
  102.         qDebug() << "libraryBuilder finished!";
  103.     });
  104.     //
  105.     QObject::connect(assetBuilder, &QGSLibraryBuilder::started, [=]()
  106.     {
  107.         qDebug() << "assetBuilder started!";
  108.     });
  109.     QObject::connect(assetBuilder, &QGSLibraryBuilder::downloadTaskStarted, [=](QGSDownloadTask * task)
  110.     {
  111.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " started!";
  112.     });
  113.     QObject::connect(assetBuilder, &QGSLibraryBuilder::downloadTaskFinished, [=](QGSDownloadTask * task)
  114.     {
  115.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " finished!" << assetBuilder->getTaskListSize() << "left!";
  116.     });
  117.     QObject::connect(assetBuilder, &QGSLibraryBuilder::downloadTaskStoped, [=](QGSDownloadTask * task)
  118.     {
  119.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " stoped!";
  120.     });
  121.     QObject::connect(assetBuilder, &QGSLibraryBuilder::downloadTaskCanceled, [=](QGSDownloadTask * task)
  122.     {
  123.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " canceled!";
  124.     });
  125.     QObject::connect(assetBuilder, &QGSLibraryBuilder::downloadTaskDownloadProgress, [](qint64 bytesReceived, qint64 bytesTotal, QGSDownloadTask * task)
  126.     {
  127.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " download progress:" << "bytes received:" << bytesReceived << "bytes total:" << bytesTotal;
  128.     });
  129.     QObject::connect(assetBuilder, &QGSLibraryBuilder::downloadTaskDownloadError, [=](QGSNetworkError error, QGSDownloadTask * task)
  130.     {
  131.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " download error!" << assetBuilder->getTaskListSize() << "left!" << "Error code:" << error.getCode();
  132.     });
  133.     QObject::connect(assetBuilder, &QGSLibraryBuilder::downloadTaskError, [=](QGSDownloadTask * task)
  134.     {
  135.         qDebug() << "download:" << task->getDownloadInfo().getUrl() << " error!" << assetBuilder->getTaskListSize() << "left!";
  136.     });
  137.     QObject::connect(assetBuilder, &QGSLibraryBuilder::error, [=]()
  138.     {
  139.         qDebug() << "assetBuilder error!";
  140.     });
  141.     QObject::connect(assetBuilder, &QGSLibraryBuilder::finished, [=]()
  142.     {
  143.         qDebug() << "assetBuilder finished!";
  144.     });
  145.     //将建造者加入线程池
  146.     threadPoolManager->addTaskBack(gameVersionBuilder);
复制代码

下载Forge(需要自行安装)

  1.     QGSDownloadTaskFactory * downloadTaskFactory(new QGSDownloadTaskFactory(new QGSOfficialDownloadSource));
  2.     QGSDownloadTask * downloadTask = nullptr;

  3.     //forge download test
  4.     downloadTask = downloadTaskFactory->generateForgeDownloadTask(new QFile(QString("./forge-installer.jar")), "1.11.2", "13.20.0.2200", "installer", "jar");
  5.     QObject::connect(downloadTask, &QGSDownloadTask::downloadProgress, [=](qint64 bytesReceived, qint64 bytesTotal, QGSTask * task)
  6.     {
  7.         qDebug() << "Forge:" << bytesReceived << ";" << bytesTotal;
  8.     });
  9.     QObject::connect(downloadTask, &QGSDownloadTask::finished, [=](QGSTask * task)
  10.     {
  11.         qDebug() << "Forge:finished!";

  12.         task->deleteLater();
  13.     });
  14.     QObject::connect(downloadTask, &QGSDownloadTask::downloadError, [=](QGSNetworkError error, QGSTask * task)
  15.     {
  16.         qDebug() << "Forge:" << "Code:" << error.getCode();
  17.     });
  18.     downloadTask->start();//也可以加入线程池中,threadPoolManager->addTaskBack(downloadTask);
复制代码

下载LiteLoader(需要自行安装)

  1.     QGSDownloadTaskFactory * downloadTaskFactory(new QGSDownloadTaskFactory(new QGSOfficialDownloadSource));
  2.     QGSDownloadTask * downloadTask = nullptr;

  3.     //liteloader download test
  4.     downloadTask = downloadTaskFactory->generateLiteLoaderDownloadTask(new QFile(QString("./liteloader.jar")), "1.11.2", "1.11.2-SNAPSHOT", "installer");
  5.     QObject::connect(downloadTask, &QGSDownloadTask::downloadProgress, [=](qint64 bytesReceived, qint64 bytesTotal, QGSTask * task)
  6.     {
  7.         qDebug() << "LiteLoader:" << bytesReceived << ";" << bytesTotal;
  8.     });
  9.     QObject::connect(downloadTask, &QGSDownloadTask::finished, [=](QGSTask * task)
  10.     {
  11.         qDebug() << "LiteLoader:finished!";

  12.         task->deleteLater();
  13.     });
  14.     QObject::connect(downloadTask, &QGSDownloadTask::downloadError, [=](QGSNetworkError error, QGSTask * task)
  15.     {
  16.         qDebug() << "LiteLoader:" << "Code:" << error.getCode();
  17.     });
  18.     downloadTask->start();//也可以加入线程池中,threadPoolManager->addTaskBack(downloadTask);
复制代码

下载Optifine(需要自行安装)

  1.     QGSDownloadTaskFactory * downloadTaskFactory(new QGSDownloadTaskFactory(new QGSOfficialDownloadSource));
  2.     QGSDownloadTask * downloadTask = nullptr;

  3.     //optifine download test
  4.     downloadTask = downloadTaskFactory->generateOptifineDownloadTask(new QFile(QString("./optifine.zip")), "1.9.2", "HD_U", "D7");
  5.     QObject::connect(downloadTask, &QGSDownloadTask::downloadProgress, [=](qint64 bytesReceived, qint64 bytesTotal, QGSTask * task)
  6.     {
  7.         qDebug() << "Optifine:" << bytesReceived << ";" << bytesTotal;
  8.     });
  9.     QObject::connect(downloadTask, &QGSDownloadTask::finished, [=](QGSTask * task)
  10.     {
  11.         qDebug() << "Optifine:finished!";

  12.         task->deleteLater();
  13.     });
  14.     QObject::connect(downloadTask, &QGSDownloadTask::downloadError, [=](QGSNetworkError error, QGSTask * task)
  15.     {
  16.         qDebug() << "Optifine:" << "Code:" << error.getCode();
  17.     });
  18.     downloadTask->start();//也可以加入线程池中,threadPoolManager->addTaskBack(downloadTask);
复制代码




分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
您需要登录后才可以回帖 登录 | 加入最MC

本版积分规则