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 <QActionGroup>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
#include "../../fceu.h"
|
#include "../../fceu.h"
|
||||||
#include "../../fds.h"
|
#include "../../fds.h"
|
||||||
|
@ -125,6 +126,12 @@ consoleWin_t::consoleWin_t(QWidget *parent)
|
||||||
//QString libpath = QLibraryInfo::location(QLibraryInfo::PluginsPath);
|
//QString libpath = QLibraryInfo::location(QLibraryInfo::PluginsPath);
|
||||||
//printf("LibPath: '%s'\n", libpath.toLocal8Bit().constData() );
|
//printf("LibPath: '%s'\n", libpath.toLocal8Bit().constData() );
|
||||||
|
|
||||||
|
tempDir = new QTemporaryDir();
|
||||||
|
if (tempDir->isValid())
|
||||||
|
{
|
||||||
|
printf("Temp Folder: %s\n", tempDir->path().toLocal8Bit().constData());
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
qt_set_sequence_auto_mnemonic(true);
|
qt_set_sequence_auto_mnemonic(true);
|
||||||
#endif
|
#endif
|
||||||
|
@ -385,6 +392,11 @@ consoleWin_t::~consoleWin_t(void)
|
||||||
consoleWindow = NULL;
|
consoleWindow = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tempDir != nullptr)
|
||||||
|
{
|
||||||
|
delete tempDir;
|
||||||
|
tempDir = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int consoleWin_t::videoInit(void)
|
int consoleWin_t::videoInit(void)
|
||||||
|
@ -4729,6 +4741,20 @@ void consoleWin_t::loadMostRecentROM(void)
|
||||||
FCEU_WRAPPER_UNLOCK();
|
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)
|
int consoleWin_t::getPeriodicInterval(void)
|
||||||
{
|
{
|
||||||
return gameTimer->interval();
|
return gameTimer->interval();
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <QCursor>
|
#include <QCursor>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <QTemporaryDir>
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
|
||||||
#include <QRecursiveMutex>
|
#include <QRecursiveMutex>
|
||||||
#endif
|
#endif
|
||||||
|
@ -184,6 +185,8 @@ class consoleWin_t : public QMainWindow
|
||||||
|
|
||||||
QColor *getVideoBgColorPtr(void){ return &videoBgColor; }
|
QColor *getVideoBgColorPtr(void){ return &videoBgColor; }
|
||||||
|
|
||||||
|
QString getTempDir();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
consoleMenuBar *menubar;
|
consoleMenuBar *menubar;
|
||||||
|
|
||||||
|
@ -271,6 +274,7 @@ class consoleWin_t : public QMainWindow
|
||||||
QTimer *gameTimer;
|
QTimer *gameTimer;
|
||||||
QColor videoBgColor;
|
QColor videoBgColor;
|
||||||
ColorMenuItem *bgColorMenuItem;
|
ColorMenuItem *bgColorMenuItem;
|
||||||
|
QTemporaryDir *tempDir;
|
||||||
|
|
||||||
std::string errorMsg;
|
std::string errorMsg;
|
||||||
bool errorMsgValid;
|
bool errorMsgValid;
|
||||||
|
|
|
@ -379,9 +379,11 @@ int NetPlayServer::sendRomLoadReq( NetPlayClient *client )
|
||||||
|
|
||||||
rewind(fp);
|
rewind(fp);
|
||||||
|
|
||||||
|
QFileInfo fileInfo(GameInfo->filename);
|
||||||
|
|
||||||
msg.hdr.msgSize += fileSize;
|
msg.hdr.msgSize += fileSize;
|
||||||
msg.fileSize = 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 );
|
printf("Sending ROM Load Request: %s %lu\n", filepath, fileSize );
|
||||||
|
|
||||||
|
@ -1958,15 +1960,17 @@ void NetPlayClient::clientProcessMessage( void *msgBuf, size_t msgSize )
|
||||||
break;
|
break;
|
||||||
case NETPLAY_LOAD_ROM_REQ:
|
case NETPLAY_LOAD_ROM_REQ:
|
||||||
{
|
{
|
||||||
QTemporaryFile tmpFile;
|
|
||||||
netPlayLoadRomReq *msg = static_cast<netPlayLoadRomReq*>(msgBuf);
|
netPlayLoadRomReq *msg = static_cast<netPlayLoadRomReq*>(msgBuf);
|
||||||
msg->toHostByteOrder();
|
msg->toHostByteOrder();
|
||||||
const char *romData = &static_cast<const char*>(msgBuf)[ sizeof(netPlayLoadRomReq) ];
|
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"));
|
QFile tmpFile( tempPath );
|
||||||
tmpFile.open();
|
//tmpFile.setFileTemplate(QDir::tempPath() + QString("/tmpRom_XXXXXX.nes"));
|
||||||
|
tmpFile.open(QIODeviceBase::ReadWrite);
|
||||||
QString filepath = tmpFile.fileName();
|
QString filepath = tmpFile.fileName();
|
||||||
printf("Dumping Temp Rom to: %s\n", tmpFile.fileName().toLocal8Bit().constData());
|
printf("Dumping Temp Rom to: %s\n", tmpFile.fileName().toLocal8Bit().constData());
|
||||||
tmpFile.write( romData, msgSize );
|
tmpFile.write( romData, msgSize );
|
||||||
|
|
Loading…
Reference in New Issue