Make it possible to re-use an existing MediaInfo binary from the "cache" sub-folder.
This commit is contained in:
parent
e6b47c5262
commit
bca17c6474
@ -103,12 +103,15 @@ static int mixp_main(int &argc, char **argv)
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString baseFolder = QDir(QCoreApplication::applicationDirPath()).canonicalPath();
|
||||||
|
qDebug("Base directory is:\n%s\n", MUTILS_UTF8(QDir::toNativeSeparators(baseFolder)));
|
||||||
|
|
||||||
//Get temp folder
|
//Get temp folder
|
||||||
const QString tempFolder = MUtils::temp_folder();
|
const QString tempFolder = MUtils::temp_folder();
|
||||||
qDebug("TEMP folder is:\n%s\n", QDir::toNativeSeparators(tempFolder).toUtf8().constData());
|
qDebug("Temp directory is:\n%s\n", MUTILS_UTF8(QDir::toNativeSeparators(tempFolder)));
|
||||||
|
|
||||||
//Create main window
|
//Create main window
|
||||||
QScopedPointer<CMainWindow> mainWindow(new CMainWindow(tempFolder, ipcChannel.data()));
|
QScopedPointer<CMainWindow> mainWindow(new CMainWindow(baseFolder, tempFolder, ipcChannel.data()));
|
||||||
mainWindow->show();
|
mainWindow->show();
|
||||||
|
|
||||||
//Run application
|
//Run application
|
||||||
|
@ -97,9 +97,10 @@ static const int FILE_RECEIVE_DELAY = 1750;
|
|||||||
// Constructor
|
// Constructor
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
CMainWindow::CMainWindow(const QString &tempFolder, MUtils::IPCChannel *const ipc, QWidget *parent)
|
CMainWindow::CMainWindow(const QString &baseFolder, const QString &tempFolder, MUtils::IPCChannel *const ipc, QWidget *parent)
|
||||||
:
|
:
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
|
m_baseFolder(baseFolder),
|
||||||
m_tempFolder(tempFolder),
|
m_tempFolder(tempFolder),
|
||||||
m_ipcThread(new IPCReceiveThread(ipc)),
|
m_ipcThread(new IPCReceiveThread(ipc)),
|
||||||
m_status(APP_STATUS_STARTING),
|
m_status(APP_STATUS_STARTING),
|
||||||
@ -767,6 +768,7 @@ static bool VALIDATE_MEDIAINFO(QFile *const handle, const char *const expected_c
|
|||||||
{
|
{
|
||||||
if(!handle->reset())
|
if(!handle->reset())
|
||||||
{
|
{
|
||||||
|
qWarning("Failed to rewind file to be checked!\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -834,9 +836,10 @@ QString CMainWindow::getMediaInfoPath(void)
|
|||||||
{
|
{
|
||||||
//Detect MediaInfo arch
|
//Detect MediaInfo arch
|
||||||
const QPair<QString, const char*> arch = getMediaInfoArch();
|
const QPair<QString, const char*> arch = getMediaInfoArch();
|
||||||
|
const QString fileName(QString("MediaInfo.%1.exe").arg(arch.first));
|
||||||
|
|
||||||
//Setup resource
|
//Setup resource
|
||||||
const QResource mediaInfoRes(QString(":/res/bin/MediaInfo.%1.exe").arg(arch.first));
|
const QResource mediaInfoRes(QString(":/res/bin/%1").arg(fileName));
|
||||||
if((!mediaInfoRes.isValid()) || (!mediaInfoRes.data()))
|
if((!mediaInfoRes.isValid()) || (!mediaInfoRes.data()))
|
||||||
{
|
{
|
||||||
qFatal("MediaInfo resource could not be initialized!");
|
qFatal("MediaInfo resource could not be initialized!");
|
||||||
@ -850,53 +853,79 @@ QString CMainWindow::getMediaInfoPath(void)
|
|||||||
{
|
{
|
||||||
return m_mediaInfoHandle->fileName();
|
return m_mediaInfoHandle->fileName();
|
||||||
}
|
}
|
||||||
m_mediaInfoHandle->remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Extract MediaInfo binary now!
|
|
||||||
qDebug("MediaInfo binary not existing yet, going to extract now...\n");
|
|
||||||
const QString filePath = MUtils::make_unique_file(m_tempFolder, "MediaInfo", arch.first + QLatin1String(".exe"));
|
|
||||||
if (!filePath.isEmpty())
|
|
||||||
{
|
|
||||||
m_mediaInfoHandle.reset(new QFile(filePath));
|
|
||||||
if (m_mediaInfoHandle->open(QIODevice::ReadWrite | QIODevice::Truncate))
|
|
||||||
{
|
|
||||||
if (m_mediaInfoHandle->write(reinterpret_cast<const char*>(mediaInfoRes.data()), mediaInfoRes.size()) == mediaInfoRes.size())
|
|
||||||
{
|
|
||||||
qDebug("MediaInfo path is:\n%s\n", m_mediaInfoHandle->fileName().toUtf8().constData());
|
|
||||||
m_mediaInfoHandle->close();
|
m_mediaInfoHandle->close();
|
||||||
if (!m_mediaInfoHandle->open(QIODevice::ReadOnly))
|
m_mediaInfoHandle.reset();
|
||||||
{
|
|
||||||
qWarning("Failed to open MediaInfo binary for reading!\n");
|
|
||||||
m_mediaInfoHandle->remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qWarning("Failed to write data to MediaInfo binary file!\n");
|
|
||||||
m_mediaInfoHandle->remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qWarning("Failed to open MediaInfo binary for writing!\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qWarning("Failed to gemerate MediaInfo outout path!\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Validate file content, after it has been extracted
|
//Try to re-use file from cache first
|
||||||
if(!m_mediaInfoHandle.isNull())
|
const QFileInfo cachedFile(QString("%1/cache/%2").arg(m_baseFolder, fileName));
|
||||||
|
if (cachedFile.exists() && cachedFile.isFile())
|
||||||
|
{
|
||||||
|
qDebug("MediaInfo binary exists in cache, re-using existing binary...\n");
|
||||||
|
m_mediaInfoHandle.reset(new QFile(cachedFile.absoluteFilePath()));
|
||||||
|
qDebug("MediaInfo path is:\n%s\n", m_mediaInfoHandle->fileName().toUtf8().constData());
|
||||||
|
if (m_mediaInfoHandle->open(QIODevice::ReadOnly))
|
||||||
{
|
{
|
||||||
if (VALIDATE_MEDIAINFO(m_mediaInfoHandle.data(), arch.second))
|
if (VALIDATE_MEDIAINFO(m_mediaInfoHandle.data(), arch.second))
|
||||||
{
|
{
|
||||||
return m_mediaInfoHandle->fileName();
|
return m_mediaInfoHandle->fileName();
|
||||||
}
|
}
|
||||||
m_mediaInfoHandle->remove();
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qWarning("Failed to open MediaInfo binary for reading!\n");
|
||||||
|
}
|
||||||
|
m_mediaInfoHandle->close();
|
||||||
|
m_mediaInfoHandle.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Generate temporary file name
|
||||||
|
qDebug("MediaInfo binary not existing yet, going to extract now...\n");
|
||||||
|
const QString filePath = MUtils::make_unique_file(m_tempFolder, "MediaInfo", arch.first + QLatin1String(".exe"));
|
||||||
|
if (filePath.isEmpty())
|
||||||
|
{
|
||||||
|
qWarning("Failed to gemerate MediaInfo outout path!\n");
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Extract the MediaInfo binary now!
|
||||||
|
m_mediaInfoHandle.reset(new QFile(filePath));
|
||||||
|
if (m_mediaInfoHandle->open(QIODevice::ReadWrite | QIODevice::Truncate))
|
||||||
|
{
|
||||||
|
qDebug("MediaInfo path is:\n%s\n", MUTILS_UTF8(m_mediaInfoHandle->fileName()));
|
||||||
|
const qint64 bytesWritten = m_mediaInfoHandle->write(reinterpret_cast<const char*>(mediaInfoRes.data()), mediaInfoRes.size());
|
||||||
|
m_mediaInfoHandle->close();
|
||||||
|
if (bytesWritten != mediaInfoRes.size())
|
||||||
|
{
|
||||||
|
qWarning("Failed to write data to MediaInfo binary file!\n");
|
||||||
|
m_mediaInfoHandle->remove();
|
||||||
|
m_mediaInfoHandle.reset();
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qWarning("Failed to open MediaInfo binary for writing!\n");
|
||||||
|
m_mediaInfoHandle.reset();
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Validate file's content, after it has been extracted
|
||||||
|
if (m_mediaInfoHandle->open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
if (VALIDATE_MEDIAINFO(m_mediaInfoHandle.data(), arch.second))
|
||||||
|
{
|
||||||
|
return m_mediaInfoHandle->fileName();
|
||||||
|
}
|
||||||
|
m_mediaInfoHandle->close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qWarning("Failed to open MediaInfo binary for reading!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
m_mediaInfoHandle->remove();
|
||||||
|
m_mediaInfoHandle.reset();
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class CMainWindow: public QMainWindow
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CMainWindow(const QString &tempFolder, MUtils::IPCChannel *const ipc, QWidget *parent = 0);
|
CMainWindow(const QString &baseFolder, const QString &tempFolder, MUtils::IPCChannel *const ipc, QWidget *parent = 0);
|
||||||
~CMainWindow(void);
|
~CMainWindow(void);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@ -88,6 +88,7 @@ private:
|
|||||||
Ui::MainWindow *ui; //for Qt UIC
|
Ui::MainWindow *ui; //for Qt UIC
|
||||||
|
|
||||||
int m_status;
|
int m_status;
|
||||||
|
const QString &m_baseFolder;
|
||||||
const QString &m_tempFolder;
|
const QString &m_tempFolder;
|
||||||
|
|
||||||
QScopedPointer<IPCReceiveThread> m_ipcThread;
|
QScopedPointer<IPCReceiveThread> m_ipcThread;
|
||||||
|
Loading…
Reference in New Issue
Block a user