Changeset 67610 in vbox
- Timestamp:
- Jun 26, 2017 4:03:40 PM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp
r66662 r67610 2032 2032 } 2033 2033 2034 bool UISession::mountAdHocImage(KDeviceType enmDeviceType, UIMediumType enmMediumType, const QString &strImage) 2035 { 2036 /* The 'none' image name means ejecting what ever is in the drive, 2037 * so leave the image variables null. */ 2038 CVirtualBox vbox = vboxGlobal().virtualBox(); 2039 UIMedium uiImage; 2040 if (strImage != "none") 2041 { 2042 /* Open the image: */ 2043 CVirtualBox vbox = vboxGlobal().virtualBox(); 2044 CMedium vboxImage = vbox.OpenMedium(strImage, enmDeviceType, KAccessMode_ReadWrite, false /* fForceNewUuid */); 2045 if (!vbox.isOk() || vboxImage.isNull()) 2046 { 2047 msgCenter().cannotOpenMedium(vbox, enmMediumType, strImage); 2034 bool UISession::mountAdHocImage(KDeviceType enmDeviceType, UIMediumType enmMediumType, const QString &strMediumName) 2035 { 2036 /* Get VBox: */ 2037 CVirtualBox comVBox = vboxGlobal().virtualBox(); 2038 2039 /* Prepare medium to mount: */ 2040 UIMedium guiMedium; 2041 2042 /* The 'none' medium name means ejecting what ever is in the drive, 2043 * in that case => leave the guiMedium variable null. */ 2044 if (strMediumName != "none") 2045 { 2046 /* Open the medium: */ 2047 const CMedium comMedium = comVBox.OpenMedium(strMediumName, enmDeviceType, KAccessMode_ReadWrite, false /* fForceNewUuid */); 2048 if (!comVBox.isOk() || comMedium.isNull()) 2049 { 2050 msgCenter().cannotOpenMedium(comVBox, enmMediumType, strMediumName); 2048 2051 return false; 2049 2052 } 2050 2053 2051 /* Work the cache and use the cached image if possible: */ 2052 uiImage = vboxGlobal().medium(vboxImage.GetId()); 2053 if (uiImage.isNull()) 2054 { 2055 uiImage = UIMedium(vboxImage, enmMediumType, KMediumState_Created); 2056 vboxGlobal().createMedium(uiImage); 2057 } 2058 } 2059 if (vbox.isOk()) 2060 { 2061 /* Find suitable storage controller: */ 2062 foreach (const CStorageController &controller, machine().GetStorageControllers()) 2063 { 2064 foreach (const CMediumAttachment &attachment, machine().GetMediumAttachmentsOfController(controller.GetName())) 2054 /* Make sure medium ID is valid: */ 2055 const QString strMediumId = comMedium.GetId(); 2056 AssertReturn(!strMediumId.isNull(), false); 2057 2058 /* Try to find UIMedium among cached: */ 2059 guiMedium = vboxGlobal().medium(strMediumId); 2060 if (guiMedium.isNull()) 2061 { 2062 /* Cache new one if necessary: */ 2063 guiMedium = UIMedium(comMedium, enmMediumType, KMediumState_Created); 2064 vboxGlobal().createMedium(guiMedium); 2065 } 2066 } 2067 2068 /* Search for a suitable storage slots: */ 2069 QList<ExactStorageSlot> aFreeStorageSlots; 2070 QList<ExactStorageSlot> aBusyStorageSlots; 2071 foreach (const CStorageController &comController, machine().GetStorageControllers()) 2072 { 2073 foreach (const CMediumAttachment &comAttachment, machine().GetMediumAttachmentsOfController(comController.GetName())) 2074 { 2075 /* Look for an optical devices only: */ 2076 if (comAttachment.GetType() == enmDeviceType) 2065 2077 { 2066 if (attachment.GetType() == enmDeviceType) 2067 { 2068 /* Mount the image: */ 2069 machine().MountMedium(controller.GetName(), attachment.GetPort(), attachment.GetDevice(), uiImage.medium(), true /* force */); 2070 if (machine().isOk()) 2071 return true; 2072 msgCenter().cannotRemountMedium(machine(), uiImage, !uiImage.isNull() /* mount */, false /* retry */); 2073 return false; 2074 } 2078 /* Append storage slot to corresponding list: */ 2079 if (comAttachment.GetMedium().isNull()) 2080 aFreeStorageSlots << ExactStorageSlot(comController.GetName(), comController.GetBus(), 2081 comAttachment.GetPort(), comAttachment.GetDevice()); 2082 else 2083 aBusyStorageSlots << ExactStorageSlot(comController.GetName(), comController.GetBus(), 2084 comAttachment.GetPort(), comAttachment.GetDevice()); 2075 2085 } 2076 2086 } 2077 msgCenter().cannotRemountMedium(machine(), uiImage, !uiImage.isNull() /* mount */, false /* retry */); 2078 } 2079 else 2080 msgCenter().cannotOpenMedium(vbox, enmMediumType, strImage); 2081 return false; 2087 } 2088 2089 /* Make sure at least one storage slot found: */ 2090 QList<ExactStorageSlot> sStorageSlots = aFreeStorageSlots + aBusyStorageSlots; 2091 if (sStorageSlots.isEmpty()) 2092 { 2093 msgCenter().cannotMountGuestAdditions(machineName()); 2094 return false; 2095 } 2096 2097 /* Try to mount medium into first available storage slot: */ 2098 while (!sStorageSlots.isEmpty()) 2099 { 2100 const ExactStorageSlot storageSlot = sStorageSlots.takeFirst(); 2101 machine().MountMedium(storageSlot.controller, storageSlot.port, storageSlot.device, guiMedium.medium(), false /* force */); 2102 if (machine().isOk()) 2103 break; 2104 } 2105 2106 /* Show error message if necessary: */ 2107 if (!machine().isOk()) 2108 { 2109 msgCenter().cannotRemountMedium(machine(), guiMedium, true /* mount? */, false /* retry? */, mainMachineWindow()); 2110 return false; 2111 } 2112 2113 /* Save machine settings: */ 2114 machine().SaveSettings(); 2115 2116 /* Show error message if necessary: */ 2117 if (!machine().isOk()) 2118 { 2119 msgCenter().cannotSaveMachineSettings(machine(), mainMachineWindow()); 2120 return false; 2121 } 2122 2123 /* True by default: */ 2124 return true; 2082 2125 } 2083 2126 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h
r66660 r67610 399 399 void setPointerShape(const uchar *pShapeData, bool fHasAlpha, uint uXHot, uint uYHot, uint uWidth, uint uHeight); 400 400 bool preprocessInitialization(); 401 bool mountAdHocImage(KDeviceType enmDeviceType, UIMediumType enmMediumType, const QString &str Image);401 bool mountAdHocImage(KDeviceType enmDeviceType, UIMediumType enmMediumType, const QString &strMediumName); 402 402 bool postprocessInitialization(); 403 403 int countOfVisibleWindows();
Note:
See TracChangeset
for help on using the changeset viewer.