mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-15 08:01:05 +08:00
Use dynamic linking for SetSuspendState function
This commit is contained in:
parent
b0e3d77975
commit
644e7d0450
@ -35,7 +35,6 @@
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
#include <powrprof.h>
|
||||
#include <Shlobj.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
@ -113,12 +112,20 @@ void Utils::Misc::shutdownComputer(const ShutdownDialogAction &action)
|
||||
if (GetLastError() != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
if (action == ShutdownDialogAction::Suspend)
|
||||
SetSuspendState(false, false, false);
|
||||
else if (action == ShutdownDialogAction::Hibernate)
|
||||
SetSuspendState(true, false, false);
|
||||
else
|
||||
using PSETSUSPENDSTATE = BOOLEAN (WINAPI *)(BOOLEAN, BOOLEAN, BOOLEAN);
|
||||
const auto setSuspendState = Utils::Misc::loadWinAPI<PSETSUSPENDSTATE>("PowrProf.dll", "SetSuspendState");
|
||||
|
||||
if (action == ShutdownDialogAction::Suspend) {
|
||||
if (setSuspendState)
|
||||
setSuspendState(false, false, false);
|
||||
}
|
||||
else if (action == ShutdownDialogAction::Hibernate) {
|
||||
if (setSuspendState)
|
||||
setSuspendState(true, false, false);
|
||||
}
|
||||
else {
|
||||
InitiateSystemShutdownA(0, QCoreApplication::translate("misc", "qBittorrent will shutdown the computer now because all downloads are complete.").toLocal8Bit().data(), 10, true, false);
|
||||
}
|
||||
|
||||
// Disable shutdown privilege.
|
||||
tkp.Privileges[0].Attributes = 0;
|
||||
|
@ -34,7 +34,7 @@ win32-g++* {
|
||||
|
||||
RC_FILE = qbittorrent_mingw.rc
|
||||
|
||||
LIBS += libadvapi32 libshell32 libuser32 libole32 libwsock32 libws2_32 libpowrprof
|
||||
LIBS += libadvapi32 libshell32 libuser32 libole32 libwsock32 libws2_32
|
||||
}
|
||||
else:win32-msvc* {
|
||||
CONFIG -= embed_manifest_exe
|
||||
@ -43,7 +43,7 @@ else:win32-msvc* {
|
||||
|
||||
RC_FILE = qbittorrent.rc
|
||||
|
||||
LIBS += advapi32.lib shell32.lib crypt32.lib User32.lib ole32.lib PowrProf.lib
|
||||
LIBS += advapi32.lib shell32.lib crypt32.lib User32.lib ole32.lib
|
||||
}
|
||||
|
||||
# See an example build configuration in "conf.pri.windows"
|
||||
|
Loading…
Reference in New Issue
Block a user