Ref T125, utility functions

This commit is contained in:
Klaus Basan
2017-08-15 02:17:42 +02:00
committed by Mathew Sutcliffe
parent c6f3a7033d
commit 329b0512eb
6 changed files with 32 additions and 2 deletions

View File

@@ -52,6 +52,16 @@ namespace BlackMisc
return true;
}
bool CFileUtils::writeByteArrayToFile(const QByteArray &data, const QString &fileNameAndPath)
{
if (fileNameAndPath.isEmpty()) { return false; }
QFile file(fileNameAndPath);
if (!file.open(QIODevice::WriteOnly)) { return false; }
qint64 c = file.write(data);
file.close();
return c == data.count();
}
bool CFileUtils::writeStringToLockedFile(const QString &content, const QString &fileNameAndPath)
{
QLockFile lock(fileNameAndPath + ".lock");

View File

@@ -60,6 +60,9 @@ namespace BlackMisc
//! Write string to text file in background
static bool writeStringToFileInBackground(const QString &content, const QString &fileNameAndPath);
//! Write byte array to file
static bool writeByteArrayToFile(const QByteArray &data, const QString &fileNameAndPath);
//! Append file paths
//! \sa CNetworkUtils::buildUrl for URLs
static QString appendFilePaths(const QString &path1, const QString &path2);

View File

@@ -37,6 +37,11 @@ namespace BlackMisc
return this->m_simulatorDirectory;
}
bool CSimulatorSettings::hasSimulatorDirectory() const
{
return !getSimulatorDirectory().isEmpty();
}
void CSimulatorSettings::setModelDirectories(const QStringList &modelDirectories)
{
this->m_modelDirectories = modelDirectories;

View File

@@ -53,6 +53,9 @@ namespace BlackMisc
//! Simulator directory
const QString &getSimulatorDirectory() const;
//! Setting has simulator setting
bool hasSimulatorDirectory() const;
//! Set model directories
void setModelDirectories(const QStringList &modelDirectories);

View File

@@ -119,7 +119,13 @@ namespace BlackMisc
{
const QString xp = xplaneRootDir();
if (xp.isEmpty()) { return xp; }
return CFileUtils::appendFilePaths(xp, "/Resources/plugins");
return CFileUtils::appendFilePaths(xp, xplanePluginPath());
}
QString CXPlaneUtil::xplanePluginPath()
{
static const QString p("/Resources/plugins");
return p;
}
bool CXPlaneUtil::isXplanePluginDirDirExisting()

View File

@@ -45,10 +45,13 @@ namespace BlackMisc
//! Is the xplaneRootDir existing?
static bool isXplaneRootDirExisting();
//! XPlane root directory
//! XPlane plugin directory
//! In case more then one XPlane version is found, the path to the highest version is used
static QString xplanePluginDir();
//! XPlane relative plugin path
static QString xplanePluginPath();
//! Is the xplanePluginDir existing?
static bool isXplanePluginDirDirExisting();