From 2cf824fd2efaec5fa0125fdde5fd513dd906d844 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Wed, 25 Sep 2013 19:25:38 +0000 Subject: plugins cleanup git-svn-id: http://svn.miranda-ng.org/main/trunk@6233 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/AutoShutdown/shutdown_10.vcxproj | 8 +- plugins/AutoShutdown/shutdown_11.vcxproj | 8 +- plugins/AutoShutdown/src/common.h | 2 + plugins/AutoShutdown/src/shutdownsvc.cpp | 121 +++++++++++++------------------ 4 files changed, 60 insertions(+), 79 deletions(-) (limited to 'plugins/AutoShutdown') 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 @@ Windows $(IntDir)$(TargetName).lib 0x11070000 - comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies) + comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies) false $(ProfileDir)..\..\bin10\lib @@ -122,7 +122,7 @@ Windows $(IntDir)$(TargetName).lib 0x11070000 - comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies) + comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies) false $(ProfileDir)..\..\bin10\lib @@ -155,7 +155,7 @@ true false $(ProfileDir)..\..\bin10\lib - comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies) + comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies) /PDBALTPATH:%_PDB% @@ -183,7 +183,7 @@ Windows $(IntDir)$(TargetName).lib 0x11070000 - comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies) + comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies) true true false 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 @@ Windows $(IntDir)$(TargetName).lib 0x11070000 - comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies) + comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies) false $(ProfileDir)..\..\bin11\lib false @@ -127,7 +127,7 @@ Windows $(IntDir)$(TargetName).lib 0x11070000 - comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies) + comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies) false $(ProfileDir)..\..\bin11\lib @@ -160,7 +160,7 @@ true false $(ProfileDir)..\..\bin11\lib - comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies) + comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies) @@ -187,7 +187,7 @@ Windows $(IntDir)$(TargetName).lib 0x11070000 - comctl32.lib;UxTheme.lib;Shlwapi.lib;%(AdditionalDependencies) + comctl32.lib;UxTheme.lib;Shlwapi.lib;PowrProf.lib;Rasapi32.lib;%(AdditionalDependencies) true true false 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 #include #include +#include +#include /* 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;dw3000) - 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); -- cgit v1.2.3