diff --git a/include/MUtils/CPUFeatures.h b/include/MUtils/CPUFeatures.h index ac70201..d1b02c4 100644 --- a/include/MUtils/CPUFeatures.h +++ b/include/MUtils/CPUFeatures.h @@ -55,6 +55,6 @@ namespace MUtils } cpu_info_t; - MUTILS_API cpu_info_t detect(const QStringList &argv); + MUTILS_API cpu_info_t detect(void); } } diff --git a/include/MUtils/OSSupport.h b/include/MUtils/OSSupport.h index d54e6bc..59f5cf8 100644 --- a/include/MUtils/OSSupport.h +++ b/include/MUtils/OSSupport.h @@ -26,6 +26,7 @@ //Qt #include +#include #include /////////////////////////////////////////////////////////////////////////////// @@ -100,7 +101,8 @@ namespace MUtils MUTILS_API void system_message_err(const wchar_t *const title, const wchar_t *const text); //CLI Arguments - MUTILS_API const QStringList &arguments(void); + typedef QMap ArgumentMap; + MUTILS_API const ArgumentMap &arguments(void); //Copy file MUTILS_API bool copy_file(const QString &sourcePath, const QString &outputPath, const bool &overwrite = true); diff --git a/src/CPUFeatures_Win32.cpp b/src/CPUFeatures_Win32.cpp index fe45cdb..7658eb1 100644 --- a/src/CPUFeatures_Win32.cpp +++ b/src/CPUFeatures_Win32.cpp @@ -25,12 +25,14 @@ //MUtils #include +#include //Qt #include -MUtils::CPUFetaures::cpu_info_t MUtils::CPUFetaures::detect(const QStringList &argv) +MUtils::CPUFetaures::cpu_info_t MUtils::CPUFetaures::detect(void) { + const OS::ArgumentMap &args = OS::arguments(); typedef BOOL (WINAPI *IsWow64ProcessFun)(__in HANDLE hProcess, __out PBOOL Wow64Process); cpu_info_t features; @@ -119,16 +121,14 @@ MUtils::CPUFetaures::cpu_info_t MUtils::CPUFetaures::detect(const QStringList &a features.count = qBound(1UL, systemInfo.dwNumberOfProcessors, 64UL); } - if(argv.count() > 0) + bool flag = false; + if(args.contains("force-cpu-no-64bit")) { flag = true; features.x64 = false; } + if(args.contains("force-cpu-no-sse" )) { flag = true; features.features &= (~(FLAG_SSE | FLAG_SSE2 | FLAG_SSE3 | FLAG_SSSE3 | FLAG_SSE4 | FLAG_SSE42)); } + if(args.contains("force-cpu-no-intel")) { flag = true; features.intel = false; } + + if(flag) { - bool flag = false; - for(int i = 0; i < argv.count(); i++) - { - if(!argv[i].compare("--force-cpu-no-64bit", Qt::CaseInsensitive)) { flag = true; features.x64 = false; } - if(!argv[i].compare("--force-cpu-no-sse", Qt::CaseInsensitive)) { flag = true; features.features &= (~(FLAG_SSE | FLAG_SSE2 | FLAG_SSE3 | FLAG_SSSE3 | FLAG_SSE4 | FLAG_SSE42)); } - if(!argv[i].compare("--force-cpu-no-intel", Qt::CaseInsensitive)) { flag = true; features.intel = false; } - } - if(flag) qWarning("CPU flags overwritten by user-defined parameters. Take care!\n"); + qWarning("CPU flags overwritten by user-defined parameters. Take care!\n"); } return features; diff --git a/src/DirLocker.h b/src/DirLocker.h index c45f79b..c1ce608 100644 --- a/src/DirLocker.h +++ b/src/DirLocker.h @@ -69,8 +69,11 @@ namespace MUtils { if(m_lockFile->write(testData) >= testData.size()) { - okay = true; - break; + if(m_lockFile->error() == QFile::NoError) + { + okay = true; + break; + } } m_lockFile->remove(); } @@ -88,26 +91,17 @@ namespace MUtils { for(int i = 0; i < 16; i++) { - if(m_lockFile->remove()) + if(m_lockFile->remove() || (!m_lockFile->exists())) { + okay = true; break; } OS::sleep_ms(125); } - m_lockFile.reset(NULL); - } - for(int i = 0; i < 16; i++) - { - if(MUtils::remove_directory(m_dirPath, true)) - { - okay = true; - break; - } - OS::sleep_ms(125); } if(!okay) { - OS::system_message_wrn(L"Directory Lock", L"Warning: Not all temporary files could be removed!"); + qWarning("DirLock: The lock file could not be removed!"); } } diff --git a/src/Global.cpp b/src/Global.cpp index 17db27c..613482b 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -152,6 +152,24 @@ static MUtils::Internal::DirLock *try_init_temp_folder(const QString &baseDir) return NULL; } +static void temp_folder_cleanup_helper(const QString &tempPath) +{ + bool okay = false; + for(int i = 0; i < 32; i++) + { + if(MUtils::remove_directory(tempPath, true)) + { + okay = true; + break; + } + MUtils::OS::sleep_ms(125); + } + if(!okay) + { + MUtils::OS::system_message_wrn(L"Temp Cleaner", L"Warning: Not all temporary files could be removed!"); + } +} + static void temp_folder_cleaup(void) { QWriteLocker writeLock(&g_temp_folder_lock); @@ -159,7 +177,9 @@ static void temp_folder_cleaup(void) //Clean the directory while(!g_temp_folder_file.isNull()) { + const QString tempPath = g_temp_folder_file->getPath(); g_temp_folder_file.reset(NULL); + temp_folder_cleanup_helper(tempPath); } } diff --git a/src/OSSupport_Win32.cpp b/src/OSSupport_Win32.cpp index 0e9062c..4f91dff 100644 --- a/src/OSSupport_Win32.cpp +++ b/src/OSSupport_Win32.cpp @@ -71,10 +71,10 @@ void MUtils::OS::system_message_err(const wchar_t *const title, const wchar_t *c // FETCH CLI ARGUMENTS /////////////////////////////////////////////////////////////////////////////// -static QReadWriteLock g_arguments_lock; -static QScopedPointer g_arguments_list; +static QReadWriteLock g_arguments_lock; +static QScopedPointer g_arguments_list; -const QStringList &MUtils::OS::arguments(void) +const MUtils::OS::ArgumentMap &MUtils::OS::arguments(void) { QReadLocker readLock(&g_arguments_lock); @@ -93,15 +93,35 @@ const QStringList &MUtils::OS::arguments(void) return (*(g_arguments_list.data())); } - g_arguments_list.reset(new QStringList); + g_arguments_list.reset(new ArgumentMap()); int nArgs = 0; LPWSTR *szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); if(NULL != szArglist) { + const QChar separator = QLatin1Char('='); + const QString argPrefix = QLatin1String("--"); for(int i = 0; i < nArgs; i++) { - *(g_arguments_list.data()) << MUTILS_QSTR(szArglist[i]); + const QString argStr = MUTILS_QSTR(szArglist[i]).trimmed(); + if(argStr.startsWith(argPrefix)) + { + const QString argData = argStr.mid(2).trimmed(); + if(argData.length() > 0) + { + const int separatorIndex = argData.indexOf(separator); + if(separatorIndex > 0) + { + const QString argKey = argData.left(separatorIndex).trimmed(); + const QString argVal = argData.mid(separatorIndex + 1).trimmed(); + g_arguments_list->insertMulti(argKey.toLower(), argVal); + } + else + { + g_arguments_list->insertMulti(argData.toLower(), QString()); + } + } + } } LocalFree(szArglist); } diff --git a/src/Startup.cpp b/src/Startup.cpp index f44c448..980b65f 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -183,7 +183,7 @@ static const char *const g_imageformats[] = {"bmp", "png", "jpg", "gif", "ico", QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString &appName) { QMutexLocker lock(&g_init_lock); - const QStringList &arguments = MUtils::OS::arguments(); + const OS::ArgumentMap &arguments = MUtils::OS::arguments(); //Don't initialized again, if done already if(QApplication::instance() != NULL) @@ -253,7 +253,7 @@ QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString & if(osVersion.overrideFlag && (osVersion <= MUtils::OS::Version::WINDOWS_WN100)) { qWarning("Windows compatibility mode detected!"); - if(!arguments.contains("--ignore-compat-mode", Qt::CaseInsensitive)) + if(!arguments.contains("ignore-compat-mode")) { qFatal("%s", QApplication::tr("Executable '%1' doesn't support Windows compatibility mode.").arg(executableName).toLatin1().constData()); return NULL; @@ -299,10 +299,10 @@ QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString & //Enable larger/smaller font size double fontScaleFactor = 1.0; - if(arguments.contains("--huge-font", Qt::CaseInsensitive)) fontScaleFactor = 1.500; - if(arguments.contains("--big-font", Qt::CaseInsensitive)) fontScaleFactor = 1.250; - if(arguments.contains("--small-font", Qt::CaseInsensitive)) fontScaleFactor = 0.875; - if(arguments.contains("--tiny-font", Qt::CaseInsensitive)) fontScaleFactor = 0.750; + if(arguments.contains("huge-font" )) fontScaleFactor = 1.500; + if(arguments.contains("big-font" )) fontScaleFactor = 1.250; + if(arguments.contains("small-font")) fontScaleFactor = 0.875; + if(arguments.contains("tiny-font" )) fontScaleFactor = 0.750; if(!qFuzzyCompare(fontScaleFactor, 1.0)) { qWarning("Application font scale factor set to: %.3f\n", fontScaleFactor);