本文整理汇总了C++中BResources::SetTo方法的典型用法代码示例。如果您正苦于以下问题:C++ BResources::SetTo方法的具体用法?C++ BResources::SetTo怎么用?C++ BResources::SetTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BResources
的用法示例。
在下文中一共展示了BResources::SetTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Flatten
status_t
DefaultCatalog::WriteToResource(const entry_ref &appOrAddOnRef)
{
BFile file;
status_t res = file.SetTo(&appOrAddOnRef, B_READ_WRITE);
if (res != B_OK)
return res;
BResources rsrc;
res = rsrc.SetTo(&file);
if (res != B_OK)
return res;
BMallocIO mallocIO;
mallocIO.SetBlockSize(max(fCatMap.Size() * 20, (int32)256));
// set a largish block-size in order to avoid reallocs
res = Flatten(&mallocIO);
int mangledLanguage = CatKey::HashFun(fLanguageName.String(), 0);
if (res == B_OK) {
res = rsrc.AddResource('CADA', mangledLanguage,
mallocIO.Buffer(), mallocIO.BufferLength(),
BString(fLanguageName));
}
return res;
}
示例2: path
int32
Project::UpdateAttributes(void)
{
BResources res;
BPath path(fPath.GetFolder());
path.Append(GetTargetName());
BFile file(path.Path(), B_READ_WRITE);
if (file.InitCheck() != B_OK)
return B_BAD_VALUE;
if (res.SetTo(&file) != B_OK)
return B_ERROR;
ResourceToAttribute(file,res,'MIMS',"BEOS:APP_SIG");
ResourceToAttribute(file,res,'MIMS',"BEOS:TYPE");
ResourceToAttribute(file,res,'MSGG',"BEOS:FILE_TYPES");
ResourceToAttribute(file,res,'APPV',"BEOS:APP_VERSION");
ResourceToAttribute(file,res,'APPF',"BEOS:APP_FLAGS");
ResourceToAttribute(file,res,'ICON',"BEOS:L:STD_ICON");
ResourceToAttribute(file,res,'MICN',"BEOS:M:STD_ICON");
ResourceToAttribute(file,res,'VICN',"BEOS:ICON");
return B_OK;
}
示例3: BBitmap
BBitmap*
MediaAlert::InitIcon()
{
// The alert icons are in the app_server resources
BBitmap* icon = NULL;
BPath path;
if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) == B_OK) {
path.Append("app_server");
BFile file;
if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK) {
BResources resources;
if (resources.SetTo(&file) == B_OK) {
// Which icon are we trying to load?
const char* iconName = "warn";
// Load the raw icon data
size_t size;
const void* rawIcon =
resources.LoadResource(B_VECTOR_ICON_TYPE, iconName, &size);
if (rawIcon != NULL) {
// Now build the bitmap
icon = new BBitmap(BRect(0, 0, 31, 31), B_RGBA32);
if (BIconUtils::GetVectorIcon((const uint8*)rawIcon, size,
icon) != B_OK) {
delete icon;
return NULL;
}
}
}
}
}
return icon;
}
示例4:
BBitmap * BitmapUtils::LoadFromResource(int32 id)
{
BArchivable *archivable;
BResources resources;
BMessage message;
const void *data;
BBitmap *bitmap;
app_info info;
BFile file;
size_t len;
if (be_app->GetAppInfo(&info) != B_OK) return NULL;
if (file.SetTo(&(info.ref), B_READ_ONLY) != B_OK) return NULL;
if (resources.SetTo(&file, false) != B_OK) return NULL;
data = resources.LoadResource('BBMP', id, &len);
if (data == NULL || len <= 0) return NULL;
if (message.Unflatten((const char *)data) != B_OK) return NULL;
archivable = BBitmap::Instantiate(&message);
if (archivable == NULL) return NULL;
bitmap = dynamic_cast<BBitmap*>(archivable);
if (bitmap == NULL) {
delete archivable;
return NULL;
}
return bitmap;
}
示例5: BBitmap
BBitmap*
AlertView::InitIcon()
{
// This is how BAlert gets to its icon
BBitmap* icon = NULL;
BPath path;
if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) == B_OK) {
path.Append("app_server");
BResources resources;
BFile file;
if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK
&& resources.SetTo(&file) == B_OK) {
size_t size;
const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE,
"warn", &size);
if (data) {
icon = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
if (BIconUtils::GetVectorIcon((const uint8*)data, size, icon)
!= B_OK) {
delete icon;
icon = NULL;
}
}
}
}
return icon;
}
示例6: file
// read_boot_code_data
static uint8 *
read_boot_code_data(const char* programPath)
{
// open our executable
BFile executableFile;
status_t error = executableFile.SetTo(programPath, B_READ_ONLY);
if (error != B_OK) {
fprintf(stderr, "Error: Failed to open my executable file (\"%s\": "
"%s\n", programPath, strerror(error));
exit(1);
}
uint8 *bootCodeData = new uint8[kBootCodeSize];
// open our resources
BResources resources;
error = resources.SetTo(&executableFile);
const void *resourceData = NULL;
if (error == B_OK) {
// read the boot block from the resources
size_t resourceSize;
resourceData = resources.LoadResource(B_RAW_TYPE, 666, &resourceSize);
if (resourceData && resourceSize != (size_t)kBootCodeSize) {
resourceData = NULL;
printf("Warning: Something is fishy with my resources! The boot "
"code doesn't have the correct size. Trying the attribute "
"instead ...\n");
}
}
if (resourceData) {
// found boot data in the resources
memcpy(bootCodeData, resourceData, kBootCodeSize);
} else {
// no boot data in the resources; try the attribute
ssize_t bytesRead = executableFile.ReadAttr("BootCode", B_RAW_TYPE,
0, bootCodeData, kBootCodeSize);
if (bytesRead < 0) {
fprintf(stderr, "Error: Failed to read boot code from resources "
"or attribute.\n");
exit(1);
}
if (bytesRead != kBootCodeSize) {
fprintf(stderr, "Error: Failed to read boot code from resources, "
"and the boot code in the attribute has the wrong size!\n");
exit(1);
}
}
return bootCodeData;
}
示例7: file
DeviceWatcher::DeviceWatcher()
: BLooper("MIDI devices watcher"),
fDeviceEndpointsMap(), fVectorIconData(NULL), fVectorIconDataSize(0),
fLargeIcon(NULL), fMiniIcon(NULL)
{
// Load midi endpoint vector icon data
app_info info;
be_app->GetAppInfo(&info);
BFile file(&info.ref, B_READ_ONLY);
BResources resources;
if (resources.SetTo(&file) == B_OK) {
size_t dataSize;
// Load MIDI port endpoint vector icon
const uint8* data = (const uint8*)resources.LoadResource(
B_VECTOR_ICON_TYPE, "endpoint_vector_icon", &dataSize);
if (data != NULL && dataSize > 0)
fVectorIconData = new(std::nothrow) uint8[dataSize];
if (fVectorIconData) {
// data is own by resources local object: copy its content for
// later use
memcpy(fVectorIconData, data, dataSize);
fVectorIconDataSize = dataSize;
}
}
// Render 32x32 and 16x16 B_CMAP8 icons for R5 compatibility
if (fVectorIconData != NULL) {
fLargeIcon = new(std::nothrow) BBitmap(BRect(0, 0, 31, 31), B_CMAP8);
fMiniIcon = new(std::nothrow) BBitmap(BRect(0, 0, 15, 15), B_CMAP8);
if (BIconUtils::GetVectorIcon(fVectorIconData, fVectorIconDataSize,
fLargeIcon) != B_OK) {
delete fLargeIcon;
fLargeIcon = NULL;
}
if (BIconUtils::GetVectorIcon(fVectorIconData, fVectorIconDataSize,
fMiniIcon) != B_OK) {
delete fMiniIcon;
fMiniIcon = NULL;
}
}
Start();
}
示例8:
static status_t
open_output_file()
{
status_t err = entry.SetTo(rsrc_file, true);
if (err == B_OK) {
uint32 openMode = B_READ_WRITE | B_CREATE_FILE;
bool clobber = false;
if (!(flags & RDEF_MERGE_RESOURCES)) {
openMode |= B_ERASE_FILE;
clobber = true;
}
err = file.SetTo(&entry, openMode);
if (err == B_OK)
err = rsrc.SetTo(&file, clobber);
}
return err;
}
示例9: file
BBitmap *GetCicnFromResource(const char *theResource)
{
// Get application info
app_info info;
be_app->GetAppInfo(&info);
BFile file(&info.ref, O_RDONLY);
if (file.InitCheck())
return NULL;
size_t size;
cicn *icon;
BResources res;
status_t err;
if ( (err = res.SetTo(&file)) != B_NO_ERROR )
return NULL;
icon = (cicn *)res.FindResource('cicn', theResource, &size);
if (!icon)
return NULL;
// Swap bytes if needed. We do this because the resources are currently
// built on Macintosh BeOS
if (B_HOST_IS_LENDIAN)
{
status_t retVal;
retVal = swap_data(B_INT16_TYPE, &icon->width, sizeof(int16), B_SWAP_BENDIAN_TO_HOST);
retVal = swap_data(B_INT16_TYPE, &icon->height, sizeof(int16), B_SWAP_BENDIAN_TO_HOST);
}
// Get cicn bounding rect
BRect bounds(0, 0, icon->width-1, icon->height-1);
// Load bitmap
BBitmap *bitmap = new BBitmap(bounds, B_COLOR_8_BIT);
ASSERT(bitmap);
bitmap->SetBits(&icon->data, size - sizeof(int16)*2, 0, B_COLOR_8_BIT);
return (bitmap);
}
示例10: file
void
ResView::OpenFile(const entry_ref &ref)
{
// Add all the 133t resources and attributes of the file
BFile file(&ref, B_READ_ONLY);
BResources resources;
if (resources.SetTo(&file) != B_OK)
return;
file.Unset();
resources.PreloadResourceType();
int32 index = 0;
ResDataRow *row;
ResourceData *resData = new ResourceData();
while (resData->SetFromResource(index, resources)) {
row = new ResDataRow(resData);
fListView->AddRow(row);
fDataList.AddItem(resData);
resData = new ResourceData();
index++;
}
delete resData;
BNode node;
if (node.SetTo(&ref) == B_OK) {
char attrName[B_ATTR_NAME_LENGTH];
node.RewindAttrs();
resData = new ResourceData();
while (node.GetNextAttrName(attrName) == B_OK) {
if (resData->SetFromAttribute(attrName, node)) {
row = new ResDataRow(resData);
fListView->AddRow(row);
fDataList.AddItem(resData);
resData = new ResourceData();
}
}
delete resData;
}
}
示例11: ResourceVectorToBitmap
BBitmap* MainWindow::ResourceVectorToBitmap(const char *resName, float iconSize)
{
BResources res;
size_t size;
app_info appInfo;
be_app->GetAppInfo(&appInfo);
BFile appFile(&appInfo.ref, B_READ_ONLY);
res.SetTo(&appFile);
BBitmap *aBmp = NULL;
const uint8* iconData = (const uint8*) res.LoadResource('VICN', resName, &size);
if (size > 0 ) {
aBmp = new BBitmap (BRect(0,0, iconSize, iconSize), 0, B_RGBA32);
status_t result = BIconUtils::GetVectorIcon(iconData, size, aBmp);
if (result != B_OK) {
delete aBmp;
aBmp = NULL;
}
}
return aBmp;
}
示例12: LoadResources
void PanelView::LoadResources(void)
////////////////////////////////////////////////////////////////////////
{
entry_ref ref;
app_info info;
m_ParentIcon = NULL;
m_UnknownIcon = NULL;
if (be_app->GetAppInfo(&info)==B_OK)
{
BFile file(&info.ref, B_READ_ONLY);
if (file.InitCheck()==B_OK)
{
BResources rsrcs;
size_t len = 0;
if (rsrcs.SetTo(&file)==B_OK)
{
const void *data;
data = rsrcs.LoadResource('MICN',1,&len);
if (data)
{
m_ParentIcon = new unsigned char[len];
memcpy(m_ParentIcon,data,len);
}
data = rsrcs.LoadResource('MICN',2,&len);
if (data)
{
m_UnknownIcon = new unsigned char[len];
memcpy(m_UnknownIcon,data,len);
}
}
}
}
}
示例13: memIO
status_t
DefaultCatalog::ReadFromResource(const entry_ref &appOrAddOnRef)
{
BFile file;
status_t res = file.SetTo(&appOrAddOnRef, B_READ_ONLY);
if (res != B_OK)
return B_ENTRY_NOT_FOUND;
BResources rsrc;
res = rsrc.SetTo(&file);
if (res != B_OK)
return res;
size_t sz;
const void *buf = rsrc.LoadResource('CADA', fLanguageName, &sz);
if (!buf)
return B_NAME_NOT_FOUND;
BMemoryIO memIO(buf, sz);
res = Unflatten(&memIO);
return res;
}
示例14: new
// fill out the icons with the stop and warn symbols from app_server
void
ConflictView::_FillIcons()
{
// return if the icons have already been filled out
if (fStopIcon != NULL && fStopIcon->InitCheck() == B_OK
&& fWarnIcon != NULL && fWarnIcon->InitCheck() == B_OK) {
return;
}
BPath path;
status_t status = find_directory(B_BEOS_SERVERS_DIRECTORY, &path);
if (status < B_OK) {
FTRACE((stderr,
"_FillIcons() - find_directory failed: %s\n",
strerror(status)));
return;
}
path.Append("app_server");
BFile file;
status = file.SetTo(path.Path(), B_READ_ONLY);
if (status < B_OK) {
FTRACE((stderr,
"_FillIcons() - BFile init failed: %s\n",
strerror(status)));
return;
}
BResources resources;
status = resources.SetTo(&file);
if (status < B_OK) {
FTRACE((stderr,
"_FillIcons() - BResources init failed: %s\n",
strerror(status)));
return;
}
size_t size = 0;
if (fStopIcon == NULL) {
// Allocate the fStopIcon bitmap
fStopIcon = new (std::nothrow) BBitmap(BRect(0, 0, 15, 15), 0,
B_RGBA32);
if (fStopIcon->InitCheck() != B_OK) {
FTRACE((stderr, "_FillIcons() - No memory for stop bitmap\n"));
delete fStopIcon;
fStopIcon = NULL;
return;
}
// load stop icon bitmap from app_server
const uint8* stopVector
= (const uint8*)resources.LoadResource(B_VECTOR_ICON_TYPE, "stop",
&size);
if (stopVector == NULL
|| BIconUtils::GetVectorIcon(stopVector, size, fStopIcon)
!= B_OK) {
delete fStopIcon;
fStopIcon = NULL;
}
}
if (fWarnIcon == NULL) {
// Allocate the fWarnIcon bitmap
fWarnIcon = new (std::nothrow) BBitmap(BRect(0, 0, 15, 15), 0,
B_RGBA32);
if (fWarnIcon->InitCheck() != B_OK) {
FTRACE((stderr, "_FillIcons() - No memory for warn bitmap\n"));
delete fWarnIcon;
fWarnIcon = NULL;
return;
}
// load warn icon bitmap from app_server
const uint8* warnVector
= (const uint8*)resources.LoadResource(B_VECTOR_ICON_TYPE, "warn",
&size);
if (warnVector == NULL
|| BIconUtils::GetVectorIcon(warnVector, size, fWarnIcon)
!= B_OK) {
delete fWarnIcon;
fWarnIcon = NULL;
}
}
}
示例15: new
BBitmap*
BAlert::_InitIcon()
{
// Save the desired alert type and set it to "empty" until
// loading the icon was successful
alert_type alertType = fMsgType;
fMsgType = B_EMPTY_ALERT;
// After a bit of a search, I found the icons in app_server. =P
BBitmap* icon = NULL;
BPath path;
status_t status = find_directory(B_BEOS_SERVERS_DIRECTORY, &path);
if (status < B_OK) {
FTRACE((stderr, "BAlert::_InitIcon() - find_directory failed: %s\n",
strerror(status)));
return NULL;
}
path.Append("app_server");
BFile file;
status = file.SetTo(path.Path(), B_READ_ONLY);
if (status < B_OK) {
FTRACE((stderr, "BAlert::_InitIcon() - BFile init failed: %s\n",
strerror(status)));
return NULL;
}
BResources resources;
status = resources.SetTo(&file);
if (status < B_OK) {
FTRACE((stderr, "BAlert::_InitIcon() - BResources init failed: %s\n",
strerror(status)));
return NULL;
}
// Which icon are we trying to load?
const char* iconName = ""; // Don't want any seg faults
switch (alertType) {
case B_INFO_ALERT:
iconName = "info";
break;
case B_IDEA_ALERT:
iconName = "idea";
break;
case B_WARNING_ALERT:
iconName = "warn";
break;
case B_STOP_ALERT:
iconName = "stop";
break;
default:
// Alert type is either invalid or B_EMPTY_ALERT;
// either way, we're not going to load an icon
return NULL;
}
int32 iconSize = 32 * icon_layout_scale();
// Allocate the icon bitmap
icon = new(std::nothrow) BBitmap(BRect(0, 0, iconSize - 1, iconSize - 1),
0, B_RGBA32);
if (icon == NULL || icon->InitCheck() < B_OK) {
FTRACE((stderr, "BAlert::_InitIcon() - No memory for bitmap\n"));
delete icon;
return NULL;
}
// Load the raw icon data
size_t size = 0;
const uint8* rawIcon;
#ifdef __ANTARES__
// Try to load vector icon
rawIcon = (const uint8*)resources.LoadResource(B_VECTOR_ICON_TYPE,
iconName, &size);
if (rawIcon != NULL
&& BIconUtils::GetVectorIcon(rawIcon, size, icon) == B_OK) {
// We have an icon, restore the saved alert type
fMsgType = alertType;
return icon;
}
#endif
// Fall back to bitmap icon
rawIcon = (const uint8*)resources.LoadResource(B_LARGE_ICON_TYPE,
iconName, &size);
if (rawIcon == NULL) {
FTRACE((stderr, "BAlert::_InitIcon() - Icon resource not found\n"));
delete icon;
return NULL;
}
// Handle color space conversion
#ifdef __ANTARES__
if (icon->ColorSpace() != B_CMAP8) {
BIconUtils::ConvertFromCMAP8(rawIcon, iconSize, iconSize,
iconSize, icon);
}
#else
icon->SetBits(rawIcon, iconSize, 0, B_CMAP8);
//.........这里部分代码省略.........