mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 11:25:33 +08:00
refs #392 XBus copy feature fine tuning
* New method: CFileUtils::copyRecursively() * Copy the XBus directory to X-Plane plugins
This commit is contained in:
committed by
Mathew Sutcliffe
parent
3781cf2095
commit
3dd86d4984
@@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Base class for plugin config window.
|
||||||
|
*/
|
||||||
class BLACKGUI_EXPORT CPluginConfigWindow : public QWidget
|
class BLACKGUI_EXPORT CPluginConfigWindow : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
@@ -47,6 +47,14 @@ QDialog::separator:hover {
|
|||||||
background: transparent;
|
background: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QFileDialog #sidebar {
|
||||||
|
background: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFileDialog QToolButton {
|
||||||
|
background: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Required when dock widget is floating
|
Required when dock widget is floating
|
||||||
1) background-image not working on QDockWidget, so I use direct children for that
|
1) background-image not working on QDockWidget, so I use direct children for that
|
||||||
|
|||||||
@@ -59,4 +59,32 @@ namespace BlackMisc
|
|||||||
return QDir::cleanPath(path1 + QDir::separator() + path2);
|
return QDir::cleanPath(path1 + QDir::separator() + path2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CFileUtils::copyRecursively(const QString &sourceDir, const QString &destinationDir)
|
||||||
|
{
|
||||||
|
QFileInfo sourceFileInfo(sourceDir);
|
||||||
|
if (sourceFileInfo.isDir())
|
||||||
|
{
|
||||||
|
QDir targetDir(destinationDir);
|
||||||
|
if (!targetDir.mkpath("."))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir originDir(sourceFileInfo.absoluteFilePath());
|
||||||
|
auto fileNames = originDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
|
||||||
|
for (const QString &fileName: fileNames)
|
||||||
|
{
|
||||||
|
if (!copyRecursively(originDir.absoluteFilePath(fileName), targetDir.absoluteFilePath(fileName)))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!QFile::copy(sourceDir, destinationDir))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ namespace BlackMisc
|
|||||||
//! Append file paths
|
//! Append file paths
|
||||||
//! \sa CNetworkUtils::buildUrl for URLs
|
//! \sa CNetworkUtils::buildUrl for URLs
|
||||||
static QString appendFilePaths(const QString &path1, const QString &path2);
|
static QString appendFilePaths(const QString &path1, const QString &path2);
|
||||||
|
|
||||||
|
//! If `sourceDir` is a directory, copies it recursively, so that `sourceDir` becomes `destinationDir`.
|
||||||
|
//! If it is a file, just copies the file.
|
||||||
|
static bool copyRecursively(const QString &sourceDir, const QString &destinationDir);
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,6 @@ HEADERS += *.h
|
|||||||
FORMS += *.ui
|
FORMS += *.ui
|
||||||
DISTFILES += simulator_xplane_config.json
|
DISTFILES += simulator_xplane_config.json
|
||||||
|
|
||||||
DESTDIR = $$BuildRoot/bin/plugins/simulator
|
DESTDIR = $$DestRoot/bin/plugins/simulator
|
||||||
|
|
||||||
load(common_post)
|
load(common_post)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "ui_simulatorxplaneconfigwindow.h"
|
#include "ui_simulatorxplaneconfigwindow.h"
|
||||||
#include "blackcore/dbus_server.h"
|
#include "blackcore/dbus_server.h"
|
||||||
#include "blackmisc/simulation/xplane/xplaneutil.h"
|
#include "blackmisc/simulation/xplane/xplaneutil.h"
|
||||||
|
#include "blackmisc/fileutilities.h"
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
@@ -10,6 +11,14 @@
|
|||||||
|
|
||||||
using namespace BlackGui;
|
using namespace BlackGui;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
QString xBusOriginDir()
|
||||||
|
{
|
||||||
|
return QCoreApplication::applicationDirPath() % QStringLiteral("/../xbus");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace BlackSimPlugin
|
namespace BlackSimPlugin
|
||||||
{
|
{
|
||||||
namespace XPlane
|
namespace XPlane
|
||||||
@@ -30,7 +39,10 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
ui->cp_XBusServer->setCurrentText(m_xbusServerSetting.get());
|
ui->cp_XBusServer->setCurrentText(m_xbusServerSetting.get());
|
||||||
|
|
||||||
|
if (xBusAvailable())
|
||||||
connect(ui->pb_InstallXBus, &QPushButton::clicked, this, &CSimulatorXPlaneConfigWindow::ps_installXBus);
|
connect(ui->pb_InstallXBus, &QPushButton::clicked, this, &CSimulatorXPlaneConfigWindow::ps_installXBus);
|
||||||
|
else
|
||||||
|
ui->pb_InstallXBus->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSimulatorXPlaneConfigWindow::~CSimulatorXPlaneConfigWindow()
|
CSimulatorXPlaneConfigWindow::~CSimulatorXPlaneConfigWindow()
|
||||||
@@ -38,6 +50,11 @@ namespace BlackSimPlugin
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSimulatorXPlaneConfigWindow::xBusAvailable()
|
||||||
|
{
|
||||||
|
return QDir(xBusOriginDir()).exists();
|
||||||
|
}
|
||||||
|
|
||||||
void CSimulatorXPlaneConfigWindow::ps_storeSettings()
|
void CSimulatorXPlaneConfigWindow::ps_storeSettings()
|
||||||
{
|
{
|
||||||
if (ui->cp_XBusServer->currentText() != m_xbusServerSetting.get())
|
if (ui->cp_XBusServer->currentText() != m_xbusServerSetting.get())
|
||||||
@@ -55,23 +72,30 @@ namespace BlackSimPlugin
|
|||||||
QString path = QFileDialog::getExistingDirectory(parentWidget(),
|
QString path = QFileDialog::getExistingDirectory(parentWidget(),
|
||||||
tr("Choose your X-Plane install directory"),
|
tr("Choose your X-Plane install directory"),
|
||||||
xPlaneLocation,
|
xPlaneLocation,
|
||||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::DontUseNativeDialog);
|
||||||
|
|
||||||
path.append("/Resources/plugins/xbus/64/");
|
if (path.isEmpty()) // canceled
|
||||||
QDir xbusDir(path);
|
return;
|
||||||
if (!xbusDir.exists())
|
|
||||||
{
|
path.append("/Resources/plugins");
|
||||||
if (!xbusDir.mkpath("."))
|
if (!QDir(path).exists())
|
||||||
{
|
{
|
||||||
|
QMessageBox::warning(this, tr("Invalid X-Plane directory"), tr("%1 is not a valid X-Plane installation.").arg(path));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
QString origin = QCoreApplication::applicationDirPath() % QStringLiteral("/../xbus/64/lin.xpl");
|
path.append("/xbus");
|
||||||
QString destination = path % "/lin.xpl";
|
|
||||||
QFile::copy(origin, destination);
|
|
||||||
|
|
||||||
|
// TODO Use QtConcurrent here, maybe?
|
||||||
|
bool result = BlackMisc::CFileUtils::copyRecursively(xBusOriginDir(), path);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
QMessageBox::information(this, tr("XBus installed"), tr("You may now launch your X-Plane and start using XBus!"));
|
QMessageBox::information(this, tr("XBus installed"), tr("You may now launch your X-Plane and start using XBus!"));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, tr("Failed installing XBus"), tr("Failed installing the XBus plugin in your X-Plane installation directory; try installing it manually."));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ namespace BlackSimPlugin
|
|||||||
//! Dtor.
|
//! Dtor.
|
||||||
virtual ~CSimulatorXPlaneConfigWindow();
|
virtual ~CSimulatorXPlaneConfigWindow();
|
||||||
|
|
||||||
|
private:
|
||||||
|
//! Checks whether xbus is present in the distributed directory.
|
||||||
|
bool xBusAvailable();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void ps_storeSettings();
|
void ps_storeSettings();
|
||||||
void ps_installXBus();
|
void ps_installXBus();
|
||||||
|
|||||||
Reference in New Issue
Block a user