2013-11-03 23:43:21 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2015-01-01 18:06:21 +01:00
|
|
|
// Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
|
2013-11-03 23:43:21 +01:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version, but always including the *additional*
|
|
|
|
// restrictions defined in the "License.txt" file.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/gpl-2.0.txt
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "Global.h"
|
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
//LameXP includes
|
|
|
|
#include "LockedFile.h"
|
|
|
|
|
2013-11-03 23:43:21 +01:00
|
|
|
//Qt includes
|
|
|
|
#include <QApplication>
|
2014-12-20 23:44:43 +01:00
|
|
|
#include <QHash>
|
2013-11-03 23:43:21 +01:00
|
|
|
#include <QReadWriteLock>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QFileInfo>
|
2014-12-20 23:44:43 +01:00
|
|
|
#include <QPair>
|
2013-11-03 23:43:21 +01:00
|
|
|
|
2014-11-25 02:14:42 +01:00
|
|
|
//MUtils
|
|
|
|
#include <MUtils/Global.h>
|
2014-11-30 21:32:23 +01:00
|
|
|
#include <MUtils/Exception.h>
|
2013-11-03 23:43:21 +01:00
|
|
|
|
2014-12-20 23:44:43 +01:00
|
|
|
//CRT
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2013-11-03 23:43:21 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// GLOBAL VARS
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-12-20 23:44:43 +01:00
|
|
|
//Typedef
|
|
|
|
typedef QPair<quint32,QString> tool_info_t;
|
|
|
|
typedef QPair<LockedFile*, tool_info_t> tool_data_t;
|
|
|
|
typedef QHash<QString, tool_data_t> tool_hash_t;
|
2013-11-03 23:43:21 +01:00
|
|
|
|
2014-12-20 23:44:43 +01:00
|
|
|
//Tool registry
|
|
|
|
static QScopedPointer<tool_hash_t> g_lamexp_tools_data;
|
|
|
|
static QReadWriteLock g_lamexp_tools_lock;
|
2013-11-03 23:43:21 +01:00
|
|
|
|
2014-12-19 23:49:11 +01:00
|
|
|
//Null String
|
2014-12-20 23:44:43 +01:00
|
|
|
static const QString g_null_string;
|
|
|
|
|
|
|
|
//UINT_MAX
|
|
|
|
static const quint32 g_max_uint32 = UINT32_MAX;
|
|
|
|
|
|
|
|
//Helper Macro
|
|
|
|
#define MAKE_ENTRY(LOCK_FILE,VER,TAG) \
|
|
|
|
qMakePair((LOCK_FILE),qMakePair((VER),(TAG)))
|
2014-12-19 23:49:11 +01:00
|
|
|
|
2013-11-03 23:43:21 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// GLOBAL FUNCTIONS
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/*
|
2014-12-20 23:44:43 +01:00
|
|
|
* Clean-up *all* registered tools
|
2013-11-03 23:43:21 +01:00
|
|
|
*/
|
2014-12-20 23:44:43 +01:00
|
|
|
static void lamexp_tools_clean_up(void)
|
2013-11-03 23:43:21 +01:00
|
|
|
{
|
2014-12-20 23:44:43 +01:00
|
|
|
QWriteLocker writeLock(&g_lamexp_tools_lock);
|
2013-11-03 23:43:21 +01:00
|
|
|
|
2014-12-20 23:44:43 +01:00
|
|
|
if(!g_lamexp_tools_data.isNull())
|
2013-11-03 23:43:21 +01:00
|
|
|
{
|
2014-12-20 23:44:43 +01:00
|
|
|
const QStringList keys = g_lamexp_tools_data->keys();
|
|
|
|
for(QStringList::ConstIterator iter = keys.constBegin(); iter != keys.constEnd(); iter++)
|
2013-11-03 23:43:21 +01:00
|
|
|
{
|
2014-12-20 23:44:43 +01:00
|
|
|
tool_data_t currentTool = (*g_lamexp_tools_data)[*iter];
|
|
|
|
MUTILS_DELETE(currentTool.first);
|
2013-11-03 23:43:21 +01:00
|
|
|
}
|
2014-12-20 23:44:43 +01:00
|
|
|
g_lamexp_tools_data->clear();
|
2013-11-03 23:43:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-12-20 23:44:43 +01:00
|
|
|
* Register tool
|
2013-11-03 23:43:21 +01:00
|
|
|
*/
|
2014-12-20 23:44:43 +01:00
|
|
|
void lamexp_tools_register(const QString &toolName, LockedFile *const file, const quint32 &version, const QString &tag)
|
2013-11-03 23:43:21 +01:00
|
|
|
{
|
2014-12-20 23:44:43 +01:00
|
|
|
QWriteLocker writeLock(&g_lamexp_tools_lock);
|
2013-11-03 23:43:21 +01:00
|
|
|
|
2015-08-30 13:47:08 +02:00
|
|
|
if(!file)
|
|
|
|
{
|
|
|
|
MUTILS_THROW("lamexp_register_tool: Tool file must not be NULL!");
|
|
|
|
}
|
|
|
|
|
2014-12-20 23:44:43 +01:00
|
|
|
if(g_lamexp_tools_data.isNull())
|
2013-11-03 23:43:21 +01:00
|
|
|
{
|
2014-12-20 23:44:43 +01:00
|
|
|
g_lamexp_tools_data.reset(new tool_hash_t());
|
|
|
|
atexit(lamexp_tools_clean_up);
|
2013-11-03 23:43:21 +01:00
|
|
|
}
|
|
|
|
|
2014-12-20 23:44:43 +01:00
|
|
|
const QString key = toolName.simplified().toLower();
|
|
|
|
if(g_lamexp_tools_data->contains(key))
|
2013-11-03 23:43:21 +01:00
|
|
|
{
|
2014-12-20 23:44:43 +01:00
|
|
|
MUTILS_THROW("lamexp_register_tool: Tool is already registered!");
|
2013-11-03 23:43:21 +01:00
|
|
|
}
|
|
|
|
|
2014-12-20 23:44:43 +01:00
|
|
|
g_lamexp_tools_data->insert(key, MAKE_ENTRY(file, version, tag));
|
2013-11-03 23:43:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-12-20 23:44:43 +01:00
|
|
|
* Check for tool
|
2013-11-03 23:43:21 +01:00
|
|
|
*/
|
2014-12-20 23:44:43 +01:00
|
|
|
bool lamexp_tools_check(const QString &toolName)
|
2013-11-03 23:43:21 +01:00
|
|
|
{
|
2014-12-20 23:44:43 +01:00
|
|
|
QReadLocker readLock(&g_lamexp_tools_lock);
|
2013-11-03 23:43:21 +01:00
|
|
|
|
2014-12-20 23:44:43 +01:00
|
|
|
if(!g_lamexp_tools_data.isNull())
|
2013-11-03 23:43:21 +01:00
|
|
|
{
|
2014-12-20 23:44:43 +01:00
|
|
|
const QString key = toolName.simplified().toLower();
|
|
|
|
return g_lamexp_tools_data->contains(key);
|
2013-11-03 23:43:21 +01:00
|
|
|
}
|
|
|
|
|
2014-12-20 23:44:43 +01:00
|
|
|
return false;
|
2013-11-03 23:43:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-12-20 23:44:43 +01:00
|
|
|
* Lookup tool path
|
2013-11-03 23:43:21 +01:00
|
|
|
*/
|
2015-11-22 17:36:54 +01:00
|
|
|
const QString lamexp_tools_lookup(const QString &toolName)
|
2013-11-03 23:43:21 +01:00
|
|
|
{
|
2014-12-20 23:44:43 +01:00
|
|
|
QReadLocker readLock(&g_lamexp_tools_lock);
|
2013-11-03 23:43:21 +01:00
|
|
|
|
2014-12-20 23:44:43 +01:00
|
|
|
if(!g_lamexp_tools_data.isNull())
|
2013-11-03 23:43:21 +01:00
|
|
|
{
|
2014-12-20 23:44:43 +01:00
|
|
|
const QString key = toolName.simplified().toLower();
|
|
|
|
if(g_lamexp_tools_data->contains(key))
|
2013-11-03 23:43:21 +01:00
|
|
|
{
|
2014-12-20 23:44:43 +01:00
|
|
|
return (*g_lamexp_tools_data)[key].first->filePath();
|
2013-11-03 23:43:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-20 23:44:43 +01:00
|
|
|
return g_null_string;
|
2013-11-03 23:43:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-12-20 23:44:43 +01:00
|
|
|
* Lookup tool version
|
2013-11-03 23:43:21 +01:00
|
|
|
*/
|
2014-12-20 23:44:43 +01:00
|
|
|
const quint32 &lamexp_tools_version(const QString &toolName, QString *const tagOut)
|
2013-11-03 23:43:21 +01:00
|
|
|
{
|
2014-12-20 23:44:43 +01:00
|
|
|
QReadLocker readLock(&g_lamexp_tools_lock);
|
2013-11-03 23:43:21 +01:00
|
|
|
|
2014-12-20 23:44:43 +01:00
|
|
|
if(!g_lamexp_tools_data.isNull())
|
2013-11-03 23:43:21 +01:00
|
|
|
{
|
2014-12-20 23:44:43 +01:00
|
|
|
const QString key = toolName.simplified().toLower();
|
|
|
|
if(g_lamexp_tools_data->contains(key))
|
2013-11-03 23:43:21 +01:00
|
|
|
{
|
2014-12-20 23:44:43 +01:00
|
|
|
const tool_info_t &info = (*g_lamexp_tools_data)[key].second;
|
|
|
|
if(tagOut)
|
|
|
|
{
|
|
|
|
*tagOut = info.second;
|
|
|
|
}
|
|
|
|
return info.first;
|
2013-11-03 23:43:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-20 23:44:43 +01:00
|
|
|
if(tagOut)
|
2013-11-26 23:00:33 +01:00
|
|
|
{
|
2014-12-20 23:44:43 +01:00
|
|
|
tagOut->clear();
|
2013-11-26 23:00:33 +01:00
|
|
|
}
|
2014-12-20 23:44:43 +01:00
|
|
|
return g_max_uint32;
|
2013-11-03 23:43:21 +01:00
|
|
|
}
|