From 06db588742e616b11c7ff1689c87605ad8ed4227 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Thu, 4 Dec 2014 00:02:42 +0100 Subject: [PATCH] Moved some more OS-specific functions into the MUtilities library. --- src/Config.h | 2 +- src/Dialog_About.cpp | 6 +- src/Dialog_CueImport.cpp | 14 +- src/Dialog_MainWindow.cpp | 57 ++--- src/Dialog_Processing.cpp | 15 +- src/Dialog_Update.cpp | 5 +- src/Global.h | 18 -- src/Global_Win32.cpp | 395 ---------------------------------- src/Main.cpp | 2 +- src/Model_Settings.cpp | 2 +- src/Thread_DiskObserver.cpp | 9 +- src/Thread_Initialization.cpp | 12 +- src/Thread_Process.cpp | 2 +- src/Tool_Abstract.cpp | 8 +- 14 files changed, 65 insertions(+), 482 deletions(-) diff --git a/src/Config.h b/src/Config.h index ff453576..afadf29f 100644 --- a/src/Config.h +++ b/src/Config.h @@ -35,7 +35,7 @@ #define VER_LAMEXP_MINOR_LO 1 #define VER_LAMEXP_TYPE Beta #define VER_LAMEXP_PATCH 4 -#define VER_LAMEXP_BUILD 1610 +#define VER_LAMEXP_BUILD 1612 #define VER_LAMEXP_CONFG 1558 /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Dialog_About.cpp b/src/Dialog_About.cpp index 1889766a..e42fe4a8 100644 --- a/src/Dialog_About.cpp +++ b/src/Dialog_About.cpp @@ -366,7 +366,7 @@ void AboutDialog::openURL(const QString &url) { if(!QDesktopServices::openUrl(QUrl(url))) { - lamexp_exec_shell(this, url); + MUtils::OS::shell_open(this, url); } } @@ -386,8 +386,8 @@ void AboutDialog::gotoLicenseTab(void) void AboutDialog::moveDisque(void) { int delta = 2; - const __int64 perfFrequ = lamexp_perfcounter_frequ(); - const __int64 perfCount = lamexp_perfcounter_value(); + const qint64 perfFrequ = MUtils::OS::perfcounter_freq(); + const qint64 perfCount = MUtils::OS::perfcounter_read(); if((perfFrequ >= 0) && (perfCount >= 0)) { diff --git a/src/Dialog_CueImport.cpp b/src/Dialog_CueImport.cpp index 55905bec..ccb61972 100644 --- a/src/Dialog_CueImport.cpp +++ b/src/Dialog_CueImport.cpp @@ -38,6 +38,7 @@ //MUtils #include +#include //Qt includes #include @@ -302,13 +303,14 @@ void CueImportDialog::importButtonClicked(void) writeTest.remove(); } - bool ok = false; - unsigned __int64 currentFreeDiskspace = lamexp_free_diskspace(m_outputDir, &ok); - - if(ok && (currentFreeDiskspace < (oneGigabyte * minimumFreeDiskspaceMultiplier))) + quint64 currentFreeDiskspace = 0; + if(MUtils::OS::free_diskspace(m_outputDir, currentFreeDiskspace)) { - QMessageBox::warning(this, tr("Low Diskspace Warning"), QString("%1
%2").arg(tr("There are less than %1 GB of free diskspace available in the selected output directory.").arg(QString::number(minimumFreeDiskspaceMultiplier)), tr("It is highly recommend to free up more diskspace before proceeding with the import!"))); - return; + if(currentFreeDiskspace < (oneGigabyte * minimumFreeDiskspaceMultiplier)) + { + QMessageBox::warning(this, tr("Low Diskspace Warning"), QString("%1
%2").arg(tr("There are less than %1 GB of free diskspace available in the selected output directory.").arg(QString::number(minimumFreeDiskspaceMultiplier)), tr("It is highly recommend to free up more diskspace before proceeding with the import!"))); + return; + } } importCueSheet(); diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index 4e408d17..8bb5a4d0 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -630,7 +630,7 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel_MetaInfo *me ui->actionCheckForBetaUpdates->setChecked(m_settings->autoUpdateCheckBeta() || lamexp_version_demo()); ui->actionCheckForBetaUpdates->setEnabled(!lamexp_version_demo()); ui->actionHibernateComputer->setChecked(m_settings->hibernateComputer()); - ui->actionHibernateComputer->setEnabled(lamexp_is_hibernation_supported()); + ui->actionHibernateComputer->setEnabled(MUtils::OS::is_hibernation_supported()); connect(ui->actionDisableUpdateReminder, SIGNAL(triggered(bool)), this, SLOT(disableUpdateReminderActionTriggered(bool))); connect(ui->actionDisableSounds, SIGNAL(triggered(bool)), this, SLOT(disableSoundsActionTriggered(bool))); connect(ui->actionDisableNeroAacNotifications, SIGNAL(triggered(bool)), this, SLOT(disableNeroAacNotificationsActionTriggered(bool))); @@ -1332,7 +1332,7 @@ void MainWindow::windowShown(void) QString uninstallerPath = uninstallerInfo.canonicalFilePath(); for(int i = 0; i < 3; i++) { - if(lamexp_exec_shell(this, QDir::toNativeSeparators(uninstallerPath), "/Force", QDir::toNativeSeparators(uninstallerDir))) break; + if(MUtils::OS::shell_open(this, QDir::toNativeSeparators(uninstallerPath), "/Force", QDir::toNativeSeparators(uninstallerDir))) break; } } QApplication::quit(); @@ -1594,31 +1594,32 @@ void MainWindow::encodeButtonClicked(void) return; } - bool ok = false; - unsigned __int64 currentFreeDiskspace = lamexp_free_diskspace(tempFolder, &ok); - - if(ok && (currentFreeDiskspace < (oneGigabyte * minimumFreeDiskspaceMultiplier))) + quint64 currentFreeDiskspace = 0; + if(MUtils::OS::free_diskspace(tempFolder, currentFreeDiskspace)) { - QStringList tempFolderParts = tempFolder.split("/", QString::SkipEmptyParts, Qt::CaseInsensitive); - tempFolderParts.takeLast(); - PLAY_SOUND_OPTIONAL("whammy", false); - QString lowDiskspaceMsg = QString("%1
%2

