Some code refactoring.

This commit is contained in:
LoRd_MuldeR 2015-08-31 22:53:19 +02:00
parent 3eb911fac9
commit e21ee2f7ae
5 changed files with 31 additions and 41 deletions

View File

@ -34,8 +34,8 @@
#define VER_LAMEXP_MINOR_HI 1 #define VER_LAMEXP_MINOR_HI 1
#define VER_LAMEXP_MINOR_LO 2 #define VER_LAMEXP_MINOR_LO 2
#define VER_LAMEXP_TYPE Beta #define VER_LAMEXP_TYPE Beta
#define VER_LAMEXP_PATCH 6 #define VER_LAMEXP_PATCH 7
#define VER_LAMEXP_BUILD 1801 #define VER_LAMEXP_BUILD 1803
#define VER_LAMEXP_CONFG 1700 #define VER_LAMEXP_CONFG 1700
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -74,6 +74,7 @@ static const quint32 g_max_uint32 = UINT32_MAX;
static void lamexp_tools_clean_up(void) static void lamexp_tools_clean_up(void)
{ {
QWriteLocker writeLock(&g_lamexp_tools_lock); QWriteLocker writeLock(&g_lamexp_tools_lock);
qWarning("------------ lamexp_tools_clean_up ------------");
if(!g_lamexp_tools_data.isNull()) if(!g_lamexp_tools_data.isNull())
{ {

View File

@ -192,6 +192,19 @@ static __forceinline void doValidateHash(HANDLE &fileHandle, const int &fileDesc
} }
} }
static __forceinline bool doRemoveFile(const QString &filePath)
{
for(int i = 0; i < 32; i++)
{
if(MUtils::remove_file(filePath))
{
return true;
}
MUtils::OS::sleep_ms(1);
}
return false;
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
LockedFile::LockedFile(QResource *const resource, const QString &outPath, const QByteArray &expectedHash, const bool bOwnsFile) LockedFile::LockedFile(QResource *const resource, const QString &outPath, const QByteArray &expectedHash, const bool bOwnsFile)
@ -263,6 +276,8 @@ LockedFile::LockedFile(const QString &filePath, const bool bOwnsFile)
LockedFile::~LockedFile(void) LockedFile::~LockedFile(void)
{ {
qWarning("------------ LockedFile::~LockedFile ------------");
if(m_fileDescriptor >= 0) if(m_fileDescriptor >= 0)
{ {
_close(m_fileDescriptor); _close(m_fileDescriptor);
@ -270,14 +285,7 @@ LockedFile::~LockedFile(void)
} }
if(m_bOwnsFile) if(m_bOwnsFile)
{ {
if(QFileInfo(m_filePath).exists()) doRemoveFile(m_filePath);
{
for(int i = 0; i < 64; i++)
{
if(QFile::remove(m_filePath)) break;
MUtils::OS::sleep_ms(1);
}
}
} }
} }

View File

@ -181,6 +181,7 @@ public:
ExtractorTask(QResource *const toolResource, const QDir &appDir, const QString &toolName, const QByteArray &toolHash, const unsigned int toolVersion, const QString &toolTag) ExtractorTask(QResource *const toolResource, const QDir &appDir, const QString &toolName, const QByteArray &toolHash, const unsigned int toolVersion, const QString &toolTag)
: :
m_appDir(appDir), m_appDir(appDir),
m_tempPath(MUtils::temp_folder()),
m_toolName(toolName), m_toolName(toolName),
m_toolHash(toolHash), m_toolHash(toolHash),
m_toolVersion(toolVersion), m_toolVersion(toolVersion),
@ -259,7 +260,7 @@ protected:
if(lockedFile.isNull()) if(lockedFile.isNull())
{ {
qDebug("Extracting file: %s -> %s", m_toolName.toLatin1().constData(), toolShrtName.toLatin1().constData()); qDebug("Extracting file: %s -> %s", m_toolName.toLatin1().constData(), toolShrtName.toLatin1().constData());
lockedFile.reset(new LockedFile(m_toolResource.data(), QString("%1/lxp_%2").arg(MUtils::temp_folder(), toolShrtName), m_toolHash)); lockedFile.reset(new LockedFile(m_toolResource.data(), QString("%1/lxp_%2").arg(m_tempPath, toolShrtName), m_toolHash));
} }
//Register tool //Register tool
@ -267,14 +268,14 @@ protected:
} }
private: private:
static volatile bool s_bCustom;
QScopedPointer<QResource> m_toolResource; QScopedPointer<QResource> m_toolResource;
const QDir m_appDir; const QDir m_appDir;
const QString m_tempPath;
const QString m_toolName; const QString m_toolName;
const QByteArray m_toolHash; const QByteArray m_toolHash;
const unsigned int m_toolVersion; const unsigned int m_toolVersion;
const QString m_toolTag; const QString m_toolTag;
static volatile bool s_bCustom;
}; };
volatile bool ExtractorTask::s_bCustom = false; volatile bool ExtractorTask::s_bCustom = false;

View File

@ -525,30 +525,10 @@ QString ProcessThread::applyRegularExpression(const QString &fileName)
QString ProcessThread::generateTempFileName(void) QString ProcessThread::generateTempFileName(void)
{ {
bool bOkay = false; const QString tempFileName = MUtils::make_temp_file(m_tempDirectory, "wav", true);
QString tempFileName; if(tempFileName.isEmpty())
for(int i = 0; i < 4096; i++)
{ {
tempFileName = QString("%1/%2.wav").arg(m_tempDirectory, MUtils::rand_str()); return QString("%1/~whoops%2.wav").arg(m_tempDirectory, QString::number(MUtils::next_rand32()));
if(m_tempFiles.contains(tempFileName, Qt::CaseInsensitive) || QFileInfo(tempFileName).exists())
{
continue;
}
QFile file(tempFileName);
if(file.open(QFile::ReadWrite))
{
file.close();
bOkay = true;
break;
}
}
if(!bOkay)
{
qWarning("Failed to generate unique temp file name!");
return QString("%1/~whoops.wav").arg(m_tempDirectory);
} }
m_tempFiles << tempFileName; m_tempFiles << tempFileName;