本文整理汇总了C++中BFile类的典型用法代码示例。如果您正苦于以下问题:C++ BFile类的具体用法?C++ BFile怎么用?C++ BFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BFile类的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: rm_rf
/*
* Given a local directory, do the equivalent of `rm -rf`
* on it, but using the actual filesystem API.
* You can't just use dir->Remove() because that
* gives an error if the directory is not empty.
*/
void
rm_rf(BDirectory *dir)
{
status_t err;
BEntry entry;
err = dir->GetNextEntry(&entry);
while(err==B_OK)
{
BFile file = BFile(&entry, B_READ_ONLY);
if(file.IsDirectory())
{
BDirectory ndir = BDirectory(&entry);
rm_rf(&ndir);
}
err = entry.Remove();
if(err != B_OK)
{
BPath path;
entry.GetPath(&path);
printf("Remove Error: %s on %s\n",strerror(err),path.Path());
//what to do if I can't remove something?
}
err = dir->GetNextEntry(&entry);
}
err = dir->GetEntry(&entry);
err = entry.Remove();
if(err != B_OK)
printf("Folder Removal Error: %s\n", strerror(err));
}
示例3:
status_t
LocaleRosterData::_LoadTimeSettings()
{
BPath path;
BFile file;
status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
if (status == B_OK) {
path.Append("Time settings");
status = file.SetTo(path.Path(), B_READ_ONLY);
}
BMessage settings;
if (status == B_OK)
status = settings.Unflatten(&file);
if (status == B_OK) {
BString timeZoneID;
if (settings.FindString(kTimezoneField, &timeZoneID) == B_OK)
_SetDefaultTimeZone(BTimeZone(timeZoneID.String()));
else
_SetDefaultTimeZone(BTimeZone(BTimeZone::kNameOfGmtZone));
return B_OK;
}
// Something went wrong (no settings file or invalid BMessage), so we
// set everything to default values
_SetDefaultTimeZone(BTimeZone(BTimeZone::kNameOfGmtZone));
return status;
}
示例4: BResources
bool
BTheme::SetTheme(const char* theme)
{
BFile file;
fCurTheme.SetTo(&ThemesFolder,NULL);
fCurTheme.Append(theme);
if(fRes!=be_app->AppResources())delete fRes;
if(file.SetTo(fCurTheme.Path(), B_READ_ONLY)==B_OK)
{
fRes=new BResources(&file);
}
else
fRes=be_app->AppResources();
type_code typeFound;
int32 idFound;
const char *nameFound;
size_t lengthFound;
int n=0;
for(n=0;fRes->GetResourceInfo(n,&typeFound,&idFound,&nameFound,&lengthFound)==true;n++);
BmpListItem *anItem;
for(int32 i=0;fBmpList->ItemAt(i)!=NULL;i++) {
anItem=(BmpListItem*)fBmpList->ItemAt(i);
delete anItem;
}
delete fBmpList;
fBmpList=new BList(n+1);
return true;
}
示例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: BMessage
Emoconfig::Emoconfig(const char* xmlfile): BMessage()
{
fEmoticonSize = 16.0; //default
numfaces = 0;
fParser = XML_ParserCreate(NULL);
XML_SetUserData(fParser, this);
XML_SetElementHandler(fParser, StartElement, EndElement);
XML_SetCharacterDataHandler(fParser, Characters);
//path!
BPath p(xmlfile);
p.GetParent(&path);
// loading the config file..
BFile* settings = new BFile(xmlfile, B_READ_ONLY);
off_t size;
settings->GetSize(&size);
if (size) {
void* buffer = malloc((size_t)size);
size = settings->Read(buffer, (size_t)size);
XML_Parse(fParser, (const char*)buffer, (int)size, true);
free(buffer);
}
delete settings;
if (fParser)
XML_ParserFree(fParser);
printf("Emoconfig: loaded %d faces\n", numfaces);
}
示例7: sizeof
status_t
Settings::WriteSwapSettings()
{
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
return B_ERROR;
path.Append("kernel/drivers");
path.Append(kVirtualMemorySettings);
BFile file;
if (file.SetTo(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE)
!= B_OK)
return B_ERROR;
fs_info info;
if (fs_stat_dev(SwapVolume(), &info) != 0)
return B_ERROR;
char buffer[1024];
snprintf(buffer, sizeof(buffer), "vm %s\nswap_auto %s\nswap_size %"
B_PRIdOFF "\nswap_volume_name %s\nswap_volume_device %s\n"
"swap_volume_filesystem %s\nswap_volume_capacity %" B_PRIdOFF "\n",
SwapEnabled() ? "on" : "off", SwapAutomatic() ? "yes" : "no",
SwapSize(), info.volume_name, info.device_name, info.fsh_name,
info.total_blocks * info.block_size);
file.Write(buffer, strlen(buffer));
return B_OK;
}
示例8:
status_t
TermWindow::_LoadWindowPosition(BRect* frame, uint32* workspaces)
{
status_t status;
BMessage position;
BFile file;
status = _GetWindowPositionFile(&file, B_READ_ONLY);
if (status != B_OK)
return status;
status = position.Unflatten(&file);
file.Unset();
if (status != B_OK)
return status;
int32 id = fTerminalRoster.ID();
status = position.FindRect("rect", id, frame);
if (status != B_OK)
return status;
int32 _workspaces;
status = position.FindInt32("workspaces", id, &_workspaces);
if (status != B_OK)
return status;
if (modifiers() & B_SHIFT_KEY)
*workspaces = _workspaces;
else
*workspaces = B_CURRENT_WORKSPACE;
return B_OK;
}
示例9: create_app
// create_app
static
entry_ref
create_app(const char *filename, const char *signature,
bool install = false, bool makeExecutable = true,
uint32 appFlags = B_SINGLE_LAUNCH)
{
BString testApp;
CHK(find_test_app("RosterBroadcastTestApp1", &testApp) == B_OK);
system((string("cp ") + testApp.String() + " " + filename).c_str());
if (makeExecutable)
system((string("chmod a+x ") + filename).c_str());
BFile file;
CHK(file.SetTo(filename, B_READ_WRITE) == B_OK);
BAppFileInfo appFileInfo;
CHK(appFileInfo.SetTo(&file) == B_OK);
if (signature)
CHK(appFileInfo.SetSignature(signature) == B_OK);
CHK(appFileInfo.SetAppFlags(appFlags) == B_OK);
if (install && signature)
CHK(BMimeType(signature).Install() == B_OK);
// We write the signature into a separate attribute, just in case we
// decide to also test files without BEOS:APP_SIG attribute.
BString signatureString(signature);
file.WriteAttrString("signature", &signatureString);
return ref_for_path(filename);
}
示例10: SetBounceMsg
void MailingList::SetBounceMsg(std::string path)
{
//attempt to read the custom bounce message file
BFile bouncemsgbfile;
status_t bouncemsgfilestatus=bouncemsgbfile.SetTo(path.c_str(),B_READ_ONLY);
if (bouncemsgfilestatus==B_NO_ERROR)
{
off_t bytes; //size of file
if (bouncemsgbfile.GetSize(&bytes) == B_NO_ERROR)
{
char* buff = new char[bytes];
off_t bytesread=bouncemsgbfile.Read(buff,bytes);
if ( (bytesread > 0) && (bytesread < 50001) )
{
//file read ok
std::string oldbouncemsg=fUnauthorisedBounceMsgContents; //save generic bounce msg so it can be appended later
fUnauthorisedBounceMsgContents=""; //clear existing contents
for (int x=0; x < bytesread; x++)
{
fUnauthorisedBounceMsgContents=fUnauthorisedBounceMsgContents+buff[x];
}
fUnauthorisedBounceMsgContents=fUnauthorisedBounceMsgContents+"\n\n"+oldbouncemsg; //append generic msg
}
delete buff;
}
bouncemsgbfile.Unset(); //close file
}
}
示例11: PRINT
status_t
ZKWindow::SaveSettings (void)
{
PRINT(("ZKWindow::SaveSettings()\n"));
status_t status;
BMessage settings;
BPath path;
BFile file;
// add settings to message
settings.AddRect("winframe", Frame());
// get path to settings-file
if ((status = find_directory(B_USER_SETTINGS_DIRECTORY, & path)) != B_OK)
return status;
if ((status = path.SetTo(path.Path(),"Kirilla/ZooKeeper/settings")) != B_OK)
return status;
if ((status = file.SetTo(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE)) != B_OK)
return status;
if ((status = settings.Flatten(& file)) != B_OK)
return status;
return B_OK;
}
示例12: PRINT
AppWindow*
AppWindow::CreateWindow()
{
PRINT(("AppWindow::CreateWindow()\n"));
BPath path;
BFile settings;
BMessage archive;
AppWindow* win = 0;
find_directory(B_USER_SETTINGS_DIRECTORY,&path);
path.Append(PROJECT_DIR);
path.Append(APPLICATION_DIR);
path.Append(WINDOW_FILE);
if((settings.SetTo(path.Path(), B_READ_ONLY) == B_OK)
&& (archive.Unflatten(&settings) == B_OK))
{
win = new AppWindow(&archive);
}
else
{
win = new AppWindow();
}
return(win);
}
示例13: sizeof
Settings::~Settings()
{
// only save the settings if something has changed
if (!fUpdated)
return;
BFile file;
if (Open(&file, B_CREATE_FILE | B_WRITE_ONLY) != B_OK)
return;
disk_probe_settings settings;
settings.window_frame = fMessage.FindRect("window_frame");
#if B_HOST_IS_BENDIAN
// settings are saved in little endian
settings.window_frame.left = B_HOST_TO_LENDIAN_FLOAT(
settings.window_frame.left);
settings.window_frame.top = B_HOST_TO_LENDIAN_FLOAT(
settings.window_frame.top);
settings.window_frame.right = B_HOST_TO_LENDIAN_FLOAT(
settings.window_frame.right);
settings.window_frame.bottom = B_HOST_TO_LENDIAN_FLOAT(
settings.window_frame.bottom);
#endif
settings.base_type = B_HOST_TO_LENDIAN_INT32(
fMessage.FindInt32("base_type"));
settings.font_size = B_HOST_TO_LENDIAN_INT32(
int32(fMessage.FindFloat("font_size") + 0.5f));
settings.flags = B_HOST_TO_LENDIAN_INT32(
(fMessage.FindBool("case_sensitive") ? kCaseSensitive : 0)
| (fMessage.FindInt8("find_mode") == kHexMode ? kHexFindMode : 0));
file.Write(&settings, sizeof(settings));
}
示例14: new
bool
Model::_LoadHistory(BList& items) const
{
BFile file;
status_t status = _OpenFile(&file, PREFS_FILE);
if (status != B_OK)
return false;
status = file.Lock();
if (status != B_OK)
return false;
BMessage message;
status = message.Unflatten(&file);
if (status != B_OK)
return false;
file.Unlock();
BString string;
for (int32 x = 0; message.FindString("string", x, &string) == B_OK; x++) {
BString* copy = new (nothrow) BString(string);
if (copy == NULL || !items.AddItem(copy)) {
delete copy;
break;
}
}
return true;
}
示例15:
//
// TPreferences::~TPreferences
//
// Write the preferences to disk.
//
TPreferences::~TPreferences() {
BFile file;
if (file.SetTo(path.Path(), B_WRITE_ONLY | B_CREATE_FILE) == B_OK) {
Flatten(&file);
}
}