For Qt GUI, store archive file index so that a hard reload knows how to refind the ROM inside the archive. For netplay, don't send entire zip archives. Instead just send the single extracted ROM of interest.

This commit is contained in:
harry 2024-05-05 05:57:11 -04:00
parent 4b36de6ec9
commit 0ea2670ae0
6 changed files with 69 additions and 40 deletions

View File

@ -343,23 +343,34 @@ int NetPlayServer::sendRomLoadReq( NetPlayClient *client )
char buf[BufferSize]; char buf[BufferSize];
size_t bytesRead; size_t bytesRead;
long fileSize = 0; long fileSize = 0;
int userCancel = 0;
int archiveIndex = -1;
netPlayLoadRomReq msg; netPlayLoadRomReq msg;
const char* romextensions[] = { "nes", "fds", "nsf", 0 };
const char *filepath = nullptr; const char *filepath = nullptr;
if ( GameInfo ) if ( GameInfo == nullptr)
{ {
printf("filename: '%s' \n", GameInfo->filename ); return -1;
printf("archiveFilename: '%s' \n", GameInfo->archiveFilename ); }
if (GameInfo->archiveFilename) //printf("filename: '%s' \n", GameInfo->filename );
{ //printf("archiveFilename: '%s' \n", GameInfo->archiveFilename );
filepath = GameInfo->archiveFilename;
} if (GameInfo->archiveFilename)
else {
{ filepath = GameInfo->archiveFilename;
filepath = GameInfo->filename; }
} else
{
filepath = GameInfo->filename;
}
archiveIndex = GameInfo->archiveIndex;
if (archiveIndex >= 0)
{
msg.archiveIndex = archiveIndex;
} }
if (filepath == nullptr) if (filepath == nullptr)
@ -367,17 +378,14 @@ int NetPlayServer::sendRomLoadReq( NetPlayClient *client )
return -1; return -1;
} }
printf("Prep ROM Load Request: %s \n", filepath ); printf("Prep ROM Load Request: %s \n", filepath );
FILE *fp = ::fopen( filepath, "rb");
FCEUFILE* fp = FCEU_fopen( filepath, nullptr, "rb", 0, archiveIndex, romextensions, &userCancel);
if (fp == nullptr) if (fp == nullptr)
{ {
return -1; return -1;
} }
fseek( fp, 0, SEEK_END); fileSize = fp->size;
fileSize = ftell(fp);
rewind(fp);
QFileInfo fileInfo(GameInfo->filename); QFileInfo fileInfo(GameInfo->filename);
@ -389,13 +397,13 @@ int NetPlayServer::sendRomLoadReq( NetPlayClient *client )
sendMsg( client, &msg, sizeof(netPlayLoadRomReq), [&msg]{ msg.toNetworkByteOrder(); } ); sendMsg( client, &msg, sizeof(netPlayLoadRomReq), [&msg]{ msg.toNetworkByteOrder(); } );
while ( (bytesRead = fread( buf, 1, sizeof(buf), fp )) > 0 ) while ( (bytesRead = FCEU_fread( buf, 1, sizeof(buf), fp )) > 0 )
{ {
sendMsg( client, buf, bytesRead ); sendMsg( client, buf, bytesRead );
} }
client->flushData(); client->flushData();
::fclose(fp); FCEU_fclose(fp);
return 0; return 0;
} }
@ -1977,7 +1985,9 @@ void NetPlayClient::clientProcessMessage( void *msgBuf, size_t msgSize )
tmpFile.close(); tmpFile.close();
FCEU_WRAPPER_LOCK(); FCEU_WRAPPER_LOCK();
fceuWrapperSetArchiveFileLoadIndex( msg->archiveIndex );
LoadGame( filepath.toLocal8Bit().constData(), true, true ); LoadGame( filepath.toLocal8Bit().constData(), true, true );
fceuWrapperClearArchiveFileLoadIndex();
opsCrc32 = 0; opsCrc32 = 0;
netPlayFrameData.reset(); netPlayFrameData.reset();

View File

