OSDN Git Service

Some code refactoring.
authorLoRd_MuldeR <mulder2@gmx.de>
Mon, 31 Aug 2015 20:53:19 +0000 (22:53 +0200)
committerLoRd_MuldeR <mulder2@gmx.de>
Mon, 31 Aug 2015 20:53:19 +0000 (22:53 +0200)
src/Config.h
src/Global_Tools.cpp
src/LockedFile.cpp
src/Thread_Initialization.cpp
src/Thread_Process.cpp

index 0951b48..f1cf440 100644 (file)
@@ -34,8 +34,8 @@
 #define VER_LAMEXP_MINOR_HI                                    1
 #define VER_LAMEXP_MINOR_LO                                    2
 #define VER_LAMEXP_TYPE                                                Beta
-#define VER_LAMEXP_PATCH                                       6
-#define VER_LAMEXP_BUILD                                       1801
+#define VER_LAMEXP_PATCH                                       7
+#define VER_LAMEXP_BUILD                                       1803
 #define VER_LAMEXP_CONFG                                       1700
 
 ///////////////////////////////////////////////////////////////////////////////
index 7a74dd3..a2caa9f 100644 (file)
@@ -74,6 +74,7 @@ static const quint32 g_max_uint32 = UINT32_MAX;
 static void lamexp_tools_clean_up(void)
 {
        QWriteLocker writeLock(&g_lamexp_tools_lock);
+       qWarning("------------ lamexp_tools_clean_up ------------");
 
        if(!g_lamexp_tools_data.isNull())
        {
index 0c45502..14d33b3 100644 (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)
@@ -263,6 +276,8 @@ LockedFile::LockedFile(const QString &filePath, const bool bOwnsFile)
 
 LockedFile::~LockedFile(void)
 {
+       qWarning("------------ LockedFile::~LockedFile ------------");
+
        if(m_fileDescriptor >= 0)
        {
                _close(m_fileDescriptor);
@@ -270,14 +285,7 @@ LockedFile::~LockedFile(void)
        }
        if(m_bOwnsFile)
        {
-               if(QFileInfo(m_filePath).exists())
-               {
-                       for(int i = 0; i < 64; i++)
-                       {
-                               if(QFile::remove(m_filePath)) break;
-                               MUtils::OS::sleep_ms(1);
-                       }
-               }
+               doRemoveFile(m_filePath);
        }
 }
 
index 3916244..1b64829 100644 (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)
        :
                m_appDir(appDir),
+               m_tempPath(MUtils::temp_folder()),
                m_toolName(toolName),
                m_toolHash(toolHash),
                m_toolVersion(toolVersion),
@@ -259,7 +260,7 @@ protected:
                if(lockedFile.isNull())
                {
                        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
@@ -267,14 +268,14 @@ protected:
        }
 
 private:
+       static volatile bool      s_bCustom;
        QScopedPointer<QResource> m_toolResource;
-       const QDir m_appDir;
-       const QString m_toolName;
-       const QByteArray m_toolHash;
-       const unsigned int m_toolVersion;
-       const QString m_toolTag;
-
-       static volatile bool s_bCustom;
+       const QDir                m_appDir;
+       const QString             m_tempPath;
+       const QString             m_toolName;
+       const QByteArray          m_toolHash;
+       const unsigned int        m_toolVersion;
+       const QString             m_toolTag;
 };
 
 volatile bool ExtractorTask::s_bCustom = false;
index 4e0267f..372375b 100644 (file)
@@ -525,30 +525,10 @@ QString ProcessThread::applyRegularExpression(const QString &fileName)
 
 QString ProcessThread::generateTempFileName(void)
 {
-       bool bOkay = false;
-       QString tempFileName;
-       
-       for(int i = 0; i < 4096; i++)
-       {
-               tempFileName = QString("%1/%2.wav").arg(m_tempDirectory, MUtils::rand_str());
-               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)
+       const QString tempFileName = MUtils::make_temp_file(m_tempDirectory, "wav", true);
+       if(tempFileName.isEmpty())
        {
-               qWarning("Failed to generate unique temp file name!");
-               return QString("%1/~whoops.wav").arg(m_tempDirectory);
+               return QString("%1/~whoops%2.wav").arg(m_tempDirectory, QString::number(MUtils::next_rand32()));
        }
 
        m_tempFiles << tempFileName;