This repository was archived by the owner on Oct 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFileEntry.cpp
More file actions
81 lines (65 loc) · 1.96 KB
/
FileEntry.cpp
File metadata and controls
81 lines (65 loc) · 1.96 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
#include "FileEntry.h"
#include <wx/wfstream.h>
FileEntry *FileEntry::Create(const wxFileName &filename,
std::function<bool()> updateFnc) {
wxArrayString paths;
bool cancelled = false;
auto root = new FileEntry(filename);
wxDir::GetAllFiles(filename.GetPath(), &paths);
auto cmp = [](const wxFileName &f1, const wxFileName &f2) {
return f1.GetFullPath() < f2.GetFullPath();
};
EntryMap entryMap(cmp);
entryMap[filename] = root;
for (int i = 0; i < paths.Count(); i++) {
AddChildrenFromPath(entryMap, paths.Item(i));
bool loadNext = updateFnc();
if (!loadNext) {
cancelled = true;
break;
}
}
if (cancelled) {
delete root;
return nullptr;
}
root->SortChildren();
return root;
}
wxInputStream *FileEntry::GetInputStream() {
if (IsDirectory())
return nullptr;
return new wxFileInputStream(filename.GetFullPath());
}
FileEntry::FileEntry(const wxFileName &filename, const bool &isRoot)
: filename(filename), isRoot(isRoot) {
mutex = new wxMutex();
if (filename.IsDir()) {
SetIsDirectory(true);
auto count = filename.GetDirCount();
auto name = filename.GetDirs()[count - 1];
SetName(name);
} else {
SetName(filename.GetFullName());
SetIsDirectory(false);
}
}
FileEntry *FileEntry::AddChildrenFromPath(EntryMap &entryMap,
const wxFileName &filename) {
auto iter = entryMap.find(filename);
if (iter != entryMap.end()) {
return iter->second;
}
wxFileName parentFileName = filename;
if (parentFileName.IsDir()) {
parentFileName.RemoveLastDir();
} else {
parentFileName.SetFullName("");
}
auto parent = AddChildrenFromPath(entryMap, parentFileName);
auto child = new FileEntry(filename);
parent->AddChild(child);
entryMap[filename] = child;
return child;
}
FileEntry::~FileEntry() { delete mutex; }