Add function to obtain minetestmapper version
parent
20b8e53234
commit
505686ff8a
|
@ -12,6 +12,9 @@
|
||||||
const QString ConfigSettings::defaultMapperExecutableName("minetestmapper");
|
const QString ConfigSettings::defaultMapperExecutableName("minetestmapper");
|
||||||
QStringList ConfigSettings::predefinedMapperLocations;
|
QStringList ConfigSettings::predefinedMapperLocations;
|
||||||
|
|
||||||
|
QString ConfigSettings::versionUnknown("(unknown)");
|
||||||
|
QString ConfigSettings::versionError("(error)");
|
||||||
|
|
||||||
ConfigSettings::InitStatics::InitStatics()
|
ConfigSettings::InitStatics::InitStatics()
|
||||||
{
|
{
|
||||||
#ifndef Q_OS_WIN
|
#ifndef Q_OS_WIN
|
||||||
|
@ -106,6 +109,39 @@ void ConfigDialog::on_browseMapper_clicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ConfigSettings::getMapperVersion(const QString &mapperBinary, QWidget *parent)
|
||||||
|
{
|
||||||
|
QProcess mapperProcess(parent);
|
||||||
|
mapperProcess.setProgram(mapperBinary);
|
||||||
|
mapperProcess.setArguments(QStringList("--version"));
|
||||||
|
mapperProcess.start();
|
||||||
|
if (!mapperProcess.waitForStarted(1000)) {
|
||||||
|
mapperProcess.terminate();
|
||||||
|
return ConfigSettings::versionError;
|
||||||
|
}
|
||||||
|
if (!mapperProcess.waitForFinished(1000)) {
|
||||||
|
mapperProcess.terminate();
|
||||||
|
if (!mapperProcess.waitForFinished(1000)) {
|
||||||
|
mapperProcess.kill();
|
||||||
|
}
|
||||||
|
return ConfigSettings::versionError;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray dataRaw;
|
||||||
|
QString data;
|
||||||
|
dataRaw = mapperProcess.readAllStandardError();
|
||||||
|
data = QString(dataRaw).trimmed();
|
||||||
|
if (data.contains("unrecognized option")) {
|
||||||
|
return ConfigSettings::versionUnknown;
|
||||||
|
}
|
||||||
|
dataRaw = mapperProcess.readAllStandardOutput();
|
||||||
|
data = QString(dataRaw).trimmed();
|
||||||
|
if (!data.contains("Version-ID:")) {
|
||||||
|
return ConfigSettings::versionUnknown;
|
||||||
|
}
|
||||||
|
return data.replace(QRegularExpression(".*Version-ID: *"),"");
|
||||||
|
}
|
||||||
|
|
||||||
QString ConfigSettings::getDefaultMapperExecutable(void)
|
QString ConfigSettings::getDefaultMapperExecutable(void)
|
||||||
{
|
{
|
||||||
QStringList locations = getMapperExecutables();
|
QStringList locations = getMapperExecutables();
|
||||||
|
|
|
@ -13,10 +13,13 @@ struct ConfigSettings
|
||||||
{
|
{
|
||||||
QString mapperPath;
|
QString mapperPath;
|
||||||
|
|
||||||
|
static QString versionUnknown;
|
||||||
|
static QString versionError;
|
||||||
static QStringList getMapperExecutables(void);
|
static QStringList getMapperExecutables(void);
|
||||||
static QString getDefaultMapperExecutable(void);
|
static QString getDefaultMapperExecutable(void);
|
||||||
static const QString defaultMapperExecutableName;
|
static const QString defaultMapperExecutableName;
|
||||||
static QStringList predefinedMapperLocations;
|
static QStringList predefinedMapperLocations;
|
||||||
|
static QString getMapperVersion(const QString &mapperBinary, QWidget *parent = NULL);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct InitStatics { InitStatics(void); };
|
struct InitStatics { InitStatics(void); };
|
||||||
|
|
|
@ -227,6 +227,8 @@ void MainWindow::on_button_generate_clicked()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug() << QString("Minetestmapper version: ") + ConfigSettings::getMapperVersion(mapperBinary.fileName(), this);
|
||||||
|
|
||||||
QDir worldPath = QDir(ui->path_World->text());
|
QDir worldPath = QDir(ui->path_World->text());
|
||||||
if(!worldPath.exists()||worldPath.path()=="."||worldPath.path()=="/"){
|
if(!worldPath.exists()||worldPath.path()=="."||worldPath.path()=="/"){
|
||||||
QMessageBox::critical(this, tr("no input world selected"),
|
QMessageBox::critical(this, tr("no input world selected"),
|
||||||
|
|
Loading…
Reference in New Issue