本文整理汇总了C++中BFile::GetAttrInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ BFile::GetAttrInfo方法的具体用法?C++ BFile::GetAttrInfo怎么用?C++ BFile::GetAttrInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BFile
的用法示例。
在下文中一共展示了BFile::GetAttrInfo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dir
BMailFilterAction
RuleFilter::HeaderFetched(entry_ref& ref, BFile& file, BMessage& attributes)
{
// That field doesn't exist? NO match
if (fAttribute == "")
return B_NO_MAIL_ACTION;
attr_info info;
if (file.GetAttrInfo("Subject", &info) != B_OK
|| info.type != B_STRING_TYPE)
return B_NO_MAIL_ACTION;
BString data = attributes.GetString(fAttribute.String(), NULL);
if (data.IsEmpty() || !fMatcher.Match(data)) {
// We're not supposed to do anything
return B_NO_MAIL_ACTION;
}
switch (fAction) {
case ACTION_MOVE_TO:
{
BDirectory dir(fMoveTarget);
node_ref nodeRef;
status_t status = dir.GetNodeRef(&nodeRef);
if (status != B_OK)
return status;
ref.device = nodeRef.device;
ref.directory = nodeRef.node;
return B_MOVE_MAIL_ACTION;
}
case ACTION_DELETE_MESSAGE:
return B_DELETE_MAIL_ACTION;
case ACTION_SET_FLAGS_TO:
file.WriteAttrString("MAIL:filter_flags", &fSetFlags);
break;
case ACTION_REPLY_WITH:
file.WriteAttr("MAIL:reply_with", B_INT32_TYPE, 0, &fReplyAccount,
sizeof(int32));
break;
case ACTION_SET_AS_READ:
{
BInboundMailProtocol& protocol
= (BInboundMailProtocol&)fMailProtocol;
protocol.MarkMessageAsRead(ref, B_READ);
break;
}
default:
fprintf(stderr,"Unknown do_what: 0x%04x!\n", fAction);
}
return B_NO_MAIL_ACTION;
}
示例2: new
void
PersonView::SetAttribute(const char* attribute, bool update)
{
char* value = NULL;
attr_info info;
BFile* file = NULL;
if (fRef != NULL)
file = new(std::nothrow) BFile(fRef, B_READ_ONLY);
if (file != NULL && file->GetAttrInfo(attribute, &info) == B_OK) {
value = (char*)calloc(info.size, 1);
file->ReadAttr(attribute, B_STRING_TYPE, 0, value, info.size);
}
SetAttribute(attribute, value, update);
free(value);
delete file;
}
示例3: ReadAttr
void PProjectWindow::ReadAttr(BFile& file, BMessage& settingsMsg)
{
char *fm = NULL;
try
{
attr_info ai;
if (file.GetAttrInfo("pe-prj-info", &ai) == B_NO_ERROR)
{
fm = (char *)malloc(ai.size);
FailNil(fm);
FailIOErr(file.ReadAttr("pe-prj-info", ai.type, 0, fm, ai.size));
FailOSErr(settingsMsg.Unflatten(fm));
}
}
catch (HErr& e) {}
if (fm)
free(fm);
}
示例4: if
void
TMailApp::RefsReceived(BMessage *msg)
{
bool have_names = false;
BString names;
char type[B_FILE_NAME_LENGTH];
int32 item = 0;
BFile file;
TMailWindow *window;
entry_ref ref;
//
// If a tracker window opened me, get a messenger from it.
//
BMessenger messenger;
if (msg->HasMessenger("TrackerViewToken"))
msg->FindMessenger("TrackerViewToken", &messenger);
while (msg->HasRef("refs", item)) {
msg->FindRef("refs", item++, &ref);
if ((window = FindWindow(ref)) != NULL)
window->Activate(true);
else {
file.SetTo(&ref, O_RDONLY);
if (file.InitCheck() == B_NO_ERROR) {
BNodeInfo node(&file);
node.GetType(type);
if (strcmp(type, B_MAIL_TYPE) == 0
|| strcmp(type, B_PARTIAL_MAIL_TYPE) == 0) {
window = NewWindow(&ref, NULL, false, &messenger);
window->Show();
} else if(strcmp(type, "application/x-person") == 0) {
/* Got a People contact info file, see if it has an Email address. */
BString name;
BString email;
attr_info info;
char *attrib;
if (file.GetAttrInfo("META:email", &info) == B_NO_ERROR) {
attrib = (char *) malloc(info.size + 1);
file.ReadAttr("META:email", B_STRING_TYPE, 0, attrib, info.size);
attrib[info.size] = 0; // Just in case it wasn't NUL terminated.
email << attrib;
free(attrib);
/* we got something... */
if (email.Length() > 0) {
/* see if we can get a username as well */
if(file.GetAttrInfo("META:name", &info) == B_NO_ERROR) {
attrib = (char *) malloc(info.size + 1);
file.ReadAttr("META:name", B_STRING_TYPE, 0, attrib, info.size);
attrib[info.size] = 0; // Just in case it wasn't NUL terminated.
name << "\"" << attrib << "\" ";
email.Prepend("<");
email.Append(">");
free(attrib);
}
if (names.Length() == 0) {
names << name << email;
} else {
names << ", " << name << email;
}
have_names = true;
email.SetTo("");
name.SetTo("");
}
}
}
else if (strcmp(type, kDraftType) == 0) {
window = NewWindow();
// If it's a draft message, open it
window->OpenMessage(&ref);
window->Show();
}
} /* end of else(file.InitCheck() == B_NO_ERROR */
}
}
if (have_names) {
window = NewWindow(NULL, names.String());
window->Show();
}
}
示例5: CopyFile
//---------------------------------------------------------------
// Copy File, not only data but also attributes ;-)
//---------------------------------------------------------------
void TJerFile::CopyFile( const char *sourcepath, const char *destinationpath )
{
BFile *source = 0L, *destination = 0L;
entry_ref ref;
uint8 data[2048];
int32 len = 2048;
char buf[B_ATTR_NAME_LENGTH];
void *buffer = NULL;
int32 lengthR,lengthW;
attr_info attribute;
BEntry entry( sourcepath );
if( B_OK == entry.InitCheck() )
{
if( B_OK == entry.GetRef( &ref ) )
{
source = new BFile( &ref ,B_READ_ONLY);
}
else
{
string truc("Error opening file in read only mode: ");
truc = truc + sourcepath;
GeneralException excep(truc.c_str(),"BJerFile::CopyFile");
throw(excep);
}
}
else
{
string truc("Error constructing file object: ");
truc = truc + sourcepath;
GeneralException excep(truc.c_str(),"BJerFile::CopyFile");
throw(excep);
}
entry.SetTo( destinationpath );
if( B_OK == entry.InitCheck() )
{
if( B_OK == entry.GetRef( &ref ) )
{
destination = new BFile( &ref ,B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
}
else
{
string truc("Error opening file in read write mode: ");
truc = truc + destinationpath;
GeneralException excep(truc.c_str(),"BJerFile::CopyFile");
throw(excep);
}
}
else
{
string truc("Error destination constructing file object: ");
truc = truc + destinationpath;
GeneralException excep(truc.c_str(),"BJerFile::CopyFile");
throw(excep);
}
if( source && destination )
{
BMessage *AMessage;
AMessage = new BMessage(B_UPDATE_STATUS_BAR);
AMessage->AddFloat("delta",1.0);
AMessage->AddString("text","Copy...");
AMessage->AddString("trailingtext",destinationpath);
MyInvoker.Invoke(AMessage);
delete AMessage;
while (source->GetNextAttrName(buf) == B_NO_ERROR)
{
source->GetAttrInfo(buf,&attribute);
if (buffer!=NULL)
{
free(buffer);
}
buffer = (void *)malloc(sizeof(char)*(attribute.size +1));
lengthR = source->ReadAttr(buf,attribute.type,0,buffer,attribute.size);
lengthW = destination->WriteAttr(buf,attribute.type,0,buffer,lengthR);
if (lengthR!=lengthW)
{
string truc("Error copying attribute for file : ");
truc = truc + destinationpath;
GeneralException excep(truc.c_str(),"BJerFile::CopyFile");
throw(excep);
}
switch(lengthR)
{
case B_ENTRY_NOT_FOUND:
{
GeneralException excep("The attribute doesn't exist.","BJerFile::CopyFile");
throw(excep);
break;
}
case B_FILE_ERROR :
{
GeneralException excep2("The object is uninitialized.","BJerFile::CopyFile");
//.........这里部分代码省略.........
示例6: BQuery
/*! \brief Search the filesystem for additional categories.
* \details Starts a whole-filesystem query for the Event files with
* categories which may be copied to the system and not appear
* in the Categories' database.
*/
static
void SearchFilesystemForAdditionalCategories( void )
{
BQuery* categoryQuery = NULL; //!< The way to fill the previously-uncatched categories.
Category* pCategory = NULL; //!< Used to traverse the list of categories
status_t status; //!< Result of the last action.
ssize_t bytesTransferred; //!< Used in I/O operations
entry_ref fileToReadAttributesFrom; //!< This is the reference to file with unknown category.
BFile* file = NULL; //!< This file will be initialized with fileToGetTheAttributesFrom.
attr_info attribute_info; //!< Information about the attribute.
rgb_color catColor; //!< Category color
char buffer[ 255 ]; //!< I'll use this buffer to read Categories from files
categoryQuery = new BQuery();
if ( !categoryQuery ) {
/* Nothing to do */
return;
}
// For initialization of the BQuery, we need to find the Volume with user's data.
BVolumeRoster volumeRoster;
BVolume bootVolume;
volumeRoster.GetBootVolume( &bootVolume );
// Setting the query to look in the boot volume
categoryQuery->SetVolume( &bootVolume );
/* First item of the predicate is the type of the file.
*/
categoryQuery->PushAttr( "BEOS:TYPE" );
categoryQuery->PushString( kEventFileMIMEType );
categoryQuery->PushOp( B_EQ );
/* Check the category attribute type's name.
*/
int i = 0;
BString categoryAttributeInternalName;
while ( AttributesArray[ i ].internalName != 0 )
{
if ( strcmp( AttributesArray[ i ].humanReadableName, "Category" ) == 0 )
{
// Found the correct attribute! Now, let's take its internal name...
break;
}
++i;
}
/* Build the query predicate.
* This is meaningful only if global list of categories contains any items,
* and if we succeeded to find the attribute with human-readable name "Category".
*/
if ( ! global_ListOfCategories.IsEmpty() &&
( AttributesArray[ i ].internalName != NULL ) )
{
for ( int i = 0, limit = global_ListOfCategories.CountItems();
i < limit;
++i )
{
pCategory = ( Category* )global_ListOfCategories.ItemAt( i );
if ( !pCategory )
continue;
categoryQuery->PushAttr( AttributesArray[ i ].internalName );
categoryQuery->PushString( pCategory->categoryName.String(), true );
categoryQuery->PushOp( B_NE );
categoryQuery->PushOp( B_AND );
} // <-- end of "for ( all currently known categories )"
} // <-- end of "if ( there are any items in the list of known categories )"
/* The predicate that we currently have looks like this:
* ((( type is Eventual ) && ( category != "Cat1" )) && ( category != "Cat2" )) && ...
* The order does not matter, since we're using "AND".
*
* Well, let's fire and see what comes...
*/
categoryQuery->Fetch();
while ( ( status = categoryQuery->GetNextRef( &fileToReadAttributesFrom ) ) == B_OK )
{
// Successfully retrieved next entry
file = new BFile( &fileToReadAttributesFrom, B_READ_ONLY );
if ( !file || file->InitCheck() != B_OK )
continue;
status = file->GetAttrInfo( AttributesArray[ i ].internalName,
&attribute_info );
if ( status != B_OK )
continue;
status = file->ReadAttr( AttributesArray[ i ].internalName,
attribute_info.type,
0,
//.........这里部分代码省略.........