status_t 
PoorManWindow::SaveConsole(BMessage* message, bool selection)
{
	entry_ref	ref;
	const char* name;
	BPath		path;
	BEntry		entry;
	status_t	err = B_OK;
	FILE*		f;
	
	err = message->FindRef("directory", &ref);
	if (err != B_OK)
		return err;
	
	err = message->FindString("name", &name);
	if (err != B_OK)
		return err;
	
	err = entry.SetTo(&ref);
	if (err != B_OK)
		return err;
	
	entry.GetPath(&path);
	path.Append(name);
	
	if (!(f = fopen(path.Path(), "w")))
		return B_ERROR;
	
	if (!selection) {
		// write the data to the file
		err = fwrite(fLoggingView->Text(), 1, fLoggingView->TextLength(), f);
	} else {
		// find the selected text and write it to a file
		int32 start = 0, end = 0;
		fLoggingView->GetSelection(&start, &end);
		
		BString buffer;
		char * buffData = buffer.LockBuffer(end - start + 1);
		// copy the selected text from the TextView to the buffer	
		fLoggingView->GetText(start, end - start, buffData);
		buffer.UnlockBuffer(end - start + 1);
		
		err = fwrite(buffer.String(), 1, end - start + 1, f);
	}
	
	fclose(f);
	
	return err;
}
Example #2
0
extern "C" void
process_refs(entry_ref directoryRef, BMessage *msg, void *)
{
	BDirectory directory(&directoryRef);
	if (directory.InitCheck() != B_OK)
		return;

	int32 errors = 0;
	entry_ref ref;
	int32 index;
	for (index = 0; msg->FindRef("refs", index, &ref) == B_OK; index ++) {
		BSymLink link(&ref);
		if (link.InitCheck() != B_OK || !link.IsSymLink()) {
			errors++;
			continue;
		}

		BEntry targetEntry;
		BPath path;
		if (link.MakeLinkedPath(&directory, &path) < B_OK
			|| targetEntry.SetTo(path.Path()) != B_OK
			|| targetEntry.GetParent(&targetEntry) != B_OK) {
			(new BAlert("Open Target Folder",
				"Cannot open target folder. Maybe this link is broken?",
				"OK", NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(NULL);
			continue;
		}

		// create Tracker message...
		entry_ref target;
		targetEntry.GetRef(&target);

		BMessage message(B_REFS_RECEIVED);
		message.AddRef("refs", &target);

		// ...and send it
		BMessenger messenger("application/x-vnd.Be-TRAK");
		messenger.SendMessage(&message);

		// TODO: select entry via scripting?
	}

	if (errors) {
		(new BAlert("Open Target Folder",
			"This add-on can only be used on symbolic links.\n"
			"It opens the folder of the link target in Tracker.",
			"OK"))->Go(NULL);
	}
}
Example #3
0
status_t
ModuleManager::_GetAddOn(const char *name, ModuleAddOn **_addon)
{
	// search list first
	for (int32 i = 0; ModuleAddOn *addon = fAddOns.ItemAt(i); i++) {
		BString addonName(addon->Name());
		addonName << "/";
		if (!strcmp(name, addon->Name())
			|| !strncmp(addonName.String(), name, addonName.Length())) {
			addon->Get();
			*_addon = addon;
			return B_OK;
		}
	}
	// not in list yet, load from disk
	// iterate through module dirs
	for (int32 i = 0; gModuleDirs[i]; i++) {
		BPath path;
		if (path.SetTo(gModuleDirs[i]) == B_OK
			&& path.SetTo(path.Path(), name) == B_OK) {
			BEntry entry;
			for (;;) {
				if (entry.SetTo(path.Path()) == B_OK && entry.Exists()) {
					// found an entry: if it is a file, try to load it
					if (entry.IsFile()) {
						ModuleAddOn *addon = new ModuleAddOn;
						if (addon->Load(path.Path(), gModuleDirs[i]) == B_OK) {
							status_t status = addon->Get();
							if (status < B_OK) {
								delete addon;
								return status;
							}

							fAddOns.AddItem(addon);
							*_addon = addon;
							return B_OK;
						}
						delete addon;
					}
					break;
				}
				// chop off last path component
				if (path.GetParent(&path) != B_OK)
					break;
			}
		}
	}
	return B_ENTRY_NOT_FOUND;
}
status_t
DecorThemesAddon::RunPreferencesPanel()
{
	status_t err;
	entry_ref ref;
	BEntry ent;
	err = ent.SetTo("/boot/beos/references/Appearance");
	if (!err) {
		err = ent.GetRef(&ref);
		if (!err) {
			err = be_roster->Launch(&ref);
		}
	}
	return err;
}
Example #5
0
// Scans a directory and adds the entries it founds as strings to the
// given list
static int32
scan_directory(const char *directory, BList *list)
{
	BEntry entry;
	BDirectory dir(SERIAL_DIR);
	char buf[B_OS_NAME_LENGTH];
	
	ASSERT(list != NULL);
	while (dir.GetNextEntry(&entry) == B_OK) {
		entry.GetName(buf);
		list->AddItem(strdup(buf));
	};
	
	return list->CountItems();
}
Example #6
0
/*! \brief Reinitializes the object to the entry referred to by the specified
	path rooted in the specified directory.
	\param dir the BDirectory, relative to which the entry's path name is
		   given
	\param path the entry's path name relative to \a dir
	\return
	- \c B_OK: Everything went fine.
	- \c B_BAD_VALUE: \c NULL \a dir or \a path.
	- \c B_ENTRY_NOT_FOUND: The entry could not be found.
	- \c B_BUSY: The entry is locked.
	\todo Implemented using SetTo(BEntry*). Check, if necessary to reimplement!
*/
status_t
BNode::SetTo(const BDirectory *dir, const char *path)
{
	Unset();
	status_t error = (dir && path ? B_OK : B_BAD_VALUE);
	if (error == B_OK && BPrivate::Storage::is_absolute_path(path))
		error = B_BAD_VALUE;
	BEntry entry;
	if (error == B_OK)
		error = entry.SetTo(dir, path);
	if (error == B_OK)
		error = SetTo(&entry);
	fCStatus = error;
	return error;
}
Example #7
0
void
InspectorApp::AddToTranslatorsList(const char *folder, int32 group)
{
	BDirectory dir;
	if (dir.SetTo(folder) == B_OK) {
	
		BEntry ent;
		while (dir.GetNextEntry(&ent) == B_OK) {
			BPath path;
			if (ent.GetPath(&path) == B_OK)
				flstTranslators.AddItem(
					new BTranslatorItem(path.Leaf(), path.Path(), group));
		}	
	}
}
Example #8
0
/*!	\brief Returns the mount point for the partition.

	If the partition is mounted this is the actual mount point. If it is not
	mounted, but contains a file system, derived from the partition name
	the name for a not yet existing directory in the root directory is
	constructed and the path to it returned.

	For partitions not containing a file system the method returns an error.

	\param mountPoint Pointer to the path to be set to refer the mount point
		   (respectively potential mount point) of the partition.
	\return \c B_OK, if everything went fine, an error code otherwise.
*/
status_t
BPartition::GetMountPoint(BPath* mountPoint) const
{
	if (!mountPoint || !ContainsFileSystem())
		return B_BAD_VALUE;

	// if the partition is mounted, return the actual mount point
	BVolume volume;
	if (GetVolume(&volume) == B_OK) {
		BDirectory dir;
		status_t error = volume.GetRootDirectory(&dir);
		if (error == B_OK)
			error = mountPoint->SetTo(&dir, NULL);
		return error;
	}

	// partition not mounted
	// get the volume name
	const char* volumeName = ContentName();
	if (!volumeName || strlen(volumeName) == 0)
		volumeName = Name();
	if (!volumeName || strlen(volumeName) == 0)
		volumeName = "unnamed volume";

	// construct a path name from the volume name
	// replace '/'s and prepend a '/'
	BString mountPointPath(volumeName);
	mountPointPath.ReplaceAll('/', '-');
	mountPointPath.Insert("/", 0);

	// make the name unique
	BString basePath(mountPointPath);
	int counter = 1;
	while (true) {
		BEntry entry;
		status_t error = entry.SetTo(mountPointPath.String());
		if (error != B_OK)
			return error;

		if (!entry.Exists())
			break;
		mountPointPath = basePath;
		mountPointPath << counter;
		counter++;
	}

	return mountPoint->SetTo(mountPointPath.String());
}
Example #9
0
void
ModulesView::PopulateScreenSaverList()
{
 	fListView->DeselectAll();
	while (ScreenSaverItem* item
			= (ScreenSaverItem*)fListView->RemoveItem((int32)0)) {
		delete item;
	}

	// Blackness is a built-in screen saver
	fListView->AddItem(new ScreenSaverItem(B_TRANSLATE("Blackness"), ""));

	// Iterate over add-on directories, and add their files to the list view

	directory_which which[] = {
		B_BEOS_ADDONS_DIRECTORY, B_USER_ADDONS_DIRECTORY};
	ScreenSaverItem* selectItem = NULL;

	for (uint32 i = 0; i < sizeof(which) / sizeof(which[0]); i++) {
		BPath basePath;
		find_directory(which[i], &basePath);
		basePath.Append("Screen Savers", true);

		BDirectory dir(basePath.Path());
		BEntry entry;
		while (dir.GetNextEntry(&entry, true) == B_OK) {
			char name[B_FILE_NAME_LENGTH];
			if (entry.GetName(name) != B_OK)
				continue;

			BPath path = basePath;
			path.Append(name);

			ScreenSaverItem* item = new ScreenSaverItem(name, path.Path());
			fListView->AddItem(item);

			if (!strcmp(fSettings.ModuleName(), item->Text())
				|| (!strcmp(fSettings.ModuleName(), "")
					&& !strcmp(item->Text(), B_TRANSLATE("Blackness"))))
				selectItem = item;
		}
	}

	fListView->SortItems(_CompareScreenSaverItems);

	fListView->Select(fListView->IndexOf(selectItem));
	fListView->ScrollToSelection();
}
void
IncludeSettingsView::AddRefsToList(BListView* list, BMessage* message, bool relative = false)
{
	//XXX - it is possible for now to select only one directory each time.
	entry_ref ref;
	BEntry entry;
	BPath path;
	BString pathString;
	status_t err;
	int32 ref_num;
	bool relpath = false;
	ref_num = 0;
	//find boolean in the message
	err =  message->FindBool("relpath", &relpath);
	if (err != B_OK) {
		DPRINT("IncludeSettingsView::AddRefsToList: boolean not found");
	}

	//add this entry to the list view
	do {
		if ( (err = message->FindRef("refs", ref_num, &ref)) != B_OK ) {
			return;
		}
		entry.SetTo(&ref, true);
		//we return if for some strange reason the entry is unavailable
		if (entry.InitCheck() != B_OK) return;
		entry.GetPath(&path);
		//XXX - if "relative" convert path
		DPRINT("IncludeSettingsView::AddRefsToList: entry name = " << path.Path());
		//convert path to relative if requested
		if (relpath) {
			//find the window we are attached to...
			DPRINT("IncludeSettingsView::AddRefsToList: add relative path");
			TargetConfig* c = ((TargetSettingsWin*) Window() )->TConfig();
			assert(c != NULL); //we *must* be attached to a window here
			c->RelPathToWorkingDir(path.Path(), &pathString);
		} else {
			DPRINT("IncludeSettingsView::AddRefsToList: add absolute path");
			pathString = path.Path();
		}
		list->AddItem(new BStringItem(pathString.String()));
		//tell the window that this view has changed
		CommunicateChanges();

		ref_num++;
	} while (1);	

}
    /*
     * 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 */
Example #12
0
status_t HModuleRoster::StartWatching( BPath *moduleDirectory )
{
	if( watching )
		return B_ERROR;
	printf("Watching %s\n", moduleDirectory->Path());
	BEntry		entry;
	
	if( (entry.SetTo( moduleDirectory->Path() ) == B_OK)&&
		(entry.GetNodeRef( &watchedRef ) == B_OK) )
	{
		watching = true;
		return watch_node( &watchedRef, B_WATCH_DIRECTORY, this );
	}
	else
		return B_ERROR;
}
Example #13
0
/*	AddFisrtInstanceAsRefToBMsg
	method adds refs of the files and folders of the "root" folder
	of the selected files to BMessage
*/
void
FileTree::AddFisrtInstanceAsRefToBMsg(BMessage *objMsg)
{
	FileTree *tmpTree;
	BEntry *objEntry = new BEntry();
	entry_ref *file_ref = new entry_ref;

	for(int i = 0; i < Nodes->CountItems(); i++) {
		tmpTree = (FileTree*)Nodes->ItemAt(i);
		objEntry->SetTo(tmpTree->Path.String());
		objEntry->GetRef(file_ref);		
		objMsg->AddRef("refs", file_ref);
	}
	
	delete objEntry;
}
Example #14
0
void InfoBox::GetFolder(BDirectory dir) {

	int32 c=dir.CountEntries();
	BEntry entry;
	
	if (c>0)
	for (int32 i=0; i<c; i++) {
		dir.GetNextEntry(&entry, true);
		if (entry.IsDirectory()) {
			folders++;
			GetFolder(BDirectory(&entry));
		}
		else
			files++;
	}
}
Example #15
0
/*!	\brief Returns whether this directory or any of its subdirectories
	at any level contain the entry referred to by the supplied path name.
	Only entries that match the node flavor specified by \a nodeFlags are
	considered.
	If the BDirectory is not properly initialized, the method returns \c false.
	A non-absolute path is considered relative to the current directory.

	\note R5's implementation always returns \c true given an absolute path or 
	an unitialized directory. This implementation is not compatible with that
	behavior. Instead it converts the path into a BEntry and passes it to the
	other version of Contains().

	\param path the entry's path name. May be relative to this directory or
		   absolute.
	\param nodeFlags Any of the following:
		   - \c B_FILE_NODE: The entry must be a file.
		   - \c B_DIRECTORY_NODE: The entry must be a directory.
		   - \c B_SYMLINK_NODE: The entry must be a symbolic link.
		   - \c B_ANY_NODE: The entry may be of any kind.
	\return
	- \c true, if the entry exists, its kind does match \nodeFlags and the
	  BDirectory is properly initialized and does contain the entry at any
	  level,
	- \c false, otherwise
*/
bool
BDirectory::Contains(const char *path, int32 nodeFlags) const
{
	// check initialization and parameters
	if (InitCheck() != B_OK)
		return false;
	if (!path)
		return true;	// mimic R5 behavior
	// turn the path into a BEntry and let the other version do the work
	BEntry entry;
	if (BPrivate::Storage::is_absolute_path(path))
		entry.SetTo(path);
	else
		entry.SetTo(this, path);
	return Contains(&entry, nodeFlags);
}
Example #16
0
bool
InitialIterator::GetTopEntry(BEntry& entry)
{
	// If the user selected one or more files, we must look
	// at the "refs" inside the message that was passed into
	// our add-on's process_refs(). If the user didn't select
	// any files, we will simply read all the entries from the
	// current working directory.

	entry_ref fileRef;

	if (fSelectedFiles.FindRef("refs", fCurrentRef, &fileRef) == B_OK) {
		entry.SetTo(&fileRef, fRecurseLinks);
		++fCurrentRef;
		return true;
	} else if (fCurrentRef > 0) {
		// when we get here, we have processed
		// all the refs from the message
		return false;
	} else if (fCurrentDir != NULL) {
		// examine the whole directory
		return fCurrentDir->GetNextEntry(&entry, fRecurseLinks) == B_OK;
	}

	return false;
}
bool PanelView::DoesEntryExist(const char *filename)
////////////////////////////////////////////////////////////////////////
{
	BEntry entry;
	
	entry.SetTo(filename);
	if (entry.InitCheck()==B_OK)
	{
		if (entry.Exists())
			return true;
		else
			return false;
	}
	else
		return false;
}
Example #18
0
void
DownloadProgressView::_StartNodeMonitor(const BEntry& entry)
{
	node_ref nref;
	if (entry.GetNodeRef(&nref) == B_OK)
		watch_node(&nref, B_WATCH_ALL, this);
}
Example #19
0
bool
BSlowContextMenu::StartBuildingItemList()
{
	//	return false when done building
	BEntry entry;

	if (fNavDir.device < 0 || entry.SetTo(&fNavDir) != B_OK
		|| !entry.Exists()) 
		return false;

	fIteratingDesktop = false;
	
	BDirectory parent;
	status_t err = entry.GetParent(&parent);
	fItemList = new BObjectList<BMenuItem>(50);

	// if ref is the root item then build list of volume root dirs
	fVolsOnly = (err == B_ENTRY_NOT_FOUND);

	if (fVolsOnly)
		return true;
		
	Model startModel(&entry, true);
	if (startModel.InitCheck() == B_OK) {
		if (!startModel.IsContainer())
			return false;

		if (startModel.IsQuery()) 
			fContainer = new QueryEntryListCollection(&startModel);
		else if (startModel.IsDesktop()) {
			fIteratingDesktop = true;
			fContainer = DesktopPoseView::InitDesktopDirentIterator(0,
				startModel.EntryRef());
			AddRootItemsIfNeeded();
			AddTrashItem();
		} else
			fContainer = new DirectoryEntryList(*dynamic_cast<BDirectory *>
				(startModel.Node()));
		
		if (fContainer->InitCheck() != B_OK)
			return false;

		fContainer->Rewind();
	}

	return true;
}
/*
* Given a local file path,
* update the corresponding file on Dropbox
*/
void
update_file_in_dropbox(const char * filepath, const char *parent_rev)
{
  char * argv[4];
  argv[0] = "db_put.py";

  BString db_filepath = local_to_db_filepath(filepath);
  const char * tmp = db_filepath.String();
  char not_const[db_filepath.CountChars()];
  strcpy(not_const,tmp);
  argv[2] = not_const;

  char not_const2[strlen(filepath)];
  strcpy(not_const2,filepath);
  argv[1] = not_const2;

  char not_const3[strlen(parent_rev)];
  strcpy(not_const3,parent_rev);
  argv[3] = not_const3;

  BString *result = run_python_script(argv,4);
  BString *real_path = parse_path(result);
  BString *new_parent_rev = parse_parent_rev(result);
  delete result;

  printf("path:|%s|\nparent_rev:|%s|\n",real_path->String(),new_parent_rev->String());

  BNode node = BNode(filepath);
  set_parent_rev(&node,new_parent_rev);
  delete new_parent_rev;

  BEntry entry = BEntry(filepath);
  BPath old_path;
  entry.GetPath(&old_path);

  BPath new_path = BPath(db_to_local_filepath(real_path->String()).String());

  printf("Should I move %s to %s?\n", old_path.Path(), new_path.Path());
  if(strcmp(new_path.Leaf(),old_path.Leaf()) != 0)
  {
    printf("moving %s to %s\n", old_path.Leaf(), new_path.Leaf());
    BEntry entry = BEntry(old_path.Path()); //entry for local path
    status_t err = entry.Rename(new_path.Leaf(),true);
    if(err != B_OK) printf("error moving: %s\n",strerror(err));
  }
  delete real_path;
}
Example #21
0
int32
add_query_menu_items(BMenu* menu, const char* attribute, uint32 what,
	const char* format, bool popup)
{
	BVolume	volume;
	BVolumeRoster().GetBootVolume(&volume);

	BQuery query;
	query.SetVolume(&volume);
	query.PushAttr(attribute);
	query.PushString("*");
	query.PushOp(B_EQ);
	query.Fetch();

	int32 index = 0;
	BEntry entry;
	while (query.GetNextEntry(&entry) == B_OK) {
		BFile file(&entry, B_READ_ONLY);
		if (file.InitCheck() == B_OK) {
			BMessage* message = new BMessage(what);

			entry_ref ref;
			entry.GetRef(&ref);
			message->AddRef("ref", &ref);

			BString value;
			if (file.ReadAttrString(attribute, &value) < B_OK)
				continue;

			message->AddString("attribute", value.String());

			BString name;
			if (format != NULL)
				name.SetToFormat(format, value.String());
			else
				name = value;

			if (index < 9 && !popup)
				menu->AddItem(new BMenuItem(name, message, '1' + index));
			else
				menu->AddItem(new BMenuItem(name, message));
			index++;
		}
	}

	return index;
}
Example #22
0
status_t
InstalledPackageInfo::Uninstall()
{
	if (fStatus != B_OK)
		return fStatus;

	BString *iter;
	uint32 i, count = fInstalledItems.CountItems();
	BEntry entry;
	status_t ret;

	// Try to remove all entries that are present in the list
	for (i = 0; i < count; i++) {
		iter = static_cast<BString *>(fInstalledItems.ItemAt(count - i - 1));
		fprintf(stderr, "Removing: %s (%ld/%ld)\n", iter->String(), i, count);
		ret = entry.SetTo(iter->String());
		if (ret == B_BUSY) {
			// The entry's directory is locked - wait a few cycles for it to
			// unlock itself
			int32 tries = 0;
			for (tries = 0; tries < P_BUSY_TRIES; tries++) {
				ret = entry.SetTo(iter->String());
				if (ret != B_BUSY)
					break;
				// Wait a moment
				usleep(1000);
			}
		}

		if (ret == B_ENTRY_NOT_FOUND)
			continue;
		else if (ret != B_OK) {
			fStatus = B_ERROR;
			return fStatus;
		}

		fprintf(stderr, "...we continue\n");

		if (entry.Exists() && entry.Remove() != B_OK) {
			fprintf(stderr, "\n%s\n", strerror(ret));
			fStatus = B_ERROR;
			return fStatus;
		}
		fInstalledItems.RemoveItem(count - i - 1);
	}

	if (entry.SetTo(fPathToInfo.Path()) != B_OK) {
		fStatus = B_ERROR;
		return fStatus;
	}
	if (entry.Exists() && entry.Remove() != B_OK) {
		fStatus = B_ERROR;
		return fStatus;
	}

	return fStatus;
}
Example #23
0
status_t TrashFile(BEntry *src)
{
	// Move a file to the Trash. If the name exists, rename the entry before moving
	
	if(!src)
		return B_ERROR;
	
	status_t status;
	BPath path;
	BEntry dest;
	BString pathstr("/boot/home/Desktop/Trash/");
	BDirectory dir(pathstr.String());
	
	char newname[B_FILE_NAME_LENGTH];
	src->GetName(newname);
	pathstr+=newname;
	
	dest.SetTo(pathstr.String());
	GetValidName(&dest);
	dest.GetPath(&path);
	
	BPath srcpath;
	src->GetPath(&srcpath);
	BNode node(srcpath.Path());
	if(node.InitCheck()==B_OK)
	{
		node.WriteAttr("_trk/original_path",B_STRING_TYPE,0,
				srcpath.Path(),strlen(srcpath.Path())+1);
	}
	
	status=src->MoveTo(&dir,path.Path(),false);
	
	if(status==B_CROSS_DEVICE_LINK)
	{
		BPath srcpath;
		src->GetPath(&srcpath);
		BString command("mv "),srcstring(srcpath.Path()),deststring(path.Path());
		srcstring.CharacterEscape(" ",'\\');
		deststring.CharacterEscape(" ",'\\');
		command+=srcstring;
		command+=" ";
		command+=deststring;
		system(command.String());
	}
	return status;

}
Example #24
0
/*!	\brief Finds and loads the next add-on of an add-on subdirectory.
	\param directory The add-on directory.
	\param image Pointer to an image_id into which the image ID of the loaded
		   add-on shall be written.
	\return
	- \c B_OK: Everything went fine.
	- \c B_ENTRY_NOT_FOUND: End of directory.
	- other error codes
*/
status_t
BDiskDeviceRoster::_GetNextAddOn(BDirectory *directory, AddOnImage *image)
{
	status_t error = (directory ? B_OK : B_ENTRY_NOT_FOUND);
	if (error == B_OK) {
		// iterate through the entry list and try to load the entries
		bool found = false;
		while (error == B_OK && !found) {
			BEntry entry;
			error = directory->GetNextEntry(&entry);
			BPath path;
			if (error == B_OK && entry.GetPath(&path) == B_OK)
				found = (image->Load(path.Path()) == B_OK);
		}
	}
	return error;
}
Example #25
0
void InfoStrView::OpenFolder (const char *path) const
{
	/* This function opens a folder entry_ref through Tracker */
	BEntry entry (path, true);
	entry_ref refToDir;
	entry.GetRef (&refToDir);
	
	if (entry.Exists() == true)
	{
		BMessage trakMsg (B_REFS_RECEIVED);
		trakMsg.AddRef ("refs", &refToDir);

		/* Just check if tracker is running */
		if (be_roster->IsRunning (trackerSignature) == true)
			BMessenger(trackerSignature).SendMessage (&trakMsg);
	}
}
Example #26
0
bool SeqNavMenu::AddNextItem()
{
	// limit nav menus to 500 items only
	if( mItems.size() >= 500 ) return false;

	BEntry			entry;
	bool			useLeafForLabel = true;
	if( IsPathMenu() ) {
		if( mDirectory.GetNextEntry( &entry ) != B_OK ) return false;
	} else if( IsPredicateMenu() ) {
		if( mQuery.GetNextEntry( &entry ) != B_OK ) return false;
		useLeafForLabel = false;
	}
	if( entry.InitCheck() != B_OK ) return false;
	AddEntry( entry, useLeafForLabel );
	return true;
}
Example #27
0
void
AddRefsToDeskbarMenu(const BMessage* m, entry_ref* subdirectory)
{
	if (m) {
		int32 count = 0;
		uint32 type = 0;
		entry_ref ref;

		m->GetInfo("refs", &type, &count);
		if (count <= 0)
			return;

		BPath path;
		BSymLink link;
		BDirectory dir;
		if (subdirectory) {
			ref = *subdirectory;
			BEntry entry(&ref);
			if (entry.Exists()) {
				// if the ref is a file get the parent and convert it to a ref
				if (entry.IsFile()) {
					BEntry parent;
					entry.GetParent(&parent);
					parent.GetRef(&ref);
				}
			} else
				return;

			dir.SetTo(&ref);
		} else {
			if (find_directory(B_USER_DESKBAR_DIRECTORY, &path) == B_OK)
				dir.SetTo(path.Path());
			else
				return;
		}

		for (long i = 0; i < count; i++) {
			if (m->FindRef("refs", i, &ref) == B_NO_ERROR) {
				BEntry entry(&ref);
				entry.GetPath(&path);

				dir.CreateSymLink(ref.name, path.Path(), &link);
			}
		}
	}
}
Example #28
0
filter_result
DCCFileFilter::HandleAlert (BMessage *msg)
{
	BTextControl *text (dynamic_cast<BTextControl *>(
		panel->Window()->FindView ("text view")));
	int32 which;

	msg->FindInt32 ("which", &which);

	if (which == 0 || text == 0)
	{
		return B_SKIP_MESSAGE;
	}

	entry_ref ref;
	panel->GetPanelDirectory (&ref);

	if (which == 2)
	{
		BDirectory dir (&ref);
		BFile file (&dir, text->Text(), B_READ_ONLY);
		BEntry entry (&dir, text->Text());
		BPath path;
		off_t position;

		file.GetSize (&position);
		entry.GetPath (&path);
		send_msg.AddString ("path", path.Path());
		send_msg.AddInt64  ("pos", position);

		send_msg.what = M_ADD_RESUME_DATA;
	}
	else
	{
		send_msg.AddRef ("directory", &ref);
		send_msg.AddString ("name", text->Text());
	}

	panel->Messenger().SendMessage (&send_msg);

	BMessage cmsg (B_CANCEL);
	cmsg.AddPointer ("source", panel);
	panel->Messenger().SendMessage (&cmsg);

	return B_SKIP_MESSAGE;
}
Example #29
0
void
LaunchDaemon::_ReadEntry(const char* context, BEntry& entry)
{
	if (entry.IsDirectory())
		_ReadDirectory(context, entry);
	else
		_ReadFile(context, entry);
}
Example #30
0
//------------------------------------------------------------------------------
bool	is_asst_installed()
{
	bool	aInstalled = true;
	BEntry	aEntry;

	try {
		aEntry.SetTo(asst_install_path(FOLDER_NAME_ASST_SPY).c_str(), true);
		if ( !aEntry.Exists() )
			throw B_ERROR;
		aEntry.SetTo(asst_install_path(FOLDER_NAME_ASST_PASTE_SENDER).c_str(), true);
		if ( !aEntry.Exists() )
			throw B_ERROR;
	} catch (...) {
		aInstalled = false;
	}
	return aInstalled;	
}