mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +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
|
||||
{
|
||||
/**
|
||||
* Base class for plugin config window.
|
||||
*/
|
||||
class BLACKGUI_EXPORT CPluginConfigWindow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -47,6 +47,14 @@ QDialog::separator:hover {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
QFileDialog #sidebar {
|
||||
background: black;
|
||||
}
|
||||
|
||||
QFileDialog QToolButton {
|
||||
background: inherit;
|
||||
}
|
||||
|
||||
/**
|
||||
Required when dock widget is floating
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -39,6 +39,10 @@ namespace BlackMisc
|
||||
//! Append file paths
|
||||
//! \sa CNetworkUtils::buildUrl for URLs
|
||||
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
|
||||
|
||||
|
||||
@@ -15,6 +15,6 @@ HEADERS += *.h
|
||||
FORMS += *.ui
|
||||
DISTFILES += simulator_xplane_config.json
|
||||
|
||||
DESTDIR = $$BuildRoot/bin/plugins/simulator
|
||||
DESTDIR = $$DestRoot/bin/plugins/simulator
|
||||
|
||||
load(common_post)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "ui_simulatorxplaneconfigwindow.h"
|
||||
#include "blackcore/dbus_server.h"
|
||||
#include "blackmisc/simulation/xplane/xplaneutil.h"
|
||||
#include "blackmisc/fileutilities.h"
|
||||
#include <QStringBuilder>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
@@ -10,6 +11,14 @@
|
||||
|
||||
using namespace BlackGui;
|
||||
|
||||
namespace
|
||||
{
|
||||
QString xBusOriginDir()
|
||||
{
|
||||
return QCoreApplication::applicationDirPath() % QStringLiteral("/../xbus");
|
||||
}
|
||||
}
|
||||
|
||||
namespace BlackSimPlugin
|
||||
{
|
||||
namespace XPlane
|
||||
@@ -30,7 +39,10 @@ namespace BlackSimPlugin
|
||||
|
||||
ui->cp_XBusServer->setCurrentText(m_xbusServerSetting.get());
|
||||
|
||||
connect(ui->pb_InstallXBus, &QPushButton::clicked, this, &CSimulatorXPlaneConfigWindow::ps_installXBus);
|
||||
if (xBusAvailable())
|
||||
connect(ui->pb_InstallXBus, &QPushButton::clicked, this, &CSimulatorXPlaneConfigWindow::ps_installXBus);
|
||||
else
|
||||
ui->pb_InstallXBus->setEnabled(false);
|
||||
}
|
||||
|
||||
CSimulatorXPlaneConfigWindow::~CSimulatorXPlaneConfigWindow()
|
||||
@@ -38,6 +50,11 @@ namespace BlackSimPlugin
|
||||
|
||||
}
|
||||
|
||||
bool CSimulatorXPlaneConfigWindow::xBusAvailable()
|
||||
{
|
||||
return QDir(xBusOriginDir()).exists();
|
||||
}
|
||||
|
||||
void CSimulatorXPlaneConfigWindow::ps_storeSettings()
|
||||
{
|
||||
if (ui->cp_XBusServer->currentText() != m_xbusServerSetting.get())
|
||||
@@ -55,23 +72,30 @@ namespace BlackSimPlugin
|
||||
QString path = QFileDialog::getExistingDirectory(parentWidget(),
|
||||
tr("Choose your X-Plane install directory"),
|
||||
xPlaneLocation,
|
||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
||||
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::DontUseNativeDialog);
|
||||
|
||||
path.append("/Resources/plugins/xbus/64/");
|
||||
QDir xbusDir(path);
|
||||
if (!xbusDir.exists())
|
||||
if (path.isEmpty()) // canceled
|
||||
return;
|
||||
|
||||
path.append("/Resources/plugins");
|
||||
if (!QDir(path).exists())
|
||||
{
|
||||
if (!xbusDir.mkpath("."))
|
||||
{
|
||||
return;
|
||||
}
|
||||
QMessageBox::warning(this, tr("Invalid X-Plane directory"), tr("%1 is not a valid X-Plane installation.").arg(path));
|
||||
return;
|
||||
}
|
||||
|
||||
QString origin = QCoreApplication::applicationDirPath() % QStringLiteral("/../xbus/64/lin.xpl");
|
||||
QString destination = path % "/lin.xpl";
|
||||
QFile::copy(origin, destination);
|
||||
path.append("/xbus");
|
||||
|
||||
QMessageBox::information(this, tr("XBus installed"), tr("You may now launch your X-Plane and start using XBus!"));
|
||||
// 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!"));
|
||||
}
|
||||
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.
|
||||
virtual ~CSimulatorXPlaneConfigWindow();
|
||||
|
||||
private:
|
||||
//! Checks whether xbus is present in the distributed directory.
|
||||
bool xBusAvailable();
|
||||
|
||||
private slots:
|
||||
void ps_storeSettings();
|
||||
void ps_installXBus();
|
||||
|
||||
Reference in New Issue
Block a user