From abef4f96887b62580236dac1f7cceecfeae0121a Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Sat, 5 Aug 2023 21:27:38 +0100 Subject: [PATCH] Use QFileInfo to get file extension. For #1760 --- plugins/channelrx/filesink/filesinksink.cpp | 22 ++++++++------------- sdrbase/dsp/filerecordinterface.cpp | 20 ++++++------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/plugins/channelrx/filesink/filesinksink.cpp b/plugins/channelrx/filesink/filesinksink.cpp index e6a0c1264..5b657647b 100644 --- a/plugins/channelrx/filesink/filesinksink.cpp +++ b/plugins/channelrx/filesink/filesinksink.cpp @@ -16,6 +16,7 @@ /////////////////////////////////////////////////////////////////////////////////// #include +#include #include "dsp/dspcommands.h" #include "dsp/spectrumvis.h" @@ -278,21 +279,14 @@ void FileSinkSink::applySettings(const FileSinkSettings& settings, bool force) if ((settings.m_fileRecordName != m_settings.m_fileRecordName) || force) { - QStringList dotBreakout = settings.m_fileRecordName.split(QLatin1Char('.')); - - if (dotBreakout.size() > 1) { - QString extension = dotBreakout.last(); - - if ((extension != "sdriq") && (extension != "wav")) { - dotBreakout.last() = "sdriq"; - } + QFileInfo fileInfo(settings.m_fileRecordName); + QString extension = fileInfo.suffix(); + if (extension.isEmpty()) { + fileRecordName.append(".sdriq"); + } else if ((extension != "sdriq") && (extension != "wav")) { + fileRecordName.chop(extension.size()); + fileRecordName.append("sdriq"); } - else - { - dotBreakout.append("sdriq"); - } - - fileRecordName = dotBreakout.join(QLatin1Char('.')); QString fileBase; FileRecordInterface::RecordType recordType = FileRecordInterface::guessTypeFromFileName(fileRecordName, fileBase); diff --git a/sdrbase/dsp/filerecordinterface.cpp b/sdrbase/dsp/filerecordinterface.cpp index 64c8221d3..954b29d02 100644 --- a/sdrbase/dsp/filerecordinterface.cpp +++ b/sdrbase/dsp/filerecordinterface.cpp @@ -18,6 +18,7 @@ /////////////////////////////////////////////////////////////////////////////////// #include +#include #include "filerecordinterface.h" @@ -40,41 +41,32 @@ QString FileRecordInterface::genUniqueFileName(unsigned int deviceUID, int istre FileRecordInterface::RecordType FileRecordInterface::guessTypeFromFileName(const QString& fileName, QString& fileBase) { - QStringList dotBreakout = fileName.split(QLatin1Char('.')); + QFileInfo fileInfo(fileName); + QString extension = fileInfo.suffix(); - if (dotBreakout.length() > 1) + fileBase = fileName; + if (!extension.isEmpty()) { - QString extension = dotBreakout.last(); - dotBreakout.removeLast(); - + fileBase.chop(extension.size() + 1); if (extension == "sdriq") { - if (dotBreakout.length() > 1) { - dotBreakout.removeLast(); - } - - fileBase = dotBreakout.join(QLatin1Char('.')); return RecordTypeSdrIQ; } else if (extension == "sigmf-meta") { - fileBase = dotBreakout.join(QLatin1Char('.')); return RecordTypeSigMF; } else if (extension == "wav") { - fileBase = dotBreakout.join(QLatin1Char('.')); return RecordTypeWav; } else { - fileBase = fileName; return RecordTypeUndefined; } } else { - fileBase = fileName; return RecordTypeUndefined; } }