本文整理汇总了C++中DirAccess::list_dir_begin方法的典型用法代码示例。如果您正苦于以下问题:C++ DirAccess::list_dir_begin方法的具体用法?C++ DirAccess::list_dir_begin怎么用?C++ DirAccess::list_dir_begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DirAccess
的用法示例。
在下文中一共展示了DirAccess::list_dir_begin方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
bool PowerX11::GetPowerInfo_Linux_proc_acpi() {
String node;
DirAccess *dirp = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
bool have_battery = false;
bool have_ac = false;
bool charging = false;
this->nsecs_left = -1;
this->percent_left = -1;
this->power_state = OS::POWERSTATE_UNKNOWN;
dirp->change_dir(proc_acpi_battery_path);
Error err = dirp->list_dir_begin();
if (err != OK) {
return false; /* can't use this interface. */
} else {
node = dirp->get_next();
while (node != "") {
check_proc_acpi_battery(node.utf8().get_data(), &have_battery, &charging /*, seconds, percent*/);
node = dirp->get_next();
}
memdelete(dirp);
}
dirp->change_dir(proc_acpi_ac_adapter_path);
err = dirp->list_dir_begin();
if (err != OK) {
return false; /* can't use this interface. */
} else {
node = dirp->get_next();
while (node != "") {
check_proc_acpi_ac_adapter(node.utf8().get_data(), &have_ac);
node = dirp->get_next();
}
memdelete(dirp);
}
if (!have_battery) {
this->power_state = OS::POWERSTATE_NO_BATTERY;
} else if (charging) {
this->power_state = OS::POWERSTATE_CHARGING;
} else if (have_ac) {
this->power_state = OS::POWERSTATE_CHARGED;
} else {
this->power_state = OS::POWERSTATE_ON_BATTERY;
}
return true; /* definitive answer. */
}
示例2: _uninstall_template_confirm
void ExportTemplateManager::_uninstall_template_confirm() {
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
Error err = d->change_dir(EditorSettings::get_singleton()->get_templates_dir());
ERR_FAIL_COND(err != OK);
err = d->change_dir(to_remove);
ERR_FAIL_COND(err != OK);
Vector<String> files;
d->list_dir_begin();
bool isdir;
String c = d->get_next(&isdir);
while (c != String()) {
if (!isdir) {
files.push_back(c);
}
c = d->get_next(&isdir);
}
d->list_dir_end();
for (int i = 0; i < files.size(); i++) {
d->remove(files[i]);
}
d->change_dir("..");
d->remove(to_remove);
_update_template_list();
}
示例3: _scan_dir
void FindInFiles::_scan_dir(String path, PoolStringArray &out_folders) {
DirAccess *dir = DirAccess::open(path);
if (dir == NULL) {
print_line("Cannot open directory! " + path);
return;
}
dir->list_dir_begin();
for (int i = 0; i < 1000; ++i) {
String file = dir->get_next();
if (file == "")
break;
// Ignore special dirs and hidden dirs (such as .git and .import)
if (file == "." || file == ".." || file.begins_with("."))
continue;
if (dir->current_is_dir())
out_folders.append(file);
else {
String file_ext = file.get_extension();
if (_extension_filter.has(file_ext)) {
_files_to_scan.push_back(path.plus_file(file));
}
}
}
}
示例4: clear_old_backups
void RotatedFileLogger::clear_old_backups() {
int max_backups = max_files - 1; // -1 for the current file
String basename = base_path.get_file().get_basename();
String extension = "." + base_path.get_extension();
DirAccess *da = DirAccess::open(base_path.get_base_dir());
if (!da) {
return;
}
da->list_dir_begin();
String f = da->get_next();
Set<String> backups;
while (f != String()) {
if (!da->current_is_dir() && f.begins_with(basename) && f.ends_with(extension) && f != base_path.get_file()) {
backups.insert(f);
}
f = da->get_next();
}
da->list_dir_end();
if (backups.size() > max_backups) {
// since backups are appended with timestamp and Set iterates them in sorted order,
// first backups are the oldest
int to_delete = backups.size() - max_backups;
for (Set<String>::Element *E = backups.front(); E && to_delete > 0; E = E->next(), --to_delete) {
da->remove(E->get());
}
}
memdelete(da);
}
示例5: memnew
MainLoop *test() {
print_line("this is test io");
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
da->change_dir(".");
print_line("Opening current dir " + da->get_current_dir());
String entry;
da->list_dir_begin();
while ((entry = da->get_next()) != "") {
print_line("entry " + entry + " is dir: " + Variant(da->current_is_dir()));
};
da->list_dir_end();
RES texture = ResourceLoader::load("test_data/rock.png");
ERR_FAIL_COND_V(texture.is_null(), NULL);
ResourceSaver::save("test_data/rock.xml", texture);
print_line("localize paths");
print_line(ProjectSettings::get_singleton()->localize_path("algo.xml"));
print_line(ProjectSettings::get_singleton()->localize_path("c:\\windows\\algo.xml"));
print_line(ProjectSettings::get_singleton()->localize_path(ProjectSettings::get_singleton()->get_resource_path() + "/something/something.xml"));
print_line(ProjectSettings::get_singleton()->localize_path("somedir/algo.xml"));
{
FileAccess *z = FileAccess::open("test_data/archive.zip", FileAccess::READ);
int len = z->get_len();
Vector<uint8_t> zip;
zip.resize(len);
z->get_buffer(&zip[0], len);
z->close();
memdelete(z);
FileAccessMemory::register_file("a_package", zip);
FileAccess::make_default<FileAccessMemory>(FileAccess::ACCESS_RESOURCES);
FileAccess::make_default<FileAccessMemory>(FileAccess::ACCESS_FILESYSTEM);
FileAccess::make_default<FileAccessMemory>(FileAccess::ACCESS_USERDATA);
print_line("archive test");
};
print_line("test done");
return memnew(TestMainLoop);
}
示例6: _files_dropped
void ProjectManager::_files_dropped(StringArray p_files, int p_screen) {
Set<String> folders_set;
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
for (int i = 0; i < p_files.size(); i++) {
String file = p_files[i];
folders_set.insert(da->dir_exists(file) ? file : file.get_base_dir());
}
memdelete(da);
if (folders_set.size()>0) {
StringArray folders;
for (Set<String>::Element *E=folders_set.front();E;E=E->next()) {
folders.append(E->get());
}
bool confirm = true;
if (folders.size()==1) {
DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
if (dir->change_dir(folders[0])==OK) {
dir->list_dir_begin();
String file = dir->get_next();
while(confirm && file!=String()) {
if (!da->current_is_dir() && file.ends_with("engine.cfg")) {
confirm = false;
}
file = dir->get_next();
}
dir->list_dir_end();
}
memdelete(dir);
}
if (confirm) {
multi_scan_ask->get_ok()->disconnect("pressed", this, "_scan_multiple_folders");
multi_scan_ask->get_ok()->connect("pressed", this, "_scan_multiple_folders", varray(folders));
multi_scan_ask->set_text(vformat(TTR("You are about the scan %s folders for existing Godot projects. Do you confirm?"), folders.size()));
multi_scan_ask->popup_centered_minsize();
} else {
_scan_multiple_folders(folders);
}
}
}
示例7: _update_template_list
void ExportTemplateManager::_update_template_list() {
while (current_hb->get_child_count()) {
memdelete(current_hb->get_child(0));
}
while (installed_vb->get_child_count()) {
memdelete(installed_vb->get_child(0));
}
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
Error err = d->change_dir(EditorSettings::get_singleton()->get_templates_dir());
d->list_dir_begin();
Set<String> templates;
if (err == OK) {
bool isdir;
String c = d->get_next(&isdir);
while (c != String()) {
if (isdir && !c.begins_with(".")) {
templates.insert(c);
}
c = d->get_next(&isdir);
}
}
d->list_dir_end();
memdelete(d);
String current_version = VERSION_FULL_CONFIG;
Label *current = memnew(Label);
current->set_h_size_flags(SIZE_EXPAND_FILL);
current_hb->add_child(current);
if (templates.has(current_version)) {
current->add_color_override("font_color", get_color("success_color", "Editor"));
Button *redownload = memnew(Button);
redownload->set_text(TTR("Re-Download"));
current_hb->add_child(redownload);
redownload->connect("pressed", this, "_download_template", varray(current_version));
Button *uninstall = memnew(Button);
uninstall->set_text(TTR("Uninstall"));
current_hb->add_child(uninstall);
current->set_text(current_version + " " + TTR("(Installed)"));
uninstall->connect("pressed", this, "_uninstall_template", varray(current_version));
} else {
current->add_color_override("font_color", get_color("error_color", "Editor"));
Button *redownload = memnew(Button);
redownload->set_text(TTR("Download"));
redownload->connect("pressed", this, "_download_template", varray(current_version));
current_hb->add_child(redownload);
current->set_text(current_version + " " + TTR("(Missing)"));
}
for (Set<String>::Element *E = templates.back(); E; E = E->prev()) {
HBoxContainer *hbc = memnew(HBoxContainer);
Label *version = memnew(Label);
version->set_modulate(get_color("disabled_font_color", "Editor"));
String text = E->get();
if (text == current_version) {
text += " " + TTR("(Current)");
}
version->set_text(text);
version->set_h_size_flags(SIZE_EXPAND_FILL);
hbc->add_child(version);
Button *uninstall = memnew(Button);
uninstall->set_text(TTR("Uninstall"));
hbc->add_child(uninstall);
uninstall->connect("pressed", this, "_uninstall_template", varray(E->get()));
installed_vb->add_child(hbc);
}
}
示例8: test
MainLoop* test() {
print_line("this is test io");
DirAccess* da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
da->change_dir(".");
print_line("Opening current dir "+ da->get_current_dir());
String entry;
da->list_dir_begin();
while ( (entry = da->get_next()) != "") {
print_line("entry "+entry+" is dir: " + Variant(da->current_is_dir()));
};
da->list_dir_end();
RES texture = ResourceLoader::load("test_data/rock.png");
ERR_FAIL_COND_V(texture.is_null(), NULL);
ResourceSaver::save("test_data/rock.xml",texture);
print_line("localize paths");
print_line(Globals::get_singleton()->localize_path("algo.xml"));
print_line(Globals::get_singleton()->localize_path("c:\\windows\\algo.xml"));
print_line(Globals::get_singleton()->localize_path(Globals::get_singleton()->get_resource_path()+"/something/something.xml"));
print_line(Globals::get_singleton()->localize_path("somedir/algo.xml"));
{
FileAccess* z = FileAccess::open("test_data/archive.zip", FileAccess::READ);
int len = z->get_len();
Vector<uint8_t> zip;
zip.resize(len);
z->get_buffer(&zip[0], len);
z->close();
memdelete(z);
FileAccessMemory::register_file("a_package", zip);
FileAccess::make_default<FileAccessMemory>(FileAccess::ACCESS_RESOURCES);
FileAccess::make_default<FileAccessMemory>(FileAccess::ACCESS_FILESYSTEM);
FileAccess::make_default<FileAccessMemory>(FileAccess::ACCESS_USERDATA);
print_line("archive test");
#if 0
Archive arch;
Archive::get_singleton()->add_package("a_package");
FileAccessArchive f;
print_line("opening for read");
f._open("file.txt", FileAccess::READ);
int pos = f.get_pos();
printf("file has %i bytes, initial pos %i\n", (int)f.get_len(), pos);
do {
printf("%c", f.get_8());
} while (!f.eof_reached());
print_line("opening for stored seek");
f.open("seek.bin", FileAccess::READ);
pos = f.get_pos();
printf("byte at pos %i is %i\n", pos, (int)f.get_8());
f.seek(128);
pos = f.get_pos();
printf("byte at pos %i is %i\n", pos, (int)f.get_8());
print_line("opening for deflated seek");
f.open("seek_deflated.bin", FileAccess::READ);
pos = f.get_pos();
printf("byte at pos %i is %i\n", pos, (int)f.get_8());
f.seek(128);
pos = f.get_pos();
printf("byte at pos %i is %i\n", pos, (int)f.get_8());
pos = f.get_pos();
printf("byte at pos %i is %i\n", pos, (int)f.get_8());
pos = f.get_pos();
printf("byte at pos %i is %i\n", pos, (int)f.get_8());
f.seek(256);
pos = f.get_pos();
printf("byte at pos %i is %i\n", pos, (int)f.get_8());
pos = f.get_pos();
printf("byte at pos %i is %i\n", pos, (int)f.get_8());
pos = f.get_pos();
printf("byte at pos %i is %i\n", pos, (int)f.get_8());
f.seek(4);
pos = f.get_pos();
printf("byte at pos %i is %i\n", pos, (int)f.get_8());
pos = f.get_pos();
printf("byte at pos %i is %i\n", pos, (int)f.get_8());
pos = f.get_pos();
printf("byte at pos %i is %i\n", pos, (int)f.get_8());
f.close();
DirAccessArchive d;
String dir = "../blah1/blah2/blahask/../blah3/.//blah4/";
printf("changing dir to %s\n", dir.utf8().get_data());
d.change_dir(dir);
printf("current dir is %s\n", d.get_current_dir().utf8().get_data());
FileAccessMemory::cleanup();
//.........这里部分代码省略.........
示例9: update_plugins
void EditorPluginSettings::update_plugins() {
plugin_list->clear();
DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
Error err = da->change_dir("res://addons");
if (err!=OK) {
memdelete(da);
return;
}
updating=true;
TreeItem *root = plugin_list->create_item();
da->list_dir_begin();
String d = da->get_next();
Vector<String> plugins;
while(d!=String()) {
bool dir = da->current_is_dir();
String path = "res://addons/"+d+"/plugin.cfg";
if (dir && FileAccess::exists(path)) {
plugins.push_back(d);
}
d = da->get_next();
}
da->list_dir_end();
memdelete(da);
plugins.sort();
Vector<String> active_plugins = GlobalConfig::get_singleton()->get("plugins/active");
for(int i=0;i<plugins.size();i++) {
Ref<ConfigFile> cf;
cf.instance();
String path = "res://addons/"+plugins[i]+"/plugin.cfg";
Error err = cf->load(path);
if (err!=OK) {
WARN_PRINTS("Can't load plugin config: "+path);
} else if (!cf->has_section_key("plugin","name")) {
WARN_PRINTS("Plugin misses plugin/name: "+path);
} else if (!cf->has_section_key("plugin","author")) {
WARN_PRINTS("Plugin misses plugin/author: "+path);
} else if (!cf->has_section_key("plugin","version")) {
WARN_PRINTS("Plugin misses plugin/version: "+path);
} else if (!cf->has_section_key("plugin","description")) {
WARN_PRINTS("Plugin misses plugin/description: "+path);
} else if (!cf->has_section_key("plugin","script")) {
WARN_PRINTS("Plugin misses plugin/script: "+path);
} else {
String d = plugins[i];
String name = cf->get_value("plugin","name");
String author = cf->get_value("plugin","author");
String version = cf->get_value("plugin","version");
String description = cf->get_value("plugin","description");
String script = cf->get_value("plugin","script");
TreeItem *item = plugin_list->create_item(root);
item->set_text(0,name);
item->set_tooltip(0,"Name: "+name+"\nPath: "+path+"\nMain Script: "+script);
item->set_metadata(0,d);
item->set_text(1,version);
item->set_metadata(1,script);
item->set_text(2,author);
item->set_metadata(2,description);
item->set_cell_mode(3,TreeItem::CELL_MODE_RANGE);
item->set_range_config(3,0,1,1);
item->set_text(3,"Inactive,Active");
item->set_editable(3,true);
if (EditorNode::get_singleton()->is_addon_plugin_enabled(d)) {
item->set_custom_color(3,Color(0.2,1,0.2));
item->set_range(3,1);
} else {
item->set_custom_color(3,Color(1,0.2,0.2));
item->set_range(3,0);
}
}
}
updating=false;
}
示例10: _scan_fs_changes
void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir,const ScanProgress& p_progress) {
uint64_t current_mtime = FileAccess::get_modified_time(p_dir->get_path());
bool updated_dir=false;
//print_line("dir: "+p_dir->get_path()+" MODTIME: "+itos(p_dir->modified_time)+" CTIME: "+itos(current_mtime));
if (current_mtime!=p_dir->modified_time) {
updated_dir=true;
p_dir->modified_time=current_mtime;
//ooooops, dir changed, see what's going on
//first mark everything as veryfied
for(int i=0;i<p_dir->files.size();i++) {
p_dir->files[i]->verified=false;
}
for(int i=0;i<p_dir->subdirs.size();i++) {
p_dir->get_subdir(i)->verified=false;
}
//then scan files and directories and check what's different
DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
String cd = p_dir->get_path();
da->change_dir(cd);
da->list_dir_begin();
while (true) {
bool isdir;
String f = da->get_next(&isdir);
if (f=="")
break;
if (isdir) {
if (f.begins_with(".")) //ignore hidden and . / ..
continue;
int idx = p_dir->find_dir_index(f);
if (idx==-1) {
if (FileAccess::exists(cd.plus_file(f).plus_file("engine.cfg"))) // skip if another project inside this
continue;
EditorFileSystemDirectory *efd = memnew( EditorFileSystemDirectory );
efd->parent=p_dir;
efd->name=f;
DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
d->change_dir(cd.plus_file(f));
_scan_new_dir(efd,d,p_progress.get_sub(1,1));
memdelete(d);
ItemAction ia;
ia.action=ItemAction::ACTION_DIR_ADD;
ia.dir=p_dir;
ia.file=f;
ia.new_dir=efd;
scan_actions.push_back(ia);
} else {
p_dir->subdirs[idx]->verified=true;
}
} else {
String ext = f.extension().to_lower();
if (!valid_extensions.has(ext))
continue; //invalid
int idx = p_dir->find_file_index(f);
if (idx==-1) {
//never seen this file, add actition to add it
EditorFileSystemDirectory::FileInfo *fi = memnew( EditorFileSystemDirectory::FileInfo );
fi->file=f;
String path = cd.plus_file(fi->file);
fi->modified_time=FileAccess::get_modified_time(path);
fi->meta=_get_meta(path);
fi->type=ResourceLoader::get_resource_type(path);
{
ItemAction ia;
ia.action=ItemAction::ACTION_FILE_ADD;
ia.dir=p_dir;
ia.file=f;
ia.new_file=fi;
scan_actions.push_back(ia);
}
//take the chance and scan sources
if (_check_meta_sources(fi->meta)) {
//.........这里部分代码省略.........
示例11: _scan_fs_changes
void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const ScanProgress &p_progress) {
uint64_t current_mtime = FileAccess::get_modified_time(p_dir->get_path());
bool updated_dir = false;
String cd = p_dir->get_path();
//print_line("dir: "+p_dir->get_path()+" MODTIME: "+itos(p_dir->modified_time)+" CTIME: "+itos(current_mtime));
if (current_mtime != p_dir->modified_time) {
updated_dir = true;
p_dir->modified_time = current_mtime;
//ooooops, dir changed, see what's going on
//first mark everything as veryfied
for (int i = 0; i < p_dir->files.size(); i++) {
p_dir->files[i]->verified = false;
}
for (int i = 0; i < p_dir->subdirs.size(); i++) {
p_dir->get_subdir(i)->verified = false;
}
//then scan files and directories and check what's different
DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
da->change_dir(cd);
da->list_dir_begin();
while (true) {
bool isdir;
String f = da->get_next(&isdir);
if (f == "")
break;
if (isdir) {
if (f.begins_with(".")) //ignore hidden and . / ..
continue;
int idx = p_dir->find_dir_index(f);
if (idx == -1) {
if (FileAccess::exists(cd.plus_file(f).plus_file("project.godot"))) // skip if another project inside this
continue;
if (FileAccess::exists(cd.plus_file(f).plus_file(".gdignore"))) // skip if another project inside this
continue;
EditorFileSystemDirectory *efd = memnew(EditorFileSystemDirectory);
efd->parent = p_dir;
efd->name = f;
DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
d->change_dir(cd.plus_file(f));
_scan_new_dir(efd, d, p_progress.get_sub(1, 1));
memdelete(d);
ItemAction ia;
ia.action = ItemAction::ACTION_DIR_ADD;
ia.dir = p_dir;
ia.file = f;
ia.new_dir = efd;
scan_actions.push_back(ia);
} else {
p_dir->subdirs[idx]->verified = true;
}
} else {
String ext = f.get_extension().to_lower();
if (!valid_extensions.has(ext))
continue; //invalid
int idx = p_dir->find_file_index(f);
if (idx == -1) {
//never seen this file, add actition to add it
EditorFileSystemDirectory::FileInfo *fi = memnew(EditorFileSystemDirectory::FileInfo);
fi->file = f;
String path = cd.plus_file(fi->file);
fi->modified_time = FileAccess::get_modified_time(path);
fi->import_modified_time = 0;
fi->type = ResourceLoader::get_resource_type(path);
{
ItemAction ia;
ia.action = ItemAction::ACTION_FILE_ADD;
ia.dir = p_dir;
ia.file = f;
ia.new_file = fi;
scan_actions.push_back(ia);
}
if (import_extensions.has(ext)) {
//if it can be imported, and it was added, it needs to be reimported
//.........这里部分代码省略.........