For Qt GUI, create a temp directory per every boot of application that can be used to store temporary files for things such as netplay roms. This folder is deleted at application exit.
This commit is contained in:
parent
151c951d63
commit
4e57ca40ae
|
@ -47,6 +47,7 @@
|
|||
#include <QActionGroup>
|
||||
#include <QShortcut>
|
||||
#include <QUrl>
|
||||
#include <QDir>
|
||||
|
||||
#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();
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <QCursor>
|
||||
#include <QMutex>
|
||||
#include <QColor>
|
||||
#include <QTemporaryDir>
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
|
||||
#include <QRecursiveMutex>
|
||||
#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;
|
||||
|
|
|
@ -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<netPlayLoadRomReq*>(msgBuf);
|
||||
msg->toHostByteOrder();
|
||||
const char *romData = &static_cast<const char*>(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 );
|
||||
|
|
Loading…
Reference in New Issue