- training_area_telegrams.cpp: Fixed QJsonObject initializer syntax (Qt6 requires {{}} not ({}))
- training_area_telegrams.cpp: Fixed fromJson() methods to access m_* members directly
- training_area_telegrams.cpp: Fixed brace mismatches in multiple toJson() methods
- training_area_telegrams.h: Changed Header struct to public members for consistency
- tx_mixin.cpp: Fixed getEquipmentNumber() template for direct member access
- lts_coordinate.cpp: Added missing #include <iomanip>
- MIGRATION_STATUS.md: Added migration progress tracking document
C++17 constraint enforced due to RTI Connext DDS 7.7.0 incompatibility with C++20+
Build status: BUILD_RTI=OFF successful (0 errors, warnings only)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
291 lines
7.5 KiB
C++
Executable File
291 lines
7.5 KiB
C++
Executable File
|
|
|
|
|
|
#include "ngltools_filesystem.h"
|
|
|
|
#include <QtCore/QCoreApplication>
|
|
#include <QtCore/QDir>
|
|
#include <QtCore/QSettings>
|
|
#include <utility>
|
|
|
|
namespace NGL
|
|
{
|
|
|
|
bool removeDirContentsRecursively(const QString &d, bool bAlsoDeleteBaseDir)
|
|
{
|
|
|
|
QDir dir(d);
|
|
if (!dir.exists())
|
|
return false;
|
|
|
|
bool success = true;
|
|
const QFileInfoList list = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries);
|
|
for (const QFileInfo &fi : list)
|
|
{
|
|
bool ret = false;
|
|
if (fi.isDir())
|
|
{
|
|
ret = removeDirContentsRecursively(fi.absoluteFilePath());
|
|
if (!ret)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
ret = dir.rmdir(fi.absoluteFilePath());
|
|
if (!ret)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
else if (fi.isFile() || fi.isSymLink())
|
|
{
|
|
ret = dir.remove(fi.fileName());
|
|
if (!ret)
|
|
{
|
|
|
|
}
|
|
}
|
|
success &= ret;
|
|
}
|
|
if (bAlsoDeleteBaseDir)
|
|
success &= dir.rmpath(d);
|
|
return success;
|
|
}
|
|
|
|
bool copyDirContentsToDir(const QString &source, const QString &destination, bool sourceIsRelative)
|
|
{
|
|
QString srcPath(source);
|
|
|
|
if (sourceIsRelative)
|
|
{
|
|
QVector<QString> pathsToSearch = directories(FileType::ConfigFile);
|
|
pathsToSearch.append(directories(FileType::ProjectConfigFile));
|
|
for (const QString &basePath : std::as_const(pathsToSearch))
|
|
{
|
|
QString absolutePath = basePath + QLatin1Char('/') + source;
|
|
if (QDir(absolutePath).exists())
|
|
{
|
|
srcPath = absolutePath;
|
|
break;
|
|
}
|
|
}
|
|
if (srcPath.isEmpty())
|
|
return false;
|
|
}
|
|
|
|
QDir srcDir(srcPath);
|
|
QDir dstDir(destination);
|
|
|
|
if (!dstDir.exists())
|
|
{
|
|
bool succ = dstDir.mkdir(destination);
|
|
if (!succ)
|
|
return false;
|
|
}
|
|
|
|
const QFileInfoList dirList = srcDir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot);
|
|
for (const QFileInfo &fi : dirList)
|
|
{
|
|
|
|
if (!dstDir.exists())
|
|
{
|
|
bool succ = dstDir.mkdir(fi.fileName());
|
|
if (!succ)
|
|
return false;
|
|
}
|
|
bool succ = copyDirContentsToDir(fi.filePath(), dstDir.absolutePath() + QLatin1Char('/') + fi.fileName());
|
|
if (!succ)
|
|
return false;
|
|
}
|
|
|
|
const QFileInfoList fileList = srcDir.entryInfoList(QDir::Files | QDir::Hidden);
|
|
for (const QFileInfo &fi : fileList)
|
|
{
|
|
QString targetFileName = dstDir.absolutePath() + QLatin1Char('/') + fi.fileName();
|
|
QFile targetFile(targetFileName);
|
|
if (targetFile.exists())
|
|
targetFile.remove();
|
|
bool succ = QFile::copy(fi.absoluteFilePath(), targetFileName);
|
|
if (!succ)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
qint64 getDirectorySize(const QString &dir)
|
|
{
|
|
QDir d(dir);
|
|
qint64 ret = QFileInfo(dir).size();
|
|
|
|
const QFileInfoList dirList = d.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot);
|
|
const QFileInfoList fileList = d.entryInfoList(QDir::Files | QDir::Hidden);
|
|
|
|
for (const QFileInfo &fi : dirList)
|
|
ret += getDirectorySize(fi.absoluteFilePath());
|
|
|
|
for (const QFileInfo &fi : fileList)
|
|
ret += fi.size();
|
|
|
|
return ret;
|
|
}
|
|
|
|
bool isAppInBuildBasePath()
|
|
{
|
|
bool ret = false;
|
|
#ifdef BUILD_BASE_PATH
|
|
const QString bbp(QString::fromLocal8Bit(BUILD_BASE_PATH));
|
|
if (!bbp.isEmpty())
|
|
ret = QCoreApplication::applicationDirPath().startsWith(bbp);
|
|
#endif
|
|
return ret;
|
|
}
|
|
|
|
QString projectConfigFileName()
|
|
{
|
|
return QLatin1String("lts-cc.conf");
|
|
}
|
|
|
|
QString findProjectConfigFile()
|
|
{
|
|
return findFile(FileType::ProjectConfigFile, projectConfigFileName());
|
|
}
|
|
|
|
static QString searchFileInDir(const QString &path, const QString &filename, bool bRecursive)
|
|
{
|
|
if (QFile::exists(path + QLatin1Char('/') + filename))
|
|
return path + QLatin1Char('/') + filename;
|
|
|
|
if (!bRecursive)
|
|
return QString();
|
|
|
|
const QDir d(path);
|
|
const QStringList entryList = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
|
|
for (const QString &entry : entryList)
|
|
{
|
|
const QString foundPath = searchFileInDir(path + QLatin1Char('/') + entry, filename, bRecursive);
|
|
if (!foundPath.isEmpty())
|
|
return foundPath;
|
|
}
|
|
return QString();
|
|
}
|
|
|
|
QString findFile(FileType fileType, const QString &filename)
|
|
{
|
|
const QFileInfo fi(filename);
|
|
if (fi.isAbsolute())
|
|
return fi.exists() ? filename : QString();
|
|
const bool bRecursive = (fileType == FileType::ConfigFile);
|
|
const QVector<QString> pathsToSearch = directories(fileType);
|
|
for (const QString &path : pathsToSearch)
|
|
{
|
|
const QString foundPath = searchFileInDir(path, filename, bRecursive);
|
|
if (!foundPath.isEmpty())
|
|
return foundPath;
|
|
}
|
|
return QString();
|
|
}
|
|
|
|
QVector<QString> directories(FileType fileType)
|
|
{
|
|
QVector<QString> pathsToSearch;
|
|
switch (fileType)
|
|
{
|
|
case FileType::ProjectConfigFile:
|
|
{
|
|
#ifdef BUILD_BASE_PATH
|
|
const QString bbp(QString::fromLocal8Bit(BUILD_BASE_PATH));
|
|
if (!bbp.isEmpty())
|
|
{
|
|
|
|
|
|
|
|
if (QCoreApplication::applicationDirPath().startsWith(bbp))
|
|
pathsToSearch += bbp;
|
|
}
|
|
#endif
|
|
pathsToSearch += QDir::homePath();
|
|
#ifdef Q_OS_UNIX
|
|
pathsToSearch += QLatin1String("/etc");
|
|
#else
|
|
pathsToSearch += QStringLiteral("C:/Rheinmetall/Lts/");
|
|
pathsToSearch += QCoreApplication::applicationDirPath();
|
|
#endif
|
|
break;
|
|
}
|
|
case FileType::ConfigFile:
|
|
{
|
|
#ifdef BUILD_BASE_PATH
|
|
const QString bbp(QString::fromLocal8Bit(BUILD_BASE_PATH));
|
|
if (!bbp.isEmpty())
|
|
{
|
|
|
|
|
|
|
|
if (QCoreApplication::applicationDirPath().startsWith(bbp))
|
|
pathsToSearch += bbp + QLatin1String("/share/Lts");
|
|
}
|
|
#endif
|
|
pathsToSearch += QCoreApplication::applicationDirPath() + QLatin1String("/share/Lts");
|
|
pathsToSearch += QCoreApplication::applicationDirPath() + QLatin1String("/../share/Lts");
|
|
pathsToSearch += QDir::homePath() + QLatin1String("/share/Lts");
|
|
#ifdef INSTALL_PREFIX
|
|
pathsToSearch += QString::fromLocal8Bit(INSTALL_PREFIX) + QLatin1String("/share/Lts");
|
|
#endif
|
|
break;
|
|
}
|
|
}
|
|
return pathsToSearch;
|
|
}
|
|
QString findServiceXmlFile(const QString &serviceShortName)
|
|
{
|
|
return findFile(FileType::ConfigFile, serviceShortName + QLatin1String(".xml"));
|
|
}
|
|
|
|
QString directory(FileType fileType, const QString &subdir)
|
|
{
|
|
const QVector<QString> pathsToSearch = directories(fileType);
|
|
QFileInfo fi;
|
|
for (const QString &path : pathsToSearch)
|
|
{
|
|
fi.setFile(path + QLatin1Char('/') + subdir);
|
|
if (fi.isDir() && fi.exists() && fi.isReadable())
|
|
return fi.absoluteFilePath() + QLatin1Char('/');
|
|
}
|
|
return QString();
|
|
}
|
|
|
|
QString postgresExecutablePath(const QString &psqlProgram, QString &errStr)
|
|
{
|
|
errStr.clear();
|
|
#ifdef Q_OS_LINUX
|
|
return QStringLiteral("/usr/bin/") + psqlProgram;
|
|
#else
|
|
static QString s_postgresBinariesPath;
|
|
if (s_postgresBinariesPath.isEmpty())
|
|
{
|
|
QSettings s(QStringLiteral("HKEY_LOCAL_MACHINE\\SOFTWARE\\PostgreSQL\\Installations"), QSettings::NativeFormat);
|
|
const QStringList installations = s.childGroups();
|
|
if (installations.isEmpty())
|
|
{
|
|
errStr = QStringLiteral("Could not find a valid PostgreSQL windows installation...");
|
|
return psqlProgram;
|
|
}
|
|
if (installations.size() > 1)
|
|
errStr = QStringLiteral("More than one PostgreSQL windows installation found - using the first one: %1").arg(installations.first());
|
|
s.beginGroup(installations.first());
|
|
const QString baseDir = s.value(QStringLiteral("Base Directory")).toString();
|
|
if (baseDir.isEmpty() || !QDir(baseDir).exists())
|
|
{
|
|
errStr = QStringLiteral("Could not find a valid PostgreSQL windows installation... - Base Directory is empty or does not exist (%1)").arg(baseDir);
|
|
return psqlProgram;
|
|
}
|
|
s_postgresBinariesPath = baseDir + QStringLiteral("/bin/");
|
|
}
|
|
return s_postgresBinariesPath + psqlProgram + QStringLiteral(".exe");
|
|
#endif
|
|
}
|
|
}
|