当前位置: 首页>>代码示例>>C++>>正文


C++ BEntry::Rename方法代码示例

本文整理汇总了C++中BEntry::Rename方法的典型用法代码示例。如果您正苦于以下问题:C++ BEntry::Rename方法的具体用法?C++ BEntry::Rename怎么用?C++ BEntry::Rename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BEntry的用法示例。


在下文中一共展示了BEntry::Rename方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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; 
}
开发者ID:Paradoxianer,项目名称:Tasks,代码行数:54,代码来源:TaskFS.cpp

示例2: sizeof

/*!	\brief Sets the name of the volume referred to by this object.
	\param name The volume's new name. Must not be longer than
		   \c B_FILE_NAME_LENGTH (including the terminating null).
	\return
	- \c B_OK: Everything went fine.
	- \c B_BAD_VALUE: \c NULL \a name or the object is not properly
	  initialized.
	- another error code
*/
status_t
BVolume::SetName(const char *name)
{
	// check initialization
	if (!name || InitCheck() != B_OK)
		return B_BAD_VALUE;
	if (strlen(name) >= B_FILE_NAME_LENGTH)
		return B_NAME_TOO_LONG;
	// get the FS stat (including the old name) first
	fs_info oldInfo;
	if (fs_stat_dev(fDevice, &oldInfo) != 0)
		return errno;
	if (strcmp(name, oldInfo.volume_name) == 0)
		return B_OK;
	// set the volume name
	fs_info newInfo;
	strlcpy(newInfo.volume_name, name, sizeof(newInfo.volume_name));
	status_t error = _kern_write_fs_info(fDevice, &newInfo,
		FS_WRITE_FSINFO_NAME);
	if (error != B_OK)
		return error;

	// change the name of the mount point

	// R5 implementation checks, if an entry with the volume's old name
	// exists in the root directory and renames that entry, if it is indeed
	// the mount point of the volume (or a link referring to it). In all other
	// cases, nothing is done (even if the mount point is named like the
	// volume, but lives in a different directory).
	// We follow suit for the time being.
	// NOTE: If the volume name itself is actually "boot", then this code
	// tries to rename /boot, but that is prevented in the kernel.

	BPath entryPath;
	BEntry entry;
	BEntry traversedEntry;
	node_ref entryNodeRef;
	if (BPrivate::Storage::check_entry_name(name) == B_OK
		&& BPrivate::Storage::check_entry_name(oldInfo.volume_name) == B_OK
		&& entryPath.SetTo("/", oldInfo.volume_name) == B_OK
		&& entry.SetTo(entryPath.Path(), false) == B_OK
		&& entry.Exists()
		&& traversedEntry.SetTo(entryPath.Path(), true) == B_OK
		&& traversedEntry.GetNodeRef(&entryNodeRef) == B_OK
		&& entryNodeRef.device == fDevice
		&& entryNodeRef.node == oldInfo.root) {
		entry.Rename(name, false);
	}
	return error;
}
开发者ID:mmanley,项目名称:Antares,代码行数:59,代码来源:Volume.cpp

示例3: strcpy

/*
* Given a local file path,
* update the corresponding file on Dropbox
*/
void
update_file_in_dropbox(const char * filepath, const char *parent_rev)
{
  char * argv[4];
  argv[0] = "db_put.py";

  BString db_filepath = local_to_db_filepath(filepath);
  const char * tmp = db_filepath.String();
  char not_const[db_filepath.CountChars()];
  strcpy(not_const,tmp);
  argv[2] = not_const;

  char not_const2[strlen(filepath)];
  strcpy(not_const2,filepath);
  argv[1] = not_const2;

  char not_const3[strlen(parent_rev)];
  strcpy(not_const3,parent_rev);
  argv[3] = not_const3;

  BString *result = run_python_script(argv,4);
  BString *real_path = parse_path(result);
  BString *new_parent_rev = parse_parent_rev(result);
  delete result;

  printf("path:|%s|\nparent_rev:|%s|\n",real_path->String(),new_parent_rev->String());

  BNode node = BNode(filepath);
  set_parent_rev(&node,new_parent_rev);
  delete new_parent_rev;

  BEntry entry = BEntry(filepath);
  BPath old_path;
  entry.GetPath(&old_path);

  BPath new_path = BPath(db_to_local_filepath(real_path->String()).String());

  printf("Should I move %s to %s?\n", old_path.Path(), new_path.Path());
  if(strcmp(new_path.Leaf(),old_path.Leaf()) != 0)
  {
    printf("moving %s to %s\n", old_path.Leaf(), new_path.Leaf());
    BEntry entry = BEntry(old_path.Path()); //entry for local path
    status_t err = entry.Rename(new_path.Leaf(),true);
    if(err != B_OK) printf("error moving: %s\n",strerror(err));
  }
  delete real_path;
}
开发者ID:astrieanna,项目名称:haiku-dropbox-client,代码行数:51,代码来源:HaikuDropbox.cpp

