206{
207 static const char *supportedFiles[] = {
208 ".C", ".cpp", ".h", ".css", ".xml", ".png", ".gif", ".csv", ".ico", 0
209 };
210
211 auto dir = std::make_unique<FileItem>("/icons/yellow-folder-open.png",
213 "");
214 FileItem *dirPtr = dir.get();
215 parent->appendRow(std::move(dir));
216 parent = dirPtr;
217 try {
218 std::set<fs::path> paths;
219
220 fs::directory_iterator end_itr;
221 for (fs::directory_iterator i(path); i != end_itr; ++i)
222 paths.insert(*i);
223
224 std::vector<std::unique_ptr<FileItem>> classes, files;
225 std::vector<fs::path> dirs;
226
227 while (!paths.empty()) {
228 fs::path p = *paths.begin();
229 paths.erase(p);
230
231
232 if (fs::is_symlink(p))
233 continue;
234
235
236 if (fs::is_regular_file(p)) {
237 std::string ext = p.extension().string();
238 bool supported = false;
239 for (const char **s = supportedFiles; *s != 0; ++s)
240 if (*s == ext) {
241 supported = true;
242 break;
243 }
244
245 if (!supported)
246 continue;
247 }
248
249
251 if (!companion.empty()) {
252 std::set<fs::path>::iterator it_companion = paths.find(companion);
253
254 if (it_companion != paths.end()) {
255 std::string className =
stem(p);
256 escapeText(className);
257 std::string label = "<i>class</i> " + className;
258
259 std::unique_ptr<FileItem> classItem =
260 std::make_unique<FileItem>("/icons/cppclass.png", label, std::string());
261 classItem->setFlags(classItem->flags() | ItemFlag::XHTMLText);
262
263 auto header
264 = std::make_unique<FileItem>(
"/icons/document.png",
filename(p),
265 p.string());
266 auto cpp
267 = std::make_unique<FileItem>("/icons/document.png",
269 (*it_companion).string());
270 classItem->appendRow(std::move(header));
271 classItem->appendRow(std::move(cpp));
272
273 classes.push_back(std::move(classItem));
274 paths.erase(it_companion);
275 } else {
276 auto file
277 = std::make_unique<FileItem>(
"/icons/document.png",
filename(p),
278 p.string());
279 files.push_back(std::move(file));
280 }
281 } else if (fs::is_directory(p)) {
282 dirs.push_back(p);
283 } else {
284 auto file
285 = std::make_unique<FileItem>(
"/icons/document.png",
filename(p),
286 p.string());
287 files.push_back(std::move(file));
288 }
289 }
290
292
293 for (unsigned int i = 0; i < classes.size(); i++)
294 parent->appendRow(std::move(classes[i]));
295
296 for (unsigned int i = 0; i < files.size(); i++)
297 parent->appendRow(std::move(files[i]));
298
299 for (unsigned int i = 0; i < dirs.size(); i++)
301 } catch (fs::filesystem_error& e) {
302 std::cerr << e.what() << std::endl;
303 }
304}
static fs::path getCompanion(const fs::path &path)
static std::string stem(const fs::path &p)
static std::string filename(const fs::path &p)
static bool comparePaths(const fs::path &p1, const fs::path &p2)
void cppTraverseDir(WStandardItem *parent, const boost::filesystem::path &path)