Some code-clean up. Removed "Windows.h" include from "Global.h", because most source files won't need the Win32 API stuff. Also got rid of some Windows 2000 compatibility cruft.

This commit is contained in:
LoRd_MuldeR 2013-10-06 19:28:12 +02:00
parent 9dbb317a5c
commit 7602317652
23 changed files with 147 additions and 104 deletions

View File

@ -34,7 +34,7 @@
#define VER_LAMEXP_MINOR_LO 9
#define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 1
#define VER_LAMEXP_BUILD 1350
#define VER_LAMEXP_BUILD 1357
#define VER_LAMEXP_CONFG 1348
///////////////////////////////////////////////////////////////////////////////

View File

@ -26,6 +26,11 @@
#include <QDir>
#include <QProcess>
#include <QRegExp>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <Shellapi.h>
#define FIX_SEPARATORS(STR) for(int i = 0; STR[i]; i++) { if(STR[i] == L'/') STR[i] = L'\\'; }

View File

@ -27,6 +27,8 @@
#include "Resource.h"
#include "Model_Settings.h"
#include <math.h>
#include <QDate>
#include <QApplication>
#include <QIcon>
@ -45,9 +47,12 @@
#include <QWindowsVistaStyle>
#include <QWindowsXPStyle>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <ShellAPI.h>
#include <MMSystem.h>
#include <math.h>
//Helper macros
#define LINK(URL) QString("<a href=\"%1\">%2</a>").arg(URL).arg(QString(URL).replace("-", "&minus;"))

View File

@ -33,6 +33,11 @@
#include <QMimeData>
#include <QTimer>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
LogViewDialog::LogViewDialog(QWidget *parent)
:
QDialog(parent),

View File

@ -73,7 +73,10 @@
#include <QResource>
#include <QScrollBar>
//System includes
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <MMSystem.h>
#include <ShellAPI.h>

View File

@ -61,7 +61,12 @@
#include <QResizeEvent>
#include <QTime>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <MMSystem.h>
#include <math.h>
#include <float.h>

View File

@ -28,6 +28,11 @@
#include <QKeyEvent>
#include <QTimer>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include "WinSevenTaskbar.h"
#define FADE_DELAY 16

View File

@ -44,7 +44,10 @@
#include <QMovie>
#include <QtConcurrentRun>
//Win32 includes
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <MMSystem.h>
#include <WinInet.h>

View File

@ -25,6 +25,11 @@
#include "Model_Settings.h"
#include <QDir>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <Shellapi.h>
#define FIX_SEPARATORS(STR) for(int i = 0; STR[i]; i++) { if(STR[i] == L'/') STR[i] = L'\\'; }

View File

