MCPcopy Create free account
hub / github.com/M2Team/NanaBox / InitializeVirtualMachine

Method InitializeVirtualMachine

NanaBox/MainWindow.cpp:518–684  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

516}
517
518void NanaBox::MainWindow::InitializeVirtualMachine()
519{
520 std::string ConfigurationFileContent = ::ReadAllTextFromUtf8TextFile(
521 this->m_ConfigurationFilePath);
522
523 this->m_Configuration = NanaBox::DeserializeConfiguration(
524 ConfigurationFileContent);
525
526 winrt::hstring HcsVmId = winrt::to_hstring(this->m_Configuration.Name);
527
528 {
529 bool VirtualMachineExisted = true;
530 try
531 {
532 winrt::make_self<NanaBox::ComputeSystem>(HcsVmId);
533 }
534 catch (...)
535 {
536 VirtualMachineExisted = false;
537 }
538
539 if (VirtualMachineExisted)
540 {
541 winrt::throw_hresult(HCS_E_SYSTEM_ALREADY_EXISTS);
542 }
543 }
544
545 for (NanaBox::ScsiDeviceConfiguration& ScsiDevice
546 : this->m_Configuration.ScsiDevices)
547 {
548 NanaBox::ValidateScsiDeviceConfiguration(HcsVmId, ScsiDevice);
549 }
550
551 if (this->m_Configuration.GuestStateFile.empty())
552 {
553 this->m_Configuration.GuestStateFile =
554 this->m_Configuration.Name + ".vmgs";
555 }
556 {
557 std::wstring GuestStateFile = ::GetAbsolutePath(Mile::ToWideString(
558 CP_UTF8, this->m_Configuration.GuestStateFile));
559 if (!::PathFileExistsW(GuestStateFile.c_str()))
560 {
561 winrt::check_hresult(::HcsCreateEmptyGuestStateFile(
562 GuestStateFile.c_str()));
563 }
564
565 winrt::check_hresult(::HcsGrantVmAccess(
566 HcsVmId.c_str(),
567 GuestStateFile.c_str()));
568 }
569
570 if (this->m_Configuration.RuntimeStateFile.empty())
571 {
572 this->m_Configuration.RuntimeStateFile =
573 this->m_Configuration.Name + ".vmrs";
574 }
575 {

Callers 2

OnCreateMethod · 0.95
OnCommandMethod · 0.95

Calls 6

GetAbsolutePathFunction · 0.85
DisconnectMethod · 0.80
StartMethod · 0.80
GetPropertiesMethod · 0.80

Tested by

no test coverage detected