17#include <QStandardPaths>
21#elif defined(Q_OS_MACOS)
32 std::streampos initialPosition = file.tellg();
36 while (c != -1 && c !=
'\n')
44 file.seekg(initialPosition, std::ios_base::beg);
51 qint64 initialPosition = file.pos();
55 while (!file.atEnd() && c !=
'\n')
62 file.seek(initialPosition);
72 for (
const auto& path: source)
74 if ( !path.isEmpty() && !target.contains(path) && QDir(path).exists() )
83 return QString::fromUtf8(qgetenv((name.toUpper()).toStdString().c_str()).constData());
88 QString dataHome = QString::fromUtf8(qgetenv(
"XDG_DATA_HOME"));
89 if (dataHome.isEmpty())
94 dataHome = QString::fromUtf8(qgetenv(
"USERPROFILE"));
96 dataHome = QString::fromUtf8(qgetenv(
"HOME"));
98 if (!dataHome.isEmpty())
100 dataHome +=
"/.local/share/";
109 if ( QDir( path ).exists() )
128 HMODULE module =
nullptr;
129 if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
130 | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
135 auto length = GetModuleFileNameW(module, path,
sizeof(path) /
sizeof(path[0]));
136 if (length > 0 && length <
sizeof(path) /
sizeof(path[0]))
138 QDir binDir = QFileInfo(QString::fromWCharArray(path, length)).absoluteDir();
139 return QDir::cleanPath(binDir.absoluteFilePath(
".."));
142#elif defined(Q_OS_MACOS)
146 && info.dli_fname !=
nullptr)
148 QDir libDir = QFileInfo(QString::fromUtf8(info.dli_fname)).absoluteDir();
149 return QDir::cleanPath(libDir.absoluteFilePath(
".."));
159 const QString& project,
160 const QString& path_prefix,
161 const QString& path_postfix = QString(
""))
163 QString systemPath = QString::fromUtf8(
"/usr/") + path_prefix + project + path_postfix;
165 if (!prefix.isEmpty()
166 && QDir(prefix + path_prefix + project + path_postfix).exists())
168 systemPath = prefix + path_prefix + project + path_postfix;
171 getEnvVar(project +
"_DIST") + path_prefix + project + path_postfix,
176 const QString& project,
177 const QString& env_postfix,
178 const QString& path_prefix,
179 const QString& path_postfix = QString(
"")
183 QString var =
getEnvVar(project + env_postfix);
184 if ( !var.isEmpty() )
191 if ( dirs.isEmpty() )
199 const QStringList& paths)
202 QStringList configDirs;
208 if (projects.empty())
210 QString var =
getEnvVar(QString::fromStdString(
"lima") +
"_CONF");
211 if ( !var.isEmpty() )
219 for (
const auto& project: projects)
221 QString var =
getEnvVar(project.toUpper() +
"_CONF");
222 if ( !var.isEmpty() )
233 if ( configDirs.isEmpty() )
235 for (
const auto& project: projects)
241 QString var =
getEnvVar(QString::fromStdString(
"LIMA_SHOW_CONFIG_PATH"));
242 if ( !var.isEmpty() )
244 qDebug() <<
"LIMA Configuration directories list built is:" << configDirs;
251 const QStringList& paths)
254 QStringList resourcesDirs;
259 for (
const auto& project: projects)
262 "/share/apps/",
"/resources");
267 QString var =
getEnvVar(QString::fromStdString(
"LIMA_SHOW_CONFIG_PATH"));
268 if ( !var.isEmpty() )
270 qDebug() <<
"LIMA Resources directories list built is:" << resourcesDirs;
273 LINFO <<
"LIMA Resources directories list built is:" << resourcesDirs;
274 return resourcesDirs;
277QString
findFileInPaths(
const QString& paths,
const QString& fileName,
const QChar& separator)
279 auto pathsList = paths.split(separator);
280 auto filesList =fileName.split(separator);
281 for (
const auto& path: pathsList)
283 for (
const auto& file: filesList)
285 if (QFileInfo::exists(path +
"/" + file))
290 LDEBUG <<
"File found:" << path +
"/" + file;
293 return path +
"/" + file;
298 LINFO <<
"findFileInPaths no '" << fileName <<
"' found in '" << paths
299 <<
"' separated by '" << separator <<
"'";
#define FILESREPORTLOGINIT
#define LIMA_PATH_SEPARATOR
QString libraryInstallPrefix()
void buildDirectoriesListForProject(QStringList &target, const QString &project, const QString &env_postfix, const QString &path_prefix, const QString &path_postfix=QString(""))
void appendFirstOrSecondForProject(QStringList &target, const QString &project, const QString &path_prefix, const QString &path_postfix=QString(""))
QString getEnvVar(const QString &name)
QStringList buildResourcesDirectoriesList(const QStringList &projects, const QStringList &paths)
Build a list of resources directories from a list of project names and a list of paths.
void appendFirstOrSecond(QStringList &target, const QString &path, const QString &alt_path)
uint64_t countLines(std::istream &file)
Count the number of lines in the given file from the current position.
void appendNonEmptyDirs(QStringList &target, const QStringList &source)
QString findFileInPaths(const QString &paths, const QString &fileName, const QChar &separator)
Find the given file in the given paths.
QStringList buildConfigurationDirectoriesList(const QStringList &projects, const QStringList &paths)
Build a list of configuration directories from a list of project names and a list of paths.