Issue #69 Menu item to launch CSL2XSB in own models component

This commit is contained in:
Mat Sutcliffe
2020-08-09 01:46:16 +01:00
parent 19e409a451
commit 660f3fc17b
3 changed files with 35 additions and 4 deletions

View File

@@ -17,6 +17,7 @@
#include "blackcore/db/databaseutils.h"
#include "blackmisc/icons.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/processctrl.h"
#include "blackmisc/statusmessage.h"
#include "blackconfig/buildconfig.h"
#include "ui_dbownmodelscomponent.h"
@@ -292,6 +293,16 @@ namespace BlackGui
this->requestSimulatorModels(simulator, IAircraftModelLoader::InBackgroundNoCache);
}
void CDbOwnModelsComponent::runScriptCSL2XSB()
{
static const QString script = QDir(CDirectoryUtils::shareDirectory()).filePath("CSL2XSB/CSL2XSB.exe");
for (const QString &modelDir : m_simulatorSettings.getModelDirectoriesOrDefault(CSimulatorInfo::xplane()))
{
CLogMessage(this).info(u"Running CSL2XSB on model directory %1") << modelDir;
CProcessCtrl::startDetached(script, { QDir::cleanPath(modelDir) }, true);
}
}
void CDbOwnModelsComponent::CLoadModelsMenu::customMenu(CMenuActions &menuActions)
{
if (!sGui || sGui->isShuttingDown()) { return; }
@@ -602,6 +613,21 @@ namespace BlackGui
}
menuActions.addAction(m_clearCacheActions[4], CMenuAction::pathSimulatorModelsClearCache());
}
if (sims.isXPlane() && CBuildConfig::isRunningOnWindowsNtPlatform() && CBuildConfig::buildWordSize() == 64)
{
if (!m_csl2xsbAction)
{
m_csl2xsbAction = new QAction(CIcons::appTerminal16(), "XPlane: run CSL2XSB on all models", this);
connect(m_csl2xsbAction, &QAction::triggered, ownModelsComp, [ownModelsComp](bool checked)
{
if (!ownModelsComp) { return; }
Q_UNUSED(checked)
ownModelsComp->runScriptCSL2XSB();
});
}
menuActions.addAction(m_csl2xsbAction, CMenuAction::pathSimulator());
}
}
this->nestedCustomMenu(menuActions);
}

View File

@@ -192,6 +192,9 @@ namespace BlackGui
//! Confirmed forced reload
void confirmedForcedReload(const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Run CSL2XSB script
void runScriptCSL2XSB();
//! The menu for loading and handling own models for mapping tasks
//! \note This is specific for that very component
//! \fixme MS 2018-12 Move to namespace scope and add Q_OBJECT
@@ -210,6 +213,7 @@ namespace BlackGui
QList<QAction *> m_loadActions; //!< load actions
QList<QAction *> m_reloadActions; //!< reload actions
QList<QAction *> m_clearCacheActions; //!< clear own models cahce if ever needed
QAction *m_csl2xsbAction = nullptr; //!< run csl2xsb script
};
};
} // ns

View File

@@ -33,10 +33,11 @@ namespace BlackMisc
memset (&startupInfo, 0, sizeof (startupInfo));
startupInfo.cb = sizeof (startupInfo);
QString command;
command += program;
command += ' ';
command += arguments.join(' ').replace('/', '\\');
QString command = '"' % QString(program).replace('/', '\\') % '"';
if (!arguments.isEmpty())
{
command += " \"" % arguments.join('" "').replace('/', '\\') % '"';
}
DWORD flags = 0;
flags |= NORMAL_PRIORITY_CLASS;