mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 08:36:52 +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;
|
||||
}
|
||||
|
||||
bool CFileUtils::isFileNameCaseSensitive()
|
||||
{
|
||||
return CFileUtils::osFileNameCaseSensitivity() == Qt::CaseSensitive;
|
||||
}
|
||||
|
||||
bool CFileUtils::matchesExcludeDirectory(const QString &directoryPath, const QString &excludePattern, Qt::CaseSensitivity cs)
|
||||
{
|
||||
if (directoryPath.isEmpty() || excludePattern.isEmpty()) { return false; }
|
||||
|
||||
@@ -113,6 +113,9 @@ namespace BlackMisc
|
||||
//! Case sensitivity for current OS
|
||||
static Qt::CaseSensitivity osFileNameCaseSensitivity();
|
||||
|
||||
//! Case sensitive file names
|
||||
static bool isFileNameCaseSensitive();
|
||||
|
||||
//! Is directory path matching the exclude path?
|
||||
static bool matchesExcludeDirectory(const QString &directoryPath, const QString &excludePattern, Qt::CaseSensitivity cs = osFileNameCaseSensitivity());
|
||||
|
||||
|
||||
@@ -729,6 +729,19 @@ namespace BlackMisc
|
||||
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
|
||||
{
|
||||
if (sensitivity == Qt::CaseInsensitive) { return caseInsensitiveStringCompare(modelString, m_modelString); }
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include <QStringList>
|
||||
#include <Qt>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <tuple>
|
||||
|
||||
namespace BlackMisc
|
||||
@@ -420,14 +421,24 @@ namespace BlackMisc
|
||||
// ---------------- simulator file related functions -------------------
|
||||
|
||||
//! 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; }
|
||||
|
||||
//! File name as lower case
|
||||
QString getFileNameLowerCase() const { return m_fileName.toLower(); }
|
||||
|
||||
//! File name?
|
||||
bool hasFileName() const { return !m_fileName.isEmpty(); }
|
||||
|
||||
//! Does the corresponding file exist?
|
||||
bool hasExistingCorrespondingFile() const;
|
||||
|
||||
//! Directory
|
||||
QDir getFileDirectory() const;
|
||||
|
||||
//! Directory path if any
|
||||
QString getFileDirectoryPath() const;
|
||||
|
||||
//! File name
|
||||
void setFileName(const QString &fileName) { m_fileName = fileName; }
|
||||
|
||||
|
||||
@@ -874,6 +874,18 @@ namespace BlackMisc
|
||||
return count;
|
||||
}
|
||||
|
||||
void CAircraftModelList::sortByFileName()
|
||||
{
|
||||
if (CFileUtils::isFileNameCaseSensitive())
|
||||
{
|
||||
this->sortBy(&CAircraftModel::getFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->sortBy(&CAircraftModel::getFileNameLowerCase);
|
||||
}
|
||||
}
|
||||
|
||||
void CAircraftModelList::updateDistributor(const CDistributor &distributor)
|
||||
{
|
||||
for (CAircraftModel &model : *this)
|
||||
@@ -1166,7 +1178,7 @@ namespace BlackMisc
|
||||
QSet<QString> workingFiles;
|
||||
int failedFilesCount = 0;
|
||||
|
||||
const bool caseSensitive = CFileUtils::isFileNameCaseSensitiv();
|
||||
const bool caseSensitive = CFileUtils::isFileNameCaseSensitive();
|
||||
for (const CAircraftModel &model : *this)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
@@ -337,6 +337,9 @@ namespace BlackMisc
|
||||
//! Models with aliases
|
||||
int countAliases() const;
|
||||
|
||||
//! Sort by file path
|
||||
void sortByFileName();
|
||||
|
||||
//! Update distributor, all models in list are set to given distributor
|
||||
void updateDistributor(const CDistributor &distributor);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user