Fix some bugs in scripting

This commit is contained in:
2024-06-10 18:55:13 +02:00
parent 37dd97e361
commit 3c8f49e932
2 changed files with 19 additions and 8 deletions
+4 -1
View File
@@ -36,7 +36,10 @@ QList<QPair<QString, QString>> 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});
}
};
+15 -7
View File
@@ -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;
}
}