mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-23 05:45:35 +08:00
Ref T515, utility functions for file name/path etc.
This commit is contained in:
committed by
Mat Sutcliffe
parent
a0c8f3778b
commit
107464d92a
@@ -249,6 +249,11 @@ namespace BlackMisc
|
|||||||
return CBuildConfig::isRunningOnWindowsNtPlatform() ? Qt::CaseInsensitive : Qt::CaseSensitive;
|
return CBuildConfig::isRunningOnWindowsNtPlatform() ? Qt::CaseInsensitive : Qt::CaseSensitive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CFileUtils::isFileNameCaseSensitive()
|
||||||
|
{
|
||||||
|
return CFileUtils::osFileNameCaseSensitivity() == Qt::CaseSensitive;
|
||||||
|
}
|
||||||
|
|
||||||
bool CFileUtils::matchesExcludeDirectory(const QString &directoryPath, const QString &excludePattern, Qt::CaseSensitivity cs)
|
bool CFileUtils::matchesExcludeDirectory(const QString &directoryPath, const QString &excludePattern, Qt::CaseSensitivity cs)
|
||||||
{
|
{
|
||||||
if (directoryPath.isEmpty() || excludePattern.isEmpty()) { return false; }
|
if (directoryPath.isEmpty() || excludePattern.isEmpty()) { return false; }
|
||||||
|
|||||||
@@ -113,6 +113,9 @@ namespace BlackMisc
|
|||||||
//! Case sensitivity for current OS
|
//! Case sensitivity for current OS
|
||||||
static Qt::CaseSensitivity osFileNameCaseSensitivity();
|
static Qt::CaseSensitivity osFileNameCaseSensitivity();
|
||||||
|
|
||||||
|
//! Case sensitive file names
|
||||||
|
static bool isFileNameCaseSensitive();
|
||||||
|
|
||||||
//! Is directory path matching the exclude path?
|
//! Is directory path matching the exclude path?
|
||||||
static bool matchesExcludeDirectory(const QString &directoryPath, const QString &excludePattern, Qt::CaseSensitivity cs = osFileNameCaseSensitivity());
|
static bool matchesExcludeDirectory(const QString &directoryPath, const QString &excludePattern, Qt::CaseSensitivity cs = osFileNameCaseSensitivity());
|
||||||
|
|
||||||
|
|||||||
@@ -729,6 +729,19 @@ namespace BlackMisc
|
|||||||
return (fi.exists() && fi.isReadable());
|
return (fi.exists() && fi.isReadable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDir CAircraftModel::getFileDirectory() const
|
||||||
|
{
|
||||||
|
if (!this->hasFileName()) { return QDir(); }
|
||||||
|
const QFileInfo fi(CFileUtils::fixWindowsUncPath(this->getFileName()));
|
||||||
|
return fi.absoluteDir();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CAircraftModel::getFileDirectoryPath() const
|
||||||
|
{
|
||||||
|
if (!this->hasFileName()) { return QStringLiteral(""); }
|
||||||
|
return this->getFileDirectory().absolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
bool CAircraftModel::matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
|
bool CAircraftModel::matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
|
||||||
{
|
{
|
||||||
if (sensitivity == Qt::CaseInsensitive) { return caseInsensitiveStringCompare(modelString, m_modelString); }
|
if (sensitivity == Qt::CaseInsensitive) { return caseInsensitiveStringCompare(modelString, m_modelString); }
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <Qt>
|
#include <Qt>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QDir>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
@@ -420,14 +421,24 @@ namespace BlackMisc
|
|||||||
// ---------------- simulator file related functions -------------------
|
// ---------------- simulator file related functions -------------------
|
||||||
|
|
||||||
//! File name (corresponding data for simulator, only available if representing simulator model
|
//! File name (corresponding data for simulator, only available if representing simulator model
|
||||||
|
//! \remark normally parh and name, like with QFile name
|
||||||
const QString &getFileName() const { return m_fileName; }
|
const QString &getFileName() const { return m_fileName; }
|
||||||
|
|
||||||
|
//! File name as lower case
|
||||||
|
QString getFileNameLowerCase() const { return m_fileName.toLower(); }
|
||||||
|
|
||||||
//! File name?
|
//! File name?
|
||||||
bool hasFileName() const { return !m_fileName.isEmpty(); }
|
bool hasFileName() const { return !m_fileName.isEmpty(); }
|
||||||
|
|
||||||
//! Does the corresponding file exist?
|
//! Does the corresponding file exist?
|
||||||
bool hasExistingCorrespondingFile() const;
|
bool hasExistingCorrespondingFile() const;
|
||||||
|
|
||||||
|
//! Directory
|
||||||
|
QDir getFileDirectory() const;
|
||||||
|
|
||||||
|
//! Directory path if any
|
||||||
|
QString getFileDirectoryPath() const;
|
||||||
|
|
||||||
//! File name
|
//! File name
|
||||||
void setFileName(const QString &fileName) { m_fileName = fileName; }
|
void setFileName(const QString &fileName) { m_fileName = fileName; }
|
||||||
|
|
||||||
|
|||||||
@@ -874,6 +874,18 @@ namespace BlackMisc
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CAircraftModelList::sortByFileName()
|
||||||
|
{
|
||||||
|
if (CFileUtils::isFileNameCaseSensitive())
|
||||||
|
{
|
||||||
|
this->sortBy(&CAircraftModel::getFileName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->sortBy(&CAircraftModel::getFileNameLowerCase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CAircraftModelList::updateDistributor(const CDistributor &distributor)
|
void CAircraftModelList::updateDistributor(const CDistributor &distributor)
|
||||||
{
|
{
|
||||||
for (CAircraftModel &model : *this)
|
for (CAircraftModel &model : *this)
|
||||||
@@ -1166,7 +1178,7 @@ namespace BlackMisc
|
|||||||
QSet<QString> workingFiles;
|
QSet<QString> workingFiles;
|
||||||
int failedFilesCount = 0;
|
int failedFilesCount = 0;
|
||||||
|
|
||||||
const bool caseSensitive = CFileUtils::isFileNameCaseSensitiv();
|
const bool caseSensitive = CFileUtils::isFileNameCaseSensitive();
|
||||||
for (const CAircraftModel &model : *this)
|
for (const CAircraftModel &model : *this)
|
||||||
{
|
{
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|||||||
@@ -337,6 +337,9 @@ namespace BlackMisc
|
|||||||
//! Models with aliases
|
//! Models with aliases
|
||||||
int countAliases() const;
|
int countAliases() const;
|
||||||
|
|
||||||
|
//! Sort by file path
|
||||||
|
void sortByFileName();
|
||||||
|
|
||||||
//! Update distributor, all models in list are set to given distributor
|
//! Update distributor, all models in list are set to given distributor
|
||||||
void updateDistributor(const CDistributor &distributor);
|
void updateDistributor(const CDistributor &distributor);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user