summaryrefslogtreecommitdiff
path: root/plugins/AutoShutdown
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/AutoShutdown')
-rw-r--r--plugins/AutoShutdown/shutdown_10.vcxproj8
-rw-r--r--plugins/AutoShutdown/shutdown_11.vcxproj8
-rw-r--r--plugins/AutoShutdown/src/common.h2
-rw-r--r--plugins/AutoShutdown/src/shutdownsvc.cpp121
4 files changed, 60 insertions, 79 deletions
diff --git a/plugins/AutoShutdown/shutdown_10.vcxproj b/plugins/AutoShutdown/shutdown_10.vcxproj
index 1518ed9509..e322560bb8 100644
--- a/plugins/AutoShutdown/shutdown_10.vcxproj
+++ b/plugins/AutoShutdown/shutdown_10.vcxproj
@@ -94,7 +94,7 @@
<SubSystem>Windows</SubSystem>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
<BaseAddress>0x11070000</BaseAddress>
- <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<AdditionalLibraryDirectories>$(ProfileDir)..\..\bin10\lib</AdditionalLibraryDirectories>
</Link>
@@ -122,7 +122,7 @@
<SubSystem>Windows</SubSystem>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
<BaseAddress>0x11070000</BaseAddress>
- <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<AdditionalLibraryDirectories>$(ProfileDir)..\..\bin10\lib</AdditionalLibraryDirectories>
</Link>
@@ -155,7 +155,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<AdditionalLibraryDirectories>$(ProfileDir)..\..\bin10\lib</AdditionalLibraryDirectories>
- <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalOptions>/PDBALTPATH:%_PDB%</AdditionalOptions>
</Link>
</ItemDefinitionGroup>
@@ -183,7 +183,7 @@
<SubSystem>Windows</SubSystem>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
<BaseAddress>0x11070000</BaseAddress>
- <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
diff --git a/plugins/AutoShutdown/shutdown_11.vcxproj b/plugins/AutoShutdown/shutdown_11.vcxproj
index 71b22a5bd5..d1a11007de 100644
--- a/plugins/AutoShutdown/shutdown_11.vcxproj
+++ b/plugins/AutoShutdown/shutdown_11.vcxproj
@@ -98,7 +98,7 @@
<SubSystem>Windows</SubSystem>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
<BaseAddress>0x11070000</BaseAddress>
- <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<AdditionalLibraryDirectories>$(ProfileDir)..\..\bin11\lib</AdditionalLibraryDirectories>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
@@ -127,7 +127,7 @@
<SubSystem>Windows</SubSystem>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
<BaseAddress>0x11070000</BaseAddress>
- <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<AdditionalLibraryDirectories>$(ProfileDir)..\..\bin11\lib</AdditionalLibraryDirectories>
</Link>
@@ -160,7 +160,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<AdditionalLibraryDirectories>$(ProfileDir)..\..\bin11\lib</AdditionalLibraryDirectories>
- <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -187,7 +187,7 @@
<SubSystem>Windows</SubSystem>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
<BaseAddress>0x11070000</BaseAddress>
- <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
diff --git a/plugins/AutoShutdown/src/common.h b/plugins/AutoShutdown/src/common.h
index 2eae1b9bab..7a59d8961f 100644
--- a/plugins/AutoShutdown/src/common.h
+++ b/plugins/AutoShutdown/src/common.h
@@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <windows.h>
#include <Uxtheme.h>
#include <Shlwapi.h>
+#include <PowrProf.h>
+#include <Ras.h>
/* WinXP+: shutdown reason codes */
#if defined(EWX_RESTARTAPPS) /* new MS Platform SDK */
diff --git a/plugins/AutoShutdown/src/shutdownsvc.cpp b/plugins/AutoShutdown/src/shutdownsvc.cpp
index fb351ebef5..f9fe70fb56 100644
--- a/plugins/AutoShutdown/src/shutdownsvc.cpp
+++ b/plugins/AutoShutdown/src/shutdownsvc.cpp
@@ -73,14 +73,7 @@ static BOOL IsShutdownTypeEnabled(BYTE shutdownType)
switch(shutdownType) {
case SDSDT_HIBERNATE:
case SDSDT_STANDBY:
- { HMODULE hPowerDLL=LoadLibraryA("POWRPROF"); /* all ascii */
- if (hPowerDLL != NULL) {
- BOOLEAN (STDAPICALLTYPE *pfnIsPwrModeAllowed)(void);
- *(PROC*)&pfnIsPwrModeAllowed=GetProcAddress(hPowerDLL,(shutdownType==SDSDT_HIBERNATE)?"IsPwrHibernateAllowed":"IsPwrSuspendAllowed");
- if (pfnIsPwrModeAllowed) bReturn=pfnIsPwrModeAllowed() != 0;
- FreeLibrary(hPowerDLL);
- }
- }
+ bReturn = shutdownType == SDSDT_HIBERNATE ? IsPwrHibernateAllowed() : IsPwrSuspendAllowed() != 0;
/* test privilege */
if (bReturn) {
bReturn=WinNT_SetPrivilege(SE_SHUTDOWN_NAME,TRUE);
@@ -117,7 +110,7 @@ static BOOL IsShutdownTypeEnabled(BYTE shutdownType)
break;
case SDSDT_CLOSERASCONNECTIONS:
/* check if RAS installed/available */
- bReturn=SearchPath(NULL,_T("RASAPI32"),_T(".DLL"),0,NULL,NULL) != 0;
+ bReturn = TRUE;
break;
case SDSDT_SETMIRANDAOFFLINE:
case SDSDT_CLOSEMIRANDA:
@@ -180,74 +173,60 @@ static DWORD ShutdownNow(BYTE shutdownType)
ShutdownNow(SDSDT_SETMIRANDAOFFLINE); /* set Miranda offline */
/* hang up all ras connections */
{
- HMODULE hRasApiDLL=LoadLibrary(_T("RASAPI32")); /* all ascii */
- if (hRasApiDLL != NULL) {
- DWORD (APIENTRY *pfnRasEnumConnections)(RASCONN*,DWORD*,DWORD*);
- DWORD (APIENTRY *pfnRasHangUp)(HRASCONN);
- DWORD (APIENTRY *pfnRasGetConnectStatus)(HRASCONN,RASCONNSTATUS*);
- *(PROC*)&pfnRasEnumConnections=GetProcAddress(hRasApiDLL,"RasEnumConnectionsW");
- *(PROC*)&pfnRasHangUp=GetProcAddress(hRasApiDLL,"RasHangUpW");
- *(PROC*)&pfnRasGetConnectStatus=GetProcAddress(hRasApiDLL,"RasGetConnectStatusW");
- if (pfnRasEnumConnections && pfnRasGetConnectStatus && pfnRasHangUp) {
- RASCONN *paConn;
- RASCONN *paConnBuf;
- DWORD dwConnSize,dwConnItems,dwRetries;
- RASCONNSTATUS rcs;
- DWORD dw,dwLastTickCount;
-
- dwConnSize=sizeof(RASCONN);
- dwConnItems=0;
- paConn=(RASCONN*)mir_alloc(dwConnSize);
- dwErrCode=ERROR_NOT_ENOUGH_MEMORY;
- if (paConn != NULL) {
- for(dwRetries=5; dwRetries != 0; dwRetries--) { /* prevent infinite loop (rare) */
- ZeroMemory(paConn, dwConnSize);
- paConn[0].dwSize = sizeof(RASCONN);
- dwErrCode = pfnRasEnumConnections(paConn,&dwConnSize,&dwConnItems);
- if (dwErrCode != ERROR_BUFFER_TOO_SMALL) break;
- paConnBuf=(RASCONN*)mir_realloc(paConn,dwConnSize);
- if (paConnBuf != NULL) {
- mir_free(paConn);
- paConn = NULL;
- dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
- break;
- }
- paConn=paConnBuf;
+ RASCONN *paConn;
+ RASCONN *paConnBuf;
+ DWORD dwConnSize,dwConnItems,dwRetries;
+ RASCONNSTATUS rcs;
+ DWORD dw,dwLastTickCount;
+
+ dwConnSize=sizeof(RASCONN);
+ dwConnItems=0;
+ paConn=(RASCONN*)mir_alloc(dwConnSize);
+ dwErrCode=ERROR_NOT_ENOUGH_MEMORY;
+ if (paConn != NULL) {
+ for(dwRetries=5; dwRetries != 0; dwRetries--) { /* prevent infinite loop (rare) */
+ ZeroMemory(paConn, dwConnSize);
+ paConn[0].dwSize = sizeof(RASCONN);
+ dwErrCode = RasEnumConnections(paConn, &dwConnSize, &dwConnItems);
+ if (dwErrCode != ERROR_BUFFER_TOO_SMALL) break;
+ paConnBuf=(RASCONN*)mir_realloc(paConn,dwConnSize);
+ if (paConnBuf != NULL) {
+ mir_free(paConn);
+ paConn = NULL;
+ dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
+ break;
+ }
+ paConn=paConnBuf;
+ }
+ if (dwErrCode==ERROR_SUCCESS || dwErrCode==ERROR_BUFFER_TOO_SMALL) {
+ for(dw=0;dw<dwConnItems;++dw) {
+ if (dwErrCode) {
+ if (RasHangUp(paConn[dw].hrasconn))
+ paConn[dw].hrasconn=NULL; /* do not wait for on error */
}
- if (dwErrCode==ERROR_SUCCESS || dwErrCode==ERROR_BUFFER_TOO_SMALL) {
- for(dw=0;dw<dwConnItems;++dw) {
- if (dwErrCode) {
- if (pfnRasHangUp(paConn[dw].hrasconn))
- paConn[dw].hrasconn=NULL; /* do not wait for on error */
- }
- else {
- dwErrCode=pfnRasHangUp(paConn[dw].hrasconn);
- if (!dwErrCode) paConn[dw].hrasconn=NULL; /* do not wait for on error */
- }
- }
- /* RAS does not allow to quit directly after HangUp (see docs) */
- dwLastTickCount = GetTickCount();
- ZeroMemory(&rcs,sizeof(RASCONNSTATUS));
- rcs.dwSize = sizeof(RASCONNSTATUS);
- for(dw=0; dw < dwConnItems; ++dw) {
- if (paConn[dw].hrasconn != NULL) {
- while(pfnRasGetConnectStatus(paConn[dw].hrasconn, &rcs) != ERROR_INVALID_HANDLE) {
- Sleep(0); /* give rest of time silce to other threads with equal priority */
- /* infinite loop protection (3000ms defined in docs) */
- dwRetries = GetTickCount();
- if (dwRetries - dwLastTickCount>3000)
- break; /* wraparound works */
- }
- }
+ else {
+ dwErrCode = RasHangUp(paConn[dw].hrasconn);
+ if (!dwErrCode) paConn[dw].hrasconn=NULL; /* do not wait for on error */
+ }
+ }
+ /* RAS does not allow to quit directly after HangUp (see docs) */
+ dwLastTickCount = GetTickCount();
+ ZeroMemory(&rcs,sizeof(RASCONNSTATUS));
+ rcs.dwSize = sizeof(RASCONNSTATUS);
+ for(dw=0; dw < dwConnItems; ++dw) {
+ if (paConn[dw].hrasconn != NULL) {
+ while(RasGetConnectStatus(paConn[dw].hrasconn, &rcs) != ERROR_INVALID_HANDLE) {
+ Sleep(0); /* give rest of time silce to other threads with equal priority */
+ /* infinite loop protection (3000ms defined in docs) */
+ dwRetries = GetTickCount();
+ if (dwRetries - dwLastTickCount>3000)
+ break; /* wraparound works */
}
}
- mir_free(paConn); /* does NULL check */
}
}
- else dwErrCode = GetLastError();
- FreeLibrary(hRasApiDLL);
+ mir_free(paConn); /* does NULL check */
}
- else dwErrCode = GetLastError();
}
/* set Miranda to offline again, to remain offline with reconnection plugins */
ShutdownNow(SDSDT_SETMIRANDAOFFLINE);