-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomponents.cpp
More file actions
109 lines (95 loc) · 3.02 KB
/
Copy pathcomponents.cpp
File metadata and controls
109 lines (95 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "components.h"
#include <QDir>
#include <QFileInfo>
#include <QProcessEnvironment>
#include "exceptions.h"
#include <QDebug>
/* Get list of components, sources and header files */
Components::Components(QObject *parent) : QObject(parent)
{
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
this->path = env.value("IDF_PATH", "")+ QDir::separator() + "components";
init();
}
Components::Components(QString path, QMap<QString, bool> dir_ignore, QObject *parent) : QObject(parent)
{
this->path = path;
this->dir_ignore = dir_ignore;
init();
}
void Components::init()
{
QDir dir = QDir(path);
if(!dir.exists())
throw BadPath(tr("path not found: %1").arg(path));
QFileInfoList comps = dir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot);
foreach(QFileInfo info, comps)
{
ComponentListEntry* entry = new ComponentListEntry(info.baseName(), info.filePath());
if(info.isDir() && dir_ignore.contains(info.baseName()) && dir_ignore.value(info.baseName()))
continue;
components.insert(info.baseName(), entry);
getFiles(info.filePath());
}
}
void Components::getFiles(QString path)
{
QDir dir(path);
QFileInfoList infoList;
infoList = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::NoSymLinks);
if(infoList.isEmpty())
return;
foreach (QFileInfo info, infoList)
{
if(info.isDir())
{
getFiles(info.filePath());
if(info.fileName() == "include")
{
QString p = info.absoluteFilePath();
if(!includeDirs.contains( p))
includeDirs.append(p);
}
}
else
{
if(!includeDirs.contains( info.absolutePath()))
includeDirs.append(info.absolutePath());
if(info.fileName().endsWith(".cpp") || info.fileName().endsWith(".c"))
{
_sources.insertMulti(info.fileName(), info.filePath());
if(info.fileName() == "font_render.c")
qDebug() << "found";
continue;
}
if(info.fileName().endsWith(".hpp") || info.fileName().endsWith(".h"))
{
_headers.insert(info.fileName(), info.filePath());
if(!includeDirs.contains( info.absolutePath()))
includeDirs.append(info.absolutePath());
continue;
}
if(info.fileName() == "CMakeLists.txt" || info.fileName().toLower().startsWith("readme")
|| info.fileName() == "sdkconfig" || info.baseName() == "sdkconfig"
|| info.fileName() == "LICENSE")
_otherFiles.insertMulti(info.fileName(), info.filePath());
}
}
}
QMap<QString, QString> Components::sources() {return _sources;}
QMap<QString, QString> Components::headers() {return _headers;}
QMap<QString, QString> Components::otherFiles() {return _otherFiles;}
void Components::update(QString path)
{
getFiles(path);
}
ComponentListEntry::ComponentListEntry(QString name, QString path, bool excluded)
{
this->_name = name;
this->_path = path;
this->_excluded = excluded;
}
QString ComponentListEntry::name() {return _name;}
QString ComponentListEntry::path() {return _path;}
bool ComponentListEntry::isExcluded() {return _excluded;}
void ComponentListEntry::setExcluded(bool b) {this->_excluded = b;}