@ -236,10 +236,11 @@ struct netPlayLoadRomReq
netPlayMsgHdr hdr; netPlayMsgHdr hdr;
uint32_t fileSize; uint32_t fileSize;
uint32_t archiveIndex;
char fileName[256]; char fileName[256];
netPlayLoadRomReq(void) netPlayLoadRomReq(void)
: hdr(NETPLAY_LOAD_ROM_REQ, sizeof(netPlayLoadRomReq)), fileSize(0) : hdr(NETPLAY_LOAD_ROM_REQ, sizeof(netPlayLoadRomReq)), fileSize(0), archiveIndex(0)
{ {
memset(fileName, 0, sizeof(fileName)); memset(fileName, 0, sizeof(fileName));
} }
@ -247,13 +248,15 @@ struct netPlayLoadRomReq
void toHostByteOrder() void toHostByteOrder()
{ {
hdr.toHostByteOrder(); hdr.toHostByteOrder();
fileSize = netPlayByteSwap(fileSize); fileSize = netPlayByteSwap(fileSize);
archiveIndex = netPlayByteSwap(archiveIndex);
} }
void toNetworkByteOrder() void toNetworkByteOrder()
{ {
hdr.toNetworkByteOrder(); hdr.toNetworkByteOrder();
fileSize = netPlayByteSwap(fileSize); fileSize = netPlayByteSwap(fileSize);
archiveIndex = netPlayByteSwap(archiveIndex);
} }
}; };

View File