示例4: volume

status_t
CDDBDaemon::_WriteCDData(dev_t device, QueryResponseData* diskData,
	ReadResponseData* readResponse)
{
	// Rename volume.
	BVolume volume(device);
	
	status_t result;
	status_t error = B_OK;
	
	BString name = diskData->artist << " - " << diskData->title;
	name.ReplaceSet("/", " ");
	
	if ((result = volume.SetName(name.String())) != B_OK) {
		printf("Can't set volume name.\n");
		return result;
	}
	
	// Rename tracks and add relevant Audio attributes.	
	BDirectory cddaRoot;
	volume.GetRootDirectory(&cddaRoot);
	
	BEntry entry;
	int index = 0;
	while (cddaRoot.GetNextEntry(&entry) == B_OK) {
		TrackData* data = (TrackData*)((readResponse->tracks).ItemAt(index));
		
		// Update name.
		name = data->title;
		name.ReplaceSet("/", " ");
		
		if ((result = entry.Rename(name.String())) != B_OK) {
			printf("Failed renaming entry at index %d to \"%s\".\n", index,
				name.String());
			error = result;
				// User can benefit from continuing through all tracks.
				// Report error later.
		}
		
		// Add relevant attributes. We consider an error here as non-fatal.
		BNode node(&entry);
		node.WriteAttr("Audio:Title", B_STRING_TYPE, 0, (data->title).String(),
			(data->title).Length());
		node.WriteAttr("Audio:Album", B_STRING_TYPE, 0,
			(readResponse->title).String(),
			(readResponse->title).Length());
		node.WriteAttr("Audio:Genre", B_STRING_TYPE, 0,
			(readResponse->genre).String(),
			(readResponse->genre).Length());
		node.WriteAttr("Audio:Year", B_INT32_TYPE, 0, &(readResponse->year),
			sizeof(int32));

		if (data->artist == "") {
			node.WriteAttr("Audio:Artist", B_STRING_TYPE, 0,
				(readResponse->artist).String(),
				(readResponse->artist).Length());
		} else {
			node.WriteAttr("Audio:Artist", B_STRING_TYPE, 0,
				(data->artist).String(), (data->artist).Length());			
		}
			
		index++;
	}
	
	return error;
}	
开发者ID:mariuz,项目名称:haiku,代码行数:66,代码来源:cddb_daemon.cpp

示例5: if

