MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / add_folder_recursive

Method add_folder_recursive

editor/export/codesign.cpp:290–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

288}
289
290bool CodeSignCodeResources::add_folder_recursive(const String &p_root, const String &p_path, const String &p_main_exe_path) {
291 Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
292 ERR_FAIL_COND_V(da.is_null(), false);
293 Error err = da->change_dir(p_root.path_join(p_path));
294 ERR_FAIL_COND_V(err != OK, false);
295
296 bool ret = true;
297 da->list_dir_begin();
298 String n = da->get_next();
299 while (n != String()) {
300 if (n != "." && n != "..") {
301 String path = p_root.path_join(p_path).path_join(n);
302 if (path == p_main_exe_path) {
303 n = da->get_next();
304 continue; // Skip main executable.
305 }
306 if (da->current_is_dir()) {
307 CRMatch found = match_rules2(p_path.path_join(n));
308 String fmw_ver = "Current"; // Framework version (default).
309 String info_path;
310 String main_exe;
311 bool bundle = false;
312 if (da->file_exists(path.path_join("Contents/Info.plist"))) {
313 info_path = path.path_join("Contents/Info.plist");
314 main_exe = path.path_join("Contents/MacOS");
315 bundle = true;
316 } else if (da->file_exists(path.path_join(vformat("Versions/%s/Resources/Info.plist", fmw_ver)))) {
317 info_path = path.path_join(vformat("Versions/%s/Resources/Info.plist", fmw_ver));
318 main_exe = path.path_join(vformat("Versions/%s", fmw_ver));
319 bundle = true;
320 } else if (da->file_exists(path.path_join("Resources/Info.plist"))) {
321 info_path = path.path_join("Resources/Info.plist");
322 main_exe = path;
323 bundle = true;
324 } else if (da->file_exists(path.path_join("Info.plist"))) {
325 info_path = path.path_join("Info.plist");
326 main_exe = path;
327 bundle = true;
328 }
329 if (bundle && found == CRMatch::CR_MATCH_NESTED && !info_path.is_empty()) {
330 // Read Info.plist.
331 PList info_plist;
332 if (info_plist.load_file(info_path)) {
333 if (info_plist.get_root()->data_type == PList::PLNodeType::PL_NODE_TYPE_DICT && info_plist.get_root()->data_dict.has("CFBundleExecutable")) {
334 main_exe = main_exe.path_join(String::utf8(info_plist.get_root()->data_dict["CFBundleExecutable"]->data_string.get_data()));
335 } else {
336 ERR_FAIL_V_MSG(false, "CodeSign/CodeResources: Invalid Info.plist, no exe name.");
337 }
338 } else {
339 ERR_FAIL_V_MSG(false, "CodeSign/CodeResources: Invalid Info.plist, can't load.");
340 }
341 ret = ret && add_nested_file(p_root, p_path.path_join(n), main_exe);
342 } else {
343 ret = ret && add_folder_recursive(p_root, p_path.path_join(n), p_main_exe_path);
344 }
345 } else {
346 ret = ret && add_file1(p_root, p_path.path_join(n));
347 ret = ret && add_file2(p_root, p_path.path_join(n));

Callers 1

_codesign_fileMethod · 0.80

Calls 15

vformatFunction · 0.85
path_joinMethod · 0.80
load_fileMethod · 0.80
createFunction · 0.50
StringClass · 0.50
is_nullMethod · 0.45
change_dirMethod · 0.45
list_dir_beginMethod · 0.45
get_nextMethod · 0.45
current_is_dirMethod · 0.45
file_existsMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected