1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

async launcher

This commit is contained in:
Laserlicht 2024-08-31 18:46:45 +02:00
parent 46872b764b
commit 23652a8ba1
2 changed files with 30 additions and 17 deletions

View File

@ -142,7 +142,7 @@ void ChroniclesExtractor::createBaseMod()
QJsonObject mod
{
{ "modType", "Extension" },
{ "modType", "Expansion" },
{ "name", "Heroes Chronicles" },
{ "description", "" },
{ "author", "3DO" },
@ -156,13 +156,13 @@ void ChroniclesExtractor::createBaseMod()
void ChroniclesExtractor::createChronicleMod(int no)
{
QDir dir(pathToQString(VCMIDirs::get().userDataPath() / "Mods" / "chronicles" / "Mods"));
dir.mkdir("chronicles_" + QString::number(no));
dir.cd("chronicles_" + QString::number(no));
QDir dir(pathToQString(VCMIDirs::get().userDataPath() / "Mods" / "chronicles" / "Mods" / ("chronicles_" + std::to_string(no))));
dir.removeRecursively();
dir.mkpath(".");
QJsonObject mod
{
{ "modType", "Extension" },
{ "modType", "Expansion" },
{ "name", "Heroes Chronicles - " + QString::number(no) },
{ "description", "" },
{ "author", "3DO" },
@ -174,11 +174,7 @@ void ChroniclesExtractor::createChronicleMod(int no)
jsonFile.write(QJsonDocument(mod).toJson());
dir.cd("content");
dir.removeRecursively();
dir.mkdir(".");
dir.mkdir("Data");
dir.mkdir("Sprites");
extractFiles(no);
}

View File

@ -839,15 +839,32 @@ void CModListView::installFiles(QStringList files)
if(!exe.empty())
{
ChroniclesExtractor ce(this, [](float progress) { });
ce.installChronicles(exe);
ui->progressBar->setFormat(tr("Installing chronicles"));
float prog = 0.0;
auto futureExtract = std::async(std::launch::async, [this, exe, &prog]()
{
ChroniclesExtractor ce(this, [this, &prog](float progress) { prog = progress; });
ce.installChronicles(exe);
return true;
});
while(futureExtract.wait_for(std::chrono::milliseconds(10)) != std::future_status::ready)
{
emit extractionProgress(int(prog * 1000.f), 1000);
qApp->processEvents();
}
if(futureExtract.get())
{
//update
CResourceHandler::get("initial")->updateFilteredFiles([](const std::string &){ return true; });
manager->loadMods();
modModel->reloadRepositories();
emit modsChanged();
}
}
if(!images.empty())
loadScreenshots();