/*
* Message Handling Function
* If it's a node monitor message,
* then figure out what to do based on it.
* Otherwise, let BApplication handle it.
*/
void
App::MessageReceived(BMessage *msg)
{
  printf("message received:\n");
  msg->PrintToStream();
  switch(msg->what)
  {
    case MY_DELTA_CONST:
    {
      printf("Pulling changes from Dropbox\n");
      pull_and_apply_deltas();
      break;
    }
    case B_NODE_MONITOR:
    {
      printf("Received Node Monitor Alert\n");
      status_t err;
      int32 opcode;
      err = msg->FindInt32("opcode",&opcode);
      if(err == B_OK)
      {
        switch(opcode)
        {
          case B_ENTRY_CREATED:
          {
            printf("CREATED NEW FILE\n");
            entry_ref ref;
            BPath path;
            const char * name;

            // unpack the message
            msg->FindInt32("device",&ref.device);
            msg->FindInt64("directory",&ref.directory);
            msg->FindString("name",&name);
            ref.set_name(name);

            BEntry new_file = BEntry(&ref);
            new_file.GetPath(&path);


            //if we said to ignore a `NEW` msg from the path, then ignore it
            if(this->ignore_created(&path)) return;

            this->track_file(&new_file);

            if(new_file.IsDirectory())
            {
               add_folder_to_dropbox(path.Path());
               BDirectory new_dir = BDirectory(&new_file);
               this->recursive_watch(&new_dir);
            }
            else
            {
              BString *result = add_file_to_dropbox(path.Path());
              BString *real_path = parse_path(result);
              BString *parent_rev = parse_parent_rev(result);
              delete result;

              printf("path:|%s|\nparent_rev:|%s|\n",real_path->String(),parent_rev->String());

              BNode node = BNode(&new_file);
              set_parent_rev(&node,parent_rev);
              delete parent_rev;
              BPath new_path = BPath(db_to_local_filepath(real_path->String()).String());

              if(strcmp(new_path.Leaf(),path.Leaf()) != 0)
              {
                printf("moving %s to %s\n", path.Leaf(), new_path.Leaf());
                BEntry entry = BEntry(path.Path()); //entry for local path
                status_t err = entry.Rename(new_path.Leaf(),true);
                if(err != B_OK) printf("error moving: %s\n",strerror(err));
              }
              
              delete real_path;
              watch_entry(&new_file,B_WATCH_STAT);
            }
            break;
          }
          case B_ENTRY_MOVED:
          {
            printf("MOVED FILE\n");
            entry_ref eref;
            BDirectory from_dir, to_dir;
            node_ref from_ref,to_ref,nref;
            BPath path;
            const char* name;

            msg->FindInt32("device",&from_ref.device);
            msg->FindInt32("device",&to_ref.device);
            msg->FindInt32("device",&eref.device);
            msg->FindInt32("device",&nref.device);

            msg->FindInt64("from directory",&from_ref.node);
            msg->FindInt64("to directory",&to_ref.node);
//.........这里部分代码省略.........
开发者ID:astrieanna,项目名称:haiku-dropbox-client,代码行数:101,代码来源:HaikuDropbox.cpp

示例6: settings

status_t
TMailApp::SaveSettings()
{
	BMailSettings accountSettings;

	if (fDefaultAccount != ~0L) {
		accountSettings.SetDefaultOutboundAccount(fDefaultAccount);
		accountSettings.Save();
	}

	BPath path;
	status_t status = GetSettingsPath(path);
	if (status != B_OK)
		return status;

	path.Append("BeMail Settings~");

	BFile file;
	status = file.SetTo(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
	if (status != B_OK)
		return status;

	BMessage settings('BeMl');
	settings.AddRect("MailWindowSize", fMailWindowFrame);
//	settings.AddInt32("ExperienceLevel", level);

	font_family fontFamily;
	font_style fontStyle;
	fContentFont.GetFamilyAndStyle(&fontFamily, &fontStyle);

	settings.AddString("FontFamily", fontFamily);
	settings.AddString("FontStyle", fontStyle);
	settings.AddFloat("FontSize", fContentFont.Size());

	settings.AddRect("SignatureWindowSize", fSignatureWindowFrame);
	settings.AddBool("WordWrapMode", fWrapMode);
	settings.AddPoint("PreferencesWindowLocation", fPrefsWindowPos);
	settings.AddBool("AutoMarkRead", fAutoMarkRead);
	settings.AddString("SignatureText", fSignature);
	settings.AddInt32("CharacterSet", fMailCharacterSet);
	settings.AddString("FindString", FindWindow::GetFindString());
	settings.AddInt8("ShowButtonBar", fShowToolBar);
	settings.AddInt32("UseAccountFrom", fUseAccountFrom);
	settings.AddBool("ColoredQuotes", fColoredQuotes);
	settings.AddString("ReplyPreamble", fReplyPreamble);
	settings.AddBool("AttachAttributes", fAttachAttributes);
	settings.AddBool("WarnAboutUnencodableCharacters", fWarnAboutUnencodableCharacters);
	settings.AddBool("StartWithSpellCheck", fStartWithSpellCheckOn);

	BEntry entry;
	status = entry.SetTo(path.Path());
	if (status != B_OK)
		return status;

	status = settings.Flatten(&file);
	if (status == B_OK) {
		// replace original settings file
		status = entry.Rename("BeMail Settings", true);
	} else
		entry.Remove();

	return status;
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:63,代码来源:MailApp.cpp

示例7: volume

status_t
CDDBLookup::_WriteCDData(dev_t device, const QueryResponseData& diskData,
	const ReadResponseData& readResponse)
{
	// Rename volume.
	BVolume volume(device);

	status_t error = B_OK;

	BString name = diskData.artist;
	name += " - ";
	name += diskData.title;
	name.ReplaceSet("/", " ");

	status_t result = volume.SetName(name.String());
	if (result != B_OK) {
		printf("Can't set volume name.\n");
		return result;
	}

	// Rename tracks and add relevant Audio attributes.
	BDirectory cddaRoot;
	volume.GetRootDirectory(&cddaRoot);

	BEntry entry;
	int index = 0;
	while (cddaRoot.GetNextEntry(&entry) == B_OK) {
		TrackData* track = readResponse.tracks.ItemAt(index);

		// Update name.
		int trackNum = index + 1; // index=0 is actually Track 1
		name.SetToFormat("%02d %s.wav", trackNum, track->title.String());
		name.ReplaceSet("/", " ");

		result = entry.Rename(name.String());
		if (result != B_OK) {
			fprintf(stderr, "%s: Failed renaming entry at index %d to "
				"\"%s\".\n", kProgramName, index, name.String());
			error = result;
				// User can benefit from continuing through all tracks.
				// Report error later.
		}

		// Add relevant attributes. We consider an error here as non-fatal.
		BNode node(&entry);
		node.WriteAttrString("Media:Title", &track->title);
		node.WriteAttrString("Audio:Album", &readResponse.title);
		if (readResponse.genre.Length() != 0)
			node.WriteAttrString("Media:Genre", &readResponse.genre);
		if (readResponse.year != 0) {
			node.WriteAttr("Media:Year", B_INT32_TYPE, 0,
				&readResponse.year, sizeof(int32));
		}

		if (track->artist == "")
			node.WriteAttrString("Audio:Artist", &readResponse.artist);
		else
			node.WriteAttrString("Audio:Artist", &track->artist);

		index++;
	}

	return error;
}
开发者ID:koletzky,项目名称:haiku,代码行数:64,代码来源:cddb_lookup.cpp

示例8: DoIt

void PecoApp::DoIt() {

	if (NothingToDo()) return;
	
	FileListItem	*ListItem;
	
	BAlert	*myAlert	= new BAlert(NULL, MESSAGE_REALLY_DOIT, STR_CONTINUE, STR_CANCEL);
	if (myAlert->Go() == 1) return;
		for (int32 i = 0; (ListItem = (FileListItem *)fListView->ItemAt(i)) != NULL; i++ ) {
		if (ListItem->fErrorStatus == 1 ) {
			BAlert	*myAlert	= new BAlert(NULL, MESSAGE_WILL_HAVE_PROBS, STR_CONTINUE, STR_CANCEL);
			if (myAlert->Go() == 1) return;
			break;
		}
	}

	bool 	noerror = true, nomoreerrors=false, canceled=false;

	fWindow->Lock();
	fStatusBar->SetText(STATUS_RENAMING);
	fStatusBar->SetMaxValue(fList->CountItems());

	BButton		*okButton = (BButton *)fWindow->FindView("DoIt");
	okButton->SetEnabled(false);
	
	BTextControl* 	pfadView = (BTextControl *)fWindow->FindView("pfadView");
	BString	Pfad(pfadView->Text());
	fWindow->Unlock();
	
	BString	AlterName, NeuerName;
	BEntry	Datei;
	
	for (int32 i = 0; (ListItem = (FileListItem *)fListView->ItemAt(i)) != NULL; i++ ) {
		fWindow->Lock();
		fStatusBar->Update(1);
		fWindow->Unlock();
		if (canceled) { ListItem->fErrorStatus=0; continue; }
		if (ListItem->fNewName.String() != "" ) {
			AlterName = Pfad; AlterName.Append("/").Append(ListItem->fName);
			NeuerName = Pfad; NeuerName.Append("/").Append(ListItem->fNewName);
			Datei.SetTo(AlterName.String());
			if ( Datei.Rename(NeuerName.String()) != B_OK ) {
				ListItem->fErrorStatus=1;
				fWindow->Lock();
				fListView->InvalidateItem(i);
				fWindow->Unlock();

				if (!nomoreerrors) {
					noerror = false;

					BString		ErrorMessage(MESSAGE_HAVE_PROBLEM);
					ErrorMessage.ReplaceFirst("%1", ListItem->fName.String());
					ErrorMessage.ReplaceFirst("%2", ListItem->fNewName.String());
					
					BAlert	*myAlert	= new BAlert(NULL, ErrorMessage.String(), STR_CANCEL, STR_CONTINUE, STR_CONTINUE_WO_MSG, B_WIDTH_AS_USUAL, B_WARNING_ALERT);

					int32	result = myAlert->Go();
					if (result == 0) { canceled = true; continue; }
					if (result == 2) nomoreerrors = true;
				}
				
			} else {
			
				fWindow->Lock();
				ListItem->SetName(ListItem->fNewName);
				ListItem->SetNewName("");
				fListView->InvalidateItem(i);
				fWindow->Unlock();

			}
		}
	}

//	NoRenamer();

	fWindow->Lock();
	fStatusBar->Reset(STATUS_STATUS);
	fWindow->Unlock();

	if (noerror) MakeList();
	else {
		fStatusBar->SetText(STATUS_DIDIT_BAD);

		BAlert	*myAlert	= new BAlert(NULL, MESSAGE_MARKED_FILES, STR_OK);
		myAlert->Go();
	}
	
}
开发者ID:diversys,项目名称:PecoRename,代码行数:88,代码来源:PecoApp.cpp


注:本文中的BEntry::Rename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。