MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / list_dir

Method list_dir

utility/pck_creator.cpp:76–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74 }
75
76 Vector<String> list_dir(const String &rel, bool is_main = false) {
77 Vector<String> ret;
78 Error err;
79 Ref<DirAccess> da = DirAccess::open(dir.path_join(rel), &err);
80 ERR_FAIL_COND_V_MSG(da.is_null(), ret, "Failed to open directory " + dir);
81
82 if (da.is_null()) {
83 return ret;
84 }
85 Vector<String> dirs;
86 Vector<String> files;
87
88 String base = absolute ? dir : "";
89 da->list_dir_begin();
90 String f = da->get_next();
91 while (!f.is_empty()) {
92 if (f == "." || f == "..") {
93 f = da->get_next();
94 continue;
95 } else if (da->current_is_dir()) {
96 dirs.push_back(f);
97 } else {
98 files.push_back(f);
99 }
100 f = da->get_next();
101 }
102 da->list_dir_end();
103
104 dirs.sort_custom<FileNoCaseComparator>();
105 if (is_main) {
106 Vector<PckCreateListDirTaskData::Token> tokens;
107 for (auto &d : dirs) {
108 tokens.push_back(PckCreateListDirTaskData::Token{ rel.path_join(d), {} });
109 }
110
111 Ref<EditorProgressGDDC> ep;
112 TaskManager::TaskManagerID group_id = -1;
113 if (tokens.size() > 0) {
114 String desc = "Reading folder " + dir + " structure...";
115 String task = "ListDirTaskData(" + dir + +")_" + String::num_int64(OS::get_singleton()->get_ticks_usec());
116 ep = EditorProgressGDDC::create(nullptr, task, desc, -1, true);
117 group_id = TaskManager::get_singleton()->add_group_task(
118 this, &PckCreateListDirTaskData::do_subdir_task,
119 tokens.ptrw(), tokens.size(),
120 &PckCreateListDirTaskData::get_step_description,
121 task, desc,
122 true, -1, true, ep, 0);
123 }
124 // while we wait for the subdirs to be read, we can filter the files
125 files.sort_custom<FileNoCaseComparator>();
126 for (int64_t i = files.size() - 1; i >= 0; i--) {
127 TaskManager::get_singleton()->update_progress_bg();
128 files.write[i] = base.path_join(rel).path_join(files[i]);
129 if (should_filter_file(files[i])) {
130 files.remove_at(i);
131 continue;
132 }
133 }

Callers

nothing calls this directly

Calls 10

createFunction · 0.85
list_dir_beginMethod · 0.80
get_nextMethod · 0.80
current_is_dirMethod · 0.80
push_backMethod · 0.80
list_dir_endMethod · 0.80
add_group_taskMethod · 0.80
update_progress_bgMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected