From 87bc566b26316d720f3c916d119bd53d2d89dd64 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Mon, 30 Oct 2017 23:01:56 +0100 Subject: [PATCH] Some code refactoring. --- src/Config.h | 2 +- src/Thread_FileAnalyzer_Task.cpp | 40 +++++++++++++++++--------------- src/Thread_FileAnalyzer_Task.h | 1 + 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/Config.h b/src/Config.h index 8989e663..b6733da3 100644 --- a/src/Config.h +++ b/src/Config.h @@ -35,7 +35,7 @@ #define VER_LAMEXP_MINOR_LO 6 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 7 -#define VER_LAMEXP_BUILD 2036 +#define VER_LAMEXP_BUILD 2037 #define VER_LAMEXP_CONFG 2002 /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Thread_FileAnalyzer_Task.cpp b/src/Thread_FileAnalyzer_Task.cpp index 05becab8..2eb82716 100644 --- a/src/Thread_FileAnalyzer_Task.cpp +++ b/src/Thread_FileAnalyzer_Task.cpp @@ -66,8 +66,8 @@ class AnalyzeTask_XmlHandler : public QXmlDefaultHandler { public: - AnalyzeTask_XmlHandler(AudioFileModel &audioFile) : - m_audioFile(audioFile), m_trackType(trackType_non), m_trackIdx(0), m_properties(initializeProperties()) {} + AnalyzeTask_XmlHandler(AudioFileModel &audioFile, const quint32 &version) : + m_audioFile(audioFile), m_version(version), m_trackType(trackType_non), m_trackIdx(0), m_properties(initializeProperties()) {} protected: virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts); @@ -96,18 +96,19 @@ private: } propertyId_t; + const quint32 m_version; const QMap, propertyId_t> &m_properties; QStack m_stack; AudioFileModel &m_audioFile; trackType_t m_trackType; quint32 m_trackIdx; - QPair m_currentProperty; + propertyId_t m_currentProperty; static QReadWriteLock s_propertiesMutex; static QScopedPointer, propertyId_t>> s_propertiesMap; - bool updatePropertry(const QPair &id, const QString &value); + bool updatePropertry(const propertyId_t &idx, const QString &value); static const QMap, propertyId_t> &initializeProperties(); static bool parseUnsigned(const QString &str, quint32 &value); @@ -123,6 +124,7 @@ AnalyzeTask::AnalyzeTask(const int taskId, const QString &inputFile, QAtomicInt m_taskId(taskId), m_inputFile(inputFile), m_mediaInfoBin(lamexp_tools_lookup("mediainfo.exe")), + m_mediaInfoVer(lamexp_tools_version("mediainfo.exe")), m_avs2wavBin(lamexp_tools_lookup("avs2wav.exe")), m_abortFlag(abortFlag) { @@ -357,7 +359,7 @@ const AudioFileModel& AnalyzeTask::parseMediaInfo(const QByteArray &data, AudioF QXmlInputSource xmlSource; xmlSource.setData(data); - QScopedPointer xmlHandler(new AnalyzeTask_XmlHandler(audioFile)); + QScopedPointer xmlHandler(new AnalyzeTask_XmlHandler(audioFile, m_mediaInfoVer)); QXmlSimpleReader xmlReader; xmlReader.setContentHandler(xmlHandler.data()); @@ -604,7 +606,6 @@ const QMap, AnalyzeTask_XmlH if (s_propertiesMap.isNull()) { - qWarning("!!! --- SETTING UP MAP --- !!!"); QMap, propertyId_t> *const builder = new QMap, propertyId_t>(); DEFINE_PROPTERY_MAPPING(gen, format); DEFINE_PROPTERY_MAPPING(gen, format_profile); @@ -631,6 +632,11 @@ bool AnalyzeTask_XmlHandler::startElement(const QString &namespaceURI, const QSt qWarning("Invalid XML structure was detected! (1)"); return false; } + if (!STR_EQ(atts.value("version"), QString().sprintf("0.%u.%02u", m_version / 100U, m_version % 100))) + { + qWarning("Invalid version property was detected!"); + return false; + } return true; case 2: if (!STR_EQ(qName, "file")) @@ -675,17 +681,17 @@ bool AnalyzeTask_XmlHandler::startElement(const QString &namespaceURI, const QSt switch (m_trackType) { case trackType_gen: - m_currentProperty = qMakePair(trackType_gen, qName.simplified().toLower()); + m_currentProperty = m_properties.value(qMakePair(trackType_gen, qName.simplified().toLower()), propertyId_t(-1)); return true; case trackType_aud: - m_currentProperty = qMakePair(trackType_aud, qName.simplified().toLower()); + m_currentProperty = m_properties.value(qMakePair(trackType_aud, qName.simplified().toLower()), propertyId_t(-1)); return true; default: - m_currentProperty = qMakePair(trackType_non, qName.simplified().toLower()); + m_currentProperty = propertyId_t(-1); return true; } default: - return false; + return true; } } @@ -697,24 +703,20 @@ bool AnalyzeTask_XmlHandler::endElement(const QString &namespaceURI, const QStri bool AnalyzeTask_XmlHandler::characters(const QString& ch) { - if ((m_stack.size() == 4) && m_currentProperty.first) + if ((m_currentProperty != propertyId_t(-1)) && (m_stack.size() == 4)) { const QString value = ch.simplified(); if (!value.isEmpty()) { - qDebug("Property: %u::%s --> \"%s\"", m_currentProperty.first, MUTILS_UTF8(m_currentProperty.second), MUTILS_UTF8(value)); - if (!updatePropertry(m_currentProperty, value)) - { - qWarning("Ignored property: %u::%s!", m_currentProperty.first, MUTILS_UTF8(m_currentProperty.second)); - } + updatePropertry(m_currentProperty, value); } } return true; } -bool AnalyzeTask_XmlHandler::updatePropertry(const QPair &id, const QString &value) +bool AnalyzeTask_XmlHandler::updatePropertry(const propertyId_t &idx, const QString &value) { - switch (m_properties.value(id, propertyId_t(-1))) + switch (idx) { case propertyId_gen_format: m_audioFile.techInfo().setContainerType(value); return true; case propertyId_gen_format_profile: m_audioFile.techInfo().setContainerProfile(value); return true; @@ -724,7 +726,7 @@ bool AnalyzeTask_XmlHandler::updatePropertry(const QPair & case propertyId_aud_format_profile: m_audioFile.techInfo().setAudioProfile(value); return true; case propertyId_aud_channel_s_: SET_OPTIONAL(quint32, parseUnsigned(value, _tmp), m_audioFile.techInfo().setAudioChannels(_tmp)); return true; case propertyId_aud_samplingrate: SET_OPTIONAL(quint32, parseUnsigned(value, _tmp), m_audioFile.techInfo().setAudioSamplerate(_tmp)); return true; - default: return false; + default: MUTILS_THROW_FMT("Invalid property ID: %d", idx); } } diff --git a/src/Thread_FileAnalyzer_Task.h b/src/Thread_FileAnalyzer_Task.h index 7409dfa6..24150191 100644 --- a/src/Thread_FileAnalyzer_Task.h +++ b/src/Thread_FileAnalyzer_Task.h @@ -78,6 +78,7 @@ private: const unsigned int m_taskId; const QString m_mediaInfoBin; + const quint32 m_mediaInfoVer; const QString m_avs2wavBin; const QString m_inputFile;