int32_t PDirectoryGetEntries(void *pobject, void *in, void *out, void *extraData) { if (!pobject || !in || !out) return B_ERROR; PDirectory *parent = static_cast<PDirectory*>(pobject); if (!parent) return B_BAD_TYPE; BDirectory *backend = (BDirectory*)parent->GetBackend(); PArgs *outArgs = static_cast<PArgs*>(out); outArgs->MakeEmpty(); PArgs nameList; backend->Rewind(); entry_ref ref; while (backend->GetNextRef(&ref) == B_OK) { if (ref.name) outArgs->AddString("name", ref.name); } return B_OK; }
/* * This function is lifted from Simple Directmedia Layer (SDL): * http://www.libsdl.org/ */ static void tryDir(const char *d, PHYSFS_StringCallback callback, void *data) { BDirectory dir; dir.SetTo(d); if (dir.InitCheck() != B_NO_ERROR) return; dir.Rewind(); BEntry entry; while (dir.GetNextEntry(&entry) >= 0) { BPath path; const char *name; entry_ref e; if (entry.GetPath(&path) != B_NO_ERROR) continue; name = path.Path(); if (entry.GetRef(&e) != B_NO_ERROR) continue; if (entry.IsDirectory()) { if (strcmp(e.name, "floppy") != 0) tryDir(name, callback, data); } /* if */ else { bool add_it = false; int devfd; device_geometry g; if (strcmp(e.name, "raw") == 0) /* ignore partitions. */ { int devfd = open(name, O_RDONLY); if (devfd >= 0) { if (ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0) { if (g.device_type == B_CD) { char *mntpnt = getMountPoint(name); if (mntpnt != NULL) { callback(data, mntpnt); allocator.Free(mntpnt); /* !!! FIXME: lose this malloc! */ } /* if */ } /* if */ } /* if */ } /* if */ } /* if */ close(devfd); } /* else */ } /* while */ } /* tryDir */
// Scan directory for CD-ROM drives, add them to prefs static void scan_for_cdrom_drives(const char *directory) { // Set directory BDirectory dir; dir.SetTo(directory); if (dir.InitCheck() != B_NO_ERROR) return; dir.Rewind(); // Scan each entry BEntry entry; while (dir.GetNextEntry(&entry) >= 0) { // Get path and ref for entry BPath path; if (entry.GetPath(&path) != B_NO_ERROR) continue; const char *name = path.Path(); entry_ref e; if (entry.GetRef(&e) != B_NO_ERROR) continue; // Recursively enter subdirectories (except for floppy) if (entry.IsDirectory()) { if (!strcmp(e.name, "floppy")) continue; scan_for_cdrom_drives(name); } else { D(bug(" checking '%s'\n", name)); // Ignore partitions if (strcmp(e.name, "raw")) continue; // Open device int fd = open(name, O_RDONLY); if (fd < 0) continue; // Get geometry and device type device_geometry g; if (ioctl(fd, B_GET_GEOMETRY, &g, sizeof(g)) < 0) { close(fd); continue; } // Insert to list if it is a CD drive if (g.device_type == B_CD) PrefsAddString("cdrom", name); close(fd); } } }
/* * This function is lifted from Simple Directmedia Layer (SDL): * https://www.libsdl.org/ ... this is zlib-licensed code, too. */ static void tryDir(const char *d, PHYSFS_StringCallback callback, void *data) { BDirectory dir; dir.SetTo(d); if (dir.InitCheck() != B_NO_ERROR) return; dir.Rewind(); BEntry entry; while (dir.GetNextEntry(&entry) >= 0) { BPath path; const char *name; entry_ref e; if (entry.GetPath(&path) != B_NO_ERROR) continue; name = path.Path(); if (entry.GetRef(&e) != B_NO_ERROR) continue; if (entry.IsDirectory()) { if (strcmp(e.name, "floppy") != 0) tryDir(name, callback, data); continue; } /* if */ const int devfd = open(name, O_RDONLY); if (devfd < 0) continue; device_geometry g; const int rc = ioctl(devfd, B_GET_GEOMETRY, &g, sizeof (g)); close(devfd); if (rc < 0) continue; if (g.device_type != B_CD) continue; char mntpnt[B_FILE_NAME_LENGTH]; if (getMountPoint(name, mntpnt, sizeof (mntpnt))) callback(data, mntpnt); } /* while */ } /* tryDir */
void BeCheckersWindow::SavedGames(BListView *list) { char name[B_FILE_NAME_LENGTH]; BEntry entry; BDirectory dir; BPath p; find_directory(B_USER_DIRECTORY, &p); p.Append(APP_SGP); dir.SetTo(p.Path()); dir.Rewind(); while (dir.GetNextEntry(&entry) == B_OK) { entry.GetName(name); strtok(name, "."); // Strip the filename extension list->AddItem(new BStringItem(name)); } }
status_t ThemeManager::LoadThemes() { FENTRY; int dirwhich; BPath path; BDirectory dir; entry_ref ref; status_t err; for (dirwhich = 0; dirwhich < 2; dirwhich++) { if (!dirwhich) /* find system settings dir */ err = find_directory(B_BEOS_ETC_DIRECTORY, &path); else /* find user settings dir */ err = find_directory(B_USER_SETTINGS_DIRECTORY, &path); if (err) return err; err = dir.SetTo(path.Path()); if (err) return err; BEntry ent; if (dir.FindEntry(Z_THEMES_FOLDER_NAME, &ent) < B_OK) { dir.CreateDirectory(Z_THEMES_FOLDER_NAME, NULL); } path.Append(Z_THEMES_FOLDER_NAME); err = dir.SetTo(path.Path()); if (err) return err; err = dir.Rewind(); if (err) return err; while ((err = dir.GetNextRef(&ref)) == B_OK) { BPath themepath(&ref); BDirectory tdir(themepath.Path()); err = tdir.InitCheck(); if (err) /* not a dir */ continue; err = LoadTheme(themepath.Path()); } } return B_OK; }
bool BTrashWatcher::CheckTrashDirs() { BVolumeRoster volRoster; volRoster.Rewind(); BVolume volume; while (volRoster.GetNextVolume(&volume) == B_OK) { if (volume.IsReadOnly() || !volume.IsPersistent()) continue; BDirectory trashDir; FSGetTrashDir(&trashDir, volume.Device()); trashDir.Rewind(); BEntry entry; if (trashDir.GetNextEntry(&entry) == B_OK) return true; } return false; }
void delete_directory_path(char *path,bool recur) { BDirectory *dir; BPath *pat,pt; BEntry *ent; if ((pat = create_path(path))) { if ((dir = create_mydir((char *)pat->Path()))) { if (dir->Rewind() == B_OK) { if ((ent = new BEntry())) { while (dir->GetNextEntry(ent,false) == B_NO_ERROR) { if (ent->GetPath(&pt) == B_NO_ERROR) { if (recur) { if (ent->IsDirectory()) { delete_directory_path((char *)pt.Path(),recur); } } } ent->Remove(); } delete ent; } } delete dir; } delete pat; } }
//--------------------------------------------------------------------- // HandleDirectory //--------------------------------------------------------------------- // iterate through the directory and pass the resulting // refs and attempt to add the resulting file // status_t TQueueDialog::HandleDirectory(entry_ref &ref, struct stat &st, BDirectory &dir) { struct stat s; BEntry entry; dir.Rewind(); while (true) { if (dir.GetNextEntry(&entry) == B_OK) { entry.GetStat(&s); entry_ref eRef; entry.GetRef(&eRef); // HandleFile(eRef, s); EvaluateRef(eRef); } else break; } return B_ERROR; }
void PrefsWindow::add_serial_names(BPopUpMenu *menu, uint32 msg) { BSerialPort *port = new BSerialPort; char name[B_PATH_NAME_LENGTH]; for (int i=0; i<port->CountDevices(); i++) { port->GetDeviceName(i, name); menu->AddItem(new BMenuItem(name, new BMessage(msg))); } if (sys_info.platform_type == B_BEBOX_PLATFORM) { BDirectory dir; BEntry entry; dir.SetTo("/dev/parallel"); if (dir.InitCheck() == B_NO_ERROR) { dir.Rewind(); while (dir.GetNextEntry(&entry) >= 0) { if (!entry.IsDirectory()) { entry.GetName(name); menu->AddItem(new BMenuItem(name, new BMessage(msg))); } } } } delete port; }
/*! \brief Reads through the database and builds a complete set of installed types lists. An initial set of cached messages are also created. */ status_t InstalledTypes::_BuildInstalledTypesList() { status_t err = B_OK; _Unset(); // Create empty "cached messages" so proper messages // will be built up as we add new types try { fCachedMessage = new BMessage(); fCachedSupertypesMessage = new BMessage(); } catch (std::bad_alloc) { err = B_NO_MEMORY; } BDirectory root; if (!err) err = root.SetTo(get_database_directory().c_str()); if (!err) { root.Rewind(); while (true) { BEntry entry; err = root.GetNextEntry(&entry); if (err) { // If we've come to the end of list, it's not an error if (err == B_ENTRY_NOT_FOUND) err = B_OK; break; } else { // Check that this entry is both a directory and a valid MIME string char supertype[B_PATH_NAME_LENGTH]; if (entry.IsDirectory() && entry.GetName(supertype) == B_OK && BMimeType::IsValid(supertype)) { // Make sure our string is all lowercase BPrivate::Storage::to_lower(supertype); // Add this supertype std::map<std::string, Supertype>::iterator i; if (_AddSupertype(supertype, i) != B_OK) DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList() -- Error adding supertype '%s': 0x%lx\n", supertype, err)); Supertype &supertypeRef = fSupertypes[supertype]; // Now iterate through this supertype directory and add // all of its subtypes BDirectory dir; if (dir.SetTo(&entry) == B_OK) { dir.Rewind(); while (true) { BEntry subEntry; err = dir.GetNextEntry(&subEntry); if (err) { // If we've come to the end of list, it's not an error if (err == B_ENTRY_NOT_FOUND) err = B_OK; break; } else { // We need to preserve the case of the type name for // queries, so we can't use the file name directly BString type; int32 subStart; BNode node(&subEntry); if (node.InitCheck() == B_OK && node.ReadAttrString(kTypeAttr, &type) >= B_OK && (subStart = type.FindFirst('/')) > 0) { // Add the subtype if (_AddSubtype(supertypeRef, type.String() + subStart + 1) != B_OK) { DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList() -- Error adding subtype '%s/%s': 0x%lx\n", supertype, type.String() + subStart + 1, err)); } } } } } else { DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList(): " "Failed opening supertype directory '%s'\n", supertype)); } } } } } else { DBG(OUT("Mime::InstalledTypes::BuildInstalledTypesList(): " "Failed opening mime database directory '%s'\n", get_database_directory().c_str())); } fHaveDoneFullBuild = true; return err; }
void BL_CDEngine::SearchForCdPlayer(const char* aDirName) { BDirectory lDirectory; if (lDirectory.SetTo(aDirName) != B_OK) { return; } lDirectory.Rewind(); BEntry lEntry; while(lDirectory.GetNextEntry(&lEntry) >= 0) { BPath lPath; if(lEntry.GetPath(&lPath) != B_OK) { continue; } const char* lpName = lPath.Path(); entry_ref lRef; if(lEntry.GetRef(&lRef) != B_OK) { continue; } if(lEntry.IsDirectory()) { // Ignore floppy. It's worth to explicitly check for the floppy // device and ignore it, because opening it to get its geometry // would just make a lot of noise, and not any sense. if(strcmp(lRef.name, "floppy") == 0) { continue; } SearchForCdPlayer(lpName); } else { // Ignore partitions. if(strcmp(lRef.name, "raw") != 0) { continue; } // Try to open the device. int lDevice = open(lpName, O_RDONLY); if(lDevice < 0) { continue; } // Figure out is the device is a CD-ROM drive. device_geometry lGeometry; if(ioctl(lDevice, B_GET_GEOMETRY, &lGeometry, sizeof(lGeometry)) < 0) { close(lDevice); continue; } // Hooray, we've found a CD-ROM drive. if(lGeometry.device_type == B_CD) { // Store the device's name in the list and close the device. mpDevices->AddItem(strdup(lpName)); close(lDevice); } } } }
void ProjectWindow::AddFolder(entry_ref folderref) { BDirectory dir; if (dir.SetTo(&folderref) != B_OK) return; if (strcmp(folderref.name,"CVS") == 0 || strcmp(folderref.name,".svn") == 0 || strcmp(folderref.name,".git") == 0 || strcmp(folderref.name,".hg") == 0) return; dir.Rewind(); entry_ref ref; while (dir.GetNextRef(&ref) == B_OK) { if (BEntry(&ref).IsDirectory()) AddFolder(ref); else { // Here is where we actually add the file to the project. The name of the folder // containing the file will be the name of the file's group. If the group doesn't // exist, it will be created at the end of the list, but if it does, we will fake // a drop onto the group item to reuse the code path by finding the group and getting // its position in the list. DPath filepath(ref); if (filepath.GetExtension() && !( strcmp(filepath.GetExtension(),"cpp") == 0 || strcmp(filepath.GetExtension(),"c") == 0 || strcmp(filepath.GetExtension(),"cc") == 0 || strcmp(filepath.GetExtension(),"cxx") == 0 || strcmp(filepath.GetExtension(),"rdef") == 0 || strcmp(filepath.GetExtension(),"rsrc") == 0) ) continue; // Don't bother adding build files from other systems if (strcmp(filepath.GetFileName(), "Jamfile") == 0 || strcmp(filepath.GetFileName(), "Makefile") == 0) continue; DPath parent(filepath.GetFolder()); SourceGroup *group = NULL; SourceGroupItem *groupItem = NULL; fProject->Lock(); group = fProject->FindGroup(parent.GetFileName()); Lock(); if (group) groupItem = fProjectList->ItemForGroup(group); else { group = fProject->AddGroup(parent.GetFileName()); groupItem = new SourceGroupItem(group); fProjectList->AddItem(groupItem); UpdateIfNeeded(); } if (groupItem) { int32 index = fProjectList->IndexOf(groupItem); BPoint pt = fProjectList->ItemFrame(index).LeftTop(); pt.x += 5; pt.y += 5; AddFile(ref,&pt); } Unlock(); fProject->Unlock(); } } }
void NetworkSetupWindow::_BuildShowMenu(BMenu* menu, int32 msg_what) { menu->SetRadioMode(true); BPath path; BPath addon_path; BDirectory dir; BEntry entry; char* search_paths = getenv("ADDON_PATH"); if (!search_paths) return; fMinAddonViewRect.Set(0, 0, 200, 200); // Minimum size search_paths = strdup(search_paths); char* next_path_token; char* search_path = strtok_r(search_paths, ":", &next_path_token); while (search_path) { if (strncmp(search_path, "%A/", 3) == 0) { app_info ai; be_app->GetAppInfo(&ai); entry.SetTo(&ai.ref); entry.GetPath(&path); path.GetParent(&path); path.Append(search_path + 3); } else { path.SetTo(search_path); path.Append("network_setup"); } search_path = strtok_r(NULL, ":", &next_path_token); dir.SetTo(path.Path()); if (dir.InitCheck() != B_OK) continue; dir.Rewind(); while (dir.GetNextEntry(&entry) >= 0) { if (entry.IsDirectory()) continue; entry.GetPath(&addon_path); image_id addon_id = load_add_on(addon_path.Path()); if (addon_id < 0) { printf("Failed to load %s addon: %s.\n", addon_path.Path(), strerror(addon_id)); continue; } network_setup_addon_instantiate get_nth_addon; status_t status = get_image_symbol(addon_id, "get_nth_addon", B_SYMBOL_TYPE_TEXT, (void **) &get_nth_addon); if (status == B_OK) { NetworkSetupAddOn *addon; int n = 0; while ((addon = get_nth_addon(addon_id, n)) != NULL) { BMessage* msg = new BMessage(msg_what); BRect r(0, 0, 0, 0); BView* addon_view = addon->CreateView(&r); fMinAddonViewRect = fMinAddonViewRect | r; msg->AddInt32("image_id", addon_id); msg->AddString("addon_path", addon_path.Path()); msg->AddPointer("addon", addon); msg->AddPointer("addon_view", addon_view); menu->AddItem(new BMenuItem(addon->Name(), msg)); n++; } continue; } // No "addon instantiate function" symbol found in this addon printf("No symbol \"get_nth_addon\" found in %s addon: not a " "network setup addon!\n", addon_path.Path()); unload_add_on(addon_id); } } free(search_paths); }
status_t ThemeManager::LoadAddons() { FENTRY; ThemesAddon *ta; BPath path; BDirectory dir; entry_ref ref; #ifndef SINGLE_BINARY uint32 addonFlags; int dirwhich; int32 i; status_t err; image_id img; ThemesAddon *(*instantiate_func)(); #endif #ifndef SINGLE_BINARY for (dirwhich = 0; dirwhich < 2; dirwhich++) { if (!dirwhich) /* find system settings dir */ err = find_directory(B_BEOS_ADDONS_DIRECTORY, &path); else /* find user settings dir */ err = find_directory(B_USER_ADDONS_DIRECTORY, &path); if (err) return err; path.Append(Z_THEMES_ADDON_FOLDER); err = dir.SetTo(path.Path()); if (err) continue; err = dir.Rewind(); if (err) continue; while ((err = dir.GetNextRef(&ref)) == B_OK) { bool screwed = false; BPath imgpath(&ref); BString p(Z_THEMES_ADDON_FOLDER); p << "/" << ref.name; PRINT(("ThemeManager: trying to load_add_on(%s)\n", p.String())); img = load_add_on(imgpath.Path()); if (img < B_OK) fprintf(stderr, "ThemeManager: load_add_on 0x%08lx\n", img); if (img < B_OK) continue; err = get_image_symbol(img, "instantiate_themes_addon", B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func); if (err) fprintf(stderr, "ThemeManager: get_image_symbol 0x%08lx\n", err); if (err) continue; ta = instantiate_func(); if (!ta) fprintf(stderr, "ThemeManager: instantiate_themes_addon returned NULL\n"); if (!ta) continue; ta->SetImageId(img); /* check for existing names */ for (i = 0; i < fAddonList.CountItems(); i++) { ThemesAddon *a = AddonAt(i); if (!a) fprintf(stderr, "ThemeManager: screwed! addon@%ld null\n", i); if (a->MessageName() && ta->MessageName() && !strcmp(a->MessageName(), ta->MessageName())) { fprintf(stderr, "ThemeManager: screwed! addon@%ld has same msgname\n", i); screwed = true; break; } if (a->Name() && ta->Name() && !strcmp(a->Name(), ta->Name())) { fprintf(stderr, "ThemeManager: screwed! addon@%ld has same name\n", i); screwed = true; break; } } if (screwed) continue; /* add it to the list */ fAddonList.AddItem((void *)ta); PRINT(("ThemeManager: Added addon %ld '%s', msgname '%s'\n", ta->ImageId(), ta->Name(), ta->MessageName())); } //if (err) return err; } #else #define ADDA(a) \ if (ta) { \ fAddonList.AddItem((void *)ta); \ PRINT(("ThemeManager: Added addon %ld '%s', msgname '%s'\n", ta->ImageId(), ta->Name(), ta->MessageName())); \ } ta = instantiate_themes_addon_backgrounds(); ADDA(ta); ta = instantiate_themes_addon_beide(); ADDA(ta); ta = instantiate_themes_addon_deskbar(); ADDA(ta); #ifndef ZETA_ADDONS ta = instantiate_themes_addon_eddie(); ADDA(ta); #endif ta = instantiate_themes_addon_pe(); ADDA(ta); ta = instantiate_themes_addon_screensaver(); ADDA(ta); #ifndef ZETA_ADDONS ta = instantiate_themes_addon_soundplay(); ADDA(ta); #endif ta = instantiate_themes_addon_sounds(); ADDA(ta); ta = instantiate_themes_addon_terminal(); ADDA(ta); #if defined(__ANTARES__) || defined(B_BEOS_VERSION_DANO) ta = instantiate_themes_addon_ui_settings(); ADDA(ta); #endif #ifndef ZETA_ADDONS ta = instantiate_themes_addon_winamp_skin(); ADDA(ta); #endif ta = instantiate_themes_addon_window_decor(); ADDA(ta); #endif //if (err) return err; fAddonCount = fAddonList.CountItems(); PRINT(("ThemeManager: %ld addons loaded\n", fAddonCount)); return B_OK; }
void NetworkSetupWindow::_BuildShowTabView(int32 msg_what) { BPath path; BPath addon_path; BDirectory dir; BEntry entry; char* search_paths = getenv("ADDON_PATH"); if (!search_paths) return; float minimumWidth = be_control_look->DefaultItemSpacing() * 37; float minimumHight = be_control_look->DefaultItemSpacing() * 25; fMinAddonViewRect.Set(0, 0, minimumWidth, minimumHight); // Minimum size search_paths = strdup(search_paths); char* next_path_token; char* search_path = strtok_r(search_paths, ":", &next_path_token); while (search_path) { if (strncmp(search_path, "%A/", 3) == 0) { app_info ai; be_app->GetAppInfo(&ai); entry.SetTo(&ai.ref); entry.GetPath(&path); path.GetParent(&path); path.Append(search_path + 3); } else { path.SetTo(search_path); path.Append("Network Setup"); } search_path = strtok_r(NULL, ":", &next_path_token); dir.SetTo(path.Path()); if (dir.InitCheck() != B_OK) continue; dir.Rewind(); while (dir.GetNextEntry(&entry) >= 0) { if (entry.IsDirectory()) continue; entry.GetPath(&addon_path); image_id addon_id = load_add_on(addon_path.Path()); if (addon_id < 0) { printf("Failed to load %s addon: %s.\n", addon_path.Path(), strerror(addon_id)); continue; } network_setup_addon_instantiate get_nth_addon; status_t status = get_image_symbol(addon_id, "get_nth_addon", B_SYMBOL_TYPE_TEXT, (void **) &get_nth_addon); int tabCount = 0; if (status != B_OK) { // No "addon instantiate function" symbol found in this addon printf("No symbol \"get_nth_addon\" found in %s addon: not a " "network setup addon!\n", addon_path.Path()); unload_add_on(addon_id); continue; } while ((fNetworkAddOnMap[fAddonCount] = get_nth_addon(addon_id, tabCount)) != NULL) { printf("Adding Tab: %d\n", fAddonCount); BMessage* msg = new BMessage(msg_what); BRect r(0, 0, 0, 0); BView* addon_view = fNetworkAddOnMap[fAddonCount]->CreateView(&r); fMinAddonViewRect = fMinAddonViewRect | r; msg->AddInt32("image_id", addon_id); msg->AddString("addon_path", addon_path.Path()); msg->AddPointer("addon", fNetworkAddOnMap[fAddonCount]); msg->AddPointer("addon_view", addon_view); BTab* tab = new BTab; fPanel->AddTab(addon_view, tab); tab->SetLabel(fNetworkAddOnMap[fAddonCount]->Name()); fAddonCount++; // Number of tab addons total tabCount++; // Tabs for *this* addon } } } free(search_paths); }