Minor JS File object fixes.

This commit is contained in:
harry 2024-02-17 21:01:24 -05:00
parent 460bf597d5
commit 9cd7b620dd
1 changed files with 12 additions and 7 deletions

View File

@ -111,7 +111,7 @@ FileScriptObject::FileScriptObject(const QString& path)
: QObject() : QObject()
{ {
numInstances++; numInstances++;
printf("FileScriptObject(%s) %p Constructor: %i\n", path.toLocal8Bit().constData(), this, numInstances); //printf("FileScriptObject(%s) %p Constructor: %i\n", path.toLocal8Bit().constData(), this, numInstances);
moveToThread(QApplication::instance()->thread()); moveToThread(QApplication::instance()->thread());
@ -128,9 +128,14 @@ FileScriptObject::~FileScriptObject()
//---------------------------------------------------- //----------------------------------------------------
void FileScriptObject::setFilePath(const QString& path) void FileScriptObject::setFilePath(const QString& path)
{ {
if (isOpen())
{
auto* engine = FCEU::JSEngine::getCurrent();
engine->throwError(QJSValue::GenericError, "cannot change file path while open");
}
QFileInfo fi(path); QFileInfo fi(path);
filepath = fi.absoluteFilePath(); filepath = fi.absoluteFilePath();
printf("FileScriptObject::filepath(%s)\n", filepath.toLocal8Bit().constData()); //printf("FileScriptObject::filepath(%s)\n", filepath.toLocal8Bit().constData());
} }
//---------------------------------------------------- //----------------------------------------------------
QString FileScriptObject::fileName() QString FileScriptObject::fileName()
@ -152,7 +157,7 @@ bool FileScriptObject::open(int mode)
if (filepath.isEmpty()) if (filepath.isEmpty())
{ {
auto* engine = FCEU::JSEngine::getCurrent(); auto* engine = FCEU::JSEngine::getCurrent();
engine->throwError(QJSValue::GenericError, "Error: unspecified file path "); engine->throwError(QJSValue::GenericError, "unspecified file path ");
return false; return false;
} }
@ -161,7 +166,7 @@ bool FileScriptObject::open(int mode)
if (file == nullptr) if (file == nullptr)
{ {
auto* engine = FCEU::JSEngine::getCurrent(); auto* engine = FCEU::JSEngine::getCurrent();
engine->throwError(QJSValue::GenericError, "Error: Failed to create QFile object"); engine->throwError(QJSValue::GenericError, "failed to create QFile object");
return false; return false;
} }
@ -216,7 +221,7 @@ int FileScriptObject::writeString(const QString& s)
if ( (file == nullptr) || !file->isOpen()) if ( (file == nullptr) || !file->isOpen())
{ {
auto* engine = FCEU::JSEngine::getCurrent(); auto* engine = FCEU::JSEngine::getCurrent();
engine->throwError(QJSValue::GenericError, "Error: file is not open "); engine->throwError(QJSValue::GenericError, "file is not open ");
return -1; return -1;
} }
int bytesWritten = file->write( s.toLocal8Bit() ); int bytesWritten = file->write( s.toLocal8Bit() );
@ -231,7 +236,7 @@ QJSValue FileScriptObject::readLine()
if ( (file == nullptr) || !file->isOpen()) if ( (file == nullptr) || !file->isOpen())
{ {
auto* engine = FCEU::JSEngine::getCurrent(); auto* engine = FCEU::JSEngine::getCurrent();
engine->throwError(QJSValue::GenericError, "Error: file is not open "); engine->throwError(QJSValue::GenericError, "file is not open ");
return obj; return obj;
} }
auto* engine = FCEU::JSEngine::getCurrent(); auto* engine = FCEU::JSEngine::getCurrent();
@ -1952,7 +1957,7 @@ void QtScriptInstance::loadUI(const QString& uiFilePath)
ui_rootWidget->show(); ui_rootWidget->show();
#else #else
throwError(QJSValue::GenericError, "Error: Application was not linked against Qt UI Tools"); throwError(QJSValue::GenericError, "Application was not linked against Qt UI Tools");
#endif #endif
} }
//---------------------------------------------------- //----------------------------------------------------