@ -21,6 +21,11 @@
#include "Global.h"
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
//Qt includes
#include <QApplication>
#include <QMessageBox>
@ -2635,7 +2640,7 @@ static const HANDLE g_debug_thread = LAMEXP_DEBUG ? NULL : lamexp_debug_thread_i
/*
* Get number private bytes [debug only]
*/
SIZE_T lamexp_dbg_private_bytes(void)
unsigned long lamexp_dbg_private_bytes(void)
{
#if LAMEXP_DEBUG
for(int i = 0; i < 8; i++) _heapmin();

View File

@ -29,11 +29,6 @@
#include <stdio.h>
#include <tchar.h>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
//Visual Leaks Detector
#include <vld.h>
@ -118,7 +113,6 @@ bool lamexp_detect_wine(void);
void lamexp_init_console(const QStringList &argv);
bool lamexp_init_qt(int argc, char* argv[]);
int lamexp_init_ipc(void);
LONG WINAPI lamexp_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo);
void lamexp_invalid_param_handler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t);
void lamexp_message_handler(QtMsgType type, const char *msg);
void lamexp_register_tool(const QString &toolName, LockedFile *file, unsigned int version = 0, const QString *tag = NULL);
@ -166,7 +160,7 @@ void lamexp_natural_string_sort(QStringList &list, const bool bIgnoreCase);
void lamexp_fatal_exit(const wchar_t* exitMessage, const wchar_t* errorBoxMessage = NULL);
//Debug-only functions
SIZE_T lamexp_dbg_private_bytes(void);
unsigned long lamexp_dbg_private_bytes(void);
//Helper macros
#define LAMEXP_DELETE(PTR) do { if(PTR) { delete PTR; PTR = NULL; } } while(0)
@ -184,13 +178,6 @@ SIZE_T lamexp_dbg_private_bytes(void);
#define LAMEXP_COMPILER_WARNING(TXT) __pragma(message(__FILE__ "(" LAMEXP_MAKE_STRING(__LINE__) ") : warning: " TXT))
#define NOBR(STR) (QString("<nobr>%1</nobr>").arg((STR)).replace("-", "&minus;"))
//Output Qt debug message (Unicode-safe versions)
/*
#define qDebug64(FORMAT, ...) qDebug("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData());
#define qWarning64(FORMAT, ...) qWarning("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData());
#define qFatal64(FORMAT, ...) qFatal("@BASE64@%s", QString(FORMAT).arg(__VA_ARGS__).toUtf8().toBase64().constData());
*/
//Check for debug build
#if defined(_DEBUG) && defined(QT_DEBUG) && !defined(NDEBUG) && !defined(QT_NO_DEBUG)
#define LAMEXP_DEBUG (1)

View File

@ -33,6 +33,11 @@
#include <io.h>
#include <fcntl.h>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
///////////////////////////////////////////////////////////////////////////////
#define THROW(STR) \

View File

@ -39,6 +39,11 @@
#include <QMutex>
#include <QDir>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
///////////////////////////////////////////////////////////////////////////////
// Main function
///////////////////////////////////////////////////////////////////////////////
@ -216,6 +221,8 @@ static int lamexp_main(int argc, char* argv[])
// Applicaton entry point
///////////////////////////////////////////////////////////////////////////////
LONG WINAPI lamexp_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionInfo);
static int _main(int argc, char* argv[])
{
if(LAMEXP_DEBUG)

View File

@ -31,6 +31,11 @@
#include <QTextCodec>
#include <QTextStream>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <float.h>
#include <limits>

View File

@ -27,6 +27,11 @@
#include <QDesktopServices>
#include <QLibrary>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#define IS_DIR(ATTR) (((ATTR) & FILE_ATTRIBUTE_DIRECTORY) && (!((ATTR) & FILE_ATTRIBUTE_HIDDEN)))
#define NO_DOT_OR_DOTDOT(STR) (wcscmp((STR), L".") && wcscmp((STR), L".."))

View File

@ -39,6 +39,11 @@
#include <QMutex>
#include <QSet>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
////////////////////////////////////////////////////////////
// SettingsCache Class
////////////////////////////////////////////////////////////

View File

@ -62,12 +62,6 @@ bool PlaylistImporter::importPlaylist(QStringList &fileList, const QString &play
QDir rootDir(baseDir);
while(rootDir.cdUp());
//Sanity check
if(file.size() < 3 || file.size() > 512000)
{
return false;
}
//Detect playlist type
playlist_t playlistType = isPlaylist(file.canonicalFilePath());
@ -87,7 +81,7 @@ bool PlaylistImporter::importPlaylist(QStringList &fileList, const QString &play
}
//Skip very large files (parsing could take very long)
if(data.size() >= 10485760i64)
if((file.size() < 3) || (file.size() > 524288))
{
qWarning("File is very big. Probably not a Playlist. Rejecting...");
return false;
@ -222,7 +216,7 @@ bool PlaylistImporter::parsePlaylist_m3u(QFile &data, QStringList &fileList, con
}
}
return true;
return foundAtLeastOneFile;
}
bool PlaylistImporter::parsePlaylist_pls(QFile &data, QStringList &fileList, const QDir &baseDir, const QDir &rootDir)
@ -306,11 +300,13 @@ bool PlaylistImporter::parsePlaylist_pls(QFile &data, QStringList &fileList, con
}
}
return true;
return foundAtLeastOneFile;
}
bool PlaylistImporter::parsePlaylist_wpl(QFile &data, QStringList &fileList, const QDir &baseDir, const QDir &rootDir)
{
bool foundAtLeastOneFile = false;
QRegExp skipData("<!--(.+)-->", Qt::CaseInsensitive);
QRegExp wplEntry("<(media|ref)[^<>]*(src|href)=\"([^\"]+)\"[^<>]*>", Qt::CaseInsensitive);
@ -340,11 +336,12 @@ bool PlaylistImporter::parsePlaylist_wpl(QFile &data, QStringList &fileList, con
if(isPlaylist(filename.canonicalFilePath()) == notPlaylist)
{
fileList << filename.canonicalFilePath();
foundAtLeastOneFile = true;
}
}
}
return true;
return foundAtLeastOneFile;
}
void PlaylistImporter::fixFilePath(QFileInfo &filename, const QDir &baseDir, const QDir &rootDir)

