Changeset 100282 in vbox
- Timestamp:
- Jun 25, 2023 2:52:31 PM (17 months ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/medium/viso
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoContentBrowser.cpp
r100281 r100282 47 47 #include <iprt/file.h> 48 48 #include <iprt/fsvfs.h> 49 #include <iprt/mem.h> 50 #include <iprt/err.h> 49 51 50 52 struct ISOFileObject … … 54 56 }; 55 57 56 static QList<ISOFileObject> readISODir(const QString &strISOFilePath) 57 { 58 // QList<KFsObjType> fileObjectTypeList; 59 // QStringList pathList; 58 59 static void readISODir(RTVFSDIR &hVfsDir, QList<ISOFileObject> &fileObjectList) 60 { 61 size_t cbDirEntry = sizeof(RTDIRENTRYEX); 62 PRTDIRENTRYEX pDirEntry = (PRTDIRENTRYEX)RTMemTmpAlloc(cbDirEntry); 63 size_t cbDirEntryAlloced = cbDirEntry; 64 for(;;) 65 { 66 if (pDirEntry) 67 { 68 int vrc = RTVfsDirReadEx(hVfsDir, pDirEntry, &cbDirEntry, RTFSOBJATTRADD_UNIX); 69 if (RT_FAILURE(vrc)) 70 { 71 if (vrc == VERR_BUFFER_OVERFLOW) 72 { 73 RTMemTmpFree(pDirEntry); 74 cbDirEntryAlloced = RT_ALIGN_Z(RT_MIN(cbDirEntry, cbDirEntryAlloced) + 64, 64); 75 pDirEntry = (PRTDIRENTRYEX)RTMemTmpAlloc(cbDirEntryAlloced); 76 if (pDirEntry) 77 continue; 78 /// @todo log error 79 //rcExit = RTMsgErrorExitFailure("Out of memory (direntry buffer)"); 80 } 81 /// @todo log error 82 // else if (rc != VERR_NO_MORE_FILES) 83 // rcExit = RTMsgErrorExitFailure("RTVfsDirReadEx failed: %Rrc\n", rc); 84 break; 85 } 86 else 87 { 88 ISOFileObject fileObject; 89 90 if (RTFS_IS_DIRECTORY(pDirEntry->Info.Attr.fMode)) 91 fileObject.enmObjectType = KFsObjType_Directory; 92 else 93 fileObject.enmObjectType = KFsObjType_File; 94 fileObject.strName = pDirEntry->szName; 95 fileObjectList << fileObject; 96 } 97 } 98 } 99 RTMemTmpFree(pDirEntry); 100 } 101 102 static QList<ISOFileObject> openAndReadISODir(const QString &strISOFilePath, QString strDirPath = QString()) 103 { 60 104 QList<ISOFileObject> fileObjectList; 61 62 105 63 106 RTVFSFILE hVfsFileIso; … … 74 117 if (RT_SUCCESS(vrc)) 75 118 { 76 size_t cbDirEntry = sizeof(RTDIRENTRYEX); 77 PRTDIRENTRYEX pDirEntry = (PRTDIRENTRYEX)RTMemTmpAlloc(cbDirEntry); 78 size_t cbDirEntryAlloced = cbDirEntry; 79 for(;;) 119 if (strDirPath.isEmpty()) 120 readISODir(hVfsSrcRootDir, fileObjectList); 121 else 80 122 { 81 if (pDirEntry) 123 RTVFSDIR hVfsDir; 124 vrc = RTVfsDirOpenDir(hVfsSrcRootDir, strDirPath.toUtf8().constData(), 0 /* fFlags */, &hVfsDir); 125 if (RT_SUCCESS(vrc)) 82 126 { 83 vrc = RTVfsDirReadEx(hVfsSrcRootDir, pDirEntry, &cbDirEntry, RTFSOBJATTRADD_UNIX); 84 if (RT_FAILURE(vrc)) 85 { 86 if (vrc == VERR_BUFFER_OVERFLOW) 87 { 88 RTMemTmpFree(pDirEntry); 89 cbDirEntryAlloced = RT_ALIGN_Z(RT_MIN(cbDirEntry, cbDirEntryAlloced) + 64, 64); 90 pDirEntry = (PRTDIRENTRYEX)RTMemTmpAlloc(cbDirEntryAlloced); 91 if (pDirEntry) 92 continue; 93 /// @todo log error 94 //rcExit = RTMsgErrorExitFailure("Out of memory (direntry buffer)"); 95 } 96 /// @todo log error 97 // else if (rc != VERR_NO_MORE_FILES) 98 // rcExit = RTMsgErrorExitFailure("RTVfsDirReadEx failed: %Rrc\n", rc); 99 break; 100 } 101 else 102 { 103 ISOFileObject fileObject; 104 105 if (RTFS_IS_DIRECTORY(pDirEntry->Info.Attr.fMode)) 106 fileObject.enmObjectType = KFsObjType_Directory; 107 else 108 fileObject.enmObjectType = KFsObjType_File; 109 fileObject.strName = pDirEntry->szName; 110 fileObjectList << fileObject; 111 } 127 readISODir(hVfsDir, fileObjectList); 128 RTVfsDirRelease(hVfsDir); 112 129 } 113 130 } 114 RTMemTmpFree(pDirEntry); 131 132 RTVfsDirRelease(hVfsSrcRootDir); 115 133 } 116 134 RTVfsRelease(hVfsIso); … … 119 137 } 120 138 return fileObjectList; 121 // if (!pathList.isEmpty() && pathList.size() == fileObjectTypeList.size() && m_pVISOContentBrowser)122 // m_pVISOContentBrowser->importISOContentToViso(selectedObjectPaths[iIndex], pathList, fileObjectTypeList);123 139 } 124 140 … … 289 305 } 290 306 291 void UIVisoContentBrowser::importISOContentToViso(const QString &strISOFilePath) 292 { 293 UICustomFileSystemItem *pParentItem = rootItem()->children()[0]; 307 void UIVisoContentBrowser::importISOContentToViso(const QString &strISOFilePath, 308 UICustomFileSystemItem *pParentItem /* = 0 */, 309 const QString &strDirPath /* = QString() */) 310 { 311 if (!pParentItem) 312 pParentItem = rootItem()->children()[0]; 294 313 if (!m_pTableView || !pParentItem) 295 314 return; 296 QList<ISOFileObject> objectList = readISODir(strISOFilePath); 315 316 /* If this is not the root directory add an "up" file object explicity since RTVfsDirReadEx does not return one:*/ 317 if (!strDirPath.isEmpty()) 318 { 319 UICustomFileSystemItem* pAddedItem = new UICustomFileSystemItem(UICustomFileSystemModel::strUpDirectoryString, 320 pParentItem, 321 KFsObjType_Directory); 322 pAddedItem->setData(strISOFilePath, UICustomFileSystemModelData_ISOFilePath); 323 } 324 QList<ISOFileObject> objectList = openAndReadISODir(strISOFilePath, strDirPath); 297 325 298 326 for (int i = 0; i < objectList.size(); ++i) … … 307 335 UICustomFileSystemItem* pAddedItem = new UICustomFileSystemItem(fileInfo.fileName(), pParentItem, 308 336 objectList[i].enmObjectType); 309 pAddedItem->setData(objectList[i].strName, UICustomFileSystemModelData_LocalPath); 337 /* VISOPAth and LocalPath is the same since we allow importing ISO content only to VISO root:*/ 338 QString path = UIPathOperations::mergePaths(pParentItem->path(), fileInfo.fileName()); 339 pAddedItem->setData(path, UICustomFileSystemModelData_LocalPath); 310 340 pAddedItem->setData(strISOFilePath, UICustomFileSystemModelData_ISOFilePath); 311 pAddedItem->setData(UIPathOperations::mergePaths(pParentItem->path(), fileInfo.fileName()), 312 UICustomFileSystemModelData_VISOPath); 341 pAddedItem->setData(path, UICustomFileSystemModelData_VISOPath); 313 342 pAddedItem->setIsOpened(false); 314 343 // if (fileInfo.isSymLink()) … … 421 450 UICustomFileSystemItem *pClickedItem = 422 451 static_cast<UICustomFileSystemItem*>(m_pTableProxyModel->mapToSource(index).internalPointer()); 452 if (!pClickedItem) 453 return; 454 QString strISOPath = pClickedItem->data(UICustomFileSystemModelData_ISOFilePath).toString(); 423 455 if (pClickedItem->isUpDirectory()) 424 456 { … … 430 462 setTreeCurrentIndex(currentRoot.parent()); 431 463 } 464 } 465 else if (!strISOPath.isEmpty()) 466 { 467 importISOContentToViso(strISOPath, pClickedItem, pClickedItem->data(UICustomFileSystemModelData_LocalPath).toString()); 468 setTableRootIndex(index); 469 setTreeCurrentIndex(index); 432 470 } 433 471 else … … 804 842 UICustomFileSystemItem *newItem = new UICustomFileSystemItem(fileInfo.fileName(), 805 843 directoryItem, 806 fileType(fileInfo));844 fileType(fileInfo)); 807 845 newItem->setData(fileInfo.filePath(), UICustomFileSystemModelData_LocalPath); 808 846 -
trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoContentBrowser.h
r100281 r100282 63 63 ~UIVisoContentBrowser(); 64 64 /* Imports pathList (relative to ISO file's root) to VISO content. */ 65 void importISOContentToViso(const QString &strISOFilePath); 65 void importISOContentToViso(const QString &strISOFilePath, 66 UICustomFileSystemItem *pParentItem = 0, 67 const QString &strDirPath = QString()); 66 68 /** Adds file objests from the host file system. @p pathList consists of list of paths to there objects. */ 67 69 void addObjectsToViso(const QStringList &pathList);
Note:
See TracChangeset
for help on using the changeset viewer.