status_t
DefaultCatalog::WriteToResource(const entry_ref &appOrAddOnRef)
{
	BFile file;
	status_t res = file.SetTo(&appOrAddOnRef, B_READ_WRITE);
	if (res != B_OK)
		return res;

	BResources rsrc;
	res = rsrc.SetTo(&file);
	if (res != B_OK)
		return res;

	BMallocIO mallocIO;
	mallocIO.SetBlockSize(max(fCatMap.Size() * 20, (int32)256));
		// set a largish block-size in order to avoid reallocs
	res = Flatten(&mallocIO);

	int mangledLanguage = CatKey::HashFun(fLanguageName.String(), 0);

	if (res == B_OK) {
		res = rsrc.AddResource('CADA', mangledLanguage,
			mallocIO.Buffer(), mallocIO.BufferLength(),
			BString(fLanguageName));
	}

	return res;
}
/*
* Given a local directory, do the equivalent of `rm -rf`
* on it, but using the actual filesystem API.
* You can't just use dir->Remove() because that
* gives an error if the directory is not empty.
*/
void
rm_rf(BDirectory *dir)
{
  status_t err;
  BEntry entry;
  err = dir->GetNextEntry(&entry);
  while(err==B_OK)
  {
    BFile file = BFile(&entry, B_READ_ONLY);
    if(file.IsDirectory())
    {
      BDirectory ndir = BDirectory(&entry);
      rm_rf(&ndir);
    }

    err = entry.Remove();
    if(err != B_OK)
    {
      BPath path;
      entry.GetPath(&path);
      printf("Remove Error: %s on %s\n",strerror(err),path.Path());
      //what to do if I can't remove something?
    }

    err = dir->GetNextEntry(&entry);
  }
  err = dir->GetEntry(&entry);
  err = entry.Remove();
  if(err != B_OK)
    printf("Folder Removal Error: %s\n", strerror(err));
}
status_t
LocaleRosterData::_LoadTimeSettings()
{
	BPath path;
	BFile file;
	status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
	if (status == B_OK) {
		path.Append("Time settings");
		status = file.SetTo(path.Path(), B_READ_ONLY);
	}
	BMessage settings;
	if (status == B_OK)
		status = settings.Unflatten(&file);
	if (status == B_OK) {
		BString timeZoneID;
		if (settings.FindString(kTimezoneField, &timeZoneID) == B_OK)
			_SetDefaultTimeZone(BTimeZone(timeZoneID.String()));
		else
			_SetDefaultTimeZone(BTimeZone(BTimeZone::kNameOfGmtZone));

		return B_OK;
	}

	// Something went wrong (no settings file or invalid BMessage), so we
	// set everything to default values
	_SetDefaultTimeZone(BTimeZone(BTimeZone::kNameOfGmtZone));

	return status;
}
Esempio n. 4
0
bool
BTheme::SetTheme(const char* theme)
{	
	BFile file;
 	fCurTheme.SetTo(&ThemesFolder,NULL);
	fCurTheme.Append(theme);
 	
	if(fRes!=be_app->AppResources())delete fRes;

 	if(file.SetTo(fCurTheme.Path(), B_READ_ONLY)==B_OK)
 		{
			fRes=new BResources(&file);
 		}
 	else	
			fRes=be_app->AppResources();

	type_code typeFound;
	int32 idFound;
	const char *nameFound;
	size_t lengthFound;
	int n=0;
	for(n=0;fRes->GetResourceInfo(n,&typeFound,&idFound,&nameFound,&lengthFound)==true;n++);
	
	BmpListItem *anItem;
	for(int32 i=0;fBmpList->ItemAt(i)!=NULL;i++) {
			anItem=(BmpListItem*)fBmpList->ItemAt(i);
			delete anItem;
	}
	delete fBmpList;
	fBmpList=new BList(n+1);

	return true;
}
Esempio n. 5
0
BBitmap*
AlertView::InitIcon()
{
	// This is how BAlert gets to its icon
	BBitmap* icon = NULL;
	BPath path;
	if (find_directory(B_BEOS_SERVERS_DIRECTORY, &path) == B_OK) {
		path.Append("app_server");
		BResources resources;
		BFile file;
		if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK
			&& resources.SetTo(&file) == B_OK) {
			size_t size;
			const void* data = resources.LoadResource(B_VECTOR_ICON_TYPE,
				"warn", &size);
			if (data) {
				icon = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
				if (BIconUtils::GetVectorIcon((const uint8*)data, size, icon)
						!= B_OK) {
					delete icon;
					icon = NULL;
				}
			}
		}
	}

	return icon;
}
Esempio n. 6
0
Emoconfig::Emoconfig(const char* xmlfile): BMessage()
{
	fEmoticonSize = 16.0; //default
	numfaces = 0;

	fParser = XML_ParserCreate(NULL);

	XML_SetUserData(fParser, this);
	XML_SetElementHandler(fParser, StartElement, EndElement);
	XML_SetCharacterDataHandler(fParser, Characters);

	//path!
	BPath p(xmlfile);
	p.GetParent(&path);

	// loading the config file..
	BFile* settings = new BFile(xmlfile, B_READ_ONLY);
	off_t size;
	settings->GetSize(&size);
	if (size) {
		void* buffer = malloc((size_t)size);
		size = settings->Read(buffer, (size_t)size);
		XML_Parse(fParser, (const char*)buffer, (int)size, true);
		free(buffer);
	}
	delete settings;

	if (fParser)
		XML_ParserFree(fParser);

	printf("Emoconfig: loaded %d faces\n", numfaces);

}
Esempio n. 7
0
/*! \brief Loads the next video chunk into fVideoChunkBuffer and assigns it
		(including the start time) to fTempPacket accordingly only if
		fTempPacket is empty.

	\returns B_OK
		1. meaning: Next video chunk is loaded.
		2. meaning: No need to load and assign anything. Proceed as usual.
	\returns B_LAST_BUFFER_ERROR No more video chunks available.
		fVideoChunkBuffer and fTempPacket are left untouched.
	\returns Other errors Caller should bail out because fVideoChunkBuffer and
		fTempPacket are in unknown states. Normal operation cannot be
		guaranteed.
*/
status_t
AVCodecDecoder::_LoadNextVideoChunkIfNeededAndAssignStartTime()
{
	// TODO: Rename fVideoChunkBuffer to fChunkBuffer, once the audio path is
	// responsible for releasing the chunk buffer, too.

	if (fTempPacket.size > 0)
		return B_OK;

	const void* chunkBuffer = NULL;
	size_t chunkBufferSize = 0;
		// In the case that GetNextChunk() returns an error fChunkBufferSize
		// should be left untouched.
	media_header chunkMediaHeader;

	status_t getNextChunkStatus = GetNextChunk(&chunkBuffer,
		&chunkBufferSize, &chunkMediaHeader);
	if (getNextChunkStatus != B_OK)
		return getNextChunkStatus;

	status_t chunkBufferPaddingStatus
		= _CopyChunkToVideoChunkBufferAndAddPadding(chunkBuffer,
		chunkBufferSize);
	if (chunkBufferPaddingStatus != B_OK)
		return chunkBufferPaddingStatus;

	fTempPacket.data = fVideoChunkBuffer;
	fTempPacket.size = fChunkBufferSize;
	fTempPacket.dts = chunkMediaHeader.start_time;
		// Let FFMPEG handle the correct relationship between start_time and
		// decoded video frame. By doing so we are simply copying the way how
		// it is implemented in ffplay.c
		// \see http://git.videolan.org/?p=ffmpeg.git;a=blob;f=ffplay.c;h=09623db374e5289ed20b7cc28c262c4375a8b2e4;hb=9153b33a742c4e2a85ff6230aea0e75f5a8b26c2#l1502
		//
		// FIXME: Research how to establish a meaningful relationship
		// between start_time and decoded video frame when the received
		// chunk buffer contains partial video frames. Maybe some data
		// formats contain time stamps (ake pts / dts fields) that can
		// be evaluated by FFMPEG. But as long as I don't have such
		// video data to test it, it makes no sense to implement it.
		//
		// FIXME: Implement tracking start_time of video frames
		// originating in data chunks that encode more than one video
		// frame at a time. In that case on would increment the
		// start_time for each consecutive frame of such a data chunk
		// (like it is done for audio frame decoding). But as long as
		// I don't have such video data to test it, it makes no sense
		// to implement it.

#ifdef LOG_STREAM_TO_FILE
	if (sDumpedPackets < 100) {
		sStreamLogFile.Write(chunkBuffer, fChunkBufferSize);
		printf("wrote %ld bytes\n", fChunkBufferSize);
		sDumpedPackets++;
	} else if (sDumpedPackets == 100)
		sStreamLogFile.Unset();
#endif

	return B_OK;
}
Esempio n. 8
0
status_t
Settings::WriteSwapSettings()
{
	BPath path;
	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
		return B_ERROR;

	path.Append("kernel/drivers");
	path.Append(kVirtualMemorySettings);

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

	fs_info info;
	if (fs_stat_dev(SwapVolume(), &info) != 0)
		return B_ERROR;

	char buffer[1024];
	snprintf(buffer, sizeof(buffer), "vm %s\nswap_auto %s\nswap_size %"
		B_PRIdOFF "\nswap_volume_name %s\nswap_volume_device %s\n"
		"swap_volume_filesystem %s\nswap_volume_capacity %" B_PRIdOFF "\n",
		SwapEnabled() ? "on" : "off", SwapAutomatic() ? "yes" : "no",
		SwapSize(), info.volume_name, info.device_name, info.fsh_name,
		info.total_blocks * info.block_size);

	file.Write(buffer, strlen(buffer));
	return B_OK;
}
Esempio n. 9
0
status_t
TermWindow::_LoadWindowPosition(BRect* frame, uint32* workspaces)
{
	status_t status;
	BMessage position;

	BFile file;
	status = _GetWindowPositionFile(&file, B_READ_ONLY);
	if (status != B_OK)
		return status;

	status = position.Unflatten(&file);

	file.Unset();

	if (status != B_OK)
		return status;

	int32 id = fTerminalRoster.ID();
	status = position.FindRect("rect", id, frame);
	if (status != B_OK)
		return status;

	int32 _workspaces;
	status = position.FindInt32("workspaces", id, &_workspaces);
	if (status != B_OK)
		return status;
	if (modifiers() & B_SHIFT_KEY)
		*workspaces = _workspaces;
	else
		*workspaces = B_CURRENT_WORKSPACE;

	return B_OK;
}
Esempio n. 10
0
// create_app
static
entry_ref
create_app(const char *filename, const char *signature,
		   bool install = false, bool makeExecutable = true,
		   uint32 appFlags = B_SINGLE_LAUNCH)
{
	BString testApp;
	CHK(find_test_app("RosterBroadcastTestApp1", &testApp) == B_OK);
	system((string("cp ") + testApp.String() + " " + filename).c_str());
	if (makeExecutable)
		system((string("chmod a+x ") + filename).c_str());
	BFile file;
	CHK(file.SetTo(filename, B_READ_WRITE) == B_OK);
	BAppFileInfo appFileInfo;
	CHK(appFileInfo.SetTo(&file) == B_OK);
	if (signature)
		CHK(appFileInfo.SetSignature(signature) == B_OK);
	CHK(appFileInfo.SetAppFlags(appFlags) == B_OK);
	if (install && signature)
		CHK(BMimeType(signature).Install() == B_OK);
	// We write the signature into a separate attribute, just in case we
	// decide to also test files without BEOS:APP_SIG attribute.
	BString signatureString(signature);
	file.WriteAttrString("signature", &signatureString);
	return ref_for_path(filename);
}
Esempio n. 11
0
void MailingList::SetBounceMsg(std::string path)
{
	//attempt to read the custom bounce message file
	BFile bouncemsgbfile;
	status_t bouncemsgfilestatus=bouncemsgbfile.SetTo(path.c_str(),B_READ_ONLY);
	if (bouncemsgfilestatus==B_NO_ERROR)
	{
		off_t bytes; //size of file
		if (bouncemsgbfile.GetSize(&bytes) == B_NO_ERROR)
		{
			
			char* buff = new char[bytes];
			off_t bytesread=bouncemsgbfile.Read(buff,bytes);
			if ( (bytesread > 0) && (bytesread < 50001)  )
			{
				//file read ok
				std::string oldbouncemsg=fUnauthorisedBounceMsgContents; //save generic bounce msg so it can be appended later
				fUnauthorisedBounceMsgContents=""; //clear existing contents
				for (int x=0; x < bytesread; x++)
				{
					fUnauthorisedBounceMsgContents=fUnauthorisedBounceMsgContents+buff[x];
				}	
				fUnauthorisedBounceMsgContents=fUnauthorisedBounceMsgContents+"\n\n"+oldbouncemsg; //append generic msg
			}
			delete buff;
			
		}
		bouncemsgbfile.Unset(); //close file
	}
}
Esempio n. 12
0
status_t 
ZKWindow::SaveSettings	(void)
{
	PRINT(("ZKWindow::SaveSettings()\n"));

	status_t	status;
	BMessage 	settings;
	BPath		path;
	BFile		file;

	// add settings to message
	settings.AddRect("winframe", Frame());
	
	// get path to settings-file
	if ((status = find_directory(B_USER_SETTINGS_DIRECTORY, & path)) != B_OK)
		return status;

	if ((status = path.SetTo(path.Path(),"Kirilla/ZooKeeper/settings")) != B_OK)
		return status;
		
	if ((status	= file.SetTo(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE)) != B_OK)
		return status;

	if ((status	= settings.Flatten(& file))	!=	B_OK)
		return status;

	return B_OK;
}
Esempio n. 13
0
status_t
ZKWindow::ReadSettings	(void)
{
	PRINT(("ZKWindow::ReadSettings()\n"));

	status_t	status;
	BMessage	settings;
	BPath		path;
	BFile		file;
	BRect 		frame;

	// get path to settings-file
	if ((status = find_directory(B_USER_SETTINGS_DIRECTORY, & path)) != B_OK)
		return status;

	if ((status = path.SetTo(path.Path(),"Kirilla/ZooKeeper/settings")) != B_OK)
		return status;
		
	if ((status	= file.SetTo(path.Path(), B_READ_ONLY)) != B_OK)
		return status;

	// get message from file
	if ((status	=	settings.Unflatten(& file)) != B_OK)
		return status;

	// get settings from message
	if (settings.FindRect("winframe", & frame) == B_OK)
	{
		MoveTo(frame.LeftTop());
		ResizeTo(frame.Width(), frame.Height());
	}

	return B_OK;
}
Esempio n. 14
0
AppWindow*
AppWindow::CreateWindow()
{
	PRINT(("AppWindow::CreateWindow()\n"));

	BPath path;
	BFile settings;
	BMessage archive;
	AppWindow* win = 0;

	find_directory(B_USER_SETTINGS_DIRECTORY,&path);
	path.Append(PROJECT_DIR);
	path.Append(APPLICATION_DIR);
	path.Append(WINDOW_FILE);

	if((settings.SetTo(path.Path(), B_READ_ONLY) == B_OK)
			&& (archive.Unflatten(&settings) == B_OK))
	{
		win = new AppWindow(&archive);
	}
	else
	{
		win = new AppWindow();
	}
	return(win);
}
Esempio n. 15
0
Settings::~Settings()
{
	// only save the settings if something has changed
	if (!fUpdated)
		return;

	BFile file;
	if (Open(&file, B_CREATE_FILE | B_WRITE_ONLY) != B_OK)
		return;

	disk_probe_settings settings;

	settings.window_frame = fMessage.FindRect("window_frame");
#if B_HOST_IS_BENDIAN
	// settings are saved in little endian
	settings.window_frame.left = B_HOST_TO_LENDIAN_FLOAT(
		settings.window_frame.left);
	settings.window_frame.top = B_HOST_TO_LENDIAN_FLOAT(
		settings.window_frame.top);
	settings.window_frame.right = B_HOST_TO_LENDIAN_FLOAT(
		settings.window_frame.right);
	settings.window_frame.bottom = B_HOST_TO_LENDIAN_FLOAT(
		settings.window_frame.bottom);
#endif

	settings.base_type = B_HOST_TO_LENDIAN_INT32(
		fMessage.FindInt32("base_type"));
	settings.font_size = B_HOST_TO_LENDIAN_INT32(
		int32(fMessage.FindFloat("font_size") + 0.5f));
	settings.flags = B_HOST_TO_LENDIAN_INT32(
		(fMessage.FindBool("case_sensitive") ? kCaseSensitive : 0)
		| (fMessage.FindInt8("find_mode") == kHexMode ? kHexFindMode : 0));

	file.Write(&settings, sizeof(settings));
}
Esempio n. 16
0
bool
Model::_LoadHistory(BList& items) const
{
	BFile file;
	status_t status = _OpenFile(&file, PREFS_FILE);
	if (status != B_OK)
		return false;

	status = file.Lock();
	if (status != B_OK)
		return false;

	BMessage message;
	status = message.Unflatten(&file);
	if (status != B_OK)
		return false;

	file.Unlock();

	BString string;
	for (int32 x = 0; message.FindString("string", x, &string) == B_OK; x++) {
		BString* copy = new (nothrow) BString(string);
		if (copy == NULL || !items.AddItem(copy)) {
			delete copy;
			break;
		}
	}

	return true;
}
Esempio n. 17
0
//
// TPreferences::~TPreferences
//
// Write the preferences to disk.
//
TPreferences::~TPreferences() {
	BFile file;
	
	if (file.SetTo(path.Path(), B_WRITE_ONLY | B_CREATE_FILE) == B_OK) {
		Flatten(&file);
	}
}
Esempio n. 18
0
status_t
Model::_SaveHistory(const BList& items) const
{
	BFile file;
	status_t status = _OpenFile(&file, PREFS_FILE,
		B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE,
		B_USER_SETTINGS_DIRECTORY, NULL);
	if (status != B_OK)
		return status;

	status = file.Lock();
	if (status != B_OK)
		return status;

	BMessage message;
	int32 count = items.CountItems();
	for (int32 i = 0; i < count; i++) {
		BString* string = static_cast<BString*>(items.ItemAtFast(i));

		if (message.AddString("string", string->String()) != B_OK)
			break;
	}

	status = message.Flatten(&file);
	file.SetSize(message.FlattenedSize());
	file.Sync();
	file.Unlock();

	return status;
}
Esempio n. 19
0
		BString version() {
			app_info appInfo;
			BFile file;
			BAppFileInfo appFileInfo;

			be_app->GetAppInfo(&appInfo);
			file.SetTo(&appInfo.ref, B_READ_WRITE);
			appFileInfo.SetTo(&file);

			BString version;

			version_info info;
			appFileInfo.GetVersionInfo(&info, B_APP_VERSION_KIND);
			version << info.major;
			version << '.';
			version << info.middle;
			version << '.';
			version << info.minor;

			switch(info.variety)
			{
				case B_BETA_VERSION:
					version << "\xCE\xB2";
			}

			if(info.internal > 0) {
				version << info.internal;
			}

			return version;
		}	
