bool UIWizardNewVD::createVirtualDisk() { /* Gather attributes: */ CMediumFormat mediumFormat = field("mediumFormat").value<CMediumFormat>(); qulonglong uVariant = field("mediumVariant").toULongLong(); QString strMediumPath = field("mediumPath").toString(); qulonglong uSize = field("mediumSize").toULongLong(); /* Check attributes: */ AssertReturn(!strMediumPath.isNull(), false); AssertReturn(uSize > 0, false); /* Get VBox object: */ CVirtualBox vbox = vboxGlobal().virtualBox(); /* Create new virtual hard-disk: */ CMedium virtualDisk = vbox.CreateMedium(mediumFormat.GetName(), strMediumPath, KAccessMode_ReadWrite, KDeviceType_HardDisk); if (!vbox.isOk()) { msgCenter().cannotCreateHardDiskStorage(vbox, strMediumPath, this); return false; } /* Compose medium-variant: */ QVector<KMediumVariant> variants(sizeof(qulonglong)*8); for (int i = 0; i < variants.size(); ++i) { qulonglong temp = uVariant; temp &= UINT64_C(1)<<i; variants[i] = (KMediumVariant)temp; } /* Create base storage for the new virtual-disk: */ CProgress progress = virtualDisk.CreateBaseStorage(uSize, variants); if (!virtualDisk.isOk()) { msgCenter().cannotCreateHardDiskStorage(virtualDisk, strMediumPath, this); return false; } /* Show creation progress: */ msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this); if (progress.GetCanceled()) return false; if (!progress.isOk() || progress.GetResultCode() != 0) { msgCenter().cannotCreateHardDiskStorage(progress, strMediumPath, this); return false; } /* Remember created virtual-disk: */ m_virtualDisk = virtualDisk; /* Inform VBoxGlobal about it: */ vboxGlobal().createMedium(UIMedium(m_virtualDisk, UIMediumType_HardDisk, KMediumState_Created)); return true; }
bool UIWizardNewVD::createVirtualDisk() { /* Gather attributes: */ CMediumFormat mediumFormat = field("mediumFormat").value<CMediumFormat>(); qulonglong uVariant = field("mediumVariant").toULongLong(); QString strMediumPath = field("mediumPath").toString(); qulonglong uSize = field("mediumSize").toULongLong(); /* Check attributes: */ AssertReturn(!strMediumPath.isNull(), false); AssertReturn(uSize > 0, false); /* Get vbox object: */ CVirtualBox vbox = vboxGlobal().virtualBox(); /* Create new virtual disk: */ CMedium virtualDisk = vbox.CreateHardDisk(mediumFormat.GetName(), strMediumPath); CProgress progress; if (!vbox.isOk()) { msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress); return false; } /* Create base storage for the new hard disk: */ progress = virtualDisk.CreateBaseStorage(uSize, uVariant); if (!virtualDisk.isOk()) { msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress); return false; } /* Show creation progress: */ msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this, true); if (progress.GetCanceled()) return false; if (!progress.isOk() || progress.GetResultCode() != 0) { msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress); return false; } /* Remember created virtual-disk: */ m_virtualDisk = virtualDisk; /* Inform everybody there is a new medium: */ vboxGlobal().addMedium(UIMedium(m_virtualDisk, UIMediumType_HardDisk, KMediumState_Created)); return true; }