PartitionListRow::PartitionListRow(BPartition* partition)
	:
	Inherited(),
	fPartitionID(partition->ID()),
	fParentID(partition->Parent() ? partition->Parent()->ID() : -1),
	fOffset(partition->Offset()),
	fSize(partition->Size())
{
	BPath path;
	partition->GetPath(&path);

	// Device icon

	BBitmap* icon = NULL;
	if (partition->IsDevice()) {
		icon_size size = B_MINI_ICON;
		icon = new BBitmap(BRect(0, 0, size - 1, size - 1), B_RGBA32);
		if (partition->GetIcon(icon, size) != B_OK) {
			delete icon;
			icon = NULL;
		}
	}

	SetField(new BBitmapStringField(icon, path.Path()), kDeviceColumn);

	// File system & volume name

	BString partitionType(partition->Type());

	if (partition->ContainsFileSystem()) {
		SetField(new BStringField(partition->ContentType()), kFilesystemColumn);
		SetField(new BStringField(partition->ContentName()), kVolumeNameColumn);
	} else if (partition->IsDevice()) {
		SetField(new BStringField(kUnavailableString), kFilesystemColumn);
		if (partition->Name() != NULL && partition->Name()[0])
			SetField(new BStringField(partition->Name()), kVolumeNameColumn);
		else
			SetField(new BStringField(kUnavailableString), kVolumeNameColumn);
	} else if (partition->CountChildren() > 0) {
		SetField(new BStringField(kUnavailableString), kFilesystemColumn);
		SetField(new BStringField(kUnavailableString), kVolumeNameColumn);
	} else {
		if (!partitionType.IsEmpty()) {
			partitionType.Prepend("(");
			partitionType.Append(")");
			SetField(new BStringField(partitionType), kFilesystemColumn);
		} else
			SetField(new BStringField(kUnavailableString), kFilesystemColumn);

		SetField(new BStringField(kUnavailableString), kVolumeNameColumn);
	}

	// Mounted at

	if (partition->IsMounted() && partition->GetMountPoint(&path) == B_OK)
		SetField(new BStringField(path.Path()), kMountedAtColumn);
	else
		SetField(new BStringField(kUnavailableString), kMountedAtColumn);

	// Size

	if (fSize > 0) {
		char size[1024];
		SetField(new BStringField(string_for_size(partition->Size(), size,
			sizeof(size))), kSizeColumn);
	} else {
		SetField(new BStringField(kUnavailableString), kSizeColumn);
	}

	// Additional parameters

	if (partition->Parameters() != NULL) {
		BString parameters;

		// check parameters
		void* handle = parse_driver_settings_string(partition->Parameters());
		if (handle != NULL) {
			bool active = get_driver_boolean_parameter(handle, "active", false, true);
			if (active)
				parameters += B_TRANSLATE("Active");

			delete_driver_settings(handle);
		}

		SetField(new BStringField(parameters), kParametersColumn);
	} else {
		SetField(new BStringField(kUnavailableString), kParametersColumn);
	}

	// Partition type

	if (partitionType.IsEmpty())
		partitionType = partition->ContentType();
	SetField(new BStringField(partitionType), kPartitionTypeColumn);
}
Ejemplo n.º 2
0
status_t
BRepositoryInfo::_SetTo(const BEntry& entry)
{
	BFile file(&entry, B_READ_ONLY);
	status_t result = file.InitCheck();
	if (result != B_OK)
		return result;

	off_t size;
	if ((result = file.GetSize(&size)) != B_OK)
		return result;

	BString configString;
	char* buffer = configString.LockBuffer(size);
	if (buffer == NULL)
		return B_NO_MEMORY;

	if ((result = file.Read(buffer, size)) < size) {
		configString.UnlockBuffer(0);
		return (result >= 0) ? B_IO_ERROR : result;
	}

	buffer[size] = '\0';
	configString.UnlockBuffer(size);

	void* settingsHandle = parse_driver_settings_string(configString.String());
	if (settingsHandle == NULL)
		return B_BAD_DATA;
	CObjectDeleter<void, status_t> settingsHandleDeleter(settingsHandle,
		&unload_driver_settings);

	const char* name = get_driver_parameter(settingsHandle, "name", NULL, NULL);
	const char* url = get_driver_parameter(settingsHandle, "url", NULL, NULL);
	const char* vendor
		= get_driver_parameter(settingsHandle, "vendor", NULL, NULL);
	const char* summary
		= get_driver_parameter(settingsHandle, "summary", NULL, NULL);
	const char* priorityString
		= get_driver_parameter(settingsHandle, "priority", NULL, NULL);
	const char* architectureString
		= get_driver_parameter(settingsHandle, "architecture", NULL, NULL);

	if (name == NULL || *name == '\0' || url == NULL || *url == '\0'
		|| vendor == NULL || *vendor == '\0'
		|| summary == NULL || *summary == '\0'
		|| priorityString == NULL || *priorityString == '\0'
		|| architectureString == NULL || *architectureString == '\0') {
		return B_BAD_DATA;
	}

	BPackageArchitecture architecture;
	if (BPackageInfo::GetArchitectureByName(architectureString, architecture)
			!= B_OK || architecture == B_PACKAGE_ARCHITECTURE_ANY) {
		return B_BAD_DATA;
	}

	fName = name;
	fOriginalBaseURL = url;
	fVendor = vendor;
	fSummary = summary;
	fPriority = atoi(priorityString);
	fArchitecture = architecture;

	return B_OK;
}