summaryrefslogtreecommitdiff
path: root/plugins/AutoShutdown/src
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2013-09-25 19:25:38 +0000
committerKirill Volinsky <mataes2007@gmail.com>2013-09-25 19:25:38 +0000
commit2cf824fd2efaec5fa0125fdde5fd513dd906d844 (patch)
treeaadae8304f8cf90c06c73ca49180c62faeef539b /plugins/AutoShutdown/src
parenta01f62f394fc01e3c6ed89924be804d2438787e5 (diff)
plugins cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@6233 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/AutoShutdown/src')
-rw-r--r--plugins/AutoShutdown/src/common.h2
-rw-r--r--plugins/AutoShutdown/src/shutdownsvc.cpp121
2 files changed, 52 insertions, 71 deletions
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);