Improved file extraction method. Will also compute and validate SHA-1 checksum now.

This commit is contained in:
LoRd_MuldeR 2014-11-16 17:36:13 +01:00
parent d79905c330
commit a34eada150
2 changed files with 67 additions and 47 deletions

View File

@ -21,12 +21,15 @@
//Version
static unsigned int mixp_versionMajor = 2;
static unsigned int mixp_versionMinor = 12;
static unsigned int mixp_versionMinor = 13;
//MediaInfo Version
static unsigned int mixp_miVersionMajor = 0;
static unsigned int mixp_miVersionMinor = 7;
static unsigned int mixp_miVersionPatch = 70;
static unsigned int mixp_miVersionPatch = 71;
//MediaInfo Checksum
static const char *mixp_checksum = "aee8cf5f0037bc1d02d148f0c780c9c9f61ac6db";
//Build date
static const char *mixp_buildDate = __DATE__;

View File

@ -35,6 +35,7 @@
#include <QScrollBar>
#include <QDesktopServices>
#include <QClipboard>
#include <QCryptographicHash>
//CRT
#include <ctime>
@ -141,7 +142,7 @@ CMainWindow::CMainWindow(const QString &tempFolder, IPC *const ipc, QWidget *par
CMainWindow::~CMainWindow(void)
{
if(m_mediaInfoHandle != NULL)
if(m_mediaInfoHandle)
{
m_mediaInfoHandle->remove();
MIXP_DELETE_OBJ(m_mediaInfoHandle);
@ -373,7 +374,7 @@ void CMainWindow::analyzeNextFile(void)
if(mediaInfoPath.isEmpty())
{
ui->textBrowser->setHtml(QString("<pre>%1</pre>").arg(tr("Oups, failed to extract MediaInfo binary!")));
QMessageBox::critical(this, tr("Failure"), tr("Error: Failed to extract MediaInfo binary!"), QMessageBox::Ok);
QMessageBox::critical(this, tr("Failure"), tr("Fatal Error: Failed to extract the MediaInfo binary!"), QMessageBox::Ok);
m_floatingLabel->hide();
ui->actionOpen->setEnabled(true);
ui->analyzeButton->setEnabled(true);
@ -636,7 +637,7 @@ void CMainWindow::showAboutScreen(void)
text += QString().sprintf("Note that this program is distributed with ABSOLUTELY NO WARRANTY.<br><br>");
text += QString().sprintf("Please check the web-site at <a href=\"%s\">%s</a> for updates !!!<br>", LINK_MULDER, LINK_MULDER);
text += QString().sprintf("<hr><br>");
text += QString().sprintf("This application is powered by MediaInfo v%u.%u.%02u<br>", mixp_miVersionMajor, mixp_miVersionMinor, mixp_miVersionPatch);
text += QString().sprintf("<b>This application is powered by MediaInfo v%u.%u.%02u</b><br>", mixp_miVersionMajor, mixp_miVersionMinor, mixp_miVersionPatch);
text += QString().sprintf("Free and OpenSource tool for displaying technical information about media files.<br>");
text += QString().sprintf("Copyright (c) 2002-%04d MediaArea.net SARL. All rights reserved.<br><br>", qMax(buildDate.year(),curntDate.year()));
text += QString().sprintf("Redistribution and use is permitted according to the (2-Clause) BSD License.<br>");
@ -718,37 +719,47 @@ void CMainWindow::fileReceived(const QString &str)
// PRIVATE FUNCTIONS
////////////////////////////////////////////////////////////
#define VALIDATE_MEDIAINFO(HANDLE) do \
{ \
if((HANDLE)) \
{ \
(HANDLE)->seek(0); \
QByteArray buffer = (HANDLE)->readAll(); \
if((buffer.size() != mediaInfoRes.size()) || (memcmp(buffer.constData(), mediaInfoRes.data(), mediaInfoRes.size()) != 0)) \
{ \
qWarning("MediaInfo binary failed to validate!"); \
(HANDLE)->remove(); \
MIXP_DELETE_OBJ((HANDLE)); \
} \
} \
} \
while(0)
static bool VALIDATE_MEDIAINFO(QFile *const handle)
{
if(!handle->reset())
{
return false;
}
const QByteArray checksum = QCryptographicHash::hash(handle->readAll(), QCryptographicHash::Sha1);
if(qstricmp(checksum.toHex().constData(), mixp_checksum) != 0)
{
qWarning("MediaInfo binary is corrupted!");
qWarning("Expected checksum: %s", mixp_checksum);
qWarning("Computed checksum: %s\n", checksum.toHex().constData());
return false;
}
qDebug("MediaInfo checksum: %s\n", checksum.toHex().constData());
return true;
}
QString CMainWindow::getMediaInfoPath(void)
{
QResource mediaInfoRes(":/res/MediaInfo.i386.exe");
QResource mediaInfoRes(":/res/MediaInfo.i686.exe");
if((!mediaInfoRes.isValid()) || (!mediaInfoRes.data()))
{
qFatal("MediaInfo resource could not be initialized!");
return QString();
}
//Validate file content
VALIDATE_MEDIAINFO(m_mediaInfoHandle);
//Extract MediaInfo
if(!m_mediaInfoHandle)
//Validate file content, if already extracted
if(m_mediaInfoHandle)
{
if(VALIDATE_MEDIAINFO(m_mediaInfoHandle))
{
return m_mediaInfoHandle->fileName();
}
m_mediaInfoHandle->remove();
MIXP_DELETE_OBJ(m_mediaInfoHandle);
}
//Extract MediaInfo binary now!
qDebug("MediaInfo binary not existing yet, going to extract now...\n");
m_mediaInfoHandle = new QFile(QString("%1/MediaInfo_%2.exe").arg(m_tempFolder, QString().sprintf("%04x", qrand() % 0xFFFF)));
if(m_mediaInfoHandle->open(QIODevice::ReadWrite | QIODevice::Truncate))
@ -776,13 +787,19 @@ QString CMainWindow::getMediaInfoPath(void)
qWarning("Failed to open MediaInfo binary for writing!\n");
MIXP_DELETE_OBJ(m_mediaInfoHandle);
}
//Validate file content, after it has been extracted
if(m_mediaInfoHandle)
{
if(VALIDATE_MEDIAINFO(m_mediaInfoHandle))
{
return m_mediaInfoHandle->fileName();
}
m_mediaInfoHandle->remove();
MIXP_DELETE_OBJ(m_mediaInfoHandle);
}
//Validate file content
VALIDATE_MEDIAINFO(m_mediaInfoHandle);
//Return current MediaInfo path
return m_mediaInfoHandle ? m_mediaInfoHandle->fileName() : QString();
return QString();
}
void CMainWindow::escapeHtmlChars(QStringList &strings)