本文整理汇总了C++中BEntry::GetStat方法的典型用法代码示例。如果您正苦于以下问题:C++ BEntry::GetStat方法的具体用法?C++ BEntry::GetStat怎么用?C++ BEntry::GetStat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BEntry
的用法示例。
在下文中一共展示了BEntry::GetStat方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool
InitialIterator::GetNextName(char* buffer)
{
BEntry entry;
struct stat fileStat;
while (true) {
// Traverse the directory to get a new BEntry.
// _GetNextEntry returns false if there are no
// more entries, and we exit the loop.
if (!_GetNextEntry(entry))
return false;
// If the entry is a subdir, then add it to the
// list of directories and continue the loop.
// If the entry is a file and we can grep it
// (i.e. it is a text file), then we're done
// here. Otherwise, continue with the next entry.
if (entry.GetStat(&fileStat) == B_OK) {
if (S_ISDIR(fileStat.st_mode)) {
// subdir
_ExamineSubdir(entry);
} else {
// file or a (non-traversed) symbolic link
if (_ExamineFile(entry, buffer, fTextOnly))
return true;
}
}
}
}
示例2: GetDirectorySize
uint64 PanelView::GetDirectorySize(const char *path)
////////////////////////////////////////////////////////////////////////
{
uint64 size = 0;
BDirectory *dir;
dir = new BDirectory(path);
if (dir)
{
BEntry entry;
if (dir->GetEntry(&entry)==B_OK)
{
while (dir->GetNextEntry(&entry)==B_OK)
{
BPath path;
entry.GetPath(&path);
if (entry.IsDirectory())
size += GetDirectorySize(path.Path());
else
{
struct stat statbuf;
entry.GetStat(&statbuf);
size += statbuf.st_size;
}
}
}
delete dir;
}
return size;
}
示例3: dir
off_t
BackupView::DirectorySize(BPath* path, bool recurse)
{
off_t bytes = 0;
if (!path) {
printf("Error: Invalid path passed!\n");
return bytes;
}
//printf("%s: %s\n", __func__, path->Path());
BDirectory dir(path->Path());
int32 entries = dir.CountEntries();
//printf("%s: items: %" B_PRId32 "\n", __func__, entries);
dir.Rewind();
for (int32 i = 0; i < entries; i++) {
BEntry entry;
dir.GetNextEntry(&entry);
struct stat st;
entry.GetStat(&st);
if (S_ISDIR(st.st_mode) && recurse == true) {
BPath nextPath;
entry.GetPath(&nextPath);
bytes += DirectorySize(&nextPath);
} else {
bytes += st.st_size;
}
}
return bytes;
}
示例4: EvaluateRef
status_t TElementsSorter::EvaluateRef(entry_ref &ref)
{
struct stat st;
BEntry entry;
// Can we create a BEntry?
if (entry.SetTo(&ref, false) != B_OK)
return B_ERROR;
// Can we get a BStatable?
if (entry.GetStat(&st) != B_OK)
return B_ERROR;
// Is it a SymLink?
if (S_ISLNK(st.st_mode))
return HandleLink(ref, st);
// How about a File?
else if (S_ISREG(st.st_mode))
return HandleFile(ref, st);
// A Directory?
else if (S_ISDIR(st.st_mode)) {
BDirectory dir;
if (dir.SetTo(&ref) != B_OK)
return B_ERROR;
if (dir.IsRootDirectory())
return HandleVolume(ref, st, dir);
else
return HandleDirectory(ref, st, dir);
}
// No luck
return B_ERROR;
}
示例5: directory
void
NetServer::_ConfigureDevices(int socket, const char* startPath,
BMessage* suggestedInterface)
{
BDirectory directory(startPath);
BEntry entry;
while (directory.GetNextEntry(&entry) == B_OK) {
char name[B_FILE_NAME_LENGTH];
struct stat stat;
BPath path;
if (entry.GetName(name) != B_OK
|| !strcmp(name, "stack")
|| entry.GetPath(&path) != B_OK
|| entry.GetStat(&stat) != B_OK)
continue;
if (S_ISBLK(stat.st_mode) || S_ISCHR(stat.st_mode)) {
if (suggestedInterface != NULL
&& suggestedInterface->RemoveName("device") == B_OK
&& suggestedInterface->AddString("device", path.Path()) == B_OK
&& _ConfigureInterface(socket, *suggestedInterface) == B_OK)
suggestedInterface = NULL;
else
_ConfigureDevice(socket, path.Path());
} else if (entry.IsDirectory())
_ConfigureDevices(socket, path.Path(), suggestedInterface);
}
}
示例6: result
filter_result
DCCFileFilter::HandleButton (BMessage *)
{
filter_result result (B_DISPATCH_MESSAGE);
BTextControl *paneltext (dynamic_cast<BTextControl *>(
panel->Window()->FindView ("text view")));
if (paneltext)
{
BDirectory dir;
struct stat s;
entry_ref ref;
BEntry entry;
panel->GetPanelDirectory (&ref);
dir.SetTo (&ref);
if (entry.SetTo (&dir, paneltext->Text()) == B_NO_ERROR
&& entry.GetStat (&s) == B_NO_ERROR
&& S_ISREG (s.st_mode))
{
if (vision_app->GetBool ("dccAutoAccept"))
{
BMessage msg (M_FILE_PANEL_ALERT);
msg.AddInt32 ("which", 2);
panel->Window()->PostMessage (&msg);
result = B_SKIP_MESSAGE;
}
else
{
BString buffer;
BAlert *alert;
buffer << "The file \""
<< paneltext->Text()
<< "\" already exists in the specified folder. "
"Do you want to continue the transfer?";
alert = new BAlert (
"DCC Request",
buffer.String(),
"Cancel",
"Replace",
"Resume",
B_WIDTH_AS_USUAL,
B_OFFSET_SPACING,
B_WARNING_ALERT);
alert->Go (new BInvoker (
new BMessage (M_FILE_PANEL_ALERT),
panel->Window()));
result = B_SKIP_MESSAGE;
}
}
}
return result;
}
示例7: path
status_t
FontManager::_AddPath(BEntry& entry, font_directory** _newDirectory)
{
node_ref nodeRef;
status_t status = entry.GetNodeRef(&nodeRef);
if (status != B_OK)
return status;
// check if we are already know this directory
font_directory* directory = _FindDirectory(nodeRef);
if (directory != NULL) {
if (_newDirectory)
*_newDirectory = directory;
return B_OK;
}
// it's a new one, so let's add it
directory = new (std::nothrow) font_directory;
if (directory == NULL)
return B_NO_MEMORY;
struct stat stat;
status = entry.GetStat(&stat);
if (status != B_OK) {
delete directory;
return status;
}
directory->directory = nodeRef;
directory->user = stat.st_uid;
directory->group = stat.st_gid;
directory->revision = 0;
status = watch_node(&nodeRef, B_WATCH_DIRECTORY, this);
if (status != B_OK) {
// we cannot watch this directory - while this is unfortunate,
// it's not a critical error
printf("could not watch directory %ld:%Ld\n", nodeRef.device,
nodeRef.node);
// TODO: should go into syslog()
} else {
BPath path(&entry);
FTRACE(("FontManager: now watching: %s\n", path.Path()));
}
fDirectories.AddItem(directory);
if (_newDirectory)
*_newDirectory = directory;
fScanned = false;
return B_OK;
}
示例8: file
/***********************************************************
* RefreshAllCaches
***********************************************************/
void
HDaemonApp::RefreshAllCaches()
{
// Refresh folders structure cache
BPath path;
entry_ref foldersCacheRef;
::find_directory(B_USER_SETTINGS_DIRECTORY,&path);
path.Append("Scooby");
path.Append("Folders.cache");
::get_ref_for_path(path.Path(),&foldersCacheRef);
BFile file(&foldersCacheRef,B_WRITE_ONLY|B_CREATE_FILE);
if(file.InitCheck() == B_OK)
{
BMessage foldersCache;
foldersCache.Unflatten(&file);
int32 count;
type_code type;
entry_ref ref;
BEntry entry;
struct stat st;
time_t oldtime;
foldersCache.GetInfo("refs",&type,&count);
for(int32 i = 0;i < count;i++)
{
if(foldersCache.FindRef("refs",i,&ref) != B_OK)
continue;
if(entry.SetTo(&ref) != B_OK)
continue;
foldersCache.FindInt32("time",i,&oldtime);
entry.GetStat(&st);
if(st.st_mtime != oldtime)
foldersCache.ReplaceInt32("time",i,st.st_mtime);
}
file.Seek(0,SEEK_SET);
foldersCache.Flatten(&file);
}
// Refresh mail caches
int32 count = fNewMailList.CountItems();
entry_ref ref;
BEntry *entry;
for(int32 i = 0;i < count;i++)
{
entry = (BEntry*)fNewMailList.ItemAt(i);
if(!entry)
continue;
entry->GetRef(&ref);
RefreshMailCache(ref);
}
}
示例9: EvaluateRef
status_t TQueueDialog::EvaluateRef(entry_ref &ref)
{
struct stat st;
BEntry entry;
// Can we create a BEntry?
if (entry.SetTo(&ref, false) != B_OK)
{
ERROR("TQueueDialog::HandleRefsMessage() - BEntry SetTo() failure -\n");
return B_ERROR;
}
// Can we get a BStatable?
if (entry.GetStat(&st) != B_OK)
{
ERROR("TQueueDialog::HandleRefsMessage() - BEntry GetStat() failure -\n");
return B_ERROR;
}
// Is it a SymLink?
if (S_ISLNK(st.st_mode))
return HandleLink(ref, st);
// How about a File?
else if (S_ISREG(st.st_mode))
return HandleFile(ref, st);
// A Directory?
else if (S_ISDIR(st.st_mode))
{
BDirectory dir;
if (dir.SetTo(&ref) != B_OK)
{
return B_ERROR;
}
if (dir.IsRootDirectory())
return HandleVolume(ref, st, dir);
else
return HandleDirectory(ref, st, dir);
}
// No luck
return B_ERROR;
}
示例10: HandleDirectory
//---------------------------------------------------------------------
// HandleDirectory
//---------------------------------------------------------------------
// iterate through the directory and pass the resulting
// refs and attempt to add the resulting file
//
status_t TQueueDialog::HandleDirectory(entry_ref &ref, struct stat &st, BDirectory &dir)
{
struct stat s;
BEntry entry;
dir.Rewind();
while (true)
{
if (dir.GetNextEntry(&entry) == B_OK)
{
entry.GetStat(&s);
entry_ref eRef;
entry.GetRef(&eRef);
// HandleFile(eRef, s);
EvaluateRef(eRef);
} else
break;
}
return B_ERROR;
}
示例11: if
CustomListItem *PanelView::AddDirectoryEntry(BEntry *entry, bool sorted)
////////////////////////////////////////////////////////////////////////
{
CustomListItem *item;
char name[B_FILE_NAME_LENGTH];
entry->GetName(name);
if (entry->IsDirectory())
{
item = new CustomListItem(name,m_Path.String(),FT_DIRECTORY, 0, this);
if (sorted)
m_CustomListView->AddSortedItem(item);
else
m_CustomListView->AddItem(item);
if (m_Setting_ShowIcons)
{
if (!item->GetIcon(entry))
item->AddIcon(m_UnknownIcon);
item->SetHeight(15.0f);
}
}
else if (entry->IsSymLink())
{
BEntry symlinkentry;
entry_ref ref;
struct stat statbuf;
entry->GetRef(&ref);
if (symlinkentry.SetTo(&ref, true)==B_OK)
{
if (symlinkentry.IsDirectory())
{
item = new CustomListItem(name,m_Path.String(),FT_SYMLINKDIR, 0, this);
if (sorted)
m_CustomListView->AddSortedItem(item);
else
m_CustomListView->AddItem(item);
if (m_Setting_ShowIcons)
{
if (!item->GetIcon(&symlinkentry))
item->AddIcon(m_UnknownIcon);
item->SetHeight(15.0f);
}
}
else
{
symlinkentry.GetStat(&statbuf);
item = new CustomListItem(name,m_Path.String(),FT_SYMLINKFILE,statbuf.st_size, this);
if (sorted)
m_CustomListView->AddSortedItem(item);
else
m_CustomListView->AddItem(item);
if (m_Setting_ShowIcons)
{
if (!item->GetIcon(&symlinkentry))
item->AddIcon(m_UnknownIcon);
item->SetHeight(15.0f);
}
}
}
else
{
// Broken link...
item = new CustomListItem(name, m_Path.String(), FT_SYMLINKBROKEN, 0 , this);
if (sorted)
m_CustomListView->AddSortedItem(item);
else
m_CustomListView->AddItem(item);
if (m_Setting_ShowIcons)
{
if (!item->GetIcon(entry))
item->AddIcon(m_UnknownIcon);
item->SetHeight(15.0f);
}
}
}
else
{
struct stat statbuf;
entry->GetStat(&statbuf);
item = new CustomListItem(name,m_Path.String(),FT_FILE,statbuf.st_size, this);
if (sorted)
m_CustomListView->AddSortedItem(item);
else
m_CustomListView->AddItem(item);
if (m_Setting_ShowIcons)
{
if (!item->GetIcon(entry))
item->AddIcon(m_UnknownIcon);
item->SetHeight(15.0f);
}
}
return item;
}
示例12: file
Shisen::Shisen():
BApplication("application/x-vnd.KWS-BShisen")
{
system_info info;
union split sp;
app_info app;
#ifdef USE_YLANGUAGE
Language.SetName("English");
if (Language.InitCheck() != B_OK)
printf("error loading language file (English\n");
BuildLanguageList();
#endif
REGISTERED = false;
NAG = false;
get_system_info(&info);get_system_info(&info);
// if (info.id[0] && info.id[1]) // P3 ?
// {
// sp.i32[0] = info.id[0];
// sp.i32[1] = info.id[1];
KEY = sp.i64;
// }
// else // make a KEY from the CPU TYPE & the speed
// {
// KEY = info.cpu_clock_speed;
// KEY |= info.cpu_revision;
// }
// sanity check
if (!KEY) KEY = 0xbebebebe;
//printf("key is %lx\n", KEY);
/*
* 1) Check the creation time
* 2) Check the last accessed time
* 3) subtract
* if > 3 days, nag++
*/
// check ~/config/settings/BShisen_prefs
BPath path;
BEntry entry;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK
&& path.Append(PREFS_FILE_NAME, true) == B_OK
&& entry.SetTo(path.Path(), true) == B_OK)
{
time_t t_t = 0;
time_t c_t;
if (entry.GetCreationTime(&c_t) == B_OK)
{
//ok, file exists. Check the creation date & see if it was > 7 days ago
t_t = (time_t)real_time_clock();
if (t_t > c_t)
{
t_t -= c_t;
// t_t == # of secs between when file was created & now
if (t_t > 7 * 24 * 60 * 60) NAG = true;
}
}
}
#if 0
if (GetAppInfo(&app) == B_OK)
{
BEntry entry;
struct stat st;
time_t t_t;
entry.SetTo(&app.ref, true);
entry.GetStat(&st);
t_t = st.st_atime - st.st_ctime;
if (t_t > 5 * 24 * 60 * 60)
NAG = true;
}
#endif
game = new GameWindow;
game->Show();
}
示例13: parser
// main
int
main(int argc, const char *const *argv)
{
kArgc = argc;
kArgv = argv;
if (argc < 2)
print_usage_and_exit(true);
// parameters
const char **files = new const char*[argc];
int fileCount = 0;
bool dryRun = false;
off_t startOffset = 0;
// parse arguments
for (int argi = 1; argi < argc;) {
const char *arg = argv[argi++];
if (arg[0] == '-') {
if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
print_usage_and_exit(false);
} else if (strcmp(arg, "--dry-run") == 0) {
dryRun = true;
} else if (strcmp(arg, "-alert") == 0) {
// ignore
} else if (strcmp(arg, "-full") == 0) {
// ignore
} else if (strcmp(arg, "--start-offset") == 0) {
if (argi >= argc)
print_usage_and_exit(true);
startOffset = strtoll(argv[argi++], NULL, 0);
} else if (strcmp(arg, "-safe") == 0) {
fprintf(stderr, "Error: Sorry, BeOS R3 isn't supported!\n");
exit(1);
} else {
print_usage_and_exit(true);
}
} else {
files[fileCount++] = arg;
}
}
// we need at least one file
if (fileCount == 0)
print_usage_and_exit(true);
// read the boot code
uint8 *bootCodeData = NULL;
#ifndef __ANTARES__
bootCodeData = read_boot_code_data(argv[0]);
#else
image_info info;
if (find_own_image(&info) == B_OK)
bootCodeData = read_boot_code_data(info.name);
#endif
if (!bootCodeData) {
fprintf(stderr, "Error: Failed to read \n");
exit(1);
}
// iterate through the files and make them bootable
status_t error;
for (int i = 0; i < fileCount; i++) {
const char *fileName = files[i];
BEntry entry;
error = entry.SetTo(fileName, true);
if (error != B_OK) {
fprintf(stderr, "Error: Failed to open \"%s\": %s\n",
fileName, strerror(error));
exit(1);
}
// get stat to check the type of the file
struct stat st;
error = entry.GetStat(&st);
if (error != B_OK) {
fprintf(stderr, "Error: Failed to stat \"%s\": %s\n",
fileName, strerror(error));
exit(1);
}
bool noPartition = false;
int64 partitionOffset = 0;
fs_info info; // needs to be here (we use the device name later)
if (S_ISDIR(st.st_mode)) {
#if defined(__BEOS__) || defined(__ANTARES__)
// a directory: get the device
error = fs_stat_dev(st.st_dev, &info);
if (error != B_OK) {
fprintf(stderr, "Error: Failed to determine device for "
"\"%s\": %s\n", fileName, strerror(error));
exit(1);
}
fileName = info.device_name;
//.........这里部分代码省略.........
示例14: CopyLink
bool GenesisCopyWindow::CopyLink(const char *linkname, const char *destination, const char *destfilename)
////////////////////////////////////////////////////////////////////////
{
BSymLink srclink;
BSymLink dstlink;
BDirectory dstdir;
BEntry srcentry;
BEntry symlinkentry;
BPath LinkPath;
char name[B_FILE_NAME_LENGTH];
struct stat statbuf;
entry_ref ref;
srcentry.SetTo(linkname);
srcentry.GetName(name);
srcentry.GetRef(&ref);
symlinkentry.SetTo(&ref, true);
symlinkentry.GetPath(&LinkPath);
if (destfilename)
sprintf(name,"%s",destfilename);
if (srcentry.GetStat(&statbuf)!=B_OK)
return false;
dstdir.SetTo(destination);
if (dstdir.InitCheck()!=B_OK)
return false;
Lock();
m_FileBar->Update(-m_FileBar->CurrentValue()); // Reset to 0.0
m_FileBar->SetMaxValue(1);
m_FileBar->SetTrailingText(name);
Unlock();
if (dstdir.CreateSymLink(name, LinkPath.Path(), &dstlink)!=B_OK && !m_SkipSymLinkCreationError)
{
BString text;
text << "Cannot create '" << name << "' symbolic link in '" << LinkPath.Path() << "'";
BAlert *myAlert = new BAlert("Copy",text.String(),"Abort","Skip all","Skip",B_WIDTH_AS_USUAL,B_OFFSET_SPACING,B_WARNING_ALERT);
myAlert->SetShortcut(0, B_ESCAPE);
switch (myAlert->Go())
{
case 0:
Close();
kill_thread(m_CopyThread);
break;
case 1:
m_SkipSymLinkCreationError = true;
break;
}
return false;
}
Lock();
m_FileBar->Update(1);
Unlock();
dstlink.SetPermissions(statbuf.st_mode);
dstlink.SetOwner(statbuf.st_uid);
dstlink.SetGroup(statbuf.st_gid);
dstlink.SetModificationTime(statbuf.st_mtime);
dstlink.SetCreationTime(statbuf.st_crtime);
// Copy attributes...
BString destlinkname;
destlinkname.SetTo("");
destlinkname << destination << "/" << name;
CopyAttr(linkname, destlinkname.String());
return true;
}