diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 4073d0787..f74617d38 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include "../../fceu.h" #include "../../fds.h" @@ -125,6 +126,12 @@ consoleWin_t::consoleWin_t(QWidget *parent) //QString libpath = QLibraryInfo::location(QLibraryInfo::PluginsPath); //printf("LibPath: '%s'\n", libpath.toLocal8Bit().constData() ); + tempDir = new QTemporaryDir(); + if (tempDir->isValid()) + { + printf("Temp Folder: %s\n", tempDir->path().toLocal8Bit().constData()); + } + #ifdef __APPLE__ qt_set_sequence_auto_mnemonic(true); #endif @@ -385,6 +392,11 @@ consoleWin_t::~consoleWin_t(void) consoleWindow = NULL; } + if (tempDir != nullptr) + { + delete tempDir; + tempDir = nullptr; + } } int consoleWin_t::videoInit(void) @@ -4729,6 +4741,20 @@ void consoleWin_t::loadMostRecentROM(void) FCEU_WRAPPER_UNLOCK(); } +QString consoleWin_t::getTempDir() +{ + QString path; + if (tempDir->isValid()) + { + path = tempDir->path(); + } + else + { + path = QDir::tempPath(); + } + return path; +} + int consoleWin_t::getPeriodicInterval(void) { return gameTimer->interval(); diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index b59f94ff5..d5bd7d3aa 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -23,6 +23,7 @@ #include #include #include +#include #if QT_VERSION >= QT_VERSION_CHECK(6,0,0) #include #endif @@ -184,6 +185,8 @@ class consoleWin_t : public QMainWindow QColor *getVideoBgColorPtr(void){ return &videoBgColor; } + QString getTempDir(); + protected: consoleMenuBar *menubar; @@ -271,6 +274,7 @@ class consoleWin_t : public QMainWindow QTimer *gameTimer; QColor videoBgColor; ColorMenuItem *bgColorMenuItem; + QTemporaryDir *tempDir; std::string errorMsg; bool errorMsgValid; diff --git a/src/drivers/Qt/NetPlay.cpp b/src/drivers/Qt/NetPlay.cpp index 6fd0c7ab0..85d576b04 100644 --- a/src/drivers/Qt/NetPlay.cpp +++ b/src/drivers/Qt/NetPlay.cpp @@ -379,9 +379,11 @@ int NetPlayServer::sendRomLoadReq( NetPlayClient *client ) rewind(fp); + QFileInfo fileInfo(GameInfo->filename); + msg.hdr.msgSize += fileSize; msg.fileSize = fileSize; - Strlcpy( msg.fileName, GameInfo->filename, sizeof(msg.fileName) ); + Strlcpy( msg.fileName, fileInfo.fileName().toLocal8Bit().constData(), sizeof(msg.fileName) ); printf("Sending ROM Load Request: %s %lu\n", filepath, fileSize ); @@ -1958,15 +1960,17 @@ void NetPlayClient::clientProcessMessage( void *msgBuf, size_t msgSize ) break; case NETPLAY_LOAD_ROM_REQ: { - QTemporaryFile tmpFile; netPlayLoadRomReq *msg = static_cast(msgBuf); msg->toHostByteOrder(); const char *romData = &static_cast(msgBuf)[ sizeof(netPlayLoadRomReq) ]; - FCEU_printf("Load ROM Request Received: %s\n", msg->fileName); + QFileInfo fileInfo = QFileInfo(msg->fileName); + QString tempPath = consoleWindow->getTempDir() + QString("/") + fileInfo.fileName(); + FCEU_printf("Load ROM Request Received: %s\n", fileInfo.fileName().toLocal8Bit().constData()); - tmpFile.setFileTemplate(QDir::tempPath() + QString("/tmpRom_XXXXXX.nes")); - tmpFile.open(); + QFile tmpFile( tempPath ); + //tmpFile.setFileTemplate(QDir::tempPath() + QString("/tmpRom_XXXXXX.nes")); + tmpFile.open(QIODeviceBase::ReadWrite); QString filepath = tmpFile.fileName(); printf("Dumping Temp Rom to: %s\n", tmpFile.fileName().toLocal8Bit().constData()); tmpFile.write( romData, msgSize );