2013-10-08 15:07:03 +08:00
/* uefitool.cpp
2015-01-31 22:00:00 +08:00
Copyright ( c ) 2015 , Nikolaj Schlej . All rights reserved .
2013-10-08 15:07:03 +08:00
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution . The full text of the license may be found at
http : //opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN " AS IS " BASIS ,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND , EITHER EXPRESS OR IMPLIED .
2014-07-25 07:59:51 +08:00
*/
2013-10-08 15:07:03 +08:00
# include "uefitool.h"
# include "ui_uefitool.h"
UEFITool : : UEFITool ( QWidget * parent ) :
2014-07-25 07:59:51 +08:00
QMainWindow ( parent ) ,
2015-08-30 16:52:19 +08:00
ui ( new Ui : : UEFITool ) ,
2015-09-13 03:01:42 +08:00
version ( tr ( " 0.21.1 " ) )
2013-10-08 15:07:03 +08:00
{
2014-07-14 06:38:34 +08:00
clipboard = QApplication : : clipboard ( ) ;
2013-12-05 04:27:12 +08:00
// Create UI
2013-10-08 15:07:03 +08:00
ui - > setupUi ( this ) ;
2013-12-05 04:27:12 +08:00
searchDialog = new SearchDialog ( this ) ;
2013-12-29 23:13:46 +08:00
ffsEngine = NULL ;
2014-11-18 23:01:20 +08:00
// Set window title
this - > setWindowTitle ( tr ( " UEFITool %1 " ) . arg ( version ) ) ;
2014-08-14 20:02:35 +08:00
2013-12-05 04:27:12 +08:00
// Connect signals to slots
2013-10-15 23:19:15 +08:00
connect ( ui - > actionOpenImageFile , SIGNAL ( triggered ( ) ) , this , SLOT ( openImageFile ( ) ) ) ;
2015-08-14 02:28:10 +08:00
connect ( ui - > actionOpenImageFileInNewWindow , SIGNAL ( triggered ( ) ) , this , SLOT ( openImageFileInNewWindow ( ) ) ) ;
2013-12-29 23:13:46 +08:00
connect ( ui - > actionSaveImageFile , SIGNAL ( triggered ( ) ) , this , SLOT ( saveImageFile ( ) ) ) ;
connect ( ui - > actionSearch , SIGNAL ( triggered ( ) ) , this , SLOT ( search ( ) ) ) ;
2013-11-17 17:01:11 +08:00
connect ( ui - > actionExtract , SIGNAL ( triggered ( ) ) , this , SLOT ( extractAsIs ( ) ) ) ;
2013-11-07 21:46:28 +08:00
connect ( ui - > actionExtractBody , SIGNAL ( triggered ( ) ) , this , SLOT ( extractBody ( ) ) ) ;
connect ( ui - > actionInsertInto , SIGNAL ( triggered ( ) ) , this , SLOT ( insertInto ( ) ) ) ;
connect ( ui - > actionInsertBefore , SIGNAL ( triggered ( ) ) , this , SLOT ( insertBefore ( ) ) ) ;
connect ( ui - > actionInsertAfter , SIGNAL ( triggered ( ) ) , this , SLOT ( insertAfter ( ) ) ) ;
2013-12-12 19:28:39 +08:00
connect ( ui - > actionReplace , SIGNAL ( triggered ( ) ) , this , SLOT ( replaceAsIs ( ) ) ) ;
2013-12-29 23:13:46 +08:00
connect ( ui - > actionReplaceBody , SIGNAL ( triggered ( ) ) , this , SLOT ( replaceBody ( ) ) ) ;
2013-11-07 21:46:28 +08:00
connect ( ui - > actionRemove , SIGNAL ( triggered ( ) ) , this , SLOT ( remove ( ) ) ) ;
2013-11-18 23:23:59 +08:00
connect ( ui - > actionRebuild , SIGNAL ( triggered ( ) ) , this , SLOT ( rebuild ( ) ) ) ;
2014-07-14 06:38:34 +08:00
connect ( ui - > actionMessagesCopy , SIGNAL ( triggered ( ) ) , this , SLOT ( copyMessage ( ) ) ) ;
2014-07-27 15:54:38 +08:00
connect ( ui - > actionMessagesCopyAll , SIGNAL ( triggered ( ) ) , this , SLOT ( copyAllMessages ( ) ) ) ;
2013-12-05 04:27:12 +08:00
connect ( ui - > actionMessagesClear , SIGNAL ( triggered ( ) ) , this , SLOT ( clearMessages ( ) ) ) ;
2013-12-29 23:13:46 +08:00
connect ( ui - > actionAbout , SIGNAL ( triggered ( ) ) , this , SLOT ( about ( ) ) ) ;
2013-11-18 23:23:59 +08:00
connect ( ui - > actionAboutQt , SIGNAL ( triggered ( ) ) , this , SLOT ( aboutQt ( ) ) ) ;
connect ( ui - > actionQuit , SIGNAL ( triggered ( ) ) , this , SLOT ( exit ( ) ) ) ;
2013-12-05 04:27:12 +08:00
connect ( QCoreApplication : : instance ( ) , SIGNAL ( aboutToQuit ( ) ) , this , SLOT ( writeSettings ( ) ) ) ;
2013-10-08 15:07:03 +08:00
2013-12-05 04:27:12 +08:00
// Enable Drag-and-Drop actions
this - > setAcceptDrops ( true ) ;
2013-11-23 06:25:15 +08:00
2014-07-25 07:59:51 +08:00
// Set current directory
currentDir = " . " ;
2014-11-16 04:40:28 +08:00
// Set monospace font for some controls
QFont font ( " Courier New " , 10 ) ;
# if defined Q_OS_OSX
font = QFont ( " Menlo " , 10 ) ;
# elif defined Q_OS_WIN
font = QFont ( " Consolas " , 9 ) ;
# endif
ui - > infoEdit - > setFont ( font ) ;
ui - > messageListWidget - > setFont ( font ) ;
ui - > structureTreeView - > setFont ( font ) ;
searchDialog - > ui - > guidEdit - > setFont ( font ) ;
searchDialog - > ui - > hexEdit - > setFont ( font ) ;
2013-11-14 18:40:39 +08:00
// Initialize non-persistent data
2013-10-08 15:07:03 +08:00
init ( ) ;
2013-12-29 23:13:46 +08:00
// Read stored settings
readSettings ( ) ;
2013-11-23 06:25:15 +08:00
}
2013-10-08 15:07:03 +08:00
UEFITool : : ~ UEFITool ( )
{
delete ui ;
2013-10-15 23:19:15 +08:00
delete ffsEngine ;
2013-12-29 23:13:46 +08:00
delete searchDialog ;
2013-10-08 15:07:03 +08:00
}
2015-08-14 02:28:10 +08:00
void UEFITool : : setProgramPath ( QString path )
2015-08-30 16:52:19 +08:00
{
currentProgramPath = path ;
2015-08-14 02:28:10 +08:00
} ;
2013-10-08 15:07:03 +08:00
void UEFITool : : init ( )
{
2013-12-29 23:13:46 +08:00
// Clear components
2013-11-17 17:01:11 +08:00
ui - > messageListWidget - > clear ( ) ;
2013-10-08 15:07:03 +08:00
ui - > infoEdit - > clear ( ) ;
2013-12-29 23:13:46 +08:00
2014-11-18 23:01:20 +08:00
// Set window title
this - > setWindowTitle ( tr ( " UEFITool %1 " ) . arg ( version ) ) ;
2014-08-14 20:02:35 +08:00
2013-12-05 04:27:12 +08:00
// Disable menus
ui - > menuCapsuleActions - > setDisabled ( true ) ;
ui - > menuImageActions - > setDisabled ( true ) ;
ui - > menuRegionActions - > setDisabled ( true ) ;
ui - > menuPaddingActions - > setDisabled ( true ) ;
ui - > menuVolumeActions - > setDisabled ( true ) ;
ui - > menuFileActions - > setDisabled ( true ) ;
ui - > menuSectionActions - > setDisabled ( true ) ;
2014-07-14 06:38:34 +08:00
ui - > actionMessagesCopy - > setDisabled ( true ) ;
2014-07-27 15:54:38 +08:00
ui - > actionMessagesCopyAll - > setDisabled ( true ) ;
2013-10-15 23:19:15 +08:00
// Make new ffsEngine
2013-12-05 04:27:12 +08:00
if ( ffsEngine )
delete ffsEngine ;
2013-10-15 23:19:15 +08:00
ffsEngine = new FfsEngine ( this ) ;
2013-12-29 23:13:46 +08:00
ui - > structureTreeView - > setModel ( ffsEngine - > treeModel ( ) ) ;
2013-10-15 23:19:15 +08:00
// Connect
2013-10-08 15:07:03 +08:00
connect ( ui - > structureTreeView - > selectionModel ( ) , SIGNAL ( currentChanged ( const QModelIndex & , const QModelIndex & ) ) ,
2014-07-25 07:59:51 +08:00
this , SLOT ( populateUi ( const QModelIndex & ) ) ) ;
2013-11-17 17:01:11 +08:00
connect ( ui - > messageListWidget , SIGNAL ( itemDoubleClicked ( QListWidgetItem * ) ) , this , SLOT ( scrollTreeView ( QListWidgetItem * ) ) ) ;
2014-07-27 15:54:38 +08:00
connect ( ui - > messageListWidget , SIGNAL ( itemEntered ( QListWidgetItem * ) ) , this , SLOT ( enableMessagesCopyActions ( QListWidgetItem * ) ) ) ;
2013-10-08 15:07:03 +08:00
}
2013-11-14 18:40:39 +08:00
void UEFITool : : populateUi ( const QModelIndex & current )
2013-10-08 15:07:03 +08:00
{
2013-11-17 17:01:11 +08:00
if ( ! current . isValid ( ) )
return ;
2013-12-29 23:13:46 +08:00
TreeModel * model = ffsEngine - > treeModel ( ) ;
UINT8 type = model - > type ( current ) ;
2015-02-06 16:47:19 +08:00
UINT8 subtype = model - > subtype ( current ) ;
2013-12-29 23:13:46 +08:00
2013-12-05 04:27:12 +08:00
// Set info text
2013-12-29 23:13:46 +08:00
ui - > infoEdit - > setPlainText ( model - > info ( current ) ) ;
2013-12-05 04:27:12 +08:00
// Enable menus
2014-02-27 17:14:41 +08:00
ui - > menuCapsuleActions - > setEnabled ( type = = Types : : Capsule ) ;
ui - > menuImageActions - > setEnabled ( type = = Types : : Image ) ;
ui - > menuRegionActions - > setEnabled ( type = = Types : : Region ) ;
ui - > menuPaddingActions - > setEnabled ( type = = Types : : Padding ) ;
ui - > menuVolumeActions - > setEnabled ( type = = Types : : Volume ) ;
ui - > menuFileActions - > setEnabled ( type = = Types : : File ) ;
ui - > menuSectionActions - > setEnabled ( type = = Types : : Section ) ;
2013-12-29 23:13:46 +08:00
2013-12-05 04:27:12 +08:00
// Enable actions
2015-01-31 22:00:00 +08:00
ui - > actionExtract - > setDisabled ( model - > hasEmptyHeader ( current ) & & model - > hasEmptyBody ( current ) ) ;
2014-02-27 17:14:41 +08:00
ui - > actionRebuild - > setEnabled ( type = = Types : : Volume | | type = = Types : : File | | type = = Types : : Section ) ;
2015-01-26 06:55:05 +08:00
ui - > actionExtractBody - > setDisabled ( model - > hasEmptyBody ( current ) ) ;
2014-02-27 17:14:41 +08:00
ui - > actionRemove - > setEnabled ( type = = Types : : Volume | | type = = Types : : File | | type = = Types : : Section ) ;
2015-02-06 16:47:19 +08:00
ui - > actionInsertInto - > setEnabled ( ( type = = Types : : Volume & & subtype ! = Subtypes : : UnknownVolume ) | |
( type = = Types : : File & & subtype ! = EFI_FV_FILETYPE_ALL & & subtype ! = EFI_FV_FILETYPE_RAW & & subtype ! = EFI_FV_FILETYPE_PAD ) | |
( type = = Types : : Section & & ( subtype = = EFI_SECTION_COMPRESSION | | subtype = = EFI_SECTION_GUID_DEFINED | | subtype = = EFI_SECTION_DISPOSABLE ) ) ) ;
2014-02-27 17:14:41 +08:00
ui - > actionInsertBefore - > setEnabled ( type = = Types : : File | | type = = Types : : Section ) ;
ui - > actionInsertAfter - > setEnabled ( type = = Types : : File | | type = = Types : : Section ) ;
2015-09-13 02:46:21 +08:00
ui - > actionReplace - > setEnabled ( ( type = = Types : : Region & & subtype ! = Subtypes : : DescriptorRegion ) | | type = = Types : : Padding | | type = = Types : : Volume | | type = = Types : : File | | type = = Types : : Section ) ;
2015-01-31 22:00:00 +08:00
ui - > actionReplaceBody - > setEnabled ( type = = Types : : Volume | | type = = Types : : File | | type = = Types : : Section ) ;
2014-07-14 06:38:34 +08:00
ui - > actionMessagesCopy - > setEnabled ( false ) ;
2013-11-18 23:23:59 +08:00
}
2013-12-05 04:27:12 +08:00
void UEFITool : : search ( )
{
2013-12-29 23:13:46 +08:00
if ( searchDialog - > exec ( ) ! = QDialog : : Accepted )
return ;
2013-12-05 04:27:12 +08:00
2014-07-09 15:20:13 +08:00
QModelIndex rootIndex = ffsEngine - > treeModel ( ) - > index ( 0 , 0 ) ;
int index = searchDialog - > ui - > tabWidget - > currentIndex ( ) ;
2013-12-29 23:13:46 +08:00
if ( index = = 0 ) { // Hex pattern
2014-07-14 06:38:34 +08:00
searchDialog - > ui - > hexEdit - > setFocus ( ) ;
2014-11-09 05:24:53 +08:00
QByteArray pattern = searchDialog - > ui - > hexEdit - > text ( ) . toLatin1 ( ) . replace ( " " , " " ) ;
2013-12-29 23:13:46 +08:00
if ( pattern . isEmpty ( ) )
return ;
UINT8 mode ;
2014-07-09 15:20:13 +08:00
if ( searchDialog - > ui - > hexScopeHeaderRadioButton - > isChecked ( ) )
2013-12-29 23:13:46 +08:00
mode = SEARCH_MODE_HEADER ;
2014-07-09 15:20:13 +08:00
else if ( searchDialog - > ui - > hexScopeBodyRadioButton - > isChecked ( ) )
2013-12-29 23:13:46 +08:00
mode = SEARCH_MODE_BODY ;
else
mode = SEARCH_MODE_ALL ;
2014-07-09 15:20:13 +08:00
ffsEngine - > findHexPattern ( rootIndex , pattern , mode ) ;
2013-12-29 23:13:46 +08:00
showMessages ( ) ;
}
2014-07-14 06:38:34 +08:00
else if ( index = = 1 ) { // GUID
searchDialog - > ui - > guidEdit - > setFocus ( ) ;
2014-07-25 07:59:51 +08:00
searchDialog - > ui - > guidEdit - > setCursorPosition ( 0 ) ;
2014-07-14 06:38:34 +08:00
QByteArray pattern = searchDialog - > ui - > guidEdit - > text ( ) . toLatin1 ( ) ;
if ( pattern . isEmpty ( ) )
return ;
UINT8 mode ;
if ( searchDialog - > ui - > guidScopeHeaderRadioButton - > isChecked ( ) )
mode = SEARCH_MODE_HEADER ;
else if ( searchDialog - > ui - > guidScopeBodyRadioButton - > isChecked ( ) )
mode = SEARCH_MODE_BODY ;
else
mode = SEARCH_MODE_ALL ;
ffsEngine - > findGuidPattern ( rootIndex , pattern , mode ) ;
showMessages ( ) ;
}
else if ( index = = 2 ) { // Text string
searchDialog - > ui - > textEdit - > setFocus ( ) ;
2014-07-09 15:20:13 +08:00
QString pattern = searchDialog - > ui - > textEdit - > text ( ) ;
2013-12-29 23:13:46 +08:00
if ( pattern . isEmpty ( ) )
return ;
2014-07-09 15:20:13 +08:00
ffsEngine - > findTextPattern ( rootIndex , pattern , searchDialog - > ui - > textUnicodeCheckBox - > isChecked ( ) ,
2014-07-25 07:59:51 +08:00
( Qt : : CaseSensitivity ) searchDialog - > ui - > textCaseSensitiveCheckBox - > isChecked ( ) ) ;
2013-12-29 23:13:46 +08:00
showMessages ( ) ;
}
2013-12-05 04:27:12 +08:00
}
2013-11-18 23:23:59 +08:00
void UEFITool : : rebuild ( )
{
QModelIndex index = ui - > structureTreeView - > selectionModel ( ) - > currentIndex ( ) ;
if ( ! index . isValid ( ) )
return ;
UINT8 result = ffsEngine - > rebuild ( index ) ;
2013-12-29 23:13:46 +08:00
2013-11-18 23:23:59 +08:00
if ( result = = ERR_SUCCESS )
ui - > actionSaveImageFile - > setEnabled ( true ) ;
2013-11-07 21:46:28 +08:00
}
void UEFITool : : remove ( )
{
2013-11-17 17:01:11 +08:00
QModelIndex index = ui - > structureTreeView - > selectionModel ( ) - > currentIndex ( ) ;
if ( ! index . isValid ( ) )
return ;
UINT8 result = ffsEngine - > remove ( index ) ;
if ( result = = ERR_SUCCESS )
2013-11-07 21:46:28 +08:00
ui - > actionSaveImageFile - > setEnabled ( true ) ;
}
2013-11-14 18:40:39 +08:00
void UEFITool : : insert ( const UINT8 mode )
2013-11-07 21:46:28 +08:00
{
2013-11-17 17:01:11 +08:00
QModelIndex index = ui - > structureTreeView - > selectionModel ( ) - > currentIndex ( ) ;
if ( ! index . isValid ( ) )
return ;
2013-12-29 23:13:46 +08:00
TreeModel * model = ffsEngine - > treeModel ( ) ;
2013-11-14 18:40:39 +08:00
UINT8 type ;
2013-11-17 17:01:11 +08:00
2013-12-12 19:28:39 +08:00
if ( mode = = CREATE_MODE_BEFORE | | mode = = CREATE_MODE_AFTER )
2013-12-29 23:13:46 +08:00
type = model - > type ( index . parent ( ) ) ;
2013-11-14 18:40:39 +08:00
else
2013-12-29 23:13:46 +08:00
type = model - > type ( index ) ;
2013-11-14 18:40:39 +08:00
2013-11-17 17:01:11 +08:00
QString path ;
2013-11-14 18:40:39 +08:00
switch ( type ) {
2014-02-27 17:14:41 +08:00
case Types : : Volume :
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getOpenFileName ( this , tr ( " Select FFS file to insert " ) , currentDir , " FFS files (*.ffs *.bin);;All files (*) " ) ;
2014-01-12 07:02:54 +08:00
break ;
2014-02-27 17:14:41 +08:00
case Types : : File :
case Types : : Section :
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getOpenFileName ( this , tr ( " Select section file to insert " ) , currentDir , " Section files (*.sct *.bin);;All files (*) " ) ;
2014-01-12 07:02:54 +08:00
break ;
2013-11-14 18:40:39 +08:00
default :
2013-11-07 21:46:28 +08:00
return ;
}
2014-04-18 20:18:11 +08:00
if ( path . trimmed ( ) . isEmpty ( ) )
return ;
2014-07-25 07:59:51 +08:00
2013-11-07 21:46:28 +08:00
QFileInfo fileInfo = QFileInfo ( path ) ;
2013-11-23 06:25:15 +08:00
if ( ! fileInfo . exists ( ) ) {
2013-11-14 18:40:39 +08:00
ui - > statusBar - > showMessage ( tr ( " Please select existing file " ) ) ;
2013-11-07 21:46:28 +08:00
return ;
}
QFile inputFile ;
inputFile . setFileName ( path ) ;
2013-11-23 06:25:15 +08:00
if ( ! inputFile . open ( QFile : : ReadOnly ) ) {
2014-01-28 21:48:04 +08:00
QMessageBox : : critical ( this , tr ( " Insertion failed " ) , tr ( " Can't open output file for reading " ) , QMessageBox : : Ok ) ;
2013-11-07 21:46:28 +08:00
return ;
}
QByteArray buffer = inputFile . readAll ( ) ;
inputFile . close ( ) ;
2013-12-12 19:28:39 +08:00
UINT8 result = ffsEngine - > insert ( index , buffer , mode ) ;
2014-07-12 18:27:42 +08:00
if ( result ) {
QMessageBox : : critical ( this , tr ( " Insertion failed " ) , errorMessage ( result ) , QMessageBox : : Ok ) ;
return ;
}
ui - > actionSaveImageFile - > setEnabled ( true ) ;
2013-10-08 15:07:03 +08:00
}
2013-11-14 18:40:39 +08:00
void UEFITool : : insertInto ( )
2013-11-07 21:46:28 +08:00
{
2013-12-12 19:28:39 +08:00
insert ( CREATE_MODE_PREPEND ) ;
2013-11-14 18:40:39 +08:00
}
2013-11-07 21:46:28 +08:00
2013-11-14 18:40:39 +08:00
void UEFITool : : insertBefore ( )
{
2013-12-12 19:28:39 +08:00
insert ( CREATE_MODE_BEFORE ) ;
2013-11-14 18:40:39 +08:00
}
2013-11-07 21:46:28 +08:00
2013-11-14 18:40:39 +08:00
void UEFITool : : insertAfter ( )
{
2013-12-12 19:28:39 +08:00
insert ( CREATE_MODE_AFTER ) ;
2013-11-07 21:46:28 +08:00
}
2013-12-12 19:28:39 +08:00
void UEFITool : : replaceAsIs ( )
2013-11-07 21:46:28 +08:00
{
2013-12-12 19:28:39 +08:00
replace ( REPLACE_MODE_AS_IS ) ;
2013-11-07 21:46:28 +08:00
}
2013-12-12 19:28:39 +08:00
void UEFITool : : replaceBody ( )
2013-11-18 23:23:59 +08:00
{
2013-12-12 19:28:39 +08:00
replace ( REPLACE_MODE_BODY ) ;
2013-11-18 23:23:59 +08:00
}
2013-12-12 19:28:39 +08:00
void UEFITool : : replace ( const UINT8 mode )
2013-11-18 23:23:59 +08:00
{
2013-12-29 23:13:46 +08:00
QModelIndex index = ui - > structureTreeView - > selectionModel ( ) - > currentIndex ( ) ;
2013-11-18 23:23:59 +08:00
if ( ! index . isValid ( ) )
return ;
2013-12-12 19:28:39 +08:00
2013-12-29 23:13:46 +08:00
TreeModel * model = ffsEngine - > treeModel ( ) ;
QString path ;
2014-02-27 17:14:41 +08:00
if ( model - > type ( index ) = = Types : : Region ) {
2014-01-29 00:42:18 +08:00
if ( mode = = REPLACE_MODE_AS_IS ) {
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getOpenFileName ( this , tr ( " Select region file to replace selected object " ) , currentDir , " Region files (*.rgn *.bin);;All files (*) " ) ;
2014-01-29 00:42:18 +08:00
}
else
return ;
}
2015-09-13 02:46:21 +08:00
else if ( model - > type ( index ) = = Types : : Padding ) {
if ( mode = = REPLACE_MODE_AS_IS ) {
path = QFileDialog : : getOpenFileName ( this , tr ( " Select padding file to replace selected object " ) , currentDir , " Padding files (*.pad *.bin);;All files (*) " ) ;
}
else
return ;
}
2015-02-18 01:56:11 +08:00
else if ( model - > type ( index ) = = Types : : Volume ) {
2015-01-31 22:00:00 +08:00
if ( mode = = REPLACE_MODE_AS_IS ) {
path = QFileDialog : : getOpenFileName ( this , tr ( " Select volume file to replace selected object " ) , currentDir , " Volume files (*.vol *.bin);;All files (*) " ) ;
}
else if ( mode = = REPLACE_MODE_BODY ) {
path = QFileDialog : : getOpenFileName ( this , tr ( " Select volume body file to replace body " ) , currentDir , " Volume body files (*.vbd *.bin);;All files (*) " ) ;
}
else
return ;
}
2014-02-27 17:14:41 +08:00
else if ( model - > type ( index ) = = Types : : File ) {
2013-12-29 23:13:46 +08:00
if ( mode = = REPLACE_MODE_AS_IS ) {
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getOpenFileName ( this , tr ( " Select FFS file to replace selected object " ) , currentDir , " FFS files (*.ffs *.bin);;All files (*) " ) ;
2013-12-29 23:13:46 +08:00
}
else if ( mode = = REPLACE_MODE_BODY ) {
2015-02-06 16:47:19 +08:00
if ( model - > subtype ( index ) = = EFI_FV_FILETYPE_ALL | | model - > subtype ( index ) = = EFI_FV_FILETYPE_RAW )
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getOpenFileName ( this , tr ( " Select raw file to replace body " ) , currentDir , " Raw files (*.raw *.bin);;All files (*) " ) ;
2015-02-06 16:47:19 +08:00
else if ( model - > subtype ( index ) = = EFI_FV_FILETYPE_PAD ) // Pad file body can't be replaced
//!TODO: handle non-empty pad files
2013-12-29 23:13:46 +08:00
return ;
else
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getOpenFileName ( this , tr ( " Select FFS file body to replace body " ) , currentDir , " FFS file body files (*.fbd *.bin);;All files (*) " ) ;
2013-12-29 23:13:46 +08:00
}
else
return ;
}
2014-02-27 17:14:41 +08:00
else if ( model - > type ( index ) = = Types : : Section ) {
2013-12-29 23:13:46 +08:00
if ( mode = = REPLACE_MODE_AS_IS ) {
2015-02-13 03:51:23 +08:00
path = QFileDialog : : getOpenFileName ( this , tr ( " Select section file to replace selected object " ) , currentDir , " Section files (*.sct *.bin);;All files (*) " ) ;
2013-12-29 23:13:46 +08:00
}
else if ( mode = = REPLACE_MODE_BODY ) {
2015-02-06 16:47:19 +08:00
if ( model - > subtype ( index ) = = EFI_SECTION_COMPRESSION | | model - > subtype ( index ) = = EFI_SECTION_GUID_DEFINED | | model - > subtype ( index ) = = EFI_SECTION_DISPOSABLE )
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getOpenFileName ( this , tr ( " Select FFS file body file to replace body " ) , currentDir , " FFS file body files (*.fbd *.bin);;All files (*) " ) ;
2015-02-06 16:47:19 +08:00
else if ( model - > subtype ( index ) = = EFI_SECTION_FIRMWARE_VOLUME_IMAGE )
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getOpenFileName ( this , tr ( " Select volume file to replace body " ) , currentDir , " Volume files (*.vol *.bin);;All files (*) " ) ;
2015-02-06 16:47:19 +08:00
else if ( model - > subtype ( index ) = = EFI_SECTION_RAW )
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getOpenFileName ( this , tr ( " Select raw file to replace body " ) , currentDir , " Raw files (*.raw *.bin);;All files (*) " ) ;
2015-08-14 02:28:10 +08:00
else if ( model - > subtype ( index ) = = EFI_SECTION_PE32 | | model - > subtype ( index ) = = EFI_SECTION_TE | | model - > subtype ( index ) = = EFI_SECTION_PIC )
path = QFileDialog : : getOpenFileName ( this , tr ( " Select EFI executable file to replace body " ) , currentDir , " EFI executable files (*.efi *.dxe *.pei *.bin);;All files (*) " ) ;
2013-12-29 23:13:46 +08:00
else
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getOpenFileName ( this , tr ( " Select file to replace body " ) , currentDir , " Binary files (*.bin);;All files (*) " ) ;
2013-12-29 23:13:46 +08:00
}
else
return ;
}
else
return ;
2014-04-18 20:18:11 +08:00
if ( path . trimmed ( ) . isEmpty ( ) )
return ;
2013-12-29 23:13:46 +08:00
QFileInfo fileInfo = QFileInfo ( path ) ;
2013-12-12 19:28:39 +08:00
if ( ! fileInfo . exists ( ) ) {
ui - > statusBar - > showMessage ( tr ( " Please select existing file " ) ) ;
return ;
}
QFile inputFile ;
inputFile . setFileName ( path ) ;
if ( ! inputFile . open ( QFile : : ReadOnly ) ) {
2014-01-28 21:48:04 +08:00
QMessageBox : : critical ( this , tr ( " Replacing failed " ) , tr ( " Can't open input file for reading " ) , QMessageBox : : Ok ) ;
2013-12-12 19:28:39 +08:00
return ;
}
QByteArray buffer = inputFile . readAll ( ) ;
inputFile . close ( ) ;
UINT8 result = ffsEngine - > replace ( index , buffer , mode ) ;
2014-07-12 18:27:42 +08:00
if ( result ) {
QMessageBox : : critical ( this , tr ( " Replacing failed " ) , errorMessage ( result ) , QMessageBox : : Ok ) ;
return ;
}
ui - > actionSaveImageFile - > setEnabled ( true ) ;
2013-11-18 23:23:59 +08:00
}
2013-12-12 19:28:39 +08:00
void UEFITool : : extractAsIs ( )
2013-11-18 23:23:59 +08:00
{
2013-12-12 19:28:39 +08:00
extract ( EXTRACT_MODE_AS_IS ) ;
}
void UEFITool : : extractBody ( )
{
extract ( EXTRACT_MODE_BODY ) ;
2013-11-18 23:23:59 +08:00
}
2013-12-12 19:28:39 +08:00
void UEFITool : : extract ( const UINT8 mode )
2013-11-19 00:11:08 +08:00
{
QModelIndex index = ui - > structureTreeView - > selectionModel ( ) - > currentIndex ( ) ;
if ( ! index . isValid ( ) )
return ;
2013-12-29 23:13:46 +08:00
TreeModel * model = ffsEngine - > treeModel ( ) ;
UINT8 type = model - > type ( index ) ;
2013-12-12 19:28:39 +08:00
QString path ;
if ( mode = = EXTRACT_MODE_AS_IS ) {
switch ( type ) {
2014-02-27 17:14:41 +08:00
case Types : : Capsule :
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save capsule to file " ) , currentDir , " Capsule files (*.cap *.bin);;All files (*) " ) ;
2013-12-12 19:28:39 +08:00
break ;
2014-02-27 17:14:41 +08:00
case Types : : Image :
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save image to file " ) , currentDir , " Image files (*.rom *.bin);;All files (*) " ) ;
2013-12-12 19:28:39 +08:00
break ;
2014-02-27 17:14:41 +08:00
case Types : : Region :
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save region to file " ) , currentDir , " Region files (*.rgn *.bin);;All files (*) " ) ;
2013-12-12 19:28:39 +08:00
break ;
2014-02-27 17:14:41 +08:00
case Types : : Padding :
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save padding to file " ) , currentDir , " Padding files (*.pad *.bin);;All files (*) " ) ;
2013-12-12 19:28:39 +08:00
break ;
2014-02-27 17:14:41 +08:00
case Types : : Volume :
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save volume to file " ) , currentDir , " Volume files (*.vol *.bin);;All files (*) " ) ;
2013-12-12 19:28:39 +08:00
break ;
2014-02-27 17:14:41 +08:00
case Types : : File :
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save FFS file to file " ) , currentDir , " FFS files (*.ffs *.bin);;All files (*) " ) ;
2013-12-12 19:28:39 +08:00
break ;
2014-02-27 17:14:41 +08:00
case Types : : Section :
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save section file to file " ) , currentDir , " Section files (*.sct *.bin);;All files (*) " ) ;
2014-01-12 07:02:54 +08:00
break ;
2013-12-12 19:28:39 +08:00
default :
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save object to file " ) , currentDir , " Binary files (*.bin);;All files (*) " ) ;
2013-12-12 19:28:39 +08:00
}
}
2013-12-29 23:13:46 +08:00
else if ( mode = = EXTRACT_MODE_BODY ) {
2013-12-12 19:28:39 +08:00
switch ( type ) {
2014-02-27 17:14:41 +08:00
case Types : : Capsule :
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save capsule body to image file " ) , currentDir , " Image files (*.rom *.bin);;All files (*) " ) ;
2013-12-12 19:28:39 +08:00
break ;
2015-08-30 16:52:19 +08:00
case Types : : Volume :
2015-01-31 22:00:00 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save volume body to file " ) , currentDir , " Volume body files (*.vbd *.bin);;All files (*) " ) ;
break ;
2014-02-27 17:14:41 +08:00
case Types : : File : {
2015-02-06 16:47:19 +08:00
if ( model - > subtype ( index ) = = EFI_FV_FILETYPE_ALL | | model - > subtype ( index ) = = EFI_FV_FILETYPE_RAW )
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save FFS file body to raw file " ) , currentDir , " Raw files (*.raw *.bin);;All files (*) " ) ;
2014-01-12 07:02:54 +08:00
else
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save FFS file body to file " ) , currentDir , " FFS file body files (*.fbd *.bin);;All files (*) " ) ;
2014-01-12 07:02:54 +08:00
}
2013-12-12 19:28:39 +08:00
break ;
2014-02-27 17:14:41 +08:00
case Types : : Section : {
2015-02-06 16:47:19 +08:00
if ( model - > subtype ( index ) = = EFI_SECTION_COMPRESSION | | model - > subtype ( index ) = = EFI_SECTION_GUID_DEFINED | | model - > subtype ( index ) = = EFI_SECTION_DISPOSABLE )
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save encapsulation section body to FFS body file " ) , currentDir , " FFS file body files (*.fbd *.bin);;All files (*) " ) ;
2015-02-06 16:47:19 +08:00
else if ( model - > subtype ( index ) = = EFI_SECTION_FIRMWARE_VOLUME_IMAGE )
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save section body to volume file " ) , currentDir , " Volume files (*.vol *.bin);;All files (*) " ) ;
2015-02-06 16:47:19 +08:00
else if ( model - > subtype ( index ) = = EFI_SECTION_RAW )
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save section body to raw file " ) , currentDir , " Raw files (*.raw *.bin);;All files (*) " ) ;
2013-12-29 23:13:46 +08:00
else
2014-11-07 22:52:55 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save section body to file " ) , currentDir , " Binary files (*.bin);;All files (*) " ) ;
2014-01-12 07:02:54 +08:00
}
break ;
2013-12-12 19:28:39 +08:00
default :
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save object to file " ) , currentDir , " Binary files (*.bin);;All files (*) " ) ;
2013-12-12 19:28:39 +08:00
}
}
else
2014-11-07 22:52:19 +08:00
path = QFileDialog : : getSaveFileName ( this , tr ( " Save object to file " ) , currentDir , " Binary files (*.bin);;All files (*) " ) ;
2013-12-29 23:13:46 +08:00
2014-04-18 20:18:11 +08:00
if ( path . trimmed ( ) . isEmpty ( ) )
return ;
2014-01-28 21:48:04 +08:00
QByteArray extracted ;
UINT8 result = ffsEngine - > extract ( index , extracted , mode ) ;
if ( result ) {
2014-07-12 18:27:42 +08:00
QMessageBox : : critical ( this , tr ( " Extraction failed " ) , errorMessage ( result ) , QMessageBox : : Ok ) ;
2014-01-28 21:48:04 +08:00
return ;
}
2013-12-12 19:28:39 +08:00
QFile outputFile ;
outputFile . setFileName ( path ) ;
if ( ! outputFile . open ( QFile : : WriteOnly ) ) {
2014-01-28 21:48:04 +08:00
QMessageBox : : critical ( this , tr ( " Extraction failed " ) , tr ( " Can't open output file for rewriting " ) , QMessageBox : : Ok ) ;
2013-12-12 19:28:39 +08:00
return ;
}
2014-01-28 21:48:04 +08:00
outputFile . resize ( 0 ) ;
outputFile . write ( extracted ) ;
outputFile . close ( ) ;
2013-11-19 00:11:08 +08:00
}
2013-11-18 23:23:59 +08:00
void UEFITool : : about ( )
{
2013-12-05 04:27:12 +08:00
QMessageBox : : about ( this , tr ( " About UEFITool " ) , tr (
2015-01-31 22:00:00 +08:00
" Copyright (c) 2015, Nikolaj Schlej aka <b>CodeRush</b>.<br> "
2014-11-18 23:01:20 +08:00
" Program icon made by <a href=https://www.behance.net/alzhidkov>Alexander Zhidkov</a>.<br><br> "
2014-07-25 07:59:51 +08:00
" The program is dedicated to <b>RevoGirl</b>. Rest in peace, young genius.<br><br> "
" The program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License.<br> "
" The full text of the license may be found at <a href=http://opensource.org/licenses/bsd-license.php>OpenSource.org</a>.<br><br> "
" <b>THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN \" AS IS \" BASIS, "
" WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, "
" EITHER EXPRESS OR IMPLIED.</b> " ) ) ;
2013-11-18 23:23:59 +08:00
}
void UEFITool : : aboutQt ( )
{
QMessageBox : : aboutQt ( this , tr ( " About Qt " ) ) ;
}
2013-11-20 10:08:39 +08:00
void UEFITool : : exit ( )
{
2013-12-29 23:13:46 +08:00
QCoreApplication : : exit ( 0 ) ;
2013-11-20 10:08:39 +08:00
}
2013-11-07 21:46:28 +08:00
void UEFITool : : saveImageFile ( )
{
2015-08-14 02:28:10 +08:00
QString path = QFileDialog : : getSaveFileName ( this , tr ( " Save BIOS image file " ) , currentDir , " BIOS image files (*.rom *.bin *.cap *.bio *.fd *.wph *.dec);;All files (*) " ) ;
2014-07-25 07:59:51 +08:00
2014-01-29 00:42:18 +08:00
if ( path . isEmpty ( ) )
return ;
2013-12-29 23:13:46 +08:00
2013-11-07 21:46:28 +08:00
QByteArray reconstructed ;
2014-01-15 04:09:18 +08:00
UINT8 result = ffsEngine - > reconstructImageFile ( reconstructed ) ;
2013-12-05 04:27:12 +08:00
showMessages ( ) ;
2013-11-23 06:25:15 +08:00
if ( result ) {
2014-07-12 18:27:42 +08:00
QMessageBox : : critical ( this , tr ( " Image reconstruction failed " ) , errorMessage ( result ) , QMessageBox : : Ok ) ;
2014-01-28 21:48:04 +08:00
return ;
}
QFile outputFile ;
outputFile . setFileName ( path ) ;
2014-11-08 19:40:06 +08:00
2014-01-28 21:48:04 +08:00
if ( ! outputFile . open ( QFile : : WriteOnly ) ) {
QMessageBox : : critical ( this , tr ( " Image reconstruction failed " ) , tr ( " Can't open output file for rewriting " ) , QMessageBox : : Ok ) ;
2013-11-07 21:46:28 +08:00
return ;
}
2013-11-14 18:40:39 +08:00
outputFile . resize ( 0 ) ;
2013-11-07 21:46:28 +08:00
outputFile . write ( reconstructed ) ;
outputFile . close ( ) ;
2014-01-28 21:48:04 +08:00
if ( QMessageBox : : information ( this , tr ( " Image reconstruction successful " ) , tr ( " Open reconstructed file? " ) , QMessageBox : : Yes , QMessageBox : : No )
= = QMessageBox : : Yes )
openImageFile ( path ) ;
2013-11-07 21:46:28 +08:00
}
2013-10-08 15:07:03 +08:00
void UEFITool : : openImageFile ( )
{
2015-08-14 02:28:10 +08:00
QString path = QFileDialog : : getOpenFileName ( this , tr ( " Open BIOS image file " ) , currentDir , " BIOS image files (*.rom *.bin *.cap *.bio *.fd *.wph *.dec);;All files (*) " ) ;
2013-10-08 15:07:03 +08:00
openImageFile ( path ) ;
}
2015-08-14 02:28:10 +08:00
void UEFITool : : openImageFileInNewWindow ( )
{
QString path = QFileDialog : : getOpenFileName ( this , tr ( " Open BIOS image file in new window " ) , currentDir , " BIOS image files (*.rom *.bin *.cap *.bio *.fd *.wph *.dec);;All files (*) " ) ;
2015-08-30 16:52:19 +08:00
if ( path . trimmed ( ) . isEmpty ( ) )
return ;
2015-08-14 02:28:10 +08:00
QProcess : : startDetached ( currentProgramPath , QStringList ( path ) ) ;
}
2013-10-08 15:07:03 +08:00
void UEFITool : : openImageFile ( QString path )
{
2014-04-18 20:18:11 +08:00
if ( path . trimmed ( ) . isEmpty ( ) )
return ;
2014-07-25 07:59:51 +08:00
2013-10-08 15:07:03 +08:00
QFileInfo fileInfo = QFileInfo ( path ) ;
2014-07-25 07:59:51 +08:00
2013-11-23 06:25:15 +08:00
if ( ! fileInfo . exists ( ) ) {
2013-11-14 18:40:39 +08:00
ui - > statusBar - > showMessage ( tr ( " Please select existing file " ) ) ;
2013-10-08 15:07:03 +08:00
return ;
}
QFile inputFile ;
inputFile . setFileName ( path ) ;
2013-11-23 06:25:15 +08:00
if ( ! inputFile . open ( QFile : : ReadOnly ) ) {
2014-01-28 21:48:04 +08:00
QMessageBox : : critical ( this , tr ( " Image parsing failed " ) , tr ( " Can't open input file for reading " ) , QMessageBox : : Ok ) ;
2013-10-08 15:07:03 +08:00
return ;
}
QByteArray buffer = inputFile . readAll ( ) ;
inputFile . close ( ) ;
init ( ) ;
2014-11-18 23:01:20 +08:00
this - > setWindowTitle ( tr ( " UEFITool %1 - %2 " ) . arg ( version ) . arg ( fileInfo . fileName ( ) ) ) ;
2014-08-14 20:02:35 +08:00
2014-01-15 04:09:18 +08:00
UINT8 result = ffsEngine - > parseImageFile ( buffer ) ;
2013-12-05 04:27:12 +08:00
showMessages ( ) ;
if ( result )
2014-07-12 18:27:42 +08:00
QMessageBox : : critical ( this , tr ( " Image parsing failed " ) , errorMessage ( result ) , QMessageBox : : Ok ) ;
2013-10-08 15:07:03 +08:00
else
ui - > statusBar - > showMessage ( tr ( " Opened: %1 " ) . arg ( fileInfo . fileName ( ) ) ) ;
2013-11-17 19:13:37 +08:00
2013-12-29 23:13:46 +08:00
// Enable search
ui - > actionSearch - > setEnabled ( true ) ;
2014-07-25 07:59:51 +08:00
// Set current directory
currentDir = fileInfo . absolutePath ( ) ;
2013-12-05 04:27:12 +08:00
}
2014-07-14 06:38:34 +08:00
void UEFITool : : copyMessage ( )
{
clipboard - > clear ( ) ;
clipboard - > setText ( ui - > messageListWidget - > currentItem ( ) - > text ( ) ) ;
}
2014-07-27 15:54:38 +08:00
void UEFITool : : copyAllMessages ( )
{
QString text ;
clipboard - > clear ( ) ;
for ( INT32 i = 0 ; i < ui - > messageListWidget - > count ( ) ; i + + )
text . append ( ui - > messageListWidget - > item ( i ) - > text ( ) ) . append ( " \n " ) ;
clipboard - > clear ( ) ;
clipboard - > setText ( text ) ;
}
void UEFITool : : enableMessagesCopyActions ( QListWidgetItem * item )
2014-07-14 06:38:34 +08:00
{
ui - > actionMessagesCopy - > setEnabled ( item ! = NULL ) ;
2014-07-27 15:54:38 +08:00
ui - > actionMessagesCopyAll - > setEnabled ( item ! = NULL ) ;
2014-07-14 06:38:34 +08:00
}
2013-12-05 04:27:12 +08:00
void UEFITool : : clearMessages ( )
{
2013-12-29 23:13:46 +08:00
ffsEngine - > clearMessages ( ) ;
messageItems . clear ( ) ;
ui - > messageListWidget - > clear ( ) ;
2014-07-14 06:38:34 +08:00
ui - > actionMessagesCopy - > setEnabled ( false ) ;
2014-07-27 15:54:38 +08:00
ui - > actionMessagesCopyAll - > setEnabled ( false ) ;
2013-10-08 15:07:03 +08:00
}
void UEFITool : : dragEnterEvent ( QDragEnterEvent * event )
{
if ( event - > mimeData ( ) - > hasFormat ( " text/uri-list " ) )
2014-01-12 07:02:54 +08:00
event - > acceptProposedAction ( ) ;
2013-10-08 15:07:03 +08:00
}
void UEFITool : : dropEvent ( QDropEvent * event )
{
QString path = event - > mimeData ( ) - > urls ( ) . at ( 0 ) . toLocalFile ( ) ;
openImageFile ( path ) ;
}
2013-12-05 04:27:12 +08:00
void UEFITool : : showMessages ( )
2013-11-15 18:48:14 +08:00
{
2013-11-17 17:01:11 +08:00
ui - > messageListWidget - > clear ( ) ;
2013-12-05 04:27:12 +08:00
if ( ! ffsEngine )
return ;
2013-11-17 19:13:37 +08:00
2013-12-05 04:27:12 +08:00
messageItems = ffsEngine - > messages ( ) ;
2013-11-17 17:01:11 +08:00
for ( int i = 0 ; i < messageItems . count ( ) ; i + + ) {
2013-11-17 19:13:37 +08:00
ui - > messageListWidget - > addItem ( new MessageListItem ( messageItems . at ( i ) ) ) ;
2013-11-15 18:48:14 +08:00
}
2014-10-30 11:56:37 +08:00
2014-11-18 23:01:20 +08:00
ui - > messageListWidget - > scrollToBottom ( ) ;
2013-11-15 18:48:14 +08:00
}
void UEFITool : : scrollTreeView ( QListWidgetItem * item )
{
2014-01-24 20:29:21 +08:00
MessageListItem * messageItem = static_cast < MessageListItem * > ( item ) ;
2013-11-17 17:01:11 +08:00
QModelIndex index = messageItem - > index ( ) ;
2013-12-29 23:13:46 +08:00
if ( index . isValid ( ) ) {
2014-11-09 20:49:47 +08:00
ui - > structureTreeView - > scrollTo ( index , QAbstractItemView : : PositionAtCenter ) ;
2013-11-17 17:01:11 +08:00
ui - > structureTreeView - > selectionModel ( ) - > clearSelection ( ) ;
2013-11-15 18:48:14 +08:00
ui - > structureTreeView - > selectionModel ( ) - > select ( index , QItemSelectionModel : : Select ) ;
}
2013-11-20 10:08:39 +08:00
}
2013-11-23 06:25:15 +08:00
2013-12-05 04:27:12 +08:00
void UEFITool : : contextMenuEvent ( QContextMenuEvent * event )
2013-11-23 06:25:15 +08:00
{
2013-12-05 04:27:12 +08:00
if ( ui - > messageListWidget - > underMouse ( ) ) {
2013-12-29 23:13:46 +08:00
ui - > menuMessages - > exec ( event - > globalPos ( ) ) ;
2013-12-05 04:27:12 +08:00
return ;
2013-12-29 23:13:46 +08:00
}
2014-07-25 07:59:51 +08:00
if ( ! ui - > structureTreeView - > underMouse ( ) )
2013-12-29 23:13:46 +08:00
return ;
QPoint pt = event - > pos ( ) ;
2013-12-05 04:27:12 +08:00
QModelIndex index = ui - > structureTreeView - > indexAt ( ui - > structureTreeView - > viewport ( ) - > mapFrom ( this , pt ) ) ;
2014-07-25 07:59:51 +08:00
if ( ! index . isValid ( ) )
2013-12-05 04:27:12 +08:00
return ;
2013-11-23 06:25:15 +08:00
2013-12-29 23:13:46 +08:00
TreeModel * model = ffsEngine - > treeModel ( ) ;
2014-07-25 07:59:51 +08:00
switch ( model - > type ( index ) )
2013-12-05 04:27:12 +08:00
{
2014-02-27 17:14:41 +08:00
case Types : : Capsule :
2013-12-05 04:27:12 +08:00
ui - > menuCapsuleActions - > exec ( event - > globalPos ( ) ) ;
break ;
2014-02-27 17:14:41 +08:00
case Types : : Image :
2013-12-05 04:27:12 +08:00
ui - > menuImageActions - > exec ( event - > globalPos ( ) ) ;
break ;
2014-02-27 17:14:41 +08:00
case Types : : Region :
2013-12-05 04:27:12 +08:00
ui - > menuRegionActions - > exec ( event - > globalPos ( ) ) ;
break ;
2014-02-27 17:14:41 +08:00
case Types : : Padding :
2013-12-05 04:27:12 +08:00
ui - > menuPaddingActions - > exec ( event - > globalPos ( ) ) ;
break ;
2014-02-27 17:14:41 +08:00
case Types : : Volume :
2013-12-05 04:27:12 +08:00
ui - > menuVolumeActions - > exec ( event - > globalPos ( ) ) ;
break ;
2014-02-27 17:14:41 +08:00
case Types : : File :
2013-12-05 04:27:12 +08:00
ui - > menuFileActions - > exec ( event - > globalPos ( ) ) ;
break ;
2014-02-27 17:14:41 +08:00
case Types : : Section :
2013-12-05 04:27:12 +08:00
ui - > menuSectionActions - > exec ( event - > globalPos ( ) ) ;
break ;
}
}
void UEFITool : : readSettings ( )
{
2014-01-11 17:20:58 +08:00
QSettings settings ( this ) ;
2013-12-29 23:13:46 +08:00
resize ( settings . value ( " mainWindow/size " , QSize ( 800 , 600 ) ) . toSize ( ) ) ;
2013-12-05 04:27:12 +08:00
move ( settings . value ( " mainWindow/position " , QPoint ( 0 , 0 ) ) . toPoint ( ) ) ;
2013-12-29 23:13:46 +08:00
QList < int > horList , vertList ;
horList . append ( settings . value ( " mainWindow/treeWidth " , 600 ) . toInt ( ) ) ;
horList . append ( settings . value ( " mainWindow/infoWidth " , 180 ) . toInt ( ) ) ;
vertList . append ( settings . value ( " mainWindow/treeHeight " , 400 ) . toInt ( ) ) ;
vertList . append ( settings . value ( " mainWindow/messageHeight " , 180 ) . toInt ( ) ) ;
ui - > infoSplitter - > setSizes ( horList ) ;
ui - > messagesSplitter - > setSizes ( vertList ) ;
ui - > structureTreeView - > setColumnWidth ( 0 , settings . value ( " tree/columnWidth0 " , ui - > structureTreeView - > columnWidth ( 0 ) ) . toInt ( ) ) ;
ui - > structureTreeView - > setColumnWidth ( 1 , settings . value ( " tree/columnWidth1 " , ui - > structureTreeView - > columnWidth ( 1 ) ) . toInt ( ) ) ;
ui - > structureTreeView - > setColumnWidth ( 2 , settings . value ( " tree/columnWidth2 " , ui - > structureTreeView - > columnWidth ( 2 ) ) . toInt ( ) ) ;
ui - > structureTreeView - > setColumnWidth ( 3 , settings . value ( " tree/columnWidth3 " , ui - > structureTreeView - > columnWidth ( 3 ) ) . toInt ( ) ) ;
2013-12-05 04:27:12 +08:00
}
void UEFITool : : writeSettings ( )
{
2014-01-11 17:20:58 +08:00
QSettings settings ( this ) ;
2013-12-29 23:13:46 +08:00
settings . setValue ( " mainWindow/size " , size ( ) ) ;
settings . setValue ( " mainWindow/position " , pos ( ) ) ;
settings . setValue ( " mainWindow/treeWidth " , ui - > structureGroupBox - > width ( ) ) ;
settings . setValue ( " mainWindow/infoWidth " , ui - > infoGroupBox - > width ( ) ) ;
settings . setValue ( " mainWindow/treeHeight " , ui - > structureGroupBox - > height ( ) ) ;
settings . setValue ( " mainWindow/messageHeight " , ui - > messageGroupBox - > height ( ) ) ;
settings . setValue ( " tree/columnWidth0 " , ui - > structureTreeView - > columnWidth ( 0 ) ) ;
settings . setValue ( " tree/columnWidth1 " , ui - > structureTreeView - > columnWidth ( 1 ) ) ;
settings . setValue ( " tree/columnWidth2 " , ui - > structureTreeView - > columnWidth ( 2 ) ) ;
settings . setValue ( " tree/columnWidth3 " , ui - > structureTreeView - > columnWidth ( 3 ) ) ;
2014-11-07 22:52:19 +08:00
}