mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-04 17:30:12 +08:00
XSwiftBus install dialog (for local environment)
* can also be called from menu * improved file check * renamed some functions
This commit is contained in:
@@ -24,11 +24,12 @@ using namespace BlackCore::Context;
|
|||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
int CCopyXSwiftBusDialog::displayDialogAndCopyBuildFiles(const QString &xplaneRootDir, QWidget *parent)
|
int CCopyXSwiftBusDialog::displayDialogAndCopyBuildFiles(const QString &xplaneRootDir, bool checkLatestFile, QWidget *parent)
|
||||||
{
|
{
|
||||||
if (!CBuildConfig::isLocalDeveloperDebugBuild()) { return -1; }
|
|
||||||
if (!CXPlaneUtil::hasNewerXSwiftBusBuild(xplaneRootDir)) { return 0; }
|
|
||||||
if (sGui && sGui->isShuttingDown()) { return 0; }
|
if (sGui && sGui->isShuttingDown()) { return 0; }
|
||||||
|
if (!CBuildConfig::isLocalDeveloperDebugBuild()) { return -1; }
|
||||||
|
if (checkLatestFile && !CXPlaneUtil::hasNewerXSwiftBusBuild(xplaneRootDir)) { return 0; }
|
||||||
|
if (!CXPlaneUtil::hasXSwiftBusBuildAndPluginDir(xplaneRootDir)) { return 0; }
|
||||||
if (sGui && sGui->getIContextSimulator())
|
if (sGui && sGui->getIContextSimulator())
|
||||||
{
|
{
|
||||||
if (sGui->getIContextSimulator()->isSimulatorAvailable())
|
if (sGui->getIContextSimulator()->isSimulatorAvailable())
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Display a dialog to copy the latest XSwiftBus files
|
//! Display a dialog to copy the latest XSwiftBus files
|
||||||
//! \remark only displayed in a local environment
|
//! \remark normally only displayed in a local environment
|
||||||
static int displayDialogAndCopyBuildFiles(const QString &xplaneRootDir, QWidget *parent = nullptr);
|
static int displayDialogAndCopyBuildFiles(const QString &xplaneRootDir, bool checkLatestFile = true, QWidget *parent = nullptr);
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -300,7 +300,7 @@ namespace BlackMisc
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo CFileUtils::findNewestFile(const QDir &dir, bool recursive, const QStringList &nameFilters, const QStringList &excludeDirectories)
|
QFileInfo CFileUtils::findLastModified(const QDir &dir, bool recursive, const QStringList &nameFilters, const QStringList &excludeDirectories)
|
||||||
{
|
{
|
||||||
if (isExcludedDirectory(dir, excludeDirectories)) { return QString(); }
|
if (isExcludedDirectory(dir, excludeDirectories)) { return QString(); }
|
||||||
const QFileInfoList files = enumerateFiles(dir, recursive, nameFilters, excludeDirectories);
|
const QFileInfoList files = enumerateFiles(dir, recursive, nameFilters, excludeDirectories);
|
||||||
@@ -313,6 +313,19 @@ namespace BlackMisc
|
|||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QFileInfo CFileUtils::findLastCreated(const QDir &dir, bool recursive, const QStringList &nameFilters, const QStringList &excludeDirectories)
|
||||||
|
{
|
||||||
|
if (isExcludedDirectory(dir, excludeDirectories)) { return QString(); }
|
||||||
|
const QFileInfoList files = enumerateFiles(dir, recursive, nameFilters, excludeDirectories);
|
||||||
|
if (files.isEmpty()) { return {}; }
|
||||||
|
|
||||||
|
auto it = std::max_element(files.cbegin(), files.cend(), [](const QFileInfo & a, const QFileInfo & b)
|
||||||
|
{
|
||||||
|
return a.created() < b.created();
|
||||||
|
});
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
|
||||||
const QStringList &CFileUtils::getSwiftExecutables()
|
const QStringList &CFileUtils::getSwiftExecutables()
|
||||||
{
|
{
|
||||||
static const QStringList executables(
|
static const QStringList executables(
|
||||||
|
|||||||
@@ -125,8 +125,11 @@ namespace BlackMisc
|
|||||||
//! Returns list of all files in dir, optionally matching a wildcard and predicate.
|
//! Returns list of all files in dir, optionally matching a wildcard and predicate.
|
||||||
static QFileInfoList enumerateFiles(const QDir &dir, bool recursive, const QStringList &nameFilters = {}, const QStringList &excludeDirectories = {}, std::function<bool(const QFileInfo &)> predicate = {});
|
static QFileInfoList enumerateFiles(const QDir &dir, bool recursive, const QStringList &nameFilters = {}, const QStringList &excludeDirectories = {}, std::function<bool(const QFileInfo &)> predicate = {});
|
||||||
|
|
||||||
//! Returns path to the newest file in dir, optionally matching a wildcard, or empty string.
|
//! Returns path to the last modifed file in dir, optionally matching a wildcard, or empty string.
|
||||||
static QFileInfo findNewestFile(const QDir &dir, bool recursive, const QStringList &nameFilters = {}, const QStringList &excludeDirectories = {});
|
static QFileInfo findLastModified(const QDir &dir, bool recursive, const QStringList &nameFilters = {}, const QStringList &excludeDirectories = {});
|
||||||
|
|
||||||
|
//! Returns path to the last created file in dir, optionally matching a wildcard, or empty string.
|
||||||
|
static QFileInfo findLastCreated(const QDir &dir, bool recursive, const QStringList &nameFilters = {}, const QStringList &excludeDirectories = {});
|
||||||
|
|
||||||
//! Get all swift executables
|
//! Get all swift executables
|
||||||
static const QStringList &getSwiftExecutables();
|
static const QStringList &getSwiftExecutables();
|
||||||
|
|||||||
@@ -205,6 +205,13 @@ namespace BlackMisc
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CXPlaneUtil::hasXSwiftBusBuildAndPluginDir(const QString &xplaneRootDir)
|
||||||
|
{
|
||||||
|
if (CDirectoryUtils::getXSwiftBusBuildDirectory().isEmpty()) { return false; }
|
||||||
|
const QString xswiftBusPluginDir = CXPlaneUtil::xswiftbusPluginDir(xplaneRootDir);
|
||||||
|
return (!xswiftBusPluginDir.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
QStringList CXPlaneUtil::findConflictingPlugins(const QString &pluginDir)
|
QStringList CXPlaneUtil::findConflictingPlugins(const QString &pluginDir)
|
||||||
{
|
{
|
||||||
const QStringList files = findAllXplFiles(pluginDir);
|
const QStringList files = findAllXplFiles(pluginDir);
|
||||||
@@ -246,10 +253,10 @@ namespace BlackMisc
|
|||||||
const QString xswiftBusPluginDir = CXPlaneUtil::xswiftbusPluginDir(xplaneRootDir);
|
const QString xswiftBusPluginDir = CXPlaneUtil::xswiftbusPluginDir(xplaneRootDir);
|
||||||
if (xswiftBusPluginDir.isEmpty()) { return false; }
|
if (xswiftBusPluginDir.isEmpty()) { return false; }
|
||||||
|
|
||||||
const QFileInfo fiLatestBuild = CFileUtils::findNewestFile(CDirectoryUtils::getXSwiftBusBuildDirectory(), true, xplFileFilter());
|
const QFileInfo fiLatestBuild = CFileUtils::findLastModified(CDirectoryUtils::getXSwiftBusBuildDirectory(), true, xplFileFilter());
|
||||||
if (!fiLatestBuild.lastModified().isValid()) { return false; }
|
if (!fiLatestBuild.lastModified().isValid()) { return false; }
|
||||||
|
|
||||||
const QFileInfo fiLatestDeployed = CFileUtils::findNewestFile(xswiftBusPluginDir, true, xplFileFilter());
|
const QFileInfo fiLatestDeployed = CFileUtils::findLastModified(xswiftBusPluginDir, true, xplFileFilter());
|
||||||
if (!fiLatestDeployed.lastModified().isValid()) { return true; } // not yet existing
|
if (!fiLatestDeployed.lastModified().isValid()) { return true; } // not yet existing
|
||||||
|
|
||||||
// newer?
|
// newer?
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ namespace BlackMisc
|
|||||||
//! XSwiftBus legacy directory
|
//! XSwiftBus legacy directory
|
||||||
static QString xswiftbusLegacyDir(const QString &xplaneRootDir = CXPlaneUtil::xplaneRootDir());
|
static QString xswiftbusLegacyDir(const QString &xplaneRootDir = CXPlaneUtil::xplaneRootDir());
|
||||||
|
|
||||||
|
//! Both directories, plugin and
|
||||||
|
static bool hasXSwiftBusBuildAndPluginDir(const QString &xplaneRootDir);
|
||||||
|
|
||||||
//! Finds conflicting plugins
|
//! Finds conflicting plugins
|
||||||
//! \remark uses CXPlaneUtil::xplanePluginPath as default
|
//! \remark uses CXPlaneUtil::xplanePluginPath as default
|
||||||
static QStringList findConflictingPlugins(const QString &pluginDir = {});
|
static QStringList findConflictingPlugins(const QString &pluginDir = {});
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
#include "blackgui/components/logcomponent.h"
|
#include "blackgui/components/logcomponent.h"
|
||||||
#include "blackgui/components/dbloaddatadialog.h"
|
#include "blackgui/components/dbloaddatadialog.h"
|
||||||
#include "blackgui/components/settingscomponent.h"
|
#include "blackgui/components/settingscomponent.h"
|
||||||
#include "blackgui/copyxswiftbusdialog.h"
|
|
||||||
#include "blackgui/guiapplication.h"
|
#include "blackgui/guiapplication.h"
|
||||||
#include "blackgui/guiutility.h"
|
#include "blackgui/guiutility.h"
|
||||||
#include "blackgui/overlaymessagesframe.h"
|
#include "blackgui/overlaymessagesframe.h"
|
||||||
@@ -425,9 +424,7 @@ void SwiftGuiStd::verifyPrerequisites()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString xPlaneRootDir = ui->comp_MainInfoArea->getSettingsComponent()->getSimulatorSettings(CSimulatorInfo::XPLANE).getSimulatorDirectoryOrDefault();
|
this->copyXSwiftBusDialog(true);
|
||||||
const int c = CCopyXSwiftBusDialog::displayDialogAndCopyBuildFiles(xPlaneRootDir, this);
|
|
||||||
if (c > 0) { CLogMessage(this).info("Copied %1 files from build directory") << c; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwiftGuiStd::checkDbDataLoaded()
|
void SwiftGuiStd::checkDbDataLoaded()
|
||||||
|
|||||||
@@ -259,6 +259,9 @@ private:
|
|||||||
|
|
||||||
//! Ckeck if the DB data have been loaded
|
//! Ckeck if the DB data have been loaded
|
||||||
void checkDbDataLoaded();
|
void checkDbDataLoaded();
|
||||||
|
|
||||||
|
//! Copy the XSwiftBus files from build directory
|
||||||
|
void copyXSwiftBusDialog(bool checkFileTimestamp);
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pop_macro("interface")
|
#pragma pop_macro("interface")
|
||||||
|
|||||||
@@ -12,11 +12,12 @@
|
|||||||
#include "blackgui/guiactionbind.h"
|
#include "blackgui/guiactionbind.h"
|
||||||
#include "blackgui/guiapplication.h"
|
#include "blackgui/guiapplication.h"
|
||||||
#include "blackgui/foreignwindows.h"
|
#include "blackgui/foreignwindows.h"
|
||||||
|
#include "blackgui/copyxswiftbusdialog.h"
|
||||||
#include "blackmisc/aviation/altitude.h"
|
#include "blackmisc/aviation/altitude.h"
|
||||||
#include "blackmisc/network/urllist.h"
|
#include "blackmisc/network/urllist.h"
|
||||||
#include "blackmisc/pq/units.h"
|
#include "blackmisc/pq/units.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
|
#include "blackconfig/buildconfig.h"
|
||||||
#include "swiftguistd.h"
|
#include "swiftguistd.h"
|
||||||
#include "ui_swiftguistd.h"
|
#include "ui_swiftguistd.h"
|
||||||
|
|
||||||
@@ -28,12 +29,14 @@
|
|||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
|
||||||
|
using namespace BlackConfig;
|
||||||
using namespace BlackGui;
|
using namespace BlackGui;
|
||||||
using namespace BlackCore;
|
using namespace BlackCore;
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
using namespace BlackMisc::PhysicalQuantities;
|
using namespace BlackMisc::PhysicalQuantities;
|
||||||
using namespace BlackMisc::Aviation;
|
using namespace BlackMisc::Aviation;
|
||||||
using namespace BlackMisc::Network;
|
using namespace BlackMisc::Network;
|
||||||
|
using namespace BlackMisc::Simulation;
|
||||||
|
|
||||||
void SwiftGuiStd::onMenuClicked()
|
void SwiftGuiStd::onMenuClicked()
|
||||||
{
|
{
|
||||||
@@ -137,6 +140,17 @@ void SwiftGuiStd::initMenus()
|
|||||||
ui->menu_InfoAreas->addActions(ui->comp_MainInfoArea->getInfoAreaSelectActions(true, ui->menu_InfoAreas));
|
ui->menu_InfoAreas->addActions(ui->comp_MainInfoArea->getInfoAreaSelectActions(true, ui->menu_InfoAreas));
|
||||||
ui->menu_MovingMap->setIcon(CIcons::swiftMap16());
|
ui->menu_MovingMap->setIcon(CIcons::swiftMap16());
|
||||||
|
|
||||||
|
if (CBuildConfig::isLocalDeveloperDebugBuild() && ui->menu_File)
|
||||||
|
{
|
||||||
|
QAction *a = new QAction(CIcons::swift16(), "Copy XSwiftBus dialog");
|
||||||
|
ui->menu_File->insertAction(ui->menu_File->actions().at(5), a);
|
||||||
|
c = connect(a, &QAction::triggered, this, [ = ]
|
||||||
|
{
|
||||||
|
this->copyXSwiftBusDialog(false);
|
||||||
|
});
|
||||||
|
Q_ASSERT_X(c, Q_FUNC_INFO, "connect failed");
|
||||||
|
}
|
||||||
|
|
||||||
// for hotkeys
|
// for hotkeys
|
||||||
const QString swift(CGuiActionBindHandler::pathSwiftPilotClient());
|
const QString swift(CGuiActionBindHandler::pathSwiftPilotClient());
|
||||||
static const CActionBind swiftRoot(swift, CIcons::swift16()); // inserts action for root folder
|
static const CActionBind swiftRoot(swift, CIcons::swift16()); // inserts action for root folder
|
||||||
@@ -145,3 +159,10 @@ void SwiftGuiStd::initMenus()
|
|||||||
m_menuHotkeyHandlers.append(CGuiActionBindHandler::bindMenu(ui->menu_File, swift + "File"));
|
m_menuHotkeyHandlers.append(CGuiActionBindHandler::bindMenu(ui->menu_File, swift + "File"));
|
||||||
m_menuHotkeyHandlers.append(CGuiActionBindHandler::bindMenu(ui->menu_Window, swift + "Window"));
|
m_menuHotkeyHandlers.append(CGuiActionBindHandler::bindMenu(ui->menu_Window, swift + "Window"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SwiftGuiStd::copyXSwiftBusDialog(bool checkFileTimestamp)
|
||||||
|
{
|
||||||
|
const QString xPlaneRootDir = ui->comp_MainInfoArea->getSettingsComponent()->getSimulatorSettings(CSimulatorInfo::XPLANE).getSimulatorDirectoryOrDefault();
|
||||||
|
const int c = CCopyXSwiftBusDialog::displayDialogAndCopyBuildFiles(xPlaneRootDir, checkFileTimestamp, this);
|
||||||
|
if (c > 0) { CLogMessage(this).info("Copied %1 files from build directory") << c; }
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user