示例#1
0
entry_ref
SourceTypeC::CreateSourceFile(const char *dir, const char *name, uint32 options)
{
	if (!dir || !name)
		return entry_ref();
	
	BString folderstr(dir);
	if (folderstr.ByteAt(folderstr.CountChars() - 1) != '/')
		folderstr << "/";
	
	DPath folder(folderstr.String()), filename(name);
	
	bool is_cpp = false;
	bool is_header = false;
	bool create_pair = ((options & SOURCEFILE_PAIR) != 0);
	
	BString ext = filename.GetExtension();
	if ( (ext.ICompare("cpp") == 0) || (ext.ICompare("c") == 0) ||
		(ext.ICompare("cxx") == 0) || (ext.ICompare("cc") == 0) )
		is_cpp = true;
	else if ((ext.ICompare("h") == 0) || (ext.ICompare("hxx") == 0) ||
			(ext.ICompare("hpp") == 0) || (ext.ICompare("h++") == 0))
		is_header = true;
	
	if (!is_cpp && !is_header)
		return entry_ref();
	
	BString sourceName, headerName;
	if (is_cpp)
	{
		sourceName = filename.GetFileName();
		headerName = filename.GetBaseName();
		headerName << ".h";
	}
	else
	{
		sourceName = filename.GetBaseName();
		sourceName << ".cpp";
		headerName = filename.GetFileName();
	}
		
	
	entry_ref sourceRef, headerRef;
	BString data;
	if (is_cpp || create_pair)
	{
		if (create_pair)
			data << "#include \"" << headerName << "\"\n\n";
		
		sourceRef = MakeProjectFile(folder.GetFullPath(),sourceName.String(),data.String());
	}
	
	if (is_header || create_pair)
	{
		data = MakeHeaderGuard(headerName.String());
		headerRef = MakeProjectFile(folder.GetFullPath(),headerName.String(),data.String());
	}
	
	return is_cpp ? sourceRef : headerRef;
}
示例#2
0
entry_ref
SourceTypeShell::CreateSourceFile(const char *dir, const char *name, uint32 options)
{
	if (!dir || !name)
		return entry_ref();
	
	BString folderstr(dir);
	if (folderstr.ByteAt(folderstr.CountChars() - 1) != '/')
		folderstr << "/";
	
	DPath folder(folderstr.String()), filename(name);
	
	BString ext = filename.GetExtension();
	if (ext.ICompare("sh") != 0)
		return entry_ref();
	
	BString fileData = "#!/bin/sh\n\n";
	entry_ref outRef = MakeProjectFile(folder, filename.GetFileName(),
							fileData.String(), "text/x-source-code");
	BFile file(&outRef, B_READ_WRITE);
	if (file.InitCheck() == B_OK)
	{
		mode_t perms;
		file.GetPermissions(&perms);
		file.SetPermissions(perms | S_IXUSR | S_IXGRP);
	}
	
	return outRef;
}
示例#3
0
status_t ArpConfigureFile::StartWatcher(void)
{
    StopWatcher();

    ArpD(cdb << ADH << "Starting watcher..." << endl);
    if( mFile != entry_ref() && mWatcher.IsValid() ) {
        ArpD(cdb << ADH << "On file: " << Path().Path() << endl);
        BEntry entry(&mFile);
        if( entry.InitCheck() != B_OK ) return entry.InitCheck();
        status_t err = entry.GetNodeRef(&mNode);
        if( err != B_OK ) return err;

        BLooper* looper=0;
        mWatcher.Target(&looper);
        ArpD(cdb << ADH << "Target is: " << looper << endl);
        if( looper == 0 ) {
            mNode = node_ref();
            return B_ERROR;
        }

        looper->AddHandler(this);

        err = watch_node(&mNode, B_WATCH_ALL, this);
        ArpD(cdb << ADH << "Result from watch_node(): " << err << endl);
        if( err != B_OK ) {
            looper->RemoveHandler(this);
            mNode = node_ref();
            return err;
        }
    }

    return B_OK;
}
示例#4
0
status_t ArpConfigureFile::WriteSettings(const BMessage* from) const
{
    if( from == 0 ) return B_BAD_VALUE;

    ArpD(cdb << ADH << "ArpConfigureFile: Writing settings with BMessage: "
         << *from << endl);

    if( mFile == entry_ref() ) return B_NO_INIT;

    status_t err;

    // We seem to need to force any symbolic link to be resolved --
    // otherwise, the BFile.Flatten() fails.
    BEntry entry(&mFile, true);

    BFile file(&entry, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
    err = file.InitCheck();
    ArpD(cdb << ADH << "Result from creating file: " << err << endl);
    if( err ) return err;

    if( (err=from->Flatten(&file)) ) return err;

    ArpD(cdb << ADH << "Result from writing settings: " << err << endl);

    if( mMimeType != "" ) {
        ArpD(cdb << ADH << "Writing MIME type: " << MimeType() << endl);
        BNodeInfo info(&file);
        if( (err=info.InitCheck()) ) return err;
        err = info.SetType(mMimeType.String());
        ArpD(cdb << ADH << "Result from writing mime type: " << err << endl);
        if( err ) return err;
    }

    return err;
}
示例#5
0
/*!	Unlike GetNextDirents() this method ignores the entries "." and "..".
	\param ref a pointer to an entry_ref to be filled in with the data of the
		   found entry
	\param traverse specifies whether to follow it, if the found entry
		   is a symbolic link.
	\note The iterator used be this method is the same one used by
		  GetNextEntry(), GetNextDirents(), Rewind() and CountEntries().
	\return
	- \c B_OK: Everything went fine.
	- \c B_BAD_VALUE: \c NULL \a ref.
	- \c B_ENTRY_NOT_FOUND: No more entries found.
	- \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_NO_MORE_FDS: The application has run out of file descriptors.
*/
status_t
BDirectory::GetNextRef(entry_ref *ref)
{
	status_t error = (ref ? B_OK : B_BAD_VALUE);
	if (error == B_OK && InitCheck() != B_OK)
		error = B_FILE_ERROR;
	if (error == B_OK) {
		BPrivate::Storage::LongDirEntry entry;
		bool next = true;
		while (error == B_OK && next) {
			if (BPrivate::Storage::read_dir(fDirFd, &entry, sizeof(entry), 1) != 1)
				error = B_ENTRY_NOT_FOUND;
			if (error == B_OK) {
				next = (!strcmp(entry.d_name, ".")
						|| !strcmp(entry.d_name, ".."));
			}
		}
		if (error == B_OK) {
#if 0
			*ref = entry_ref(entry.d_dev, entry.d_ino, entry.d_name);
#endif
		}
	}
	return error;
}
示例#6
0
BPath ArpConfigureFile::Path() const
{
    BPath path;
    if( mFile != entry_ref() ) {
        BEntry entry(&mFile);
        if( entry.InitCheck() == B_OK ) entry.GetPath(&path);
    }
    return path;
}
示例#7
0
FilePlaylistItem::FilePlaylistItem(const BMessage* archive)
	:
	fRef(),
	fNameInTrash("")
{
	const char* path;
	if (archive != NULL && archive->FindString(kPathKey, &path) == B_OK) {
		if (get_ref_for_path(path, &fRef) != B_OK)
			fRef = entry_ref();
	}
}
示例#8
0
status_t ArpConfigureFile::ReadSettings(BMessage* to) const
{
    if( to == 0 ) return B_BAD_VALUE;

    if( mFile == entry_ref() ) return B_NO_INIT;

    status_t err;
    BFile file(&mFile, B_READ_ONLY);
    if( (err=file.InitCheck()) ) return err;

    if( (err=to->Unflatten(&file)) ) return err;

    return err;
}
示例#9
0
void 
MediaFileInfoView::Update(BMediaFile* file, entry_ref* ref)
{
	if (fMediaFile == file)
		return;

	fMediaFile = file;

	if (file != NULL && ref != NULL)
		fRef = *ref;
	else
		fRef = entry_ref();

	Invalidate();
}
示例#10
0
void
DecorInfo::Unset()
{
	fRef = entry_ref();
	fPath = "";
	fName = "";
	fAuthors = "";
	fShortDescription = "";
	fLicenseURL = "";
	fLicenseName = "";
	fSupportURL = "";
	fVersion = 0;
	fModificationTime = 0;
	fInitStatus = B_NO_INIT;
}
示例#11
0
文件: MainApp.cpp 项目: DonCN/haiku
void
MainApp::_ShowFilePanel(BFilePanel* panel, uint32 command,
	const BMessage* message, const char* defaultTitle,
	const char* defaultLabel)
{
//	printf("_ShowFilePanel()\n");
//	message->PrintToStream();

	BMessage panelMessage(command);

	if (message != NULL) {
		BMessage targetMessage;
		if (message->FindMessage("message", &targetMessage) == B_OK)
			panelMessage.AddMessage("message", &targetMessage);

		BMessenger target;
		if (message->FindMessenger("target", &target) == B_OK)
			panelMessage.AddMessenger("target", target);

		const char* panelTitle;
		if (message->FindString("title", &panelTitle) != B_OK)
			panelTitle = defaultTitle;
		{
			BString finalPanelTitle = "MediaPlayer: ";
			finalPanelTitle << panelTitle;
			BAutolock lock(panel->Window());
			panel->Window()->SetTitle(finalPanelTitle.String());
		}
		const char* buttonLabel;
		if (message->FindString("label", &buttonLabel) != B_OK)
			buttonLabel = defaultLabel;
		panel->SetButtonLabel(B_DEFAULT_BUTTON, buttonLabel);
	}

//	panelMessage.PrintToStream();
	panel->SetMessage(&panelMessage);

	if (fLastFilePanelFolder != entry_ref()) {
		panel->SetPanelDirectory(&fLastFilePanelFolder);
	}

	panel->Show();
}
示例#12
0
FilePlaylistItem::FilePlaylistItem(const BMessage* archive)
{
	const char* path;
	entry_ref	ref;
	if (archive != NULL) {
		int32 i = 0;
		while (archive->FindString(kPathKey, i, &path) == B_OK) {
			if (get_ref_for_path(path, &ref) == B_OK) {
				fRefs.push_back(ref);
			}
			i++;
		}
	}
	if (fRefs.empty()) {
		fRefs.push_back(entry_ref());
	}
	for (vector<entry_ref>::size_type i = 0; i < fRefs.size(); i++) {
		fNamesInTrash.push_back("");
	}
}
示例#13
0
entry_ref
Settings::FilePanelFolder() const
{
	BAutolock locker(const_cast<Settings*>(this));
	return fSettingsMessage.GetValue("filePanelDirectory", entry_ref());
}
bool
TemplatesMenu::BuildMenu(bool addItems)
{
	// Clear everything...
	fOpenItem = NULL;
	int32 count = CountItems();
	while (count--)
		delete RemoveItem((int32)0);

	// Add the Folder
	IconMenuItem* menuItem = new IconMenuItem(B_TRANSLATE("New folder"),
		new BMessage(kNewFolder), B_DIR_MIMETYPE, B_MINI_ICON);
	AddItem(menuItem);
	menuItem->SetShortcut('N', 0);

	// The Templates folder
	BPath path;
	find_directory (B_USER_SETTINGS_DIRECTORY, &path, true);
	path.Append(kTemplatesDirectory);
	mkdir(path.Path(), 0777);

	count = 0;

	BEntry entry;
	BDirectory templatesDir(path.Path());
	while (templatesDir.GetNextEntry(&entry) == B_OK) {
		BNode node(&entry);
		BNodeInfo nodeInfo(&node);
		char fileName[B_FILE_NAME_LENGTH];
		entry.GetName(fileName);
		if (nodeInfo.InitCheck() == B_OK) {
			char mimeType[B_MIME_TYPE_LENGTH];
			nodeInfo.GetType(mimeType);

			BMimeType mime(mimeType);
			if (mime.IsValid()) {
				if (count == 0)
					AddSeparatorItem();

				count++;

				// If not adding items, we are just seeing if there
				// are any to list.  So if we find one, immediately
				// bail and return the result.
				if (!addItems)
					break;

				entry_ref ref;
				entry.GetRef(&ref);

				BMessage* message = new BMessage(kNewEntryFromTemplate);
				message->AddRef("refs_template", &ref);
				message->AddString("name", fileName);
				AddItem(new IconMenuItem(fileName, message, &nodeInfo,
					B_MINI_ICON));
			}
		}
	}

	AddSeparatorItem();

	// This is the message sent to open the templates folder.
	BMessage* message = new BMessage(B_REFS_RECEIVED);
	entry_ref dirRef;
	if (templatesDir.GetEntry(&entry) == B_OK)
		entry.GetRef(&dirRef);
	message->AddRef("refs", &dirRef);

	// Add item to show templates folder.
	fOpenItem =	new BMenuItem(B_TRANSLATE("Edit templates" B_UTF8_ELLIPSIS),
			message);
	AddItem(fOpenItem);
	if (dirRef == entry_ref())
		fOpenItem->SetEnabled(false);

	return count > 0;
}
示例#15
0
entry_ref
GetPartnerRef(entry_ref ref)
{
	DPath refpath(BPath(&ref).Path());
	BString ext(refpath.GetExtension());
	if (ext.CountChars() < 1)
		return entry_ref();
	
	BString pathbase = refpath.GetFullPath();
	pathbase.Truncate(pathbase.FindLast(".") + 1);
	
	const char *cpp_ext[] = { "cpp","c","cxx","cc", NULL };
	const char *hpp_ext[] = { "h","hpp","hxx","hh", NULL };
	
	bool isSource = false;
	bool isHeader = false;
	
	int i = 0;
	while (cpp_ext[i])
	{
		if (ext == cpp_ext[i])
		{
			isSource = true;
			break;
		}
		i++;
	}
	
	if (!isSource)
	{
		i = 0;
		while (hpp_ext[i])
		{
			if (ext == hpp_ext[i])
			{
				isHeader = true;
				break;
			}
			i++;
		}
	}
	else
	{
		i = 0;
		while (hpp_ext[i])
		{
			BString partpath = pathbase;
			partpath << hpp_ext[i];
			BEntry entry(partpath.String());
			if (entry.Exists())
			{
				entry_ref header_ref;
				entry.GetRef(&header_ref);
				return header_ref;
			}
			i++;
		}
	}
	
	if (isHeader)
	{
		i = 0;
		while (cpp_ext[i])
		{
			BString partpath = pathbase;
			partpath << cpp_ext[i];
			BEntry entry(partpath.String());
			if (entry.Exists())
			{
				entry_ref source_ref;
				entry.GetRef(&source_ref);
				return source_ref;
			}
			i++;
		}
	}
	
	return entry_ref();
}
示例#16
0
bool ArpConfigureFile::HasFile() const
{
    return mFile == entry_ref() ? false : true;
}