@ -65,6 +65,7 @@
#include "common/os_utils.h" #include "common/os_utils.h"
#include "common/configSys.h" #include "common/configSys.h"
#include "utils/timeStamp.h" #include "utils/timeStamp.h"
#include "utils/StringUtils.h"
#include "../../oldmovie.h" #include "../../oldmovie.h"
#include "../../types.h" #include "../../types.h"
@ -109,6 +110,7 @@ static int mutexLocks = 0;
static int mutexPending = 0; static int mutexPending = 0;
static bool emulatorHasMutex = 0; static bool emulatorHasMutex = 0;
unsigned int emulatorCycleCount = 0; unsigned int emulatorCycleCount = 0;
static int archiveFileLoadIndex = -1;
extern double g_fpsScale; extern double g_fpsScale;
@ -341,16 +343,6 @@ int LoadGame(const char *path, bool silent, bool netPlayRequested)
{ {
fullpath.assign( path ); fullpath.assign( path );
} }
//#if defined(__linux__) || defined(__APPLE__) || defined(__unix__)
//
// // Resolve absolute path to file
// if ( realpath( path, fullpath ) == NULL )
// {
// strcpy( fullpath, path );
// }
//#else
// strcpy( fullpath, path );
//#endif
//printf("Fullpath: %zi '%s'\n", sizeof(fullpath), fullpath ); //printf("Fullpath: %zi '%s'\n", sizeof(fullpath), fullpath );
@ -600,12 +592,13 @@ int fceuWrapperHardReset(void)
if ( GameInfo->archiveFilename ) if ( GameInfo->archiveFilename )
{ {
strcpy( romPath, GameInfo->archiveFilename ); Strlcpy( romPath, GameInfo->archiveFilename, sizeof(romPath) );
} }
else if ( GameInfo->filename ) else if ( GameInfo->filename )
{ {
strcpy( romPath, GameInfo->filename ); Strlcpy( romPath, GameInfo->filename, sizeof(romPath) );
} }
fceuWrapperSetArchiveFileLoadIndex( GameInfo->archiveIndex );
if ( romPath[0] != 0 ) if ( romPath[0] != 0 )
{ {
@ -613,6 +606,7 @@ int fceuWrapperHardReset(void)
//printf("Loading: '%s'\n", romPath ); //printf("Loading: '%s'\n", romPath );
LoadGame ( romPath ); LoadGame ( romPath );
} }
fceuWrapperClearArchiveFileLoadIndex();
} }
return 0; return 0;
} }
@ -1739,7 +1733,7 @@ static FCEUFILE* minizip_OpenArchive(ArchiveScanRecord& asr, std::string &fname,
//printf("Filename: %u '%s' \n", fi.uncompressed_size, filename ); //printf("Filename: %u '%s' \n", fi.uncompressed_size, filename );
if (searchFile) if ( (searchFile != nullptr) && !searchFile->empty())
{ {
if ( strcmp( searchFile->c_str(), filename ) == 0 ) if ( strcmp( searchFile->c_str(), filename ) == 0 )
{ {
@ -1858,7 +1852,8 @@ static FCEUFILE* libarchive_OpenArchive( ArchiveScanRecord& asr, std::string& fn
filename = archive_entry_pathname(entry); filename = archive_entry_pathname(entry);
fileSize = archive_entry_size(entry); fileSize = archive_entry_size(entry);
if (searchFile) printf("ArchiveFile:%i %s\n", idx, filename);
if ( (searchFile != nullptr) && !searchFile->empty())
{ {
if (strcmp( filename, searchFile->c_str() ) == 0) if (strcmp( filename, searchFile->c_str() ) == 0)
{ {
@ -1923,6 +1918,16 @@ static FCEUFILE* libarchive_OpenArchive( ArchiveScanRecord& asr, std::string& fn
#endif #endif
void fceuWrapperSetArchiveFileLoadIndex(int idx)
{
archiveFileLoadIndex = idx;
}
void fceuWrapperClearArchiveFileLoadIndex()
{
archiveFileLoadIndex = -1;
}
FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::string* innerFilename, int* userCancel) FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::string* innerFilename, int* userCancel)
{ {
FCEUFILE* fp = nullptr; FCEUFILE* fp = nullptr;
@ -1940,6 +1945,7 @@ FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::str
{ {
char base[512], suffix[128]; char base[512], suffix[128];
//printf("File:%zi %s\n", i, asr.files[i].name.c_str() );
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) ||
@ -1954,7 +1960,11 @@ FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::str
if ( fileList.size() > 1 ) if ( fileList.size() > 1 )
{ {
if ( consoleWindow != NULL ) if ( (archiveFileLoadIndex >= 0) && (static_cast<size_t>(archiveFileLoadIndex) < asr.files.size()))
{
searchFile.clear();
}
else if ( consoleWindow != NULL )
{ {
int sel = consoleWindow->showListSelectDialog( "Select ROM From Archive", fileList ); int sel = consoleWindow->showListSelectDialog( "Select ROM From Archive", fileList );
@ -1973,16 +1983,18 @@ FCEUFILE* FCEUD_OpenArchive(ArchiveScanRecord& asr, std::string& fname, std::str
{ {
searchFile = fileList[0]; searchFile = fileList[0];
} }
//printf("Archive Search File: %s\n", searchFile.c_str());
} }
#ifdef _USE_LIBARCHIVE #ifdef _USE_LIBARCHIVE
fp = libarchive_OpenArchive(asr, fname, &searchFile, -1 ); fp = libarchive_OpenArchive(asr, fname, &searchFile, archiveFileLoadIndex );
#endif #endif
if (fp == nullptr) if (fp == nullptr)
{ {
fp = minizip_OpenArchive(asr, fname, &searchFile, -1 ); fp = minizip_OpenArchive(asr, fname, &searchFile, archiveFileLoadIndex );
} }
//printf("Archive File Index: %i\n", fp->archiveIndex);
return fp; return fp;
} }

View File

@ -48,6 +48,8 @@ int fceuWrapperHardReset(void);
int fceuWrapperTogglePause(void); int fceuWrapperTogglePause(void);
bool fceuWrapperGameLoaded(void); bool fceuWrapperGameLoaded(void);
void fceuWrapperRequestAppExit(void); void fceuWrapperRequestAppExit(void);
void fceuWrapperClearArchiveFileLoadIndex(void);
void fceuWrapperSetArchiveFileLoadIndex(int idx);
class fceuCriticalSection class fceuCriticalSection
{ {

View File

@ -483,6 +483,7 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode, bool silen
if (fp->archiveFilename != "") if (fp->archiveFilename != "")
GameInfo->archiveFilename = strdup(fp->archiveFilename.c_str()); GameInfo->archiveFilename = strdup(fp->archiveFilename.c_str());
GameInfo->archiveCount = fp->archiveCount; GameInfo->archiveCount = fp->archiveCount;
GameInfo->archiveIndex = fp->archiveIndex;
GameInfo->soundchan = 0; GameInfo->soundchan = 0;
GameInfo->soundrate = 0; GameInfo->soundrate = 0;

View File

@ -173,7 +173,8 @@ struct FCEUGI
char* filename = nullptr; char* filename = nullptr;
char* archiveFilename = nullptr; char* archiveFilename = nullptr;
int archiveCount = 0; int archiveCount = 0; // the number of files that were in the archive
int archiveIndex = -1; // the index of the file within the archive
bool loadedFromTmpFile = false; // Was loaded from temporary file, file most likely no longer exists bool loadedFromTmpFile = false; // Was loaded from temporary file, file most likely no longer exists
}; };