本文整理汇总了C++中BPath::InitCheck方法的典型用法代码示例。如果您正苦于以下问题:C++ BPath::InitCheck方法的具体用法?C++ BPath::InitCheck怎么用?C++ BPath::InitCheck使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BPath
的用法示例。
在下文中一共展示了BPath::InitCheck方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetFile
status_t ArpConfigureFile::SetFile(const char* name)
{
ArpD(cdb << ADH << "ArpConfigureFile: setting file from path = "
<< name << endl);
BEntry entry(&mFile);
if( entry.InitCheck() != B_OK ) return entry.InitCheck();
BPath path;
status_t err = entry.GetPath(&path);
if( err != B_OK ) return err;
ArpD(cdb << ADH << "ArpConfigureFile: orig path = "
<< path << endl);
err = path.InitCheck();
if( err == B_OK ) err = path.GetParent(&path);
if( err == B_OK ) err = path.Append(name);
ArpD(cdb << ADH << "ArpConfigureFile: renamed path = "
<< path.Path() << endl);
if( err != B_OK ) return err;
entry.SetTo(path.Path());
err = entry.InitCheck();
if( err != B_OK ) return err;
entry_ref ref;
err = entry.GetRef(&ref);
if( err != B_OK ) return err;
return SetFile(ref);
}
示例2: testPath
void
DCCPrefsView::MessageReceived (BMessage *msg)
{
switch (msg->what)
{
case M_BLOCK_SIZE_CHANGED:
{
BMenuItem *it (NULL);
msg->FindPointer ("source", reinterpret_cast<void **>(&it));
if (it)
vision_app->SetString ("dccBlockSize", 0, it->Label());
}
break;
case M_DEFAULT_PATH_CHANGED:
{
const char *path (fDefDir->Text());
BPath testPath (path, NULL, true);
if (testPath.InitCheck() == B_OK)
vision_app->SetString ("dccDefPath", 0, path);
}
break;
case M_AUTO_ACCEPT_CHANGED:
{
int32 val (fAutoAccept->Value());
fDefDir->SetEnabled (val == B_CONTROL_ON);
vision_app->SetBool ("dccAutoAccept", val);
}
break;
case M_DCC_MIN_PORT_CHANGED:
{
const char *portMin (fDccPortMin->Text());
if (portMin != NULL)
vision_app->SetString ("dccMinPort", 0, portMin);
}
break;
case M_DCC_MAX_PORT_CHANGED:
{
const char *portMax (fDccPortMax->Text());
if (portMax != NULL)
vision_app->SetString ("dccMaxPort", 0, portMax);
}
break;
case M_DCC_PRIVATE_CHANGED:
{
vision_app->SetBool("dccPrivateCheck", fPrivateCheck->Value() == B_CONTROL_ON);
}
break;
default:
BView::MessageReceived (msg);
break;
}
}
示例3: AddDirectory
status_t ArpMultiDir::AddDirectory(const char* dir, const char* leaf)
{
BPath* path = new BPath(dir,leaf,true);
if( path ) {
if( path->InitCheck() != B_OK ) return path->InitCheck();
ArpD(cdb << ADH << "Adding directory: " << path->Path() << endl);
for( int32 i=0; i<dirs.CountItems(); i++ ) {
BPath* existing = (BPath*)(dirs.ItemAt(i));
if( existing && (*existing) == (*path) ) {
ArpD(cdb << ADH << "Already have it!" << endl);
delete path;
return B_OK;
}
}
if( !dirs.AddItem(path) ) return B_ERROR;
return B_OK;
}
return B_NO_MEMORY;
}
示例4: while
/*! \brief Creates all missing directories along a given path.
\param path the directory path name.
\param mode a permission specification, which shall be used for the
newly created directories.
\return
- \c B_OK: Everything went fine.
- \c B_BAD_VALUE: \c NULL \a path.
- \c B_ENTRY_NOT_FOUND: \a path does not refer to a possible entry.
- \c B_PERMISSION_DENIED: Directory permissions didn't allow operation.
- \c B_NO_MEMORY: Insufficient memory for operation.
- \c B_LINK_LIMIT: Indicates a cyclic loop within the file system.
- \c B_BUSY: A node was busy.
- \c B_FILE_ERROR: A general file error.
- \c B_NOT_A_DIRECTORY: An entry other than a directory with that name does
already exist.
- \c B_NO_MORE_FDS: The application has run out of file descriptors.
\todo Check for efficency.
*/
status_t
create_directory(const char* path, mode_t mode)
{
if (!path)
return B_BAD_VALUE;
// That's the strategy: We start with the first component of the supplied
// path, create a BPath object from it and successively add the following
// components. Each time we get a new path, we check, if the entry it
// refers to exists and is a directory. If it doesn't exist, we try
// to create it. This goes on, until we're done with the input path or
// an error occurs.
BPath dirPath;
char* component;
int32 nextComponent;
do {
// get the next path component
status_t error = BPrivate::Storage::parse_first_path_component(path,
component, nextComponent);
if (error != B_OK)
return error;
// append it to the BPath
if (dirPath.InitCheck() == B_NO_INIT) // first component
error = dirPath.SetTo(component);
else
error = dirPath.Append(component);
delete[] component;
if (error != B_OK)
return error;
path += nextComponent;
// create a BEntry from the BPath
BEntry entry;
error = entry.SetTo(dirPath.Path(), true);
if (error != B_OK)
return error;
// check, if it exists
if (entry.Exists()) {
// yep, it exists
if (!entry.IsDirectory()) // but is no directory
return B_NOT_A_DIRECTORY;
} else {
// it doesn't exist -- create it
error = _kern_create_dir(-1, dirPath.Path(), mode & ~__gUmask);
if (error != B_OK)
return error;
}
} while (nextComponent != 0);
return B_OK;
}
示例5: entry
status_t
BIconButton::SetIcon(const char* pathToBitmap)
{
if (pathToBitmap == NULL)
return B_BAD_VALUE;
status_t status = B_BAD_VALUE;
BBitmap* fileBitmap = NULL;
// try to load bitmap from either relative or absolute path
BEntry entry(pathToBitmap, true);
if (!entry.Exists()) {
app_info info;
status = be_app->GetAppInfo(&info);
if (status == B_OK) {
BEntry app_entry(&info.ref, true);
BPath path;
app_entry.GetPath(&path);
status = path.InitCheck();
if (status == B_OK) {
status = path.GetParent(&path);
if (status == B_OK) {
status = path.Append(pathToBitmap, true);
if (status == B_OK)
fileBitmap = BTranslationUtils::GetBitmap(path.Path());
else {
printf("BIconButton::SetIcon() - path.Append() failed: "
"%s\n", strerror(status));
}
} else {
printf("BIconButton::SetIcon() - path.GetParent() failed: "
"%s\n", strerror(status));
}
} else {
printf("BIconButton::SetIcon() - path.InitCheck() failed: "
"%s\n", strerror(status));
}
} else {
printf("BIconButton::SetIcon() - be_app->GetAppInfo() failed: "
"%s\n", strerror(status));
}
} else
fileBitmap = BTranslationUtils::GetBitmap(pathToBitmap);
if (fileBitmap) {
status = _MakeBitmaps(fileBitmap);
delete fileBitmap;
} else
status = B_ERROR;
return status;
}
示例6: SaveAliases
void VisionApp::SaveAliases(void)
{
BPath settingsPath;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &settingsPath) < B_OK) return;
settingsPath.Append(kAliasPathName);
if (settingsPath.InitCheck() < B_OK) return;
BFile file(settingsPath.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
if (file.InitCheck() == B_OK) {
for (map<BString, BString>::iterator it = fAliases.begin(); it != fAliases.end(); ++it) {
file.Write(it->first.String(), it->first.Length());
file.Write("\t", 1);
file.Write(it->second.String(), it->second.Length());
file.Write("\n", 1);
}
file.Unset();
}
}
示例7: BPath
BPath *
create_path(char *path)
{
BPath *pt;
if ((pt = new BPath(path)))
{
if (pt->InitCheck() == B_NO_ERROR)
{
return(pt);
}
delete pt;
}
return(NULL);
}
示例8: lock
status_t
TResourceSet::AddDirectory(const char* fullPath)
{
if (!fullPath)
return B_BAD_VALUE;
BPath* path = new BPath(fullPath);
status_t err = path->InitCheck();
if (err != B_OK) {
delete path;
return err;
}
BAutolock lock(&fLock);
err = fDirectories.AddItem(path) ? B_OK : B_ERROR;
if (err != B_OK)
delete path;
return err;
}
示例9:
uint32
FetchQuery(query_op op, const char* selection, vector<BString>& results,
bool caseSensitive = false)
{
BQuery query;
query.PushAttr("BEOS:TYPE");
query.PushString("application/x-vnd.Be-doc_bookmark");
query.PushOp(B_EQ);
query.PushAttr("name");
query.PushString(selection, caseSensitive);
query.PushOp(op);
query.PushOp(B_AND);
BVolume vol;
BVolumeRoster roster;
roster.GetBootVolume(&vol);
query.SetVolume(&vol);
if (B_NO_INIT == query.Fetch())
return 0;
BEntry entry;
BPath path;
int32 counter = 0;
while (query.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) {
if (entry.InitCheck() == B_OK) {
entry.GetPath(&path);
if (path.InitCheck() == B_OK) {
results.push_back(path.Path());
counter++;
}
}
}
return counter;
}
示例10:
void
CliWriteCoreFileCommand::Execute(int argc, const char* const* argv, CliContext& context)
{
BPath path;
if (argc > 1) {
path.SetTo(argv[1]);
if (path.InitCheck() != B_OK) {
printf("Invalid core file path %s given.\n", argv[1]);
return;
}
} else {
char buffer[B_FILE_NAME_LENGTH];
UiUtils::CoreFileNameForTeam(context.GetTeam(), buffer,
sizeof(buffer));
find_directory(B_DESKTOP_DIRECTORY, &path);
path.Append(buffer);
}
entry_ref ref;
if (get_ref_for_path(path.Path(), &ref) == B_OK) {
printf("Writing core file to %s...\n", path.Path());
context.GetUserInterfaceListener()->WriteCoreFileRequested(&ref);
}
}
示例11: LoadAliases
void VisionApp::LoadAliases(void)
{
BPath settingsPath;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &settingsPath) < B_OK) return;
settingsPath.Append(kAliasPathName);
if (settingsPath.InitCheck() < B_OK) return;
BFile file(settingsPath.Path(), B_READ_ONLY);
if (file.InitCheck() == B_OK) {
BString data;
char buffer[2048];
memset(buffer, 0, sizeof(buffer));
while (file.Read((void*)buffer, 2048) > 0) {
data += buffer;
memset(buffer, 0, sizeof(buffer));
}
file.Unset();
while (data.Length() > 0) {
BString cmd, value;
int32 idx = data.IFindFirst("\t");
if (idx != B_ERROR) {
data.MoveInto(cmd, 0, idx);
data.Remove(0, 1);
} else {
break;
}
idx = data.IFindFirst("\n");
if (idx != B_ERROR) {
data.MoveInto(value, 0, idx);
data.Remove(0, 1);
} else {
break;
}
fAliases[cmd.ToUpper()] = value;
}
}
}
示例12: BMessenger
/*! \brief Creates and initializes the file panels.
*
*/
void EventEditorMainWindow::InitializeFilePanels( BString path )
{
BPath eventualDirectoryPath;
BPath pathToFile;
bool initToDefaults = false;
BDirectory parentDirectory, eventualDirectory;
status_t status;
// Initializing from a submitted path
do {
if ( path != BString("") ) {
pathToFile.SetTo( path.String() );
if ( ( pathToFile.InitCheck() != B_OK ) ||
( pathToFile.GetParent( &eventualDirectoryPath ) != B_OK ) ||
( eventualDirectory.SetTo( eventualDirectoryPath.Path() ) != B_OK ) )
{
initToDefaults = true;
break; // Go to after "while"
}
}
else
{
initToDefaults = true;
}
} while ( false );
// Else, initialize to defaults
if ( initToDefaults )
{
find_directory( B_USER_DIRECTORY,
&eventualDirectoryPath,
true ); // Useless flag - system can't boot without "home"
parentDirectory.SetTo( eventualDirectoryPath.Path() );
status = parentDirectory.CreateDirectory( "events", &eventualDirectory );
if ( status == B_FILE_EXISTS ) {
eventualDirectory.SetTo( &parentDirectory, "events" );
status = eventualDirectory.InitCheck();
}
if ( status != B_OK )
{
global_toReturn = ( uint32 )status;
be_app->PostMessage( B_QUIT_REQUESTED );
}
} // <-- end of setting default directories
// At this point, eventualDirectory is set to the directory where files
// should be stored.
BEntry entry;
entry_ref ref;
eventualDirectory.GetEntry( &entry );
entry.GetRef( &ref );
// Construct file panels
fOpenFile = new BFilePanel( B_OPEN_PANEL,
new BMessenger( Looper(), this ),
&ref,
B_FILE_NODE,
false,
new BMessage( kFileOpenConfirmed ),
fRefFilter );
fSaveFile = new BFilePanel( B_SAVE_PANEL,
new BMessenger( Looper(), this ),
&ref,
B_FILE_NODE,
false,
new BMessage( kFileSaveConfirmed ),
fRefFilter );
entry.Unset();
if ( !fOpenFile || !fSaveFile ) {
global_toReturn = ( uint32 )B_NO_MEMORY;
be_app->PostMessage( B_QUIT_REQUESTED );
}
} // <-- end of function EventEditorMainWindow::InitializeFilePanels
示例13: ArgvReceived
void PApp::ArgvReceived(int32 argc, char **argv)
{
try
{
int i = 1, lineNr = -1;
char *p;
while (i < argc)
{
switch (argv[i][0])
{
case '-':
if (strcmp(argv[i], "-reload_worksheet") == 0)
{
PDoc *d = OpenWorksheet();
if (d && d->Lock())
d->Quit();
d = OpenWorksheet();
} else {
Usage();
}
break;
case '+':
lineNr = strtoul(argv[i] + 1, &p, 10) - 1;
if (!p || p == argv[i] + 1) Usage();
break;
default:
{
BPath path;
if (argv[i][0] == '/')
path.SetTo(argv[i]);
else
path.SetTo("/boot/home");
FailOSErr (path.InitCheck());
entry_ref doc;
CDocWindow *d;
FailOSErr (get_ref_for_path(path.Path(), &doc));
BEntry e;
FailOSErr(e.SetTo(&doc));
if (e.Exists())
d = dynamic_cast<CDocWindow*>(OpenWindow(doc));
else
{
d = NewWindow(NULL);
d->SetEntryRef(&doc);
}
if (d && lineNr >= 0)
{
BMessage m(msg_SelectLines);
m.AddInt32("from", lineNr);
m.AddInt32("to", lineNr - 1);
d->PostMessage(&m, d->PreferredHandler());
}
break;
}
}
i++;
}
}
catch (HErr& e)
{
e.DoError();
}
} /* PApp::ArgvReceived */
示例14: equals
// MakeLinkedPathTest
void
SymLinkTest::MakeLinkedPathTest()
{
const char *dirLink = dirLinkname;
const char *fileLink = fileLinkname;
const char *relDirLink = relDirLinkname;
const char *relFileLink = relFileLinkname;
const char *cyclicLink1 = cyclicLinkname1;
const char *cyclicLink2 = cyclicLinkname2;
const char *existingDir = existingDirname;
const char *existingSuperDir = existingSuperDirname;
const char *existingFile = existingFilename;
const char *existingSuperFile = existingSuperFilename;
const char *nonExisting = nonExistingDirname;
BSymLink link;
BPath path;
// 1. MakeLinkedPath(const char*, BPath*)
// uninitialized
NextSubTest();
CPPUNIT_ASSERT( link.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( equals(link.MakeLinkedPath("/boot", &path), B_BAD_ADDRESS,
B_FILE_ERROR) );
link.Unset();
path.Unset();
// existing absolute dir link
NextSubTest();
CPPUNIT_ASSERT( link.SetTo(dirLink) == B_OK );
CPPUNIT_ASSERT( link.MakeLinkedPath("/boot", &path)
== (ssize_t)strlen(existingDir) );
CPPUNIT_ASSERT( path.InitCheck() == B_OK );
CPPUNIT_ASSERT( string(existingDir) == path.Path() );
link.Unset();
path.Unset();
// existing absolute file link
NextSubTest();
CPPUNIT_ASSERT( link.SetTo(fileLink) == B_OK );
CPPUNIT_ASSERT( link.MakeLinkedPath("/boot", &path)
== (ssize_t)strlen(existingFile) );
CPPUNIT_ASSERT( path.InitCheck() == B_OK );
CPPUNIT_ASSERT( string(existingFile) == path.Path() );
link.Unset();
path.Unset();
// existing absolute cyclic link
NextSubTest();
CPPUNIT_ASSERT( link.SetTo(cyclicLink1) == B_OK );
CPPUNIT_ASSERT( link.MakeLinkedPath("/boot", &path)
== (ssize_t)strlen(cyclicLink2) );
CPPUNIT_ASSERT( path.InitCheck() == B_OK );
CPPUNIT_ASSERT( string(cyclicLink2) == path.Path() );
link.Unset();
path.Unset();
// existing relative dir link
NextSubTest();
BEntry entry;
BPath entryPath;
CPPUNIT_ASSERT( entry.SetTo(existingDir) == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&entryPath) == B_OK );
CPPUNIT_ASSERT( link.SetTo(relDirLink) == B_OK );
CPPUNIT_ASSERT( link.MakeLinkedPath(existingSuperDir, &path)
== (ssize_t)strlen(entryPath.Path()) );
CPPUNIT_ASSERT( path.InitCheck() == B_OK );
CPPUNIT_ASSERT( entryPath == path );
link.Unset();
path.Unset();
entry.Unset();
entryPath.Unset();
// existing relative file link
NextSubTest();
CPPUNIT_ASSERT( entry.SetTo(existingFile) == B_OK );
CPPUNIT_ASSERT( entry.GetPath(&entryPath) == B_OK );
CPPUNIT_ASSERT( link.SetTo(relFileLink) == B_OK );
CPPUNIT_ASSERT( link.MakeLinkedPath(existingSuperFile, &path)
== (ssize_t)strlen(entryPath.Path()) );
CPPUNIT_ASSERT( path.InitCheck() == B_OK );
CPPUNIT_ASSERT( entryPath == path );
link.Unset();
path.Unset();
entry.Unset();
entryPath.Unset();
// bad args
NextSubTest();
CPPUNIT_ASSERT( link.SetTo(dirLink) == B_OK );
// R5: crashs, when passing a NULL path
#if !TEST_R5
CPPUNIT_ASSERT( link.MakeLinkedPath("/boot", NULL) == B_BAD_VALUE );
#endif
CPPUNIT_ASSERT( link.MakeLinkedPath((const char*)NULL, &path)
== B_BAD_VALUE );
// R5: crashs, when passing a NULL path
#if !TEST_R5
CPPUNIT_ASSERT( link.MakeLinkedPath((const char*)NULL, NULL)
== B_BAD_VALUE );
#endif
link.Unset();
path.Unset();
// 2. MakeLinkedPath(const BDirectory*, BPath*)
// uninitialized
NextSubTest();
//.........这里部分代码省略.........
示例15: Show
//-------------------------------------------------------------------------
//
// Show - Display the file dialog
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval)
{
PRBool result = PR_TRUE;
nsFilePanelBeOS *ppanel;
file_panel_mode panel_mode;
bool allow_multiple_selection = false;
uint32 node_flavors;
if (mMode == modeGetFolder) {
node_flavors = B_DIRECTORY_NODE;
panel_mode = B_OPEN_PANEL;
}
else if (mMode == modeOpen) {
node_flavors = B_FILE_NODE;
panel_mode = B_OPEN_PANEL;
}
else if (mMode == modeOpenMultiple) {
node_flavors = B_FILE_NODE;
panel_mode = B_OPEN_PANEL;
allow_multiple_selection = true;
}
else if (mMode == modeSave) {
node_flavors = B_FILE_NODE;
panel_mode = B_SAVE_PANEL;
}
else {
printf("nsFilePicker::Show() wrong mode");
return PR_FALSE;
}
ppanel = new nsFilePanelBeOS(
panel_mode, //file_panel_mode mode
node_flavors, //uint32 node_flavors
allow_multiple_selection, //bool allow_multiple_selection
false, //bool modal
true //bool hide_when_done
);
if (!ppanel) return PR_FALSE;
// set title
if (!mTitle.IsEmpty()) {
char *title_utf8 = ToNewUTF8String(mTitle);
ppanel->Window()->SetTitle(title_utf8);
Recycle(title_utf8);
}
// set default text
if (!mDefault.IsEmpty()) {
char *defaultText = ToNewUTF8String(mDefault);
ppanel->SetSaveText(defaultText);
Recycle(defaultText);
}
// set initial directory
nsCAutoString initialDir;
if (mDisplayDirectory)
mDisplayDirectory->GetNativePath(initialDir);
if(initialDir.IsEmpty()) {
#ifdef FILEPICKER_SAVE_LAST_DIR
if (strlen(mLastUsedDirectory) < 2)
initialDir.Assign("/boot/home");
else
initialDir.Assign(mLastUsedDirectory);
#else
ppanel->SetPanelDirectory(initialDir.get());
#endif
}
#ifdef FILEPICKER_SAVE_LAST_DIR
ppanel->SetPanelDirectory(initialDir.get());
#endif
// set modal feel
if (ppanel->LockLooper()) {
ppanel->Window()->SetFeel(B_MODAL_APP_WINDOW_FEEL);
ppanel->UnlockLooper();
}
// Show File Panel
ppanel->Show();
ppanel->WaitForSelection();
if (ppanel->IsCancelSelected()) {
result = PR_FALSE;
}
if ((mMode == modeOpen || mMode == modeOpenMultiple || mMode == modeGetFolder) && ppanel->IsOpenSelected()) {
BList *list = ppanel->OpenRefs();
uint32 numfiles = list->CountItems();
if ((list) && numfiles >= 1) {
nsresult rv = NS_NewISupportsArray(getter_AddRefs(mFiles));
for (uint32 i = 0; i< numfiles; i++) {
BPath *path = (BPath *)list->ItemAt(i);
if (path->InitCheck() == B_OK) {
//.........这里部分代码省略.........