Error DirAccess::_copy_dir(DirAccess *p_target_da, String p_to, int p_chmod_flags) { List<String> dirs; String curdir = get_current_dir(); list_dir_begin(); String n = get_next(); while (n != String()) { if (n != "." && n != "..") { if (current_is_dir()) dirs.push_back(n); else { String rel_path = n; if (!n.is_rel_path()) { list_dir_end(); return ERR_BUG; } Error err = copy(get_current_dir() + "/" + n, p_to + rel_path, p_chmod_flags); if (err) { list_dir_end(); return err; } } } n = get_next(); } list_dir_end(); for (List<String>::Element *E = dirs.front(); E; E = E->next()) { String rel_path = E->get(); String target_dir = p_to + rel_path; if (!p_target_da->dir_exists(target_dir)) { Error err = p_target_da->make_dir(target_dir); ERR_FAIL_COND_V(err, err); } Error err = change_dir(E->get()); ERR_FAIL_COND_V(err, err); err = _copy_dir(p_target_da, p_to + rel_path + "/", p_chmod_flags); if (err) { change_dir(".."); ERR_PRINT("Failed to copy recursively"); return err; } err = change_dir(".."); if (err) { ERR_PRINT("Failed to go back"); return err; } } return OK; }
bool DirAccessWindows::list_dir_begin() { _cisdir = false; _cishidden = false; list_dir_end(); p->h = FindFirstFileExW((current_dir + "\\*").c_str(), FindExInfoStandard, &p->fu, FindExSearchNameMatch, NULL, 0); return (p->h == INVALID_HANDLE_VALUE); }
bool DirAccessFlash::list_dir_begin() { list_dir_end(); dir_stream = opendir(current_dir.utf8().get_data()); if (!dir_stream) return true; //error! return false; };
bool DirAccessAndroid::list_dir_begin() { list_dir_end(); AAssetDir* aad = AAssetManager_openDir(FileAccessAndroid::asset_manager,current_dir.utf8().get_data()); if (!aad) return true; //nothing return false; }
Error DirAccessJAndroid::list_dir_begin() { list_dir_end(); JNIEnv *env = ThreadAndroid::get_env(); jstring js = env->NewStringUTF(current_dir.utf8().get_data()); int res = env->CallIntMethod(io, _dir_open, js); if (res <= 0) return ERR_CANT_OPEN; id = res; return OK; }
Error DirAccessUnix::list_dir_begin() { list_dir_end(); //close any previous dir opening! //char real_current_dir_name[2048]; //is this enough?! //getcwd(real_current_dir_name,2048); //chdir(current_path.utf8().get_data()); dir_stream = opendir(current_dir.utf8().get_data()); //chdir(real_current_dir_name); if (!dir_stream) return ERR_CANT_OPEN; //error! return OK; }
String DirAccessFlash::get_next() { if (!dir_stream) return ""; dirent *entry; entry=readdir(dir_stream); if (entry==NULL) { list_dir_end(); return ""; } //typedef struct stat Stat; struct stat flags; String fname; if (fname.parse_utf8(entry->d_name)) fname=entry->d_name; //no utf8, maybe latin? String f=current_dir+"/"+fname; if (stat(f.utf8().get_data(),&flags)==0) { if (S_ISDIR(flags.st_mode)) { _cisdir=true; } else { _cisdir=false; } } else { _cisdir=false; } return fname; };
DirAccessJAndroid::~DirAccessJAndroid() { list_dir_end(); }