From 3c8f49e932a544cba1786596962b969fa84932e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Poizl?= Date: Mon, 10 Jun 2024 18:55:13 +0200 Subject: [PATCH] Fix some bugs in scripting --- batchprocessing.cpp | 5 ++++- scriptengine.cpp | 22 +++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/batchprocessing.cpp b/batchprocessing.cpp index 7e2cdd7..53e2eb2 100644 --- a/batchprocessing.cpp +++ b/batchprocessing.cpp @@ -36,7 +36,10 @@ QList> scanDirectories(const QStringList &paths) } else if(info.isFile()) { - files.append({path, root}); + if(path == root) + files.append({path, info.absolutePath()}); + else + files.append({path, root}); } }; diff --git a/scriptengine.cpp b/scriptengine.cpp index e803123..14c3f0f 100644 --- a/scriptengine.cpp +++ b/scriptengine.cpp @@ -129,16 +129,23 @@ bool ScriptEngine::convert(File *file, QString &outpath, const QString &format, else path = dir.absoluteFilePath(outpath); + QString f = format.toLower(); + if(f != "xisf" && f != "fits" && f != "png" && f != "bmp" && f != "jpg") + { + logError("Output format must be one of xisf fits jpg png bmp"); + return false; + } + info.setFile(path); - outpath = info.absolutePath() + "/" + info.completeBaseName() + "." + format.toLower(); + outpath = info.absolutePath() + "/" + info.completeBaseName() + "." + f; if(async) { _semaphore.acquire(); - _pool->start(new ConvertRunable(file->absoluteFilePath(), outpath, format, params, &_semaphore)); + _pool->start(new ConvertRunable(file->absoluteFilePath(), outpath, f, params, &_semaphore)); } else { - ConvertRunable crun(file->absoluteFilePath(), outpath, format, params, nullptr); + ConvertRunable crun(file->absoluteFilePath(), outpath, f, params, nullptr); crun.run(); } return true; @@ -192,11 +199,11 @@ void File::loadFitsKeywords() { _fitsKeywordsLoaded = true; ImageInfoData info; - if(suffix() == "xisf") + if(suffix().toLower() == "xisf") { readXISFHeader(_path, info); } - else if(suffix() == "fits") + else if(suffix().toLower() == "fits" || suffix().toLower() == "fit") { readFITSHeader(_path, info); } @@ -343,7 +350,7 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify) _fitsKeywordsLoaded = false; _fitsKeywords.clear(); - if(QRegularExpression("fits", QRegularExpression::CaseInsensitiveOption).match(suffix()).hasMatch()) + if(QRegularExpression("fits?", QRegularExpression::CaseInsensitiveOption).match(suffix()).hasMatch()) { fitsfile *file; int status = 0; @@ -371,6 +378,7 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify) for(auto &remove : modify->_remove) { + int status = 0;//we ignore errors from here fits_delete_key(file, remove.toLatin1().data(), &status); } for(auto &record : modify->_update) @@ -412,7 +420,7 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify) { char error[100]; fits_get_errstatus(status, error); - _engine->newMessage(QString("Error when updating KEY {} {}").arg(record.key).arg(error), true); + _engine->newMessage(QString("Error when updating KEY %1 %2").arg(record.key).arg(error), true); return false; } }