mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
code review (second part)
This commit is contained in:
parent
609906f015
commit
7655149d52
@ -17,6 +17,7 @@ set(launcher_SRCS
|
|||||||
firstLaunch/firstlaunch_moc.cpp
|
firstLaunch/firstlaunch_moc.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
helper.cpp
|
helper.cpp
|
||||||
|
innoextract.cpp
|
||||||
mainwindow_moc.cpp
|
mainwindow_moc.cpp
|
||||||
languages.cpp
|
languages.cpp
|
||||||
launcherdirs.cpp
|
launcherdirs.cpp
|
||||||
@ -53,6 +54,7 @@ set(launcher_HEADERS
|
|||||||
updatedialog_moc.h
|
updatedialog_moc.h
|
||||||
main.h
|
main.h
|
||||||
helper.h
|
helper.h
|
||||||
|
innoextract.h
|
||||||
prepare.h
|
prepare.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,11 +21,7 @@
|
|||||||
#include "../../lib/filesystem/Filesystem.h"
|
#include "../../lib/filesystem/Filesystem.h"
|
||||||
#include "../helper.h"
|
#include "../helper.h"
|
||||||
#include "../languages.h"
|
#include "../languages.h"
|
||||||
|
#include "../innoextract.h"
|
||||||
#ifdef ENABLE_INNOEXTRACT
|
|
||||||
#include "cli/extract.hpp"
|
|
||||||
#include "setup/version.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef VCMI_IOS
|
#ifdef VCMI_IOS
|
||||||
#include "ios/selectdirectory.h"
|
#include "ios/selectdirectory.h"
|
||||||
@ -386,44 +382,11 @@ void FirstLaunchView::extractGogData()
|
|||||||
if(isGogGalaxyExe(tmpFileExe))
|
if(isGogGalaxyExe(tmpFileExe))
|
||||||
errorText = tr("You've provided GOG Galaxy installer! This file doesn't contain the game. Please download the offline backup game installer!");
|
errorText = tr("You've provided GOG Galaxy installer! This file doesn't contain the game. Please download the offline backup game installer!");
|
||||||
|
|
||||||
::extract_options o;
|
|
||||||
o.extract = true;
|
|
||||||
|
|
||||||
// standard settings
|
|
||||||
o.gog_galaxy = true;
|
|
||||||
o.codepage = 0U;
|
|
||||||
o.output_dir = tempDir.path().toStdString();
|
|
||||||
o.extract_temp = true;
|
|
||||||
o.extract_unknown = true;
|
|
||||||
o.filenames.set_expand(true);
|
|
||||||
|
|
||||||
o.preserve_file_times = true; // also correctly closes file -> without it: on Windows the files are not written completely
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if(errorText.isEmpty())
|
if(errorText.isEmpty())
|
||||||
process_file(tmpFileExe.toStdString(), o, [this](float progress) {
|
errorText = Innoextract::extract(tmpFileExe, tempDir.path(), [this](float progress) {
|
||||||
ui->progressBarGog->setValue(progress * 100);
|
ui->progressBarGog->setValue(progress * 100);
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
catch(const std::ios_base::failure & e)
|
|
||||||
{
|
|
||||||
errorText = tr("Stream error while extracting files!\nerror reason: ");
|
|
||||||
errorText += e.what();
|
|
||||||
}
|
|
||||||
catch(const format_error & e)
|
|
||||||
{
|
|
||||||
errorText = e.what();
|
|
||||||
}
|
|
||||||
catch(const std::runtime_error & e)
|
|
||||||
{
|
|
||||||
errorText = e.what();
|
|
||||||
}
|
|
||||||
catch(const setup::version_error &)
|
|
||||||
{
|
|
||||||
errorText = tr("Not a supported Inno Setup installer!");
|
|
||||||
}
|
|
||||||
|
|
||||||
ui->progressBarGog->setVisible(false);
|
ui->progressBarGog->setVisible(false);
|
||||||
ui->pushButtonGogInstall->setVisible(true);
|
ui->pushButtonGogInstall->setVisible(true);
|
||||||
|
62
launcher/innoextract.cpp
Normal file
62
launcher/innoextract.cpp
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* innoextract.cpp, part of VCMI engine
|
||||||
|
*
|
||||||
|
* Authors: listed in file AUTHORS in main folder
|
||||||
|
*
|
||||||
|
* License: GNU General Public License v2.0 or later
|
||||||
|
* Full text of license available in license.txt file, in main folder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "StdInc.h"
|
||||||
|
#include "innoextract.h"
|
||||||
|
|
||||||
|
#ifdef ENABLE_INNOEXTRACT
|
||||||
|
#include "cli/extract.hpp"
|
||||||
|
#include "setup/version.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QString Innoextract::extract(QString installer, QString outDir, std::function<void (float percent)> cb)
|
||||||
|
{
|
||||||
|
QString errorText{};
|
||||||
|
|
||||||
|
#ifdef ENABLE_INNOEXTRACT
|
||||||
|
::extract_options o;
|
||||||
|
o.extract = true;
|
||||||
|
|
||||||
|
// standard settings
|
||||||
|
o.gog_galaxy = true;
|
||||||
|
o.codepage = 0U;
|
||||||
|
o.output_dir = outDir.toStdString();
|
||||||
|
o.extract_temp = true;
|
||||||
|
o.extract_unknown = true;
|
||||||
|
o.filenames.set_expand(true);
|
||||||
|
|
||||||
|
o.preserve_file_times = true; // also correctly closes file -> without it: on Windows the files are not written completely
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
process_file(installer.toStdString(), o, cb);
|
||||||
|
}
|
||||||
|
catch(const std::ios_base::failure & e)
|
||||||
|
{
|
||||||
|
errorText = tr("Stream error while extracting files!\nerror reason: ");
|
||||||
|
errorText += e.what();
|
||||||
|
}
|
||||||
|
catch(const format_error & e)
|
||||||
|
{
|
||||||
|
errorText = e.what();
|
||||||
|
}
|
||||||
|
catch(const std::runtime_error & e)
|
||||||
|
{
|
||||||
|
errorText = e.what();
|
||||||
|
}
|
||||||
|
catch(const setup::version_error &)
|
||||||
|
{
|
||||||
|
errorText = tr("Not a supported Inno Setup installer!");
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
errorText = tr("VCMI was compiled without innoextract support, which is needed to extract exe files!");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return errorText;
|
||||||
|
}
|
16
launcher/innoextract.h
Normal file
16
launcher/innoextract.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* innoextract.h, part of VCMI engine
|
||||||
|
*
|
||||||
|
* Authors: listed in file AUTHORS in main folder
|
||||||
|
*
|
||||||
|
* License: GNU General Public License v2.0 or later
|
||||||
|
* Full text of license available in license.txt file, in main folder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
class Innoextract : public QObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QString extract(QString installer, QString outDir, std::function<void (float percent)> cb = nullptr);
|
||||||
|
};
|
@ -14,19 +14,14 @@
|
|||||||
#include "../../lib/VCMIDirs.h"
|
#include "../../lib/VCMIDirs.h"
|
||||||
#include "../../lib/filesystem/CArchiveLoader.h"
|
#include "../../lib/filesystem/CArchiveLoader.h"
|
||||||
|
|
||||||
#ifdef ENABLE_INNOEXTRACT
|
#include "../innoextract.h"
|
||||||
#include "cli/extract.hpp"
|
|
||||||
#include "setup/version.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ChroniclesExtractor::ChroniclesExtractor(QWidget *p, std::function<void(float percent)> cb) :
|
ChroniclesExtractor::ChroniclesExtractor(QWidget *p, std::function<void(float percent)> cb) :
|
||||||
parent(p), cb(cb)
|
parent(p), cb(cb)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChroniclesExtractor::handleTempDir(bool create)
|
bool ChroniclesExtractor::createTempDir()
|
||||||
{
|
|
||||||
if(create)
|
|
||||||
{
|
{
|
||||||
tempDir = QDir(pathToQString(VCMIDirs::get().userDataPath()));
|
tempDir = QDir(pathToQString(VCMIDirs::get().userDataPath()));
|
||||||
if(tempDir.cd("tmp"))
|
if(tempDir.cd("tmp"))
|
||||||
@ -37,13 +32,15 @@ bool ChroniclesExtractor::handleTempDir(bool create)
|
|||||||
tempDir.mkdir("tmp");
|
tempDir.mkdir("tmp");
|
||||||
if(!tempDir.cd("tmp"))
|
if(!tempDir.cd("tmp"))
|
||||||
return false; // should not happen - but avoid deleting wrong folder in any case
|
return false; // should not happen - but avoid deleting wrong folder in any case
|
||||||
}
|
|
||||||
else
|
|
||||||
tempDir.removeRecursively();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChroniclesExtractor::removeTempDir()
|
||||||
|
{
|
||||||
|
tempDir.removeRecursively();
|
||||||
|
}
|
||||||
|
|
||||||
int ChroniclesExtractor::getChronicleNo(QFile & file)
|
int ChroniclesExtractor::getChronicleNo(QFile & file)
|
||||||
{
|
{
|
||||||
if(!file.open(QIODevice::ReadOnly))
|
if(!file.open(QIODevice::ReadOnly))
|
||||||
@ -79,49 +76,11 @@ int ChroniclesExtractor::getChronicleNo(QFile & file)
|
|||||||
|
|
||||||
bool ChroniclesExtractor::extractGogInstaller(QString file)
|
bool ChroniclesExtractor::extractGogInstaller(QString file)
|
||||||
{
|
{
|
||||||
#ifndef ENABLE_INNOEXTRACT
|
QString errorText = Innoextract::extract(file, tempDir.path(), [this](float progress) {
|
||||||
QMessageBox::critical(parent, tr("Innoextract functionality missing"), "VCMI was compiled without innoextract support, which is needed to extract chroncles!");
|
|
||||||
return false;
|
|
||||||
#else
|
|
||||||
::extract_options o;
|
|
||||||
o.extract = true;
|
|
||||||
|
|
||||||
// standard settings
|
|
||||||
o.gog_galaxy = true;
|
|
||||||
o.codepage = 0U;
|
|
||||||
o.output_dir = tempDir.path().toStdString();
|
|
||||||
o.extract_temp = true;
|
|
||||||
o.extract_unknown = true;
|
|
||||||
o.filenames.set_expand(true);
|
|
||||||
|
|
||||||
o.preserve_file_times = true; // also correctly closes file -> without it: on Windows the files are not written completely
|
|
||||||
|
|
||||||
QString errorText = "";
|
|
||||||
try
|
|
||||||
{
|
|
||||||
process_file(file.toStdString(), o, [this](float progress) {
|
|
||||||
float overallProgress = ((1.0 / static_cast<float>(fileCount)) * static_cast<float>(extractionFile)) + (progress / static_cast<float>(fileCount));
|
float overallProgress = ((1.0 / static_cast<float>(fileCount)) * static_cast<float>(extractionFile)) + (progress / static_cast<float>(fileCount));
|
||||||
if(cb)
|
if(cb)
|
||||||
cb(overallProgress);
|
cb(overallProgress);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
catch(const std::ios_base::failure & e)
|
|
||||||
{
|
|
||||||
errorText = tr("Stream error while extracting files!\nerror reason: ");
|
|
||||||
errorText += e.what();
|
|
||||||
}
|
|
||||||
catch(const format_error & e)
|
|
||||||
{
|
|
||||||
errorText = e.what();
|
|
||||||
}
|
|
||||||
catch(const std::runtime_error & e)
|
|
||||||
{
|
|
||||||
errorText = e.what();
|
|
||||||
}
|
|
||||||
catch(const setup::version_error &)
|
|
||||||
{
|
|
||||||
errorText = tr("Not a supported Inno Setup installer!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!errorText.isEmpty())
|
if(!errorText.isEmpty())
|
||||||
{
|
{
|
||||||
@ -130,7 +89,6 @@ bool ChroniclesExtractor::extractGogInstaller(QString file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChroniclesExtractor::createBaseMod() const
|
void ChroniclesExtractor::createBaseMod() const
|
||||||
@ -143,8 +101,8 @@ void ChroniclesExtractor::createBaseMod() const
|
|||||||
QJsonObject mod
|
QJsonObject mod
|
||||||
{
|
{
|
||||||
{ "modType", "Expansion" },
|
{ "modType", "Expansion" },
|
||||||
{ "name", "Heroes Chronicles" },
|
{ "name", tr("Heroes Chronicles") },
|
||||||
{ "description", "Heroes Chronicles" },
|
{ "description", tr("Heroes Chronicles") },
|
||||||
{ "author", "3DO" },
|
{ "author", "3DO" },
|
||||||
{ "version", "1.0" },
|
{ "version", "1.0" },
|
||||||
{ "contact", "vcmi.eu" },
|
{ "contact", "vcmi.eu" },
|
||||||
@ -161,11 +119,14 @@ void ChroniclesExtractor::createChronicleMod(int no)
|
|||||||
dir.removeRecursively();
|
dir.removeRecursively();
|
||||||
dir.mkpath(".");
|
dir.mkpath(".");
|
||||||
|
|
||||||
|
QByteArray tmpChronicles = chronicles.at(no);
|
||||||
|
tmpChronicles.replace('\0', "");
|
||||||
|
|
||||||
QJsonObject mod
|
QJsonObject mod
|
||||||
{
|
{
|
||||||
{ "modType", "Expansion" },
|
{ "modType", "Expansion" },
|
||||||
{ "name", "Heroes Chronicles - " + QString::number(no) },
|
{ "name", QString::number(no) + " - " + QString(tmpChronicles) },
|
||||||
{ "description", "Heroes Chronicles - " + QString::number(no) },
|
{ "description", tr("Heroes Chronicles") + " - " + QString::number(no) + " - " + QString(tmpChronicles) },
|
||||||
{ "author", "3DO" },
|
{ "author", "3DO" },
|
||||||
{ "version", "1.0" },
|
{ "version", "1.0" },
|
||||||
{ "contact", "vcmi.eu" },
|
{ "contact", "vcmi.eu" },
|
||||||
@ -250,7 +211,7 @@ void ChroniclesExtractor::installChronicles(QStringList exe)
|
|||||||
if(!chronicleNo)
|
if(!chronicleNo)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(!handleTempDir(true))
|
if(!createTempDir())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(!extractGogInstaller(f))
|
if(!extractGogInstaller(f))
|
||||||
@ -259,6 +220,6 @@ void ChroniclesExtractor::installChronicles(QStringList exe)
|
|||||||
createBaseMod();
|
createBaseMod();
|
||||||
createChronicleMod(chronicleNo);
|
createChronicleMod(chronicleNo);
|
||||||
|
|
||||||
handleTempDir(false);
|
removeTempDir();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,8 @@ class ChroniclesExtractor : public QObject
|
|||||||
int extractionFile;
|
int extractionFile;
|
||||||
int fileCount;
|
int fileCount;
|
||||||
|
|
||||||
bool handleTempDir(bool create);
|
bool createTempDir();
|
||||||
|
void removeTempDir();
|
||||||
int getChronicleNo(QFile & file);
|
int getChronicleNo(QFile & file);
|
||||||
bool extractGogInstaller(QString filePath);
|
bool extractGogInstaller(QString filePath);
|
||||||
void createBaseMod() const;
|
void createBaseMod() const;
|
||||||
|
Loading…
Reference in New Issue
Block a user