本文整理汇总了C++中BFile::InitCheck方法的典型用法代码示例。如果您正苦于以下问题:C++ BFile::InitCheck方法的具体用法?C++ BFile::InitCheck怎么用?C++ BFile::InitCheck使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BFile
的用法示例。
在下文中一共展示了BFile::InitCheck方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SniffRef
status_t AVIProducer::SniffRef( const entry_ref &file, char *outMimeType, float *outQuality)
{
status_t retVal = B_MEDIA_NO_HANDLER;
// Create a file from entry_ref
BFile *theFile = new BFile(&file, B_READ_ONLY);
if (theFile->InitCheck() == B_NO_ERROR){
if ( IsRIFFFile(theFile)){
// We like this file
retVal = B_OK;
// Set the MIME type
strcpy(outMimeType, "video/x-msvideo");
// Set quality and ID
*outQuality = 1.0;
}
}
// Clean up
delete theFile;
// Return result
return retVal;
}
示例2: Load
void Filters::Load()
{
status_t err;
// figure out where the file should be
BPath path;
err = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
if (err != B_NO_ERROR)
return;
path.Append(FileNames::filtersFileName);
// open the file
BFile* file = new BFile(path.Path(), B_READ_ONLY);
if (file->InitCheck() != B_NO_ERROR) {
delete file;
return;
}
// load the text
off_t fileSize;
file->GetSize(&fileSize);
char* text = new char[fileSize];
file->ReadAt(0, text, fileSize);
delete file;
// parse it
TextReader reader(string_slice(text, text + fileSize));
FilterGroup* curGroup = NULL;
while (!reader.AtEOF()) {
// get the groupName
string_slice groupName = reader.NextTabField();
if (groupName.length() > 0) {
curGroup = GetFilterGroup(groupName);
if (curGroup == NULL) {
curGroup = new FilterGroup(groupName);
AddFilterGroup(curGroup);
}
reader.NextLine();
}
// if none, this is a filter line (if it's not blank)
else {
string_slice filterLine = reader.NextLine();
if (filterLine.length() > 0 && curGroup != NULL) {
Filter* filter = new Filter();
TextReader lineReader(filterLine);
filter->ReadFrom(&lineReader);
curGroup->AddFilter(filter);
}
}
}
// clean up
delete text;
}
示例3: TaskToFile
status_t TaskFS::TaskToFile(Task *theTask, bool overwrite)
{
BFile taskFile;
BEntry entry;
status_t err;
TaskList *tskLst = theTask->GetTaskList();
BDirectory dir = BDirectory();
bool completed = theTask->IsCompleted();
uint32 priority = theTask->Priority();
time_t due = theTask->DueTime();
//first find directory.. then create files in this directory
if (tskLst!=NULL)
dir.SetTo(&tasksDir,tskLst->Name());
else
dir.SetTo(&tasksDir,".");
//first check if the File already exists..
//if not and overwrite is on check the ids..
// and search for the correspondending file...
if (dir.FindEntry(theTask->Title(),&entry) == B_OK) {
taskFile.SetTo((const BEntry*)&entry,B_READ_WRITE);
err = B_OK;
}
else {
entry_ref *ref= FileForId(theTask);
if (ref==NULL){
dir.CreateFile(theTask->Title(),&taskFile,overwrite);
dir.FindEntry(theTask->Title(),&entry);
}
else {
entry.SetTo(ref);
taskFile.SetTo((const BEntry*)ref,B_READ_WRITE);
}
}
if (taskFile.InitCheck() == B_OK){
taskFile.WriteAttr("META:completed",B_BOOL_TYPE, 0, &completed, sizeof(completed));
entry.Rename(theTask->Title());
taskFile.WriteAttrString("META:tasks",new BString(theTask->GetTaskList()->ID()));
taskFile.WriteAttrString("META:notes",new BString(theTask->Notes()));
taskFile.WriteAttr("META:priority", B_UINT32_TYPE, 0, &priority, sizeof(priority));
taskFile.WriteAttr("META:due", B_TIME_TYPE, 0, &due, sizeof(due));
taskFile.WriteAttrString("META:task_id", new BString(theTask->ID()));
taskFile.WriteAttrString("META:task_url",new BString(theTask->URL()));
}
else
err=B_ERROR;
return err;
}
示例4: prefdir
Preferences::~Preferences()
{
if (fSavePreferences) {
BFile file;
status_t set = B_ERROR;
if (fSettingsFile)
file.SetTo(fSettingsFile, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
else {
BPath prefpath;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &prefpath, true) == B_OK) {
BDirectory prefdir(prefpath.Path());
set = prefdir.CreateFile(fName, &file, false);
}
}
if (file.InitCheck () == B_OK) {
Flatten(&file);
if (fSignature) {
file.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0, fSignature,
strlen(fSignature) + 1);
}
} else {
// implement saving somewhere else!
BString error;
snprintf(error.LockBuffer(256), 256,
B_TRANSLATE("Your setting file could not be saved!\n(%s)"),
strerror(file.InitCheck()));
error.UnlockBuffer();
BAlert *alert = new BAlert(B_TRANSLATE("Error saving file"),
error.String(), B_TRANSLATE("Damned!"), NULL, NULL,
B_WIDTH_AS_USUAL, B_STOP_ALERT);
alert->SetShortcut(0, B_ESCAPE);
alert->Go();
}
}
delete fSettingsFile;
free(fName);
free(fSignature);
}
示例5: am_log_cstr
void am_log_cstr(const char* str)
{
BFile file;
if (!gLogged) {
gLogged = true;
file.SetTo(LOG_STR, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
} else {
file.SetTo(LOG_STR, B_WRITE_ONLY | B_CREATE_FILE | B_OPEN_AT_END);
}
if (file.InitCheck() != B_OK) return;
file.Write(str, strlen(str));
}
示例6: am_log_bstr
void am_log_bstr(BString& str)
{
BFile file;
if (!gLogged) {
gLogged = true;
file.SetTo(LOG_STR, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
} else {
file.SetTo(LOG_STR, B_WRITE_ONLY | B_CREATE_FILE | B_OPEN_AT_END);
}
if (file.InitCheck() != B_OK) return;
file.Write(str.String(), str.Length());
}
示例7:
static BFile *
get_file(BDataIO * data)
{
// try to cast to BFile then perform a series of
// sanity checks to ensure that the file is okay
BFile * file = dynamic_cast<BFile *>(data);
if (file == 0) {
return 0;
}
if (file->InitCheck() != B_OK) {
return 0;
}
return file;
}
示例8: BNodeInfo
void
TSigTextView::MessageReceived(BMessage *msg)
{
char type[B_FILE_NAME_LENGTH];
char *text;
int32 end;
int32 start;
BFile file;
BNodeInfo *node;
entry_ref ref;
off_t size;
switch (msg->what) {
case B_SIMPLE_DATA:
if (msg->HasRef("refs")) {
msg->FindRef("refs", &ref);
file.SetTo(&ref, O_RDONLY);
if (file.InitCheck() == B_NO_ERROR) {
node = new BNodeInfo(&file);
node->GetType(type);
delete node;
file.GetSize(&size);
if ((!strncasecmp(type, "text/", 5)) && (size)) {
text = (char *)malloc(size);
file.Read(text, size);
Delete();
GetSelection(&start, &end);
Insert(text, size);
Select(start, start + size);
free(text);
}
}
}
else
BTextView::MessageReceived(msg);
break;
case M_SELECT:
if (IsSelectable())
Select(0, TextLength());
break;
default:
BTextView::MessageReceived(msg);
}
}
示例9: BFile
void
TPeopleApp::RefsReceived(BMessage* message)
{
int32 index = 0;
while (message->HasRef("refs", index)) {
entry_ref ref;
message->FindRef("refs", index++, &ref);
PersonWindow* window = _FindWindow(ref);
if (window != NULL) {
window->Activate(true);
} else {
BFile* file = new BFile(&ref, B_READ_WRITE);
if (file->InitCheck() == B_OK)
_NewWindow(&ref, file);
}
}
}
示例10: Load
int Language::Load(const char* name) {
BFile *languageFile = new BFile (name, B_READ_ONLY);
if (languageFile->InitCheck() != B_OK) return B_ERROR;
for (int i = 0; i < L_MAX_LINES; i++) {
strcpy( lines[i], "");
char k = '.';
while (k != '\n') {
if (languageFile->Read(&k,1) != 1) return B_ERROR;
if (k != '\n' && k != '+') strncat(lines[i],&k,1);
if (k == '+') strncat(lines[i],"\n",1);
}
}
return B_OK;
}
示例11: BPopUpMenu
BPopUpMenu*
TPrefsWindow::_BuildSignatureMenu(char* sig)
{
char name[B_FILE_NAME_LENGTH];
BEntry entry;
BFile file;
BMenuItem* item;
BMessage* msg;
BQuery query;
BVolume vol;
BVolumeRoster volume;
BPopUpMenu* menu = new BPopUpMenu("");
msg = new BMessage(P_SIG);
msg->AddString("signature", B_TRANSLATE("None"));
menu->AddItem(item = new BMenuItem(B_TRANSLATE("None"), msg));
if (!strcmp(sig, B_TRANSLATE("None")))
item->SetMarked(true);
msg = new BMessage(P_SIG);
msg->AddString("signature", B_TRANSLATE("Random"));
menu->AddItem(item = new BMenuItem(B_TRANSLATE("Random"), msg));
if (!strcmp(sig, B_TRANSLATE("Random")))
item->SetMarked(true);
menu->AddSeparatorItem();
volume.GetBootVolume(&vol);
query.SetVolume(&vol);
query.SetPredicate("_signature = *");
query.Fetch();
while (query.GetNextEntry(&entry) == B_NO_ERROR) {
file.SetTo(&entry, O_RDONLY);
if (file.InitCheck() == B_NO_ERROR) {
msg = new BMessage(P_SIG);
file.ReadAttr("_signature", B_STRING_TYPE, 0, name, sizeof(name));
msg->AddString("signature", name);
menu->AddItem(item = new BMenuItem(name, msg));
if (!strcmp(sig, name))
item->SetMarked(true);
}
}
return menu;
}
示例12:
bool
WriteMessageDriverSettings(BFile& file, const BMessage& message)
{
if(file.InitCheck() != B_OK || !file.IsWritable())
return false;
file.SetSize(0);
file.Seek(0, SEEK_SET);
BMessage parameter;
for(int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index, ¶meter) == B_OK;
index++) {
if(index > 0)
file.Write("\n", 1);
WriteParameter(file, parameter, 0);
}
return true;
}
示例13: Include
void Include(const char *file)
{
BFile f;
const char **i = gIncludePaths;
char path[PATH_MAX];
do
{
strcpy(path, *i++);
strcat(path, "/");
strcat(path, file);
}
while (f.SetTo(path, B_READ_ONLY) != B_OK && *i);
if (f.InitCheck() != B_OK) error("Error opening file %s: %s", file, strerror(errno));
if (resFile)
resFile->MergeFrom(&f);
else
error("Should write to a resource file for Include to work!");
} // Include
示例14: m
status_t
PoorManWindow::SaveSettings()
{
BPath p;
BFile f;
BMessage m(MSG_PREF_FILE);
//site tab
m.AddString("fWebDirectory", fWebDirectory);
m.AddString("fIndexFileName", fIndexFileName);
m.AddBool("fDirListFlag", fDirListFlag);
//logging tab
m.AddBool("fLogConsoleFlag", fLogConsoleFlag);
m.AddBool("fLogFileFlag", fLogFileFlag);
m.AddString("fLogPath", fLogPath);
//advance tab
m.AddInt16("fMaxConnections", fMaxConnections);
//windows' position and size
m.AddRect("frame", fFrame);
m.AddRect("fSetwindowFrame", fSetwindowFrame);
m.AddBool("fIsZoomed", fIsZoomed);
m.AddFloat("fLastWidth", fLastWidth);
m.AddFloat("fLastHeight", fLastHeight);
if (find_directory(B_USER_SETTINGS_DIRECTORY, &p) != B_OK)
return B_ERROR;
p.Append(STR_SETTINGS_FILE_NAME);
f.SetTo(p.Path(), B_WRITE_ONLY | B_ERASE_FILE | B_CREATE_FILE);
if (f.InitCheck() != B_OK)
return B_ERROR;
if (m.Flatten(&f) != B_OK)
return B_ERROR;
return B_OK;
}
示例15: Save
void Filters::Save()
{
status_t err;
// figure out where to put it
BPath path;
err = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
if (err != B_NO_ERROR)
return;
path.Append(FileNames::filtersFileName);
// open the file
BFile* file = new BFile(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
if (file->InitCheck() != B_NO_ERROR)
return;
// write
WalkObjects(WriteFilterGroup, file);
// clean up
delete file;
}