For Qt GUI, added a zip archive ROM list selection window for the case where a zip file contains more than one ROM file in it.

This commit is contained in:
Matthew Budd 2020-10-25 11:34:33 -04:00
parent b0c460fd1d
commit c09b1f6c7a
3 changed files with 125 additions and 11 deletions

View File

@ -3,6 +3,7 @@
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <QHeaderView>
#include <QFileDialog>
#include <QMessageBox>
#include <QInputDialog>
@ -703,6 +704,82 @@ void consoleWin_t::closeApp(void)
qApp->quit();
}
//---------------------------------------------------------------------------
int consoleWin_t::showListSelectDialog( const char *title, std::vector <std::string> &l )
{
if ( QThread::currentThread() == emulatorThread )
{
printf("Cannot display list selection dialog from within emulation thread...\n");
return 0;
}
int ret, idx = 0;
QDialog dialog(this);
QVBoxLayout *mainLayout;
QHBoxLayout *hbox;
QPushButton *okButton, *cancelButton;
QTreeWidget *tree;
QTreeWidgetItem *item;
dialog.setWindowTitle( tr(title) );
tree = new QTreeWidget();
tree->setColumnCount(1);
item = new QTreeWidgetItem();
item->setText( 0, QString::fromStdString( "File" ) );
item->setTextAlignment( 0, Qt::AlignLeft);
tree->setHeaderItem( item );
tree->header()->setSectionResizeMode( QHeaderView::ResizeToContents );
for (size_t i=0; i<l.size(); i++)
{
item = new QTreeWidgetItem();
item->setText( 0, QString::fromStdString( l[i] ) );
item->setTextAlignment( 0, Qt::AlignLeft);
tree->addTopLevelItem( item );
}
mainLayout = new QVBoxLayout();
hbox = new QHBoxLayout();
okButton = new QPushButton( tr("OK") );
cancelButton = new QPushButton( tr("Cancel") );
mainLayout->addWidget( tree );
mainLayout->addLayout( hbox );
hbox->addWidget( cancelButton );
hbox->addWidget( okButton );
connect( okButton, SIGNAL(clicked(void)), &dialog, SLOT(accept(void)) );
connect( cancelButton, SIGNAL(clicked(void)), &dialog, SLOT(reject(void)) );
dialog.setLayout( mainLayout );
ret = dialog.exec();
if ( ret == QDialog::Accepted )
{
idx = 0;
item = tree->currentItem();
if ( item != NULL )
{
idx = tree->indexOfTopLevelItem(item);
}
}
else
{
idx = -1;
}
return idx;
}
//---------------------------------------------------------------------------
void consoleWin_t::openROMFile(void)
{

View File

@ -4,6 +4,9 @@
#ifndef __GameAppH__
#define __GameAppH__
#include <vector>
#include <string>
#include <QApplication>
#include <QMainWindow>
#include <QWidget>
@ -48,6 +51,8 @@ class consoleWin_t : public QMainWindow
void QueueErrorMsgWindow( const char *msg );
int showListSelectDialog( const char *title, std::vector <std::string> &l );
protected:
QMenu *fileMenu;
QMenu *optMenu;

View File

@ -1028,14 +1028,17 @@ int fceuWrapperUpdate( void )
if ( !lock_acq )
{
printf("Error: Emulator Failed to Acquire Mutex\n");
if ( GameInfo )
{
printf("Error: Emulator Failed to Acquire Mutex\n");
}
usleep( 100000 );
return -1;
}
emulatorHasMutux = 1;
if ( GameInfo /*&& !FCEUI_EmulationPaused()*/ )
if ( GameInfo )
{
DoFun(frameskip, periodic_saves);
@ -1118,30 +1121,59 @@ FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::str
void *tmpMem = NULL;
std::string searchFile;
zf = unzOpen( fname.c_str() );
if ( zf == NULL )
{
//printf("Error: Failed to open Zip File: '%s'\n", fname.c_str() );
return fp;
}
if ( innerFilename != NULL )
{
searchFile = *innerFilename;
}
else
{
std::vector <std::string> fileList;
for (size_t i=0; i<asr.files.size(); i++)
{
char base[512], suffix[32];
getFileBaseName( asr.files[i].name.c_str(), base, suffix );
if ( strcasecmp( suffix, ".nes" ) == 0 )
if ( (strcasecmp( suffix, ".nes" ) == 0) ||
(strcasecmp( suffix, ".nsf" ) == 0) ||
(strcasecmp( suffix, ".fds" ) == 0) ||
(strcasecmp( suffix, ".unf" ) == 0) ||
(strcasecmp( suffix, ".unif") == 0) )
{
searchFile = asr.files[i].name; break;
fileList.push_back( asr.files[i].name );
}
}
if ( fileList.size() > 1 )
{
if ( consoleWindow != NULL )
{
int sel = consoleWindow->showListSelectDialog( "Select ROM From Archive", fileList );
if ( sel < 0 )
{
if ( userCancel )
{
*userCancel = 1;
}
return fp;
}
searchFile = fileList[sel];
}
}
else if ( fileList.size() > 0 )
{
searchFile = fileList[0];
}
}
zf = unzOpen( fname.c_str() );
if ( zf == NULL )
{
//printf("Error: Failed to open Zip File: '%s'\n", fname.c_str() );
return fp;
}
//printf("Searching for %s in %s \n", searchFile.c_str(), fname.c_str() );