| 248 | } |
| 249 | |
| 250 | void UEFITool::insert(const UINT8 mode) |
| 251 | { |
| 252 | QModelIndex index = ui->structureTreeView->selectionModel()->currentIndex(); |
| 253 | if (!index.isValid()) |
| 254 | return; |
| 255 | |
| 256 | TreeModel* model = ffsEngine->treeModel(); |
| 257 | UINT8 type; |
| 258 | |
| 259 | if (mode == CREATE_MODE_BEFORE || mode == CREATE_MODE_AFTER) |
| 260 | type = model->type(index.parent()); |
| 261 | else |
| 262 | type = model->type(index); |
| 263 | |
| 264 | QString path; |
| 265 | switch (type) { |
| 266 | case Types::Volume: |
| 267 | path = QFileDialog::getOpenFileName(this, tr("Select FFS file to insert"), currentDir, "FFS files (*.ffs *.bin);;All files (*)"); |
| 268 | break; |
| 269 | case Types::File: |
| 270 | case Types::Section: |
| 271 | path = QFileDialog::getOpenFileName(this, tr("Select section file to insert"), currentDir, "Section files (*.sct *.bin);;All files (*)"); |
| 272 | break; |
| 273 | default: |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | if (path.trimmed().isEmpty()) |
| 278 | return; |
| 279 | |
| 280 | QFileInfo fileInfo = QFileInfo(path); |
| 281 | if (!fileInfo.exists()) { |
| 282 | ui->statusBar->showMessage(tr("Please select existing file")); |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | QFile inputFile; |
| 287 | inputFile.setFileName(path); |
| 288 | |
| 289 | if (!inputFile.open(QFile::ReadOnly)) { |
| 290 | QMessageBox::critical(this, tr("Insertion failed"), tr("Can't open output file for reading"), QMessageBox::Ok); |
| 291 | return; |
| 292 | } |
| 293 | |
| 294 | QByteArray buffer = inputFile.readAll(); |
| 295 | inputFile.close(); |
| 296 | |
| 297 | UINT8 result = ffsEngine->insert(index, buffer, mode); |
| 298 | if (result) { |
| 299 | QMessageBox::critical(this, tr("Insertion failed"), errorMessage(result), QMessageBox::Ok); |
| 300 | return; |
| 301 | } |
| 302 | ui->actionSaveImageFile->setEnabled(true); |
| 303 | } |
| 304 | |
| 305 | void UEFITool::insertInto() |
| 306 | { |
no test coverage detected