Merge pull request #203 from mjbudd77/master

Various Improvements/Fixes for Qt GUI Zip File Archive Support
This commit is contained in:
mjbudd77 2020-10-25 12:43:14 -04:00 committed by GitHub
commit 3f571003d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 166 additions and 15 deletions

View File

@ -623,7 +623,14 @@ static int getDefaultCDLFile( char *filepath )
parseFilepath( romFile, dir, baseFile ); parseFilepath( romFile, dir, baseFile );
if ( dir[0] == 0 )
{
sprintf( filepath, "%s.cdl", baseFile );
}
else
{
sprintf( filepath, "%s/%s.cdl", dir, baseFile ); sprintf( filepath, "%s/%s.cdl", dir, baseFile );
}
//printf("%s\n", filepath ); //printf("%s\n", filepath );
@ -827,7 +834,7 @@ void SaveCDLogFile(void)
FP = fopen(loadedcdfile, "wb"); FP = fopen(loadedcdfile, "wb");
if (FP == NULL) if (FP == NULL)
{ {
FCEUD_PrintError("Error Saving File"); FCEUD_PrintError("Error Saving CDL File");
return; return;
} }
fwrite(cdloggerdata, cdloggerdataSize, 1, FP); fwrite(cdloggerdata, cdloggerdataSize, 1, FP);

View File

@ -2443,7 +2443,7 @@ void saveGameDebugBreakpoints(void)
debuggerBookmark_t *bm; debuggerBookmark_t *bm;
// If no breakpoints are loaded, skip saving // If no breakpoints are loaded, skip saving
if ( numWPs == 0 ) if ( (numWPs == 0) && (dbgBmMgr.size() == 0) )
{ {
return; return;
} }

View File

@ -38,10 +38,40 @@ int getDirFromFile( const char *path, char *dir )
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
const char *getRomFile( void ) const char *getRomFile( void )
{ {
static char filePath[2048];
if ( GameInfo ) if ( GameInfo )
{
//printf("filename: '%s' \n", GameInfo->filename );
//printf("archiveFilename: '%s' \n", GameInfo->archiveFilename );
if ( GameInfo->archiveFilename != NULL )
{
char dir[1024], base[512], suffix[64];
parseFilepath( GameInfo->archiveFilename, dir, base, suffix );
filePath[0] = 0;
if ( dir[0] != 0 )
{
strcat( filePath, dir );
}
parseFilepath( GameInfo->filename, dir, base, suffix );
strcat( filePath, base );
strcat( filePath, suffix );
//printf("ArchivePath: '%s' \n", filePath );
return filePath;
}
else
{ {
return GameInfo->filename; return GameInfo->filename;
} }
}
return NULL; return NULL;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -3,6 +3,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
#include <QHeaderView>
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QInputDialog> #include <QInputDialog>
@ -703,6 +704,82 @@ void consoleWin_t::closeApp(void)
qApp->quit(); 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) void consoleWin_t::openROMFile(void)
{ {

View File

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

View File

@ -1027,15 +1027,18 @@ int fceuWrapperUpdate( void )
lock_acq = fceuWrapperTryLock(); lock_acq = fceuWrapperTryLock();
if ( !lock_acq ) if ( !lock_acq )
{
if ( GameInfo )
{ {
printf("Error: Emulator Failed to Acquire Mutex\n"); printf("Error: Emulator Failed to Acquire Mutex\n");
}
usleep( 100000 ); usleep( 100000 );
return -1; return -1;
} }
emulatorHasMutux = 1; emulatorHasMutux = 1;
if ( GameInfo /*&& !FCEUI_EmulationPaused()*/ ) if ( GameInfo )
{ {
DoFun(frameskip, periodic_saves); DoFun(frameskip, periodic_saves);
@ -1118,30 +1121,59 @@ FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::str
void *tmpMem = NULL; void *tmpMem = NULL;
std::string searchFile; 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 ) if ( innerFilename != NULL )
{ {
searchFile = *innerFilename; searchFile = *innerFilename;
} }
else else
{ {
std::vector <std::string> fileList;
for (size_t i=0; i<asr.files.size(); i++) for (size_t i=0; i<asr.files.size(); i++)
{ {
char base[512], suffix[32]; char base[512], suffix[32];
getFileBaseName( asr.files[i].name.c_str(), base, suffix ); 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() ); //printf("Searching for %s in %s \n", searchFile.c_str(), fname.c_str() );