Esempio n. 20
0
void
TermApp::RefsReceived(BMessage* message)
{
	// Works Only Launced by Double-Click file, or Drags file to App.
	if (!IsLaunching())
		return;

	entry_ref ref;
	if (message->FindRef("refs", 0, &ref) != B_OK)
		return;

	BFile file;
	if (file.SetTo(&ref, B_READ_WRITE) != B_OK)
		return;

	BNodeInfo info(&file);
	char mimetype[B_MIME_TYPE_LENGTH];
	info.GetType(mimetype);

	// if App opened by Pref file
	if (strcmp(mimetype, PREFFILE_MIMETYPE) == 0) {

		BEntry ent(&ref);
		BPath path(&ent);
		PrefHandler::Default()->OpenText(path.Path());
		return;
	}

	// if App opened by Shell Script
	if (strcmp(mimetype, "text/x-haiku-shscript") == 0) {
		// Not implemented.
		//    beep();
		return;
	}
}
Esempio n. 21
0
void TSorterListItem::Init()
{
	// Set DataType based on entry_ref
	BFile theFile; 
	if ( theFile.SetTo(&m_EntryRef, B_READ_WRITE) == B_OK )
	{		
		// Create node
		BNodeInfo nodeInfo(&theFile);
		if (nodeInfo.InitCheck() == B_NO_ERROR)
		{
			if (IsAudio(nodeInfo))
				m_DataType = kAudioType;
			else if (IsImage(nodeInfo))
				m_DataType = kPictureType;
			else if (IsText(nodeInfo))
				m_DataType = kTextType;
			else if (IsVideo(nodeInfo))
				m_DataType = kVideoType;
		}
		else
		{
			m_DataType = kUnknownType;	
		}	
		
		theFile.Unset();
	}
}
Esempio n. 22
0
status_t
DefaultCatalog::WriteToFile(const char *path)
{
	BFile catalogFile;
	if (path)
		fPath = path;
	status_t res = catalogFile.SetTo(fPath.String(),
		B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
	if (res != B_OK)
		return res;

	BMallocIO mallocIO;
	mallocIO.SetBlockSize(max(fCatMap.Size() * 20, 256L));
		// set a largish block-size in order to avoid reallocs
	res = Flatten(&mallocIO);
	if (res == B_OK) {
		ssize_t wsz;
		wsz = catalogFile.Write(mallocIO.Buffer(), mallocIO.BufferLength());
		if (wsz != (ssize_t)mallocIO.BufferLength())
			return B_FILE_ERROR;

		// set mimetype-, language- and signature-attributes:
		UpdateAttributes(catalogFile);
	}
	if (res == B_OK)
		UpdateAttributes(catalogFile);
	return res;
}
Esempio n. 23
0
void
MyApp	::	RefsReceived(	BMessage * paramMessage)
{
	uint32 type;
	int32 count;
	entry_ref ref;
	warning("debug RefsReceived");
	paramMessage->GetInfo("refs", &type, &count); 
	if ( type != B_REF_TYPE )
	{
		return;
	}
	for	(	long i = --count;
			i >= 0;
			i-- 
		)
	{
		if (paramMessage->FindRef("refs", i, &ref) == B_OK )
		{
			BFile file;
			if ( file.SetTo(&ref, B_READ_ONLY) == B_OK )
			{
				warning("debug good file");
			}
		}
	} 
}//end
Esempio n. 24
0
status_t
DefaultCatalog::WriteToResource(entry_ref *appOrAddOnRef)
{
	BFile file;
	status_t res = file.SetTo(appOrAddOnRef, B_READ_WRITE);
	if (res != B_OK)
		return res;

	BResources rsrc;
	res = rsrc.SetTo(&file);
	if (res != B_OK)
		return res;

	BMallocIO mallocIO;
	mallocIO.SetBlockSize(max(fCatMap.Size() * 20, 256L));
		// set a largish block-size in order to avoid reallocs
	res = Flatten(&mallocIO);

	if (res == B_OK) {
		res = rsrc.AddResource(B_MESSAGE_TYPE, BLocaleRoster::kEmbeddedCatResId,
			mallocIO.Buffer(), mallocIO.BufferLength(), "embedded catalog");
	}

	return res;
}
/*
* Given a directory, subscribe to Node Monitor
* messages on it and all it's descendents.
* For all directories, use B_WATCH_DIRECTORY.
* For all file, use B_WATCH_STAT.
* It also watches the directory itself
* with B_WATCH_DIRECOTRY.
*/
void
App::recursive_watch(BDirectory *dir)
{
  status_t err;

  BEntry entry;
  err = dir->GetNextEntry(&entry);

  //for each file in the current directory
  while(err == B_OK)
  {
    //put this file in global list
    this->track_file(&entry);
    BFile file = BFile(&entry,B_READ_ONLY);
    if(file.IsDirectory())
    {
      watch_entry(&entry,B_WATCH_DIRECTORY);
      BDirectory *ndir = new BDirectory(&entry);
      this->recursive_watch(ndir);
      delete ndir;
    }
    else
    {
      watch_entry(&entry,B_WATCH_STAT);
    }

    err = dir->GetNextEntry(&entry);
  }
}
status_t
ScreenWindow::_WriteVesaModeFile(const screen_mode& mode) const
{
	BPath path;
	status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
	if (status < B_OK)
		return status;

	path.Append("kernel/drivers");
	status = create_directory(path.Path(), 0755);
	if (status < B_OK)
		return status;

	path.Append("vesa");
	BFile file;
	status = file.SetTo(path.Path(), B_CREATE_FILE | B_WRITE_ONLY | B_ERASE_FILE);
	if (status < B_OK)
		return status;

	char buffer[256];
	snprintf(buffer, sizeof(buffer), "mode %ld %ld %ld\n",
		mode.width, mode.height, mode.BitsPerPixel());

	ssize_t bytesWritten = file.Write(buffer, strlen(buffer));
	if (bytesWritten < B_OK)
		return bytesWritten;

	return B_OK;
}
Esempio n. 27
0
PersonView::PersonView(const char* name, const char* categoryAttribute,
		const entry_ref *ref)
	:
	BGridView(),
	fLastModificationTime(0),
	fGroups(NULL),
	fControls(20, false),
	fCategoryAttribute(categoryAttribute),
	fPictureView(NULL),
	fSaving(false)
{
	SetName(name);
	SetFlags(Flags() | B_WILL_DRAW);

	fRef = ref;
	BFile* file = NULL;
	if (fRef != NULL)
		file = new BFile(fRef, B_READ_ONLY);

	// Add picture "field", using ID photo 35mm x 45mm ratio
	fPictureView = new PictureView(70, 90, ref);

	BGridLayout* layout = GridLayout();

	float spacing = be_control_look->DefaultItemSpacing();
	layout->SetInsets(spacing, spacing, spacing, spacing);

	layout->AddView(fPictureView, 0, 0, 1, 5);
	layout->ItemAt(0, 0)->SetExplicitAlignment(
		BAlignment(B_ALIGN_CENTER, B_ALIGN_TOP));

	if (file != NULL)
		file->GetModificationTime(&fLastModificationTime);
	delete file;
}
Esempio n. 28
0
status_t
DefaultCatalog::WriteToFile(const char *path)
{
	BFile catalogFile;
	if (path)
		fPath = path;
	status_t status = catalogFile.SetTo(fPath.String(),
		B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
	if (status != B_OK)
		return status;

	BMallocIO mallocIO;
	mallocIO.SetBlockSize(max_c(fCatMap.Size() * 20, 256));
		// set a largish block-size in order to avoid reallocs
	status = Flatten(&mallocIO);
	if (status != B_OK)
		return status;

	ssize_t bytesWritten
		= catalogFile.Write(mallocIO.Buffer(), mallocIO.BufferLength());
	if (bytesWritten < 0)
		return bytesWritten;
	if (bytesWritten != (ssize_t)mallocIO.BufferLength())
		return B_IO_ERROR;

	// set mimetype-, language- and signature-attributes:
	UpdateAttributes(catalogFile);

	return B_OK;
}
status_t
LocaleRosterData::_SaveLocaleSettings()
{
	BMessage settings;
	status_t status = _AddDefaultFormattingConventionsToMessage(&settings);
	if (status == B_OK)
		_AddPreferredLanguagesToMessage(&settings);
	if (status == B_OK)
		_AddFilesystemTranslationPreferenceToMessage(&settings);

	BPath path;
	if (status == B_OK)
		status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);

	BFile file;
	if (status == B_OK) {
		path.Append("Locale settings");
		status = file.SetTo(path.Path(),
			B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY);
	}
	if (status == B_OK)
		status = settings.Flatten(&file);
	if (status == B_OK)
		status = file.Sync();

	return status;
}
Esempio n. 30
0
/*!	\brief		Reloads the preferences from the disk.
 */
status_t		pref_ReloadAllPreferences( void )
{
	status_t status = B_OK;
	BFile preferencesFile;
	
		/* Open the file - its location is predefined */
	status = OpenFileWithPreferences( &preferencesFile, B_READ_ONLY );
	if ( status == B_OK )
	{	
		if ( !global_PreferencesMessage ) {
				/* Allocate the global preferences placeholder */
			global_PreferencesMessage = new BMessage( kOverallPreferences );
		} else {
				/* If it was already allocated, clear it */
			status = global_PreferencesMessage->MakeEmpty();
		}
		if ( status == B_OK && global_PreferencesMessage )
		{
			/* Read the preferences */
			status = ReadFileWithPreferences( &preferencesFile );
			if ( status == B_OK )
			{
				pref_PopulateCalendarModulePreferences( global_PreferencesMessage );
				pref_PopulateEmailPreferences( global_PreferencesMessage );
				pref_PopulateTimePreferences( global_PreferencesMessage );
				pref_PopulateCategories( global_PreferencesMessage );
			}
		}	// <-- the placeholder for global messages exists
		preferencesFile.Unset();
	} // <-- end of "if ( succeeded to open the file with preferences )"

	return status;	
}	// <-- end of function pref_ReloadAllPreferences