%3
%4
").arg - ( - NOBR(tr("There are less than %1 GB of free diskspace available on your system's TEMP folder.").arg(QString::number(minimumFreeDiskspaceMultiplier))), - NOBR(tr("It is highly recommend to free up more diskspace before proceeding with the encode!")), - NOBR(tr("Your TEMP folder is located at:")), - QString("%1").arg(FSLINK(tempFolderParts.join("\\"))) - ); - switch(QMessageBox::warning(this, tr("Low Diskspace Warning"), lowDiskspaceMsg, tr("Abort Encoding Process"), tr("Clean Disk Now"), tr("Ignore"))) + if(currentFreeDiskspace < (oneGigabyte * minimumFreeDiskspaceMultiplier)) { - case 1: - QProcess::startDetached(QString("%1/cleanmgr.exe").arg(MUtils::OS::known_folder(MUtils::OS::FOLDER_SYSTEMFOLDER)), QStringList() << "/D" << tempFolderParts.first()); - case 0: - return; - break; - default: - QMessageBox::warning(this, tr("Low Diskspace"), NOBR(tr("You are proceeding with low diskspace. Problems might occur!"))); - break; + QStringList tempFolderParts = tempFolder.split("/", QString::SkipEmptyParts, Qt::CaseInsensitive); + tempFolderParts.takeLast(); + PLAY_SOUND_OPTIONAL("whammy", false); + QString lowDiskspaceMsg = QString("%1
%2

%3
%4
").arg + ( + NOBR(tr("There are less than %1 GB of free diskspace available on your system's TEMP folder.").arg(QString::number(minimumFreeDiskspaceMultiplier))), + NOBR(tr("It is highly recommend to free up more diskspace before proceeding with the encode!")), + NOBR(tr("Your TEMP folder is located at:")), + QString("%1").arg(FSLINK(tempFolderParts.join("\\"))) + ); + switch(QMessageBox::warning(this, tr("Low Diskspace Warning"), lowDiskspaceMsg, tr("Abort Encoding Process"), tr("Clean Disk Now"), tr("Ignore"))) + { + case 1: + QProcess::startDetached(QString("%1/cleanmgr.exe").arg(MUtils::OS::known_folder(MUtils::OS::FOLDER_SYSTEMFOLDER)), QStringList() << "/D" << tempFolderParts.first()); + case 0: + return; + break; + default: + QMessageBox::warning(this, tr("Low Diskspace"), NOBR(tr("You are proceeding with low diskspace. Problems might occur!"))); + break; + } } } @@ -2468,7 +2469,7 @@ void MainWindow::previewContextActionTriggered(void) return; } - if(!lamexp_open_media_file(m_fileListModel->getFile(index).filePath())) + if(!MUtils::OS::open_media_file(m_fileListModel->getFile(index).filePath())) { qDebug("Player not found, falling back to default application..."); QDesktopServices::openUrl(QString("file:///").append(m_fileListModel->getFile(index).filePath())); @@ -3011,7 +3012,7 @@ void MainWindow::showFolderContextActionTriggered(void) QString path = QDir::toNativeSeparators(m_fileSystemModel->filePath(ui->outputFolderView->currentIndex())); if(!path.endsWith(QDir::separator())) path.append(QDir::separator()); - lamexp_exec_shell(this, path, true); + MUtils::OS::shell_open(this, path, true); } /* @@ -3282,7 +3283,7 @@ void MainWindow::outputFolderMouseEventOccurred(QWidget *sender, QEvent *event) { QString path = ui->outputFolderLabel->text(); if(!path.endsWith(QDir::separator())) path.append(QDir::separator()); - lamexp_exec_shell(this, path, true); + MUtils::OS::shell_open(this, path, true); } break; case QEvent::Enter: diff --git a/src/Dialog_Processing.cpp b/src/Dialog_Processing.cpp index b07cfaa4..04b00705 100644 --- a/src/Dialog_Processing.cpp +++ b/src/Dialog_Processing.cpp @@ -389,7 +389,7 @@ void ProcessingDialog::showEvent(QShowEvent *event) m_progressIndicator->start(); m_systemTray->setVisible(true); - lamexp_change_process_priority(1); + MUtils::OS::change_process_priority(1); ui->label_cpu->setText(NA); ui->label_disk->setText(NA); @@ -559,16 +559,9 @@ void ProcessingDialog::initEncoding(void) m_threadPool->setMaxThreadCount(maximumInstances); } - //for(int i = 0; i < m_threadPool->maxThreadCount(); i++) - //{ - // startNextJob(); - // qApp->processEvents(QEventLoop::ExcludeUserInputEvents); - // QThread::yieldCurrentThread(); - //} - m_initThreads = m_threadPool->maxThreadCount(); QTimer::singleShot(100, this, SLOT(initNextJob())); - m_timerStart = lamexp_perfcounter_value(); + m_timerStart = MUtils::OS::perfcounter_read(); } void ProcessingDialog::initNextJob(void) @@ -718,8 +711,8 @@ void ProcessingDialog::doneEncoding(void) } else { - const __int64 counter = lamexp_perfcounter_value(); - const __int64 frequency = lamexp_perfcounter_frequ(); + const qint64 counter = MUtils::OS::perfcounter_read(); + const qint64 frequency = MUtils::OS::perfcounter_freq(); if((counter >= 0I64) && (frequency >= 0)) { if((m_timerStart >= 0I64) && (m_timerStart < counter)) diff --git a/src/Dialog_Update.cpp b/src/Dialog_Update.cpp index bf8d385d..5e409848 100644 --- a/src/Dialog_Update.cpp +++ b/src/Dialog_Update.cpp @@ -35,6 +35,7 @@ #include #include #include +#include //Qt includes #include @@ -241,7 +242,7 @@ void UpdateDialog::checkForUpdates(void) qWarning("Update in progress, cannot check for updates now!"); } - if(!lamexp_user_is_admin()) + if(!MUtils::OS::user_is_admin()) { qWarning("User is not in the \"admin\" group, cannot update!"); QString message; @@ -413,7 +414,7 @@ void UpdateDialog::applyUpdate(void) bool updateStarted = process.waitForStarted(); if(updateStarted) { - m_updaterProcess = lamexp_process_id(&process); + m_updaterProcess = MUtils::OS::process_id(&process); loop.exec(QEventLoop::ExcludeUserInputEvents); } diff --git a/src/Global.h b/src/Global.h index 7f21ca1b..bec468ce 100644 --- a/src/Global.h +++ b/src/Global.h @@ -87,48 +87,31 @@ void lamexp_blink_window(QWidget *poWindow, unsigned int count = 10, unsigned in bool lamexp_block_window_move(void *message); bool lamexp_bring_process_to_front(const unsigned long pid); bool lamexp_bring_to_front(const QWidget *win); -bool lamexp_change_process_priority(const int priority); -bool lamexp_change_process_priority(void *hProcess, const int priority); -bool lamexp_change_process_priority(const QProcess *proc, const int priority); bool lamexp_check_escape_state(void); bool lamexp_check_sysmenu_msg(void *message, const unsigned int identifier); bool lamexp_check_tool(const QString &toolName); const QString lamexp_clean_filename(const QString &str); const QString lamexp_clean_filepath(const QString &str); -unsigned __int64 lamexp_current_file_time(void); -void lamexp_dbg_dbg_output_string(const char* format, ...); unsigned long lamexp_dbg_private_bytes(void); bool lamexp_enable_close_button(const QWidget *win, const bool bEnable = true); -bool lamexp_exec_shell(const QWidget *win, const QString &url, const bool explore = false); -bool lamexp_exec_shell(const QWidget *win, const QString &url, const QString ¶meters, const QString &directory, const bool explore = false); void lamexp_finalization(void); -unsigned __int64 lamexp_free_diskspace(const QString &path, bool *ok = NULL); void lamexp_free_window_icon(lamexp_icon_t *icon); int lamexp_init_ipc(void); bool lamexp_install_translator(const QString &language); bool lamexp_install_translator_from_file(const QString &qmFile); void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize); void lamexp_ipc_send(unsigned int command, const char* message); -bool lamexp_is_executable(const QString &path); -bool lamexp_is_hibernation_supported(void); const QString lamexp_lookup_tool(const QString &toolName); const char *lamexp_mulders_url(void); -int lamexp_network_status(void); -bool lamexp_open_media_file(const QString &mediaFilePath); -QString lamexp_path_to_short(const QString &longPath); -__int64 lamexp_perfcounter_frequ(void); -__int64 lamexp_perfcounter_value(void); bool lamexp_play_sound(const QString &name, const bool bAsync); bool lamexp_play_sound_file(const QString &library, const unsigned short uiSoundIdx, const bool bAsync); bool lamexp_play_sound_alias(const QString &alias, const bool bAsync); bool lamexp_portable_mode(void); -unsigned long lamexp_process_id(const QProcess *proc); QStringList lamexp_query_translations(void); void lamexp_register_tool(const QString &toolName, LockedFile *file, unsigned int version = 0, const QString *tag = NULL); lamexp_icon_t *lamexp_set_window_icon(QWidget *window, const QIcon &icon, const bool bIsBigIcon); bool lamexp_sheet_of_glass(QWidget *window); bool lamexp_sheet_of_glass_update(QWidget *window); -bool lamexp_shutdown_computer(const QString &message, const unsigned long timeout = 30, const bool forceShutdown = true, const bool hibernate = false); QColor lamexp_system_color(const int color_id); const char *lamexp_support_url(void); bool lamexp_themes_enabled(void); @@ -144,7 +127,6 @@ QString lamexp_translation_name(const QString &language); bool lamexp_translation_register(const QString &langId, const QString &qmFile, const QString &langName, unsigned int &systemId, unsigned int &country); unsigned int lamexp_translation_sysid(const QString &langId); bool lamexp_update_sysmenu(const QWidget *win, const unsigned int identifier, const QString &text); -bool lamexp_user_is_admin(void); const QString lamexp_version2string(const QString &pattern, unsigned int version, const QString &defaultText, const QString *tag = NULL); unsigned int lamexp_version_build(void); unsigned int lamexp_version_confg(void); diff --git a/src/Global_Win32.cpp b/src/Global_Win32.cpp index 155213c4..503889c0 100644 --- a/src/Global_Win32.cpp +++ b/src/Global_Win32.cpp @@ -214,76 +214,6 @@ bool lamexp_themes_enabled(void) return g_lamexp_themes_enabled.bThemesEnabled; } -/* - * Get number of free bytes on disk - */ -unsigned __int64 lamexp_free_diskspace(const QString &path, bool *ok) -{ - ULARGE_INTEGER freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes; - if(GetDiskFreeSpaceExW(reinterpret_cast(QDir::toNativeSeparators(path).utf16()), &freeBytesAvailable, &totalNumberOfBytes, &totalNumberOfFreeBytes)) - { - if(ok) *ok = true; - return freeBytesAvailable.QuadPart; - } - else - { - if(ok) *ok = false; - return 0; - } -} - -/* - * Check if computer does support hibernation - */ -bool lamexp_is_hibernation_supported(void) -{ - bool hibernationSupported = false; - - SYSTEM_POWER_CAPABILITIES pwrCaps; - SecureZeroMemory(&pwrCaps, sizeof(SYSTEM_POWER_CAPABILITIES)); - - if(GetPwrCapabilities(&pwrCaps)) - { - hibernationSupported = pwrCaps.SystemS4 && pwrCaps.HiberFilePresent; - } - - return hibernationSupported; -} - -/* - * Shutdown the computer - */ -bool lamexp_shutdown_computer(const QString &message, const unsigned long timeout, const bool forceShutdown, const bool hibernate) -{ - HANDLE hToken = NULL; - - if(OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) - { - TOKEN_PRIVILEGES privileges; - memset(&privileges, 0, sizeof(TOKEN_PRIVILEGES)); - privileges.PrivilegeCount = 1; - privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; - - if(LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &privileges.Privileges[0].Luid)) - { - if(AdjustTokenPrivileges(hToken, FALSE, &privileges, NULL, NULL, NULL)) - { - if(hibernate) - { - if(SetSuspendState(TRUE, TRUE, TRUE)) - { - return true; - } - } - const DWORD reason = SHTDN_REASON_MAJOR_APPLICATION | SHTDN_REASON_FLAG_PLANNED; - return InitiateSystemShutdownEx(NULL, const_cast(MUTILS_WCHR(message)), timeout, forceShutdown ? TRUE : FALSE, FALSE, reason); - } - } - } - - return false; -} - /* * Block window "move" message */ @@ -304,14 +234,6 @@ bool lamexp_block_window_move(void *message) return false; } -/* - * Suspend calling thread for N milliseconds - */ -inline void lamexp_sleep(const unsigned int delay) -{ - Sleep(delay); -} - bool lamexp_beep(int beepType) { switch(beepType) @@ -409,48 +331,6 @@ bool lamexp_play_sound_file(const QString &library, const unsigned short uiSound return result; } -/* - * Open file using the shell - */ -bool lamexp_exec_shell(const QWidget *win, const QString &url, const bool explore) -{ - return lamexp_exec_shell(win, url, QString(), QString(), explore); -} - -/* - * Open file using the shell (with parameters) - */ -bool lamexp_exec_shell(const QWidget *win, const QString &url, const QString ¶meters, const QString &directory, const bool explore) -{ - return ((int) ShellExecuteW(((win) ? win->winId() : NULL), (explore ? L"explore" : L"open"), MUTILS_WCHR(url), ((!parameters.isEmpty()) ? MUTILS_WCHR(parameters) : NULL), ((!directory.isEmpty()) ? MUTILS_WCHR(directory) : NULL), SW_SHOW)) > 32; -} - - /* - * Query value of the performance counter - */ -__int64 lamexp_perfcounter_value(void) -{ - LARGE_INTEGER counter; - if(QueryPerformanceCounter(&counter) == TRUE) - { - return counter.QuadPart; - } - return -1; -} - -/* - * Query frequency of the performance counter - */ -__int64 lamexp_perfcounter_frequ(void) -{ - LARGE_INTEGER frequency; - if(QueryPerformanceFrequency(&frequency) == TRUE) - { - return frequency.QuadPart; - } - return -1; -} - /* * Insert entry to the window's system menu */ @@ -512,79 +392,6 @@ bool lamexp_check_escape_state(void) return (GetAsyncKeyState(VK_ESCAPE) & 0x0001) != 0; } -/* - * Set the process priority class for current process - */ -bool lamexp_change_process_priority(const int priority) -{ - return lamexp_change_process_priority(GetCurrentProcess(), priority); -} - -/* - * Set the process priority class for specified process - */ -bool lamexp_change_process_priority(const QProcess *proc, const int priority) -{ - if(Q_PID qPid = proc->pid()) - { - return lamexp_change_process_priority(qPid->hProcess, priority); - } - else - { - return false; - } -} - -/* - * Set the process priority class for specified process - */ -bool lamexp_change_process_priority(void *hProcess, const int priority) -{ - bool ok = false; - - switch(qBound(-2, priority, 2)) - { - case 2: - ok = (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS) == TRUE); - break; - case 1: - if(!(ok = (SetPriorityClass(hProcess, ABOVE_NORMAL_PRIORITY_CLASS) == TRUE))) - { - ok = (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS) == TRUE); - } - break; - case 0: - ok = (SetPriorityClass(hProcess, NORMAL_PRIORITY_CLASS) == TRUE); - break; - case -1: - if(!(ok = (SetPriorityClass(hProcess, BELOW_NORMAL_PRIORITY_CLASS) == TRUE))) - { - ok = (SetPriorityClass(hProcess, IDLE_PRIORITY_CLASS) == TRUE); - } - break; - case -2: - ok = (SetPriorityClass(hProcess, IDLE_PRIORITY_CLASS) == TRUE); - break; - } - - return ok; -} - -/* - * Returns the current file time - */ -unsigned __int64 lamexp_current_file_time(void) -{ - FILETIME fileTime; - GetSystemTimeAsFileTime(&fileTime); - - ULARGE_INTEGER temp; - temp.HighPart = fileTime.dwHighDateTime; - temp.LowPart = fileTime.dwLowDateTime; - - return temp.QuadPart; -} - /* * Bring the specifed window to the front */ @@ -631,102 +438,6 @@ bool lamexp_bring_process_to_front(const unsigned long pid) return EnumWindows(lamexp_bring_process_to_front_helper, reinterpret_cast(&pid)) == TRUE; } -/* - * Retrun the process ID of the given QProcess - */ -unsigned long lamexp_process_id(const QProcess *proc) -{ - PROCESS_INFORMATION *procInf = proc->pid(); - return (procInf) ? procInf->dwProcessId : NULL; -} - -/* - * Convert long path to short path - */ -QString lamexp_path_to_short(const QString &longPath) -{ - QString shortPath; - DWORD buffSize = GetShortPathNameW(reinterpret_cast(longPath.utf16()), NULL, NULL); - - if(buffSize > 0) - { - wchar_t *buffer = new wchar_t[buffSize]; - DWORD result = GetShortPathNameW(reinterpret_cast(longPath.utf16()), buffer, buffSize); - - if(result > 0 && result < buffSize) - { - shortPath = QString::fromUtf16(reinterpret_cast(buffer)); - } - - delete[] buffer; - } - - return (shortPath.isEmpty() ? longPath : shortPath); -} - -/* - * Open media file in external player - */ -bool lamexp_open_media_file(const QString &mediaFilePath) -{ - const static wchar_t *registryPrefix[2] = { L"SOFTWARE\\", L"SOFTWARE\\Wow6432Node\\" }; - const static wchar_t *registryKeys[3] = - { - L"Microsoft\\Windows\\CurrentVersion\\Uninstall\\{97D341C8-B0D1-4E4A-A49A-C30B52F168E9}", - L"Microsoft\\Windows\\CurrentVersion\\Uninstall\\{DB9E4EAB-2717-499F-8D56-4CC8A644AB60}", - L"foobar2000" - }; - const static wchar_t *appNames[4] = { L"smplayer_portable.exe", L"smplayer.exe", L"MPUI.exe", L"foobar2000.exe" }; - const static wchar_t *valueNames[2] = { L"InstallLocation", L"InstallDir" }; - - for(size_t i = 0; i < 3; i++) - { - for(size_t j = 0; j < 2; j++) - { - QString mplayerPath; - HKEY registryKeyHandle = NULL; - - const QString currentKey = MUTILS_QSTR(registryPrefix[j]).append(MUTILS_QSTR(registryKeys[i])); - if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, MUTILS_WCHR(currentKey), 0, KEY_READ, ®istryKeyHandle) == ERROR_SUCCESS) - { - for(size_t k = 0; k < 2; k++) - { - wchar_t Buffer[4096]; - DWORD BuffSize = sizeof(wchar_t*) * 4096; - DWORD DataType = REG_NONE; - if(RegQueryValueExW(registryKeyHandle, valueNames[k], 0, &DataType, reinterpret_cast(Buffer), &BuffSize) == ERROR_SUCCESS) - { - if((DataType == REG_SZ) || (DataType == REG_EXPAND_SZ) || (DataType == REG_LINK)) - { - mplayerPath = MUTILS_QSTR(Buffer); - break; - } - } - } - RegCloseKey(registryKeyHandle); - } - - if(!mplayerPath.isEmpty()) - { - QDir mplayerDir(mplayerPath); - if(mplayerDir.exists()) - { - for(size_t k = 0; k < 4; k++) - { - if(mplayerDir.exists(MUTILS_QSTR(appNames[k]))) - { - qDebug("Player found at:\n%s\n", MUTILS_UTF8(mplayerDir.absoluteFilePath(MUTILS_QSTR(appNames[k])))); - QProcess::startDetached(mplayerDir.absoluteFilePath(MUTILS_QSTR(appNames[k])), QStringList() << QDir::toNativeSeparators(mediaFilePath)); - return true; - } - } - } - } - } - } - return false; -} - static void lamexp_init_dwmapi(void) { QReadLocker writeLock(&g_lamexp_dwmapi.lock); @@ -930,112 +641,6 @@ QColor lamexp_system_color(const int color_id) return color; } -/* - * Check if the current user is an administartor (helper function) - */ -static bool lamexp_user_is_admin_helper(void) -{ - HANDLE hToken = NULL; - if(!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) - { - return false; - } - - DWORD dwSize = 0; - if(!GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize)) - { - if(GetLastError() != ERROR_INSUFFICIENT_BUFFER) - { - CloseHandle(hToken); - return false; - } - } - - PTOKEN_GROUPS lpGroups = (PTOKEN_GROUPS) malloc(dwSize); - if(!lpGroups) - { - CloseHandle(hToken); - return false; - } - - if(!GetTokenInformation(hToken, TokenGroups, lpGroups, dwSize, &dwSize)) - { - free(lpGroups); - CloseHandle(hToken); - return false; - } - - PSID lpSid = NULL; SID_IDENTIFIER_AUTHORITY Authority = {SECURITY_NT_AUTHORITY}; - if(!AllocateAndInitializeSid(&Authority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &lpSid)) - { - free(lpGroups); - CloseHandle(hToken); - return false; - } - - bool bResult = false; - for(DWORD i = 0; i < lpGroups->GroupCount; i++) - { - if(EqualSid(lpSid, lpGroups->Groups[i].Sid)) - { - bResult = true; - break; - } - } - - FreeSid(lpSid); - free(lpGroups); - CloseHandle(hToken); - return bResult; -} - -/* - * Check if the current user is an administartor - */ -bool lamexp_user_is_admin(void) -{ - bool isAdmin = false; - - //Check for process elevation and UAC support first! - if(MUtils::OS::is_elevated(&isAdmin)) - { - qWarning("Process is elevated -> user is admin!"); - return true; - } - - //If not elevated and UAC is not available -> user must be in admin group! - if(!isAdmin) - { - qDebug("UAC is disabled/unavailable -> checking for Administrators group"); - isAdmin = lamexp_user_is_admin_helper(); - } - - return isAdmin; -} - -/* - * Check if file is a valid Win32/Win64 executable - */ -bool lamexp_is_executable(const QString &path) -{ - bool bIsExecutable = false; - DWORD binaryType; - if(GetBinaryType(MUTILS_WCHR(QDir::toNativeSeparators(path)), &binaryType)) - { - bIsExecutable = (binaryType == SCS_32BIT_BINARY || binaryType == SCS_64BIT_BINARY); - } - return bIsExecutable; -} - -/* - * Fatal application exit - helper - */ -static DWORD WINAPI lamexp_fatal_exit_helper(LPVOID lpParameter) -{ - MessageBoxA(NULL, ((LPCSTR) lpParameter), "LameXP - Guru Meditation", MB_OK | MB_ICONERROR | MB_TASKMODAL | MB_TOPMOST | MB_SETFOREGROUND); - return 0; -} - /////////////////////////////////////////////////////////////////////////////// // INITIALIZATION /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Main.cpp b/src/Main.cpp index b93b6833..90ab4eab 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -219,7 +219,7 @@ static int lamexp_main(int &argc, char **argv) //Shotdown computer if(iShutdown > shutdownFlag_None) { - if(!lamexp_shutdown_computer(QApplication::applicationFilePath(), 12, true, (iShutdown == shutdownFlag_Hibernate))) + if(!MUtils::OS::shutdown_computer(QApplication::applicationFilePath(), 12, true, (iShutdown == shutdownFlag_Hibernate))) { QMessageBox messageBox(QMessageBox::Critical, "LameXP", "Sorry, LameXP was unable to shutdown your computer!", QMessageBox::NoButton, NULL, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowStaysOnTopHint); } diff --git a/src/Model_Settings.cpp b/src/Model_Settings.cpp index f4478135..db6f135f 100644 --- a/src/Model_Settings.cpp +++ b/src/Model_Settings.cpp @@ -425,7 +425,7 @@ void SettingsModel::validate(void) if(this->hibernateComputer()) { - if(!lamexp_is_hibernation_supported()) + if(!MUtils::OS::is_hibernation_supported()) { this->hibernateComputer(false); } diff --git a/src/Thread_DiskObserver.cpp b/src/Thread_DiskObserver.cpp index aecc04fe..def25713 100644 --- a/src/Thread_DiskObserver.cpp +++ b/src/Thread_DiskObserver.cpp @@ -78,14 +78,13 @@ void DiskObserverThread::run(void) void DiskObserverThread::observe(void) { - unsigned __int64 minimumSpace = MIN_DISKSPACE; - unsigned __int64 freeSpace, previousSpace = 0ui64; - bool ok = false; + quint64 minimumSpace = MIN_DISKSPACE; + quint64 previousSpace = quint64(-1); forever { - freeSpace = lamexp_free_diskspace(m_path, &ok); - if(ok) + quint64 freeSpace = 0ui64; + if(MUtils::OS::free_diskspace(m_path, freeSpace)) { if(freeSpace < minimumSpace) { diff --git a/src/Thread_Initialization.cpp b/src/Thread_Initialization.cpp index bf6b1357..b2021303 100644 --- a/src/Thread_Initialization.cpp +++ b/src/Thread_Initialization.cpp @@ -319,7 +319,7 @@ double InitializationThread::doInit(const size_t threadCount) LockedFile::selfTest(); ExtractorTask::clearFlags(); - const long long timeExtractStart = lamexp_perfcounter_value(); + const long long timeExtractStart = MUtils::OS::perfcounter_read(); //Extract all files while(!(queueToolName.isEmpty() || queueChecksum.isEmpty() || queueVersInfo.isEmpty() || queueCpuTypes.isEmpty() || queueVersions.isEmpty())) @@ -364,7 +364,7 @@ double InitializationThread::doInit(const size_t threadCount) pool->waitForDone(); MUTILS_DELETE(pool); - const long long timeExtractEnd = lamexp_perfcounter_value(); + const long long timeExtractEnd = MUtils::OS::perfcounter_read(); //Make sure all files were extracted correctly if(ExtractorTask::getExcept()) @@ -388,7 +388,7 @@ double InitializationThread::doInit(const size_t threadCount) } //Check delay - const double delayExtract = static_cast(timeExtractEnd - timeExtractStart) / static_cast(lamexp_perfcounter_frequ()); + const double delayExtract = static_cast(timeExtractEnd - timeExtractStart) / static_cast(MUtils::OS::perfcounter_freq()); if(delayExtract > g_allowedExtractDelay) { m_slowIndicator = true; @@ -555,7 +555,7 @@ void InitializationThread::initNeroAac(void) for(int i = 0; i < 3; i++) { - if(!lamexp_is_executable(neroFileInfo[i].canonicalFilePath())) + if(!MUtils::OS::is_executable_file(neroFileInfo[i].canonicalFilePath())) { qDebug("%s executbale is invalid -> AAC encoding support will be disabled!\n", MUTILS_UTF8(neroFileInfo[i].fileName())); return; @@ -667,7 +667,7 @@ void InitializationThread::initFhgAac(void) return; } - if(!lamexp_is_executable(fhgFileInfo[0].canonicalFilePath())) + if(!MUtils::OS::is_executable_file(fhgFileInfo[0].canonicalFilePath())) { qDebug("FhgAacEnc executbale is invalid -> FhgAacEnc support will be disabled!\n"); return; @@ -774,7 +774,7 @@ void InitializationThread::initQAac(void) return; } - if(!lamexp_is_executable(qaacFileInfo[0].canonicalFilePath())) + if(!MUtils::OS::is_executable_file(qaacFileInfo[0].canonicalFilePath())) { qDebug("QAAC executbale is invalid -> QAAC support will be disabled!\n"); return; diff --git a/src/Thread_Process.cpp b/src/Thread_Process.cpp index 9d919baf..4ba65689 100644 --- a/src/Thread_Process.cpp +++ b/src/Thread_Process.cpp @@ -118,7 +118,7 @@ bool ProcessThread::init(void) emit processStateInitialized(m_jobId, QFileInfo(m_audioFile.filePath()).fileName(), tr("Starting..."), ProgressModel::JobRunning); //Initialize log - handleMessage(QString().sprintf("LameXP v%u.%02u (Build #%u), compiled on %s at %s", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build(), MUTILS_UTF8(MUtils::Version::app_build_date().toString(Qt::ISODate)), MUTILS_UTF8(MUtils::Version::app_build_time().toString(Qt::ISODate)))); + handleMessage(QString().sprintf("LameXP v%u.%02u (Build #%u), compiled on %s at %s", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build(), MUTILS_UTF8(MUtils::Version::app_build_date().toString(Qt::ISODate)), MUTILS_UTF8(MUtils::Version::app_build_time().toString(Qt::ISODate)))); handleMessage("\n-------------------------------\n"); return true; diff --git a/src/Tool_Abstract.cpp b/src/Tool_Abstract.cpp index 35450a34..a1f7066b 100644 --- a/src/Tool_Abstract.cpp +++ b/src/Tool_Abstract.cpp @@ -96,7 +96,7 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const { QMutexLocker lock(&s_mutex_startProcess); - if(lamexp_current_file_time() <= s_lastLaunchTime) + if(MUtils::OS::current_file_time() <= s_lastLaunchTime) { MUtils::OS::sleep_ms(START_DELAY); } @@ -116,7 +116,7 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const } } - lamexp_change_process_priority(&process, -1); + MUtils::OS::change_process_priority(&process, -1); lock.unlock(); if(m_firstLaunch) @@ -125,7 +125,7 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const m_firstLaunch = false; } - s_lastLaunchTime = lamexp_current_file_time() + START_DELAY_NANO; + s_lastLaunchTime = MUtils::OS::current_file_time() + START_DELAY_NANO; return true; } @@ -136,7 +136,7 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const process.kill(); process.waitForFinished(-1); - s_lastLaunchTime = lamexp_current_file_time() + START_DELAY_NANO; + s_lastLaunchTime = MUtils::OS::current_file_time() + START_DELAY_NANO; return false; }