本文整理汇总了C++中BPartition::CanInitialize方法的典型用法代码示例。如果您正苦于以下问题:C++ BPartition::CanInitialize方法的具体用法?C++ BPartition::CanInitialize怎么用?C++ BPartition::CanInitialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BPartition
的用法示例。
在下文中一共展示了BPartition::CanInitialize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _InitializePartition
void _InitializePartition()
{
if (!fPrepared) {
if (fDevice->IsReadOnly())
printf("Device is read-only!\n");
else
printf("Sorry, not prepared for modifications!\n");
return;
}
// get the partition
int32 partitionIndex;
BPartition* partition = NULL;
if (!_SelectPartition("partition index [-1 to abort]: ", partition,
partitionIndex)) {
return;
}
printf("\nselected partition:\n\n");
print_partition_table_header();
print_partition(partition, 0, partitionIndex);
// get available disk systems
BObjectList<BDiskSystem> diskSystems(20, true);
BDiskDeviceRoster roster;
{
BDiskSystem diskSystem;
while (roster.GetNextDiskSystem(&diskSystem) == B_OK) {
if (partition->CanInitialize(diskSystem.PrettyName()))
diskSystems.AddItem(new BDiskSystem(diskSystem));
}
}
if (diskSystems.IsEmpty()) {
printf("There are no disk systems, that can initialize this "
"partition.\n");
return;
}
// print the available disk systems
printf("\ndisk systems that can initialize the selected partition:\n");
for (int32 i = 0; BDiskSystem* diskSystem = diskSystems.ItemAt(i); i++)
printf("%2ld %s\n", i, diskSystem->PrettyName());
printf("\n");
// get the disk system
int64 diskSystemIndex;
if (!_ReadNumber("disk system index [-1 to abort]: ", 0,
diskSystems.CountItems() - 1, -1, "invalid index",
diskSystemIndex)) {
return;
}
BDiskSystem* diskSystem = diskSystems.ItemAt(diskSystemIndex);
bool supportsName = diskSystem->SupportsContentName();
BString name;
BString parameters;
while (true) {
// let the user enter name and parameters
if (supportsName && !_ReadLine("partition name: ", name)
|| !_ReadLine("partition parameters: ", parameters)) {
return;
}
// validate parameters
BString validatedName(name);
if (partition->ValidateInitialize(diskSystem->PrettyName(),
supportsName ? &validatedName : NULL, parameters.String())
!= B_OK) {
printf("Validation of the given values failed. Sorry, can't "
"continue.\n");
return;
}
// did the disk system change the name?
if (!supportsName || name == validatedName) {
printf("Everything looks dandy.\n");
} else {
printf("The disk system adjusted the file name to \"%s\".\n",
validatedName.String());
name = validatedName;
}
// let the user decide whether to continue, change parameters, or
// abort
bool changeParameters = false;
while (true) {
BString line;
_ReadLine("[c]ontinue, change [p]arameters, or [a]bort? ", line);
if (line == "a")
return;
if (line == "p") {
changeParameters = true;
break;
}
if (line == "c")
break;
printf("invalid input\n");
//.........这里部分代码省略.........
示例2: BMessage
void
MainWindow::_UpdateMenus(BDiskDevice* disk,
partition_id selectedPartition, partition_id parentID)
{
while (BMenuItem* item = fFormatMenu->RemoveItem(0L))
delete item;
while (BMenuItem* item = fDiskInitMenu->RemoveItem(0L))
delete item;
fCreateMI->SetEnabled(false);
fUnmountMI->SetEnabled(false);
fDiskInitMenu->SetEnabled(false);
fFormatMenu->SetEnabled(false);
if (!disk) {
fWipeMI->SetEnabled(false);
fEjectMI->SetEnabled(false);
fSurfaceTestMI->SetEnabled(false);
} else {
// fWipeMI->SetEnabled(true);
fWipeMI->SetEnabled(false);
fEjectMI->SetEnabled(disk->IsRemovableMedia());
// fSurfaceTestMI->SetEnabled(true);
fSurfaceTestMI->SetEnabled(false);
// Create menu and items
BPartition* parentPartition = NULL;
if (selectedPartition <= -2) {
// a partitionable space item is selected
parentPartition = disk->FindDescendant(parentID);
}
if (parentPartition && parentPartition->ContainsPartitioningSystem())
fCreateMI->SetEnabled(true);
bool prepared = disk->PrepareModifications() == B_OK;
fFormatMenu->SetEnabled(prepared);
fDeleteMI->SetEnabled(prepared);
BPartition* partition = disk->FindDescendant(selectedPartition);
BDiskSystem diskSystem;
fDDRoster.RewindDiskSystems();
while (fDDRoster.GetNextDiskSystem(&diskSystem) == B_OK) {
if (!diskSystem.SupportsInitializing())
continue;
BMessage* message = new BMessage(MSG_INITIALIZE);
message->AddInt32("parent id", parentID);
message->AddString("disk system", diskSystem.PrettyName());
BString label = diskSystem.PrettyName();
label << B_UTF8_ELLIPSIS;
BMenuItem* item = new BMenuItem(label.String(), message);
// TODO: Very unintuitive that we have to use PrettyName (vs Name)
item->SetEnabled(partition != NULL
&& partition->CanInitialize(diskSystem.PrettyName()));
if (disk->ID() == selectedPartition
&& !diskSystem.IsFileSystem()) {
// Disk is selected, and DiskSystem is a partition map
fDiskInitMenu->AddItem(item);
} else if (diskSystem.IsFileSystem()) {
// Otherwise a filesystem
fFormatMenu->AddItem(item);
}
}
// Mount items
if (partition) {
fFormatMenu->SetEnabled(!partition->IsMounted()
&& !partition->IsReadOnly()
&& partition->Device()->HasMedia()
&& fFormatMenu->CountItems() > 0);
fDiskInitMenu->SetEnabled(!partition->IsMounted()
&& !partition->IsReadOnly()
&& partition->Device()->HasMedia()
&& partition->IsDevice()
&& fDiskInitMenu->CountItems() > 0);
fDeleteMI->SetEnabled(!partition->IsMounted()
&& !partition->IsDevice());
fMountMI->SetEnabled(!partition->IsMounted());
bool unMountable = false;
if (partition->IsMounted()) {
// see if this partition is the boot volume
BVolume volume;
BVolume bootVolume;
if (BVolumeRoster().GetBootVolume(&bootVolume) == B_OK
&& partition->GetVolume(&volume) == B_OK) {
unMountable = volume != bootVolume;
} else
unMountable = true;
}
fUnmountMI->SetEnabled(unMountable);
} else {
//.........这里部分代码省略.........