View File

@ -25,6 +25,11 @@
#include <QDir>
#include <QLibrary>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
////////////////////////////////////////////////////////////
typedef enum { SystemProcInfo = 8 } SYSTEM_INFO_CLASS;

View File

@ -29,6 +29,11 @@
#include <limits.h>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////

View File

@ -24,6 +24,11 @@
#include <QDir>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
////////////////////////////////////////////////////////////
// Constructor & Destructor
////////////////////////////////////////////////////////////

View File

@ -30,12 +30,10 @@
#include <QProcessEnvironment>
#include <QDir>
/*
* Win32 API definitions
*/
typedef HANDLE (WINAPI *CreateJobObjectFun)(__in_opt LPSECURITY_ATTRIBUTES lpJobAttributes, __in_opt LPCSTR lpName);
typedef BOOL (WINAPI *SetInformationJobObjectFun)(__in HANDLE hJob, __in JOBOBJECTINFOCLASS JobObjectInformationClass, __in_bcount(cbJobObjectInformationLength) LPVOID lpJobObjectInformation, __in DWORD cbJobObjectInformationLength);
typedef BOOL (WINAPI *AssignProcessToJobObjectFun)(__in HANDLE hJob, __in HANDLE hProcess);
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
/*
* Static vars
@ -56,48 +54,32 @@ static const quint64 START_DELAY_NANO = START_DELAY * 1000 * 10; //in 100-nanose
*/
AbstractTool::AbstractTool(void)
{
static CreateJobObjectFun CreateJobObjectPtr = NULL;
static SetInformationJobObjectFun SetInformationJobObjectPtr = NULL;
QMutexLocker lock(&s_mutex_startProcess);
if(s_jobObjRefCount < 1U)
{
const lamexp_os_version_t *osVersionNo = lamexp_get_os_version();
if(LAMEXP_MIN_OS_VER(osVersionNo, 5, 1))
HANDLE jobObject = CreateJobObject(NULL, NULL);
if((jobObject != NULL) && (jobObject != INVALID_HANDLE_VALUE))
{
if((!CreateJobObjectPtr) || (!SetInformationJobObjectPtr))
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jobExtendedLimitInfo;
memset(&jobExtendedLimitInfo, 0, sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
memset(&jobExtendedLimitInfo.BasicLimitInformation, 0, sizeof(JOBOBJECT_BASIC_LIMIT_INFORMATION));
jobExtendedLimitInfo.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE | JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION;
if(SetInformationJobObject(jobObject, JobObjectExtendedLimitInformation, &jobExtendedLimitInfo, sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION)))
{
QLibrary Kernel32Lib("kernel32.dll");
CreateJobObjectPtr = (CreateJobObjectFun) Kernel32Lib.resolve("CreateJobObjectA");
SetInformationJobObjectPtr = (SetInformationJobObjectFun) Kernel32Lib.resolve("SetInformationJobObject");
}
}
if(CreateJobObjectPtr && SetInformationJobObjectPtr)
{
HANDLE jobObject = CreateJobObjectPtr(NULL, NULL);
if((jobObject != NULL) && (jobObject != INVALID_HANDLE_VALUE))
{
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jobExtendedLimitInfo;
memset(&jobExtendedLimitInfo, 0, sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
memset(&jobExtendedLimitInfo.BasicLimitInformation, 0, sizeof(JOBOBJECT_BASIC_LIMIT_INFORMATION));
jobExtendedLimitInfo.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE | JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION;
if(SetInformationJobObjectPtr(jobObject, JobObjectExtendedLimitInformation, &jobExtendedLimitInfo, sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION)))
{
s_handle_jobObject = jobObject;
s_jobObjRefCount = 1U;
}
else
{
qWarning("Failed to set job object information!");
CloseHandle(jobObject);
}
s_handle_jobObject = jobObject;
s_jobObjRefCount = 1U;
}
else
{
qWarning("Failed to create the job object!");
qWarning("Failed to set job object information!");
CloseHandle(jobObject);
}
}
else
{
qWarning("Failed to create the job object!");
}
}
else
{
@ -130,8 +112,6 @@ AbstractTool::~AbstractTool(void)
*/
bool AbstractTool::startProcess(QProcess &process, const QString &program, const QStringList &args)
{
static AssignProcessToJobObjectFun AssignProcessToJobObjectPtr = NULL;
QMutexLocker lock(&s_mutex_startProcess);
if(currentTime() <= s_lastLaunchTime)
@ -146,22 +126,16 @@ bool AbstractTool::startProcess(QProcess &process, const QString &program, const
env.insert("TEMP", QDir::toNativeSeparators(lamexp_temp_folder2()));
env.insert("TMP", QDir::toNativeSeparators(lamexp_temp_folder2()));
process.setProcessEnvironment(env);
if(!AssignProcessToJobObjectPtr)
{
QLibrary Kernel32Lib("kernel32.dll");
AssignProcessToJobObjectPtr = (AssignProcessToJobObjectFun) Kernel32Lib.resolve("AssignProcessToJobObject");
}
process.setProcessChannelMode(QProcess::MergedChannels);
process.setReadChannel(QProcess::StandardOutput);
process.start(program, args);
if(process.waitForStarted())
{
if(AssignProcessToJobObjectPtr && s_handle_jobObject)
if(s_handle_jobObject)
{
if(!AssignProcessToJobObjectPtr(s_handle_jobObject, process.pid()->hProcess))
if(!AssignProcessToJobObject(s_handle_jobObject, process.pid()->hProcess))
{
qWarning("Failed to assign process to job object!");
}

View File

@ -23,10 +23,15 @@
#include <QWidget>
#include <QIcon>
//Windows includes
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <ShObjIdl.h>
UINT WinSevenTaskbar::m_winMsg = 0;
ITaskbarList3 *WinSevenTaskbar::m_ptbl = NULL;
static UINT s_winMsg = 0;
static ITaskbarList3 *s_ptbl = NULL;
WinSevenTaskbar::WinSevenTaskbar(void)
{
@ -43,27 +48,27 @@ WinSevenTaskbar::~WinSevenTaskbar(void)
void WinSevenTaskbar::init(void)
{
m_winMsg = RegisterWindowMessageW(L"TaskbarButtonCreated");
m_ptbl = NULL;
s_winMsg = RegisterWindowMessageW(L"TaskbarButtonCreated");
s_ptbl = NULL;
}
void WinSevenTaskbar::uninit(void)
{
if(m_ptbl)
if(s_ptbl)
{
m_ptbl->Release();
m_ptbl = NULL;
s_ptbl->Release();
s_ptbl = NULL;
}
}
bool WinSevenTaskbar::handleWinEvent(MSG *message, long *result)
bool WinSevenTaskbar::handleWinEvent(void *message, long *result)
{
bool stopEvent = false;
if(message->message == m_winMsg)
if(((MSG*)message)->message == s_winMsg)
{
if(!m_ptbl) createInterface();
*result = (m_ptbl) ? S_OK : S_FALSE;
if(!s_ptbl) createInterface();
*result = (s_ptbl) ? S_OK : S_FALSE;
stopEvent = true;
}
@ -72,7 +77,7 @@ bool WinSevenTaskbar::handleWinEvent(MSG *message, long *result)
void WinSevenTaskbar::createInterface(void)
{
if(!m_ptbl)
if(!s_ptbl)
{
ITaskbarList3 *ptbl = NULL;
HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&ptbl));
@ -82,7 +87,7 @@ void WinSevenTaskbar::createInterface(void)
HRESULT hr2 = ptbl->HrInit();
if(SUCCEEDED(hr2))
{
m_ptbl = ptbl;
s_ptbl = ptbl;
/*qDebug("ITaskbarList3::HrInit() succeeded.");*/
}
else
@ -102,26 +107,26 @@ bool WinSevenTaskbar::setTaskbarState(QWidget *window, WinSevenTaskbarState stat
{
bool result = false;
if(m_ptbl && window)
if(s_ptbl && window)
{
HRESULT hr = HRESULT(-1);
switch(state)
{
case WinSevenTaskbarNoState:
hr = m_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_NOPROGRESS);
hr = s_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_NOPROGRESS);
break;
case WinSevenTaskbarNormalState:
hr = m_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_NORMAL);
hr = s_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_NORMAL);
break;
case WinSevenTaskbarIndeterminateState:
hr = m_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_INDETERMINATE);
hr = s_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_INDETERMINATE);
break;
case WinSevenTaskbarErrorState:
hr = m_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_ERROR);
hr = s_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_ERROR);
break;
case WinSevenTaskbarPausedState:
hr = m_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_PAUSED);
hr = s_ptbl->SetProgressState(reinterpret_cast<HWND>(window->winId()), TBPF_PAUSED);
break;
}
@ -133,18 +138,18 @@ bool WinSevenTaskbar::setTaskbarState(QWidget *window, WinSevenTaskbarState stat
void WinSevenTaskbar::setTaskbarProgress(QWidget *window, unsigned __int64 currentValue, unsigned __int64 maximumValue)
{
if(m_ptbl && window)
if(s_ptbl && window)
{
m_ptbl->SetProgressValue(reinterpret_cast<HWND>(window->winId()), currentValue, maximumValue);
s_ptbl->SetProgressValue(reinterpret_cast<HWND>(window->winId()), currentValue, maximumValue);
}
}
void WinSevenTaskbar::setOverlayIcon(QWidget *window, QIcon *icon)
{
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
if(m_ptbl && window)
if(s_ptbl && window)
{
m_ptbl->SetOverlayIcon(window->winId(), (icon ? icon->pixmap(16,16).toWinHICON() : NULL), L"LameXP");
s_ptbl->SetOverlayIcon(window->winId(), (icon ? icon->pixmap(16,16).toWinHICON() : NULL), L"LameXP");
}
#endif
}

View File

@ -25,7 +25,6 @@
class QWidget;
class QIcon;
struct ITaskbarList3;
class WinSevenTaskbar
{
@ -44,7 +43,7 @@ public:
};
//Public interface
static bool handleWinEvent(MSG *message, long *result);
static bool handleWinEvent(void *message, long *result);
static bool setTaskbarState(QWidget *window, WinSevenTaskbarState state);
static void setTaskbarProgress(QWidget *window, unsigned __int64 currentValue, unsigned __int64 maximumValue);
static void setOverlayIcon(QWidget *window, QIcon *icon);
@ -53,7 +52,5 @@ public:
static void uninit(void);
private:
static ITaskbarList3 *m_ptbl;
static UINT m_winMsg;
static void createInterface(void);
};