Avoid recursion in filesystem scanning, closes #3838
(cherry picked from commit 41a26528e4
)
This commit is contained in:
parent
3ce0380ba4
commit
a2d2eb9a63
|
@ -583,31 +583,40 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir,DirAccess
|
||||||
int total = dirs.size()+files.size();
|
int total = dirs.size()+files.size();
|
||||||
int idx=0;
|
int idx=0;
|
||||||
|
|
||||||
|
|
||||||
for (List<String>::Element *E=dirs.front();E;E=E->next(),idx++) {
|
for (List<String>::Element *E=dirs.front();E;E=E->next(),idx++) {
|
||||||
|
|
||||||
if (da->change_dir(E->get())==OK) {
|
if (da->change_dir(E->get())==OK) {
|
||||||
|
|
||||||
EditorFileSystemDirectory *efd = memnew( EditorFileSystemDirectory );
|
String d = da->get_current_dir();
|
||||||
|
|
||||||
efd->parent=p_dir;
|
if (d==cd || !d.begins_with(cd)) {
|
||||||
efd->name=E->get();
|
da->change_dir(cd); //avoid recursion
|
||||||
|
|
||||||
_scan_new_dir(efd,da,p_progress.get_sub(idx,total));
|
|
||||||
|
|
||||||
int idx=0;
|
|
||||||
for(int i=0;i<p_dir->subdirs.size();i++) {
|
|
||||||
|
|
||||||
if (efd->name<p_dir->subdirs[i]->name)
|
|
||||||
break;
|
|
||||||
idx++;
|
|
||||||
}
|
|
||||||
if (idx==p_dir->subdirs.size()) {
|
|
||||||
p_dir->subdirs.push_back(efd);
|
|
||||||
} else {
|
} else {
|
||||||
p_dir->subdirs.insert(idx,efd);
|
|
||||||
}
|
|
||||||
|
|
||||||
da->change_dir("..");
|
|
||||||
|
EditorFileSystemDirectory *efd = memnew( EditorFileSystemDirectory );
|
||||||
|
|
||||||
|
efd->parent=p_dir;
|
||||||
|
efd->name=E->get();
|
||||||
|
|
||||||
|
_scan_new_dir(efd,da,p_progress.get_sub(idx,total));
|
||||||
|
|
||||||
|
int idx=0;
|
||||||
|
for(int i=0;i<p_dir->subdirs.size();i++) {
|
||||||
|
|
||||||
|
if (efd->name<p_dir->subdirs[i]->name)
|
||||||
|
break;
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
if (idx==p_dir->subdirs.size()) {
|
||||||
|
p_dir->subdirs.push_back(efd);
|
||||||
|
} else {
|
||||||
|
p_dir->subdirs.insert(idx,efd);
|
||||||
|
}
|
||||||
|
|
||||||
|
da->change_dir("..");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ERR_PRINTS("Can't go into subdir: "+E->get());
|
ERR_PRINTS("Can't go into subdir: "+E->get());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue