diff options
author | George Hazan <george.hazan@gmail.com> | 2013-09-25 13:50:57 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-09-25 13:50:57 +0000 |
commit | 125264843b0e1f8afccc85ea30c329f0366eb716 (patch) | |
tree | d29170f7259bfec7410bb082e44b1d670b8134b8 /plugins/AutoShutdown | |
parent | e4b8e9d9704a986c71565ef723cc8de208d97740 (diff) |
- custom screen saver detection code removed
- code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@6230 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/AutoShutdown')
-rw-r--r-- | plugins/AutoShutdown/src/cpuusage.cpp | 44 | ||||
-rw-r--r-- | plugins/AutoShutdown/src/frame.cpp | 132 | ||||
-rw-r--r-- | plugins/AutoShutdown/src/main.cpp | 4 | ||||
-rw-r--r-- | plugins/AutoShutdown/src/options.cpp | 118 | ||||
-rw-r--r-- | plugins/AutoShutdown/src/settingsdlg.cpp | 108 | ||||
-rw-r--r-- | plugins/AutoShutdown/src/shutdownsvc.cpp | 607 | ||||
-rw-r--r-- | plugins/AutoShutdown/src/utils.cpp | 50 | ||||
-rw-r--r-- | plugins/AutoShutdown/src/watcher.cpp | 182 |
8 files changed, 634 insertions, 611 deletions
diff --git a/plugins/AutoShutdown/src/cpuusage.cpp b/plugins/AutoShutdown/src/cpuusage.cpp index 8ab1fa91c0..cc4a3fac15 100644 --- a/plugins/AutoShutdown/src/cpuusage.cpp +++ b/plugins/AutoShutdown/src/cpuusage.cpp @@ -31,12 +31,12 @@ static BOOL WinNT_PerfStatsSwitch(TCHAR *pszServiceName,BOOL fDisable) DWORD dwData,dwDataSize;
BOOL fSwitched=FALSE;
/* Win2000+ */
- if(!RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("System\\CurrentControlSet\\Services"),0,KEY_QUERY_VALUE|KEY_SET_VALUE,&hKeyServices)) {
- if(!RegOpenKeyEx(hKeyServices,pszServiceName,0,KEY_QUERY_VALUE|KEY_SET_VALUE,&hKeyService)) {
- if(!RegOpenKeyEx(hKeyService,_T("Performance"),0,KEY_QUERY_VALUE|KEY_SET_VALUE,&hKeyPerf)) {
+ if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("System\\CurrentControlSet\\Services"),0,KEY_QUERY_VALUE|KEY_SET_VALUE,&hKeyServices)) {
+ if (!RegOpenKeyEx(hKeyServices,pszServiceName,0,KEY_QUERY_VALUE|KEY_SET_VALUE,&hKeyService)) {
+ if (!RegOpenKeyEx(hKeyService,_T("Performance"),0,KEY_QUERY_VALUE|KEY_SET_VALUE,&hKeyPerf)) {
dwDataSize=sizeof(DWORD);
- if(!RegQueryValueEx(hKeyPerf,_T("Disable Performance Counters"),NULL,NULL,(BYTE*)&dwData,&dwDataSize))
- if((dwData!=0)!=fDisable)
+ if (!RegQueryValueEx(hKeyPerf,_T("Disable Performance Counters"),NULL,NULL,(BYTE*)&dwData,&dwDataSize))
+ if ((dwData != 0) != fDisable)
fSwitched=!RegSetValueEx(hKeyPerf,_T("Disable Performance Counters"),0,REG_DWORD,(BYTE*)&fDisable,dwDataSize);
RegCloseKey(hKeyPerf);
}
@@ -58,7 +58,7 @@ struct CpuUsageThreadParams { static BOOL CallBackAndWait(struct CpuUsageThreadParams *param,BYTE nCpuUsage)
{
- if(param->hFirstEvent!=NULL) {
+ if (param->hFirstEvent != NULL) {
/* return value for PollCpuUsage() */
*param->pidThread=GetCurrentThreadId();
SetEvent(param->hFirstEvent);
@@ -66,7 +66,7 @@ static BOOL CallBackAndWait(struct CpuUsageThreadParams *param,BYTE nCpuUsage) /* lower priority after first call */
SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_IDLE);
}
- if(!param->pfnDataAvailProc(nCpuUsage,param->lParam)) return FALSE;
+ if (!param->pfnDataAvailProc(nCpuUsage,param->lParam)) return FALSE;
SleepEx(param->dwDelayMillis,TRUE);
return !Miranda_Terminated();
}
@@ -102,25 +102,25 @@ static void WinNT_PollThread(void *vparam) res=RegQueryValueExW(HKEY_PERFORMANCE_DATA,wszValueName,NULL,NULL,(BYTE*)pPerfData,&dwBufferSize);
while(!pBuffer || res==ERROR_MORE_DATA) {
pBuffer=(BYTE*)mir_realloc(pPerfData,dwBufferSize+=256);
- if(!pBuffer) break;
+ if (!pBuffer) break;
pPerfData=(PERF_DATA_BLOCK*)pBuffer;
res=RegQueryValueExW(HKEY_PERFORMANCE_DATA,wszValueName,NULL,NULL,pBuffer,&dwBufferSize);
}
- if(res!=ERROR_SUCCESS) break;
+ if (res != ERROR_SUCCESS) break;
/* find object in data */
fFound=FALSE;
/* first object */
pPerfObj=(PERF_OBJECT_TYPE*)((BYTE*)pPerfData+pPerfData->HeaderLength);
for(dwCount=0;dwCount<pPerfData->NumObjectTypes;++dwCount) {
- if(pPerfObj->ObjectNameTitleIndex==dwObjectId) {
+ if (pPerfObj->ObjectNameTitleIndex==dwObjectId) {
/* find counter in object data */
/* first counter */
pPerfCounter=(PERF_COUNTER_DEFINITION*)((BYTE*)pPerfObj+pPerfObj->HeaderLength);
for(dwCount=0;dwCount<(pPerfObj->NumCounters);++dwCount) {
- if(pPerfCounter->CounterNameTitleIndex==dwCounterId) {
+ if (pPerfCounter->CounterNameTitleIndex==dwCounterId) {
/* find instance in counter data */
- if(pPerfObj->NumInstances==PERF_NO_INSTANCES) {
+ if (pPerfObj->NumInstances==PERF_NO_INSTANCES) {
pPerfCounterBlock=(PERF_COUNTER_BLOCK*)((BYTE*)pPerfObj+pPerfObj->DefinitionLength);
liCurrentCounterValue=*(LARGE_INTEGER*)((BYTE*)pPerfCounterBlock+pPerfCounter->CounterOffset);
fFound=TRUE;
@@ -130,7 +130,7 @@ static void WinNT_PollThread(void *vparam) pPerfInstance=(PERF_INSTANCE_DEFINITION*)((BYTE*)pPerfObj+pPerfObj->DefinitionLength);
for(lCount=0;lCount<(pPerfObj->NumInstances);++lCount) {
pPerfCounterBlock=(PERF_COUNTER_BLOCK*)((BYTE*)pPerfInstance+pPerfInstance->ByteLength);
- if(!lstrcmpiW(pwszInstanceName,(WCHAR*)((BYTE*)pPerfInstance+pPerfInstance->NameOffset)) || !pwszInstanceName) {
+ if (!lstrcmpiW(pwszInstanceName,(WCHAR*)((BYTE*)pPerfInstance+pPerfInstance->NameOffset)) || !pwszInstanceName) {
liCurrentCounterValue=*(LARGE_INTEGER*)((BYTE*)pPerfCounterBlock+pPerfCounter->CounterOffset);
fFound=TRUE;
break;
@@ -149,14 +149,14 @@ static void WinNT_PollThread(void *vparam) /* next object */
pPerfObj=(PERF_OBJECT_TYPE*)((BYTE*)pPerfObj+pPerfObj->TotalByteLength);
}
- if(!fFound) break;
+ if (!fFound) break;
/* calc val from data, we need two samplings
* counter type: PERF_100NSEC_TIMER_INV
* calc: time base=100Ns, value=100*(1-(data_diff)/(100NsTime_diff)) */
- if(!fIsFirst) {
+ if (!fIsFirst) {
nCpuUsage=(BYTE)((1.0-(Li2Double(liCurrentCounterValue)-Li2Double(liPrevCounterValue))/(Li2Double(pPerfData->PerfTime100nSec)-Li2Double(liPrevPerfTime100nSec)))*100.0+0.5);
- if(!CallBackAndWait(param,nCpuUsage)) break;
+ if (!CallBackAndWait(param,nCpuUsage)) break;
}
else fIsFirst=FALSE;
/* store current sampling for next */
@@ -165,11 +165,11 @@ static void WinNT_PollThread(void *vparam) }
/* uninit */
- if(pPerfData) mir_free(pPerfData);
- if(fSwitched) WinNT_PerfStatsSwitch(_T("PerfOS"),TRUE);
+ if (pPerfData) mir_free(pPerfData);
+ if (fSwitched) WinNT_PerfStatsSwitch(_T("PerfOS"),TRUE);
/* return error for PollCpuUsage() if never succeeded */
- if(param->hFirstEvent!=NULL) SetEvent(param->hFirstEvent);
+ if (param->hFirstEvent != NULL) SetEvent(param->hFirstEvent);
mir_free(param);
}
@@ -184,18 +184,18 @@ DWORD PollCpuUsage(CPUUSAGEAVAILPROC pfnDataAvailProc,LPARAM lParam,DWORD dwDela /* init params */
param=(struct CpuUsageThreadParams*)mir_alloc(sizeof(struct CpuUsageThreadParams));
- if(param==NULL) return FALSE;
+ if (param==NULL) return FALSE;
param->dwDelayMillis=dwDelayMillis;
param->pfnDataAvailProc=pfnDataAvailProc;
param->lParam=lParam;
param->pidThread=&idThread;
param->hFirstEvent=hFirstEvent=CreateEvent(NULL,FALSE,FALSE,NULL);
- if(hFirstEvent==NULL) {
+ if (hFirstEvent==NULL) {
mir_free(param);
return 0;
}
/* start thread */
- if((int)mir_forkthread(WinNT_PollThread, param) != -1)
+ if ((int)mir_forkthread(WinNT_PollThread, param) != -1)
WaitForSingleObject(hFirstEvent,INFINITE); /* wait for first success */
else
mir_free(param); /* thread not started */
diff --git a/plugins/AutoShutdown/src/frame.cpp b/plugins/AutoShutdown/src/frame.cpp index 04b0a10422..9c0e8ff9fd 100644 --- a/plugins/AutoShutdown/src/frame.cpp +++ b/plugins/AutoShutdown/src/frame.cpp @@ -51,7 +51,7 @@ static LOGFONT* GetDefaultFont(LOGFONT *lf) NONCLIENTMETRICS ncm;
ZeroMemory(&ncm,sizeof(ncm));
ncm.cbSize=sizeof(ncm);
- if(SystemParametersInfo(SPI_GETNONCLIENTMETRICS,ncm.cbSize,&ncm,0)) {
+ if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,ncm.cbSize,&ncm,0)) {
*lf=ncm.lfStatusFont;
return lf;
}
@@ -63,7 +63,7 @@ static HICON SetFrameTitleIcon(WORD hFrame,HICON hNewIcon) HICON hPrevIcon;
hPrevIcon=(HICON)CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS,MAKEWPARAM(FO_ICON,hFrame),0);
CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS,MAKEWPARAM(FO_ICON,hFrame),(LPARAM)hNewIcon);
- if((int)hPrevIcon==-1) return (HICON)NULL;
+ if ((int)hPrevIcon==-1) return (HICON)NULL;
return hPrevIcon;
}
@@ -123,7 +123,7 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA case WM_NCCREATE: /* init window data */
dat=(struct CountdownFrameWndData*)mir_calloc(sizeof(*dat));
SetWindowLongPtr(hwndFrame, GWLP_USERDATA, (LONG)dat);
- if(dat==NULL) return FALSE; /* creation failed */
+ if (dat==NULL) return FALSE; /* creation failed */
dat->fTimeFlags=*(WORD*)((CREATESTRUCT*)lParam)->lpCreateParams;
dat->flags=FWPDF_COUNTDOWNINVALID;
break;
@@ -151,7 +151,7 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA NULL,
params->hInstance,
NULL);
- if(dat->hwndProgress==NULL) return -1; /* creation failed, calls WM_DESTROY */
+ if (dat->hwndProgress==NULL) return -1; /* creation failed, calls WM_DESTROY */
SendMessage(dat->hwndProgress,PBM_SETSTEP,(WPARAM)1,0);
mir_subclassWindow(dat->hwndProgress, ProgressBarSubclassProc);
dat->hwndDesc=CreateWindowEx(WS_EX_NOPARENTNOTIFY,
@@ -178,7 +178,7 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA NULL,
params->hInstance,
NULL);
- if(dat->hwndTime==NULL) return -1; /* creation failed, calls WM_DESTROY */
+ if (dat->hwndTime==NULL) return -1; /* creation failed, calls WM_DESTROY */
/* create tooltips */
TTTOOLINFO ti;
dat->hwndToolTip=CreateWindowEx(WS_EX_TOPMOST,
@@ -191,7 +191,7 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA NULL,
params->hInstance,
NULL);
- if(dat->hwndToolTip!=NULL) {
+ if (dat->hwndToolTip != NULL) {
SetWindowPos(dat->hwndToolTip,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
ZeroMemory(&ti,sizeof(ti));
ti.cbSize=sizeof(ti);
@@ -203,11 +203,11 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA ti.uFlags&=~TTF_TRANSPARENT;
ti.uId=(UINT)dat->hwndProgress;
SendMessage(dat->hwndToolTip,TTM_ADDTOOL,0,(LPARAM)&ti);
- if(dat->hwndDesc!=NULL) {
+ if (dat->hwndDesc != NULL) {
ti.uId=(UINT)dat->hwndDesc;
SendMessage(dat->hwndToolTip,TTM_ADDTOOL,0,(LPARAM)&ti);
}
- if(dat->hwndIcon!=NULL) {
+ if (dat->hwndIcon != NULL) {
ti.uId=(UINT)dat->hwndIcon;
SendMessage(dat->hwndToolTip,TTM_ADDTOOL,0,(LPARAM)&ti);
}
@@ -221,24 +221,24 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA SendMessage(hwndFrame,M_REFRESH_ICONS,0,0);
SendMessage(hwndFrame,M_SET_COUNTDOWN,0,0);
SendMessage(hwndFrame,M_UPDATE_COUNTDOWN,0,0);
- if(!SetTimer(hwndFrame,1,1000,NULL)) return -1; /* creation failed, calls WM_DESTROY */
+ if (!SetTimer(hwndFrame,1,1000,NULL)) return -1; /* creation failed, calls WM_DESTROY */
return 0;
}
case WM_DESTROY:
{
- if(dat==NULL) return 0;
+ if (dat==NULL) return 0;
UnhookEvent(dat->hHookColorsChanged);
UnhookEvent(dat->hHookFontsChanged);
UnhookEvent(dat->hHookIconsChanged);
/* other childs are destroyed automatically */
- if(dat->hwndToolTip!=NULL) DestroyWindow(dat->hwndToolTip);
+ if (dat->hwndToolTip != NULL) DestroyWindow(dat->hwndToolTip);
HICON hIcon=(HICON)SendMessage(dat->hwndIcon,STM_SETIMAGE,IMAGE_ICON,0);
break;
}
case WM_NCDESTROY:
- if(dat==NULL) return 0;
- if(dat->hFont!=NULL) DeleteObject(dat->hFont);
- if(dat->hbrBackground!=NULL) DeleteObject(dat->hbrBackground);
+ if (dat==NULL) return 0;
+ if (dat->hFont != NULL) DeleteObject(dat->hFont);
+ if (dat->hbrBackground != NULL) DeleteObject(dat->hbrBackground);
mir_free(dat);
SetWindowLongPtr(hwndFrame, GWLP_USERDATA, (LONG)NULL);
break;
@@ -256,7 +256,7 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA height=rc.bottom-(GetSystemMetrics(SM_CYICON)/2)-5;
hdwp=DeferWindowPos(hdwp,dat->hwndProgress,NULL,0,0,width,height,SWP_NOMOVE|defflg);
/* desc */
- if(dat->hwndDesc!=NULL) hdwp=DeferWindowPos(hdwp,dat->hwndDesc,NULL,GetSystemMetrics(SM_CXICON)+5,5+height,0,0,SWP_NOSIZE|defflg);
+ if (dat->hwndDesc != NULL) hdwp=DeferWindowPos(hdwp,dat->hwndDesc,NULL,GetSystemMetrics(SM_CXICON)+5,5+height,0,0,SWP_NOSIZE|defflg);
/* time */
hdwp=DeferWindowPos(hdwp,dat->hwndTime,NULL,GetSystemMetrics(SM_CXICON)+85,5+height,width-80,(GetSystemMetrics(SM_CXICON)/2),defflg);
EndDeferWindowPos(hdwp);
@@ -266,11 +266,11 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA case M_REFRESH_COLORS:
{
COLORREF clrBar;
- if(FontService_GetColor(_T("Automatic Shutdown"),_T("Progress Bar"),&clrBar))
+ if (FontService_GetColor(_T("Automatic Shutdown"),_T("Progress Bar"),&clrBar))
clrBar=GetDefaultColor(FRAMEELEMENT_BAR);
- if(FontService_GetColor(_T("Automatic Shutdown"),_T("Background"),&dat->clrBackground))
+ if (FontService_GetColor(_T("Automatic Shutdown"),_T("Background"),&dat->clrBackground))
dat->clrBackground=GetDefaultColor(FRAMEELEMENT_BKGRND);
- if(dat->hbrBackground!=NULL) DeleteObject(dat->hbrBackground);
+ if (dat->hbrBackground != NULL) DeleteObject(dat->hbrBackground);
dat->hbrBackground=CreateSolidBrush(dat->clrBackground);
SendMessage(dat->hwndProgress,PBM_SETBARCOLOR,0,(LPARAM)clrBar);
SendMessage(dat->hwndProgress,PBM_SETBKCOLOR,0,(LPARAM)dat->clrBackground);
@@ -282,18 +282,18 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA case M_REFRESH_FONTS:
{
LOGFONT lf;
- if(!FontService_GetFont(_T("Automatic Shutdown"),_T("Countdown on Frame"),&dat->clrText,&lf)) {
- if(dat->hFont!=NULL) DeleteObject(dat->hFont);
+ if (!FontService_GetFont(_T("Automatic Shutdown"),_T("Countdown on Frame"),&dat->clrText,&lf)) {
+ if (dat->hFont != NULL) DeleteObject(dat->hFont);
dat->hFont=CreateFontIndirect(&lf);
}
else {
dat->clrText=GetDefaultColor(FRAMEELEMENT_TEXT);
- if(GetDefaultFont(&lf)!=NULL) {
- if(dat->hFont!=NULL) DeleteObject(dat->hFont);
+ if (GetDefaultFont(&lf) != NULL) {
+ if (dat->hFont != NULL) DeleteObject(dat->hFont);
dat->hFont=CreateFontIndirect(&lf);
}
}
- if(dat->hwndDesc!=NULL)
+ if (dat->hwndDesc != NULL)
SendMessage(dat->hwndDesc,WM_SETFONT,(WPARAM)dat->hFont,FALSE);
SendMessage(dat->hwndTime,WM_SETFONT,(WPARAM)dat->hFont,FALSE);
InvalidateRect(hwndFrame,NULL,FALSE);
@@ -319,20 +319,20 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA return (BOOL)dat->hbrBackground;
case WM_ERASEBKGND:
{ RECT rc;
- if(dat->hbrBackground!=NULL && GetClientRect(hwndFrame,&rc)) {
+ if (dat->hbrBackground != NULL && GetClientRect(hwndFrame,&rc)) {
FillRect((HDC)wParam,&rc,dat->hbrBackground);
return TRUE;
}
return FALSE;
}
case M_SET_COUNTDOWN:
- if(dat->fTimeFlags&SDWTF_ST_TIME) {
+ if (dat->fTimeFlags&SDWTF_ST_TIME) {
dat->settingLastTime=(time_t)db_get_dw(NULL,"AutoShutdown","TimeStamp",SETTING_TIMESTAMP_DEFAULT);
dat->countdown=time(NULL);
- if(dat->settingLastTime>dat->countdown) dat->countdown=dat->settingLastTime-dat->countdown;
+ if (dat->settingLastTime>dat->countdown) dat->countdown=dat->settingLastTime-dat->countdown;
else dat->countdown=0;
}
- else if(dat->flags&FWPDF_COUNTDOWNINVALID) {
+ else if (dat->flags&FWPDF_COUNTDOWNINVALID) {
dat->countdown=(time_t)db_get_dw(NULL,"AutoShutdown","Countdown",SETTING_COUNTDOWN_DEFAULT);
dat->countdown*=(time_t)db_get_dw(NULL,"AutoShutdown","CountdownUnit",SETTING_COUNTDOWNUNIT_DEFAULT);
}
@@ -341,13 +341,13 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA SendMessage(dat->hwndProgress,PBM_SETRANGE32,0,(LPARAM)dat->countdown);
return 0;
case WM_TIMER:
- if(dat==NULL) return 0;
- if(dat->countdown!=0 && !(dat->flags&FWPDF_COUNTDOWNINVALID) && !(dat->flags&FWPDF_PAUSED)) {
+ if (dat==NULL) return 0;
+ if (dat->countdown != 0 && !(dat->flags&FWPDF_COUNTDOWNINVALID) && !(dat->flags&FWPDF_PAUSED)) {
dat->countdown--;
PostMessage(dat->hwndProgress,PBM_STEPIT,0,0);
}
- if(IsWindowVisible(hwndFrame)) PostMessage(hwndFrame,M_UPDATE_COUNTDOWN,0,0);
- if(dat->countdown==0) {
+ if (IsWindowVisible(hwndFrame)) PostMessage(hwndFrame,M_UPDATE_COUNTDOWN,0,0);
+ if (dat->countdown==0) {
SendMessage(hwndFrame,M_CLOSE_COUNTDOWN,0,0);
ServiceShutdown(0,TRUE);
ServiceStopWatcher(0,0);
@@ -355,25 +355,25 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA return 0;
case WM_SHOWWINDOW:
/* the text is kept unchanged while hidden */
- if((BOOL)wParam) SendMessage(hwndFrame,M_UPDATE_COUNTDOWN,0,0);
+ if ((BOOL)wParam) SendMessage(hwndFrame,M_UPDATE_COUNTDOWN,0,0);
break;
case M_UPDATE_COUNTDOWN:
- if(dat->flags&FWPDF_PAUSED && !(dat->flags&FWPDF_PAUSEDSHOWN)) {
+ if (dat->flags&FWPDF_PAUSED && !(dat->flags&FWPDF_PAUSEDSHOWN)) {
SetWindowText(dat->hwndTime,TranslateT("Paused"));
dat->flags|=FWPDF_PAUSEDSHOWN;
}
else {
TCHAR szOutput[256];
- if(dat->fTimeFlags&SDWTF_ST_TIME)
+ if (dat->fTimeFlags&SDWTF_ST_TIME)
GetFormatedDateTime(szOutput,SIZEOF(szOutput),dat->settingLastTime,TRUE);
else GetFormatedCountdown(szOutput,SIZEOF(szOutput),dat->countdown);
SetWindowText(dat->hwndTime,szOutput);
PostMessage(hwndFrame,M_CHECK_CLIPPED,0,0);
/* update tooltip text (if shown) */
- if(dat->hwndToolTip!=NULL && !(dat->flags&FWPDF_PAUSED)) {
+ if (dat->hwndToolTip != NULL && !(dat->flags&FWPDF_PAUSED)) {
TTTOOLINFO ti;
ti.cbSize=sizeof(ti);
- if(SendMessage(dat->hwndToolTip,TTM_GETCURRENTTOOL,0,(LPARAM)&ti) && (HWND)ti.uId!=dat->hwndIcon)
+ if (SendMessage(dat->hwndToolTip,TTM_GETCURRENTTOOL,0,(LPARAM)&ti) && (HWND)ti.uId != dat->hwndIcon)
SendMessage(dat->hwndToolTip,TTM_UPDATE,0,0);
} else dat->flags&=~FWPDF_PAUSEDSHOWN;
}
@@ -390,7 +390,7 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA SendMessage(dat->hwndProgress,PBM_SETMARQUEE,TRUE,10); /* marquee for rest of time */
return 0;
case M_PAUSE_COUNTDOWN:
- if(dat->flags&FWPDF_PAUSED) {
+ if (dat->flags&FWPDF_PAUSED) {
/* unpause */
dat->flags&=~(FWPDF_PAUSED|FWPDF_PAUSEDSHOWN);
SendMessage(hwndFrame,M_SET_COUNTDOWN,0,0);
@@ -406,17 +406,17 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA case WM_CONTEXTMENU:
{ HMENU hContextMenu;
POINT pt;
- if(dat->flags&FWPDF_COUNTDOWNINVALID) return 0;
+ if (dat->flags&FWPDF_COUNTDOWNINVALID) return 0;
POINTSTOPOINT(pt,MAKEPOINTS(lParam));
- if(pt.x==-1 && pt.y==-1) { /* invoked by keyboard */
+ if (pt.x==-1 && pt.y==-1) { /* invoked by keyboard */
RECT rc;
/* position in middle above rect */
- if(!GetWindowRect(hwndFrame, &rc)) return 0;
+ if (!GetWindowRect(hwndFrame, &rc)) return 0;
pt.x=rc.left+((int)(rc.right-rc.left)/2);
pt.y=rc.top+((int)(rc.bottom-rc.top)/2);
}
hContextMenu=CreatePopupMenu();
- if(hContextMenu!=NULL) {
+ if (hContextMenu != NULL) {
AppendMenu(hContextMenu,MF_STRING,MENUITEM_PAUSECOUNTDOWN,(dat->flags&FWPDF_PAUSED)?TranslateT("&Unpause Countdown"):TranslateT("&Pause Countdown"));
SetMenuDefaultItem(hContextMenu,MENUITEM_PAUSECOUNTDOWN,FALSE);
AppendMenu(hContextMenu,MF_STRING,MENUITEM_STOPCOUNTDOWN,TranslateT("&Cancel Countdown"));
@@ -426,14 +426,14 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA return 0;
}
case WM_LBUTTONDBLCLK:
- if(!(dat->flags&FWPDF_COUNTDOWNINVALID))
+ if (!(dat->flags&FWPDF_COUNTDOWNINVALID))
SendMessage(hwndFrame,M_PAUSE_COUNTDOWN,0,0);
return 0;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case MENUITEM_STOPCOUNTDOWN:
/* close only countdown window when other watcher types running */
- if(dat->fTimeFlags&~(SDWTF_SPECIFICTIME|SDWTF_ST_MASK))
+ if (dat->fTimeFlags&~(SDWTF_SPECIFICTIME|SDWTF_ST_MASK))
CloseCountdownFrame(); /* something else is running */
else ServiceStopWatcher(0,0); /* calls CloseCountdownFrame() */
return 0;
@@ -449,16 +449,16 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA HFONT hFontPrev=NULL;
TCHAR szOutput[256];
dat->flags&=~FWPDF_TIMEISCLIPPED;
- if(GetWindowText(dat->hwndTime,szOutput,SIZEOF(szOutput)-1))
- if(GetClientRect(dat->hwndTime,&rc)) {
+ if (GetWindowText(dat->hwndTime,szOutput,SIZEOF(szOutput)-1))
+ if (GetClientRect(dat->hwndTime,&rc)) {
hdc=GetDC(dat->hwndTime);
- if(hdc!=NULL) {
- if(dat->hFont!=NULL)
+ if (hdc != NULL) {
+ if (dat->hFont != NULL)
hFontPrev = (HFONT)SelectObject(hdc,dat->hFont);
- if(GetTextExtentPoint32(hdc,szOutput,lstrlen(szOutput),&size))
- if(size.cx>=(rc.right-rc.left))
+ if (GetTextExtentPoint32(hdc,szOutput,lstrlen(szOutput),&size))
+ if (size.cx>=(rc.right-rc.left))
dat->flags&=FWPDF_TIMEISCLIPPED;
- if(dat->hFont!=NULL)
+ if (dat->hFont != NULL)
SelectObject(hdc,hFontPrev);
ReleaseDC(dat->hwndTime,hdc);
}
@@ -466,12 +466,12 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA return 0;
}
case WM_NOTIFY:
- if(((NMHDR*)lParam)->hwndFrom==dat->hwndToolTip)
+ if (((NMHDR*)lParam)->hwndFrom==dat->hwndToolTip)
switch(((NMHDR*)lParam)->code) {
case TTN_SHOW: /* 'in-place' tooltip on dat->hwndTime */
- if(dat->flags&FWPDF_TIMEISCLIPPED && (HWND)wParam==dat->hwndTime) {
+ if (dat->flags&FWPDF_TIMEISCLIPPED && (HWND)wParam==dat->hwndTime) {
RECT rc;
- if(GetWindowRect(dat->hwndTime,&rc)) {
+ if (GetWindowRect(dat->hwndTime,&rc)) {
SetWindowLongPtr(dat->hwndToolTip, GWL_STYLE, GetWindowLongPtr(dat->hwndToolTip, GWL_STYLE) | TTS_NOANIMATE);
SetWindowLongPtr(dat->hwndToolTip, GWL_EXSTYLE, GetWindowLongPtr(dat->hwndToolTip, GWL_EXSTYLE) | WS_EX_TRANSPARENT);
SendMessage(dat->hwndToolTip,TTM_ADJUSTRECT,TRUE,(LPARAM)&rc);
@@ -489,15 +489,15 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARA return 0;
case TTN_NEEDTEXT:
{ NMTTDISPINFO *ttdi=(NMTTDISPINFO*)lParam;
- if(dat->flags&FWPDF_TIMEISCLIPPED && (HWND)wParam==dat->hwndTime) {
- if(GetWindowText(dat->hwndTime,ttdi->szText,SIZEOF(ttdi->szText)-1))
+ if (dat->flags&FWPDF_TIMEISCLIPPED && (HWND)wParam==dat->hwndTime) {
+ if (GetWindowText(dat->hwndTime,ttdi->szText,SIZEOF(ttdi->szText)-1))
ttdi->lpszText=ttdi->szText;
}
- else if((HWND)wParam==dat->hwndIcon)
+ else if ((HWND)wParam==dat->hwndIcon)
ttdi->lpszText=TranslateT("Automatic Shutdown");
else {
TCHAR szTime[SIZEOF(ttdi->szText)];
- if(dat->fTimeFlags&SDWTF_ST_TIME)
+ if (dat->fTimeFlags&SDWTF_ST_TIME)
GetFormatedDateTime(szTime,SIZEOF(szTime),dat->settingLastTime,FALSE);
else GetFormatedCountdown(szTime,SIZEOF(szTime),dat->countdown);
mir_sntprintf(ttdi->szText,SIZEOF(ttdi->szText),_T("%s %s"),(dat->fTimeFlags&SDWTF_ST_TIME)?TranslateT("Shutdown at:"):TranslateT("Time left:"),szTime);
@@ -526,9 +526,9 @@ void ShowCountdownFrame(WORD fTimeFlags) NULL,
hInst,
&fTimeFlags);
- if(hwndCountdownFrame==NULL) return;
+ if (hwndCountdownFrame==NULL) return;
- if(ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) {
+ if (ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) {
CLISTFrame clf = { sizeof(clf) };
clf.hIcon=Skin_GetIcon("AutoShutdown_Active"); /* CListFrames does not make a copy */
clf.align=alBottom;
@@ -538,7 +538,7 @@ void ShowCountdownFrame(WORD fTimeFlags) clf.TBname=Translate("Automatic Shutdown");
clf.hWnd=hwndCountdownFrame;
hFrame=(WORD)CallService(MS_CLIST_FRAMES_ADDFRAME,(WPARAM)&clf,0);
- if(hFrame) {
+ if (hFrame) {
ShowWindow(hwndCountdownFrame,SW_SHOW);
CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS,MAKEWPARAM(FO_TBTIPNAME,hFrame),(LPARAM)clf.name);
/* HACKS TO FIX CLUI FRAMES:
@@ -548,7 +548,7 @@ void ShowCountdownFrame(WORD fTimeFlags) /* workaround #2: drawing glitch after adding a frame (frame positioned wrongly when hidden) */
CallService(MS_CLIST_FRAMES_UPDATEFRAME,hFrame,FU_FMPOS|FU_FMREDRAW);
/* workaround #3: MS_CLIST_FRAMES_SETFRAMEOPTIONS does cause redrawing problems */
- if(!(CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS,MAKEWPARAM(FO_FLAGS,hFrame),0)&F_VISIBLE))
+ if (!(CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS,MAKEWPARAM(FO_FLAGS,hFrame),0)&F_VISIBLE))
CallService(MS_CLIST_FRAMES_SHFRAME,hFrame,0);
/* workaround #4: MS_CLIST_FRAMES_SHFRAME does cause redrawing problems when frame was hidden */
RedrawWindow(hwndCountdownFrame,NULL,NULL,RDW_INVALIDATE|RDW_ALLCHILDREN|RDW_ERASE);
@@ -560,9 +560,9 @@ void ShowCountdownFrame(WORD fTimeFlags) void CloseCountdownFrame(void)
{
- if(hwndCountdownFrame!=NULL) {
+ if (hwndCountdownFrame != NULL) {
SendMessage(hwndCountdownFrame,M_CLOSE_COUNTDOWN,0,0);
- if(hFrame) {
+ if (hFrame) {
/* HACKS TO FIX CLUIFrames:
* workaround #6: MS_CLIST_FRAMES_REMOVEFRAME does not finish with
* destroy cycle (clist_modern, clist_nicer crashes) */
@@ -584,14 +584,14 @@ void CloseCountdownFrame(void) static int FrameModulesLoaded(WPARAM wParam,LPARAM lParam)
{
- if(ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) {
+ if (ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) {
LOGFONT lf;
/* built-in font module is not available before this hook */
COLORREF clr = GetDefaultColor(FRAMEELEMENT_TEXT);
FontService_RegisterFont("AutoShutdown","CountdownFont",LPGENT("Automatic Shutdown"),LPGENT("Countdown on Frame"),LPGENT("Automatic Shutdown"),LPGENT("Background"),0,FALSE,GetDefaultFont(&lf),clr);
clr=GetDefaultColor(FRAMEELEMENT_BKGRND);
FontService_RegisterColor("AutoShutdown","BkgColor",LPGENT("Automatic Shutdown"),LPGENT("Background"),clr);
- if( !IsThemeActive()) {
+ if ( !IsThemeActive()) {
/* progressbar color can only be changed with classic theme */
clr=GetDefaultColor(FRAMEELEMENT_BAR);
FontService_RegisterColor("AutoShutdown","ProgressColor",TranslateT("Automatic Shutdown"),TranslateT("Progress Bar"),clr);
@@ -610,7 +610,7 @@ int InitFrame(void) wcx.hInstance =hInst;
wcx.hCursor =(HCURSOR)LoadImage(NULL,IDC_ARROW,IMAGE_CURSOR,0,0,LR_SHARED);
wcx.lpszClassName =COUNTDOWNFRAME_CLASS;
- if(!RegisterClassEx(&wcx)) return 1;
+ if (!RegisterClassEx(&wcx)) return 1;
hwndCountdownFrame=NULL;
hHookModulesLoaded=HookEvent(ME_SYSTEM_MODULESLOADED,FrameModulesLoaded);
diff --git a/plugins/AutoShutdown/src/main.cpp b/plugins/AutoShutdown/src/main.cpp index 636fc3e0fd..5341f7d7d0 100644 --- a/plugins/AutoShutdown/src/main.cpp +++ b/plugins/AutoShutdown/src/main.cpp @@ -74,9 +74,9 @@ extern "C" __declspec(dllexport) int Load(void) INITCOMMONCONTROLSEX icc;
icc.dwSize=sizeof(icc);
icc.dwICC=ICC_DATE_CLASSES|ICC_UPDOWN_CLASS|ICC_PROGRESS_CLASS;
- if(!InitCommonControlsEx(&icc)) return 1;
+ if (!InitCommonControlsEx(&icc)) return 1;
- if(InitFrame()) return 1; /* before icons */
+ if (InitFrame()) return 1; /* before icons */
/* shared */
Icon_Register(hInst, "Automatic Shutdown", iconList, SIZEOF(iconList));
diff --git a/plugins/AutoShutdown/src/options.cpp b/plugins/AutoShutdown/src/options.cpp index 2c3ce593df..4cadbe61c4 100644 --- a/plugins/AutoShutdown/src/options.cpp +++ b/plugins/AutoShutdown/src/options.cpp @@ -34,35 +34,39 @@ static HANDLE hHookModulesLoaded; static INT_PTR CALLBACK ShutdownOptDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- { WORD setting=db_get_w(NULL,"AutoShutdown","ConfirmDlgCountdown",SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT);
- if(setting<3) setting=SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT;
- SendDlgItemMessage(hwndDlg,IDC_SPIN_CONFIRMDLGCOUNTDOWN,UDM_SETRANGE,0,MAKELPARAM(999,3));
- SendDlgItemMessage(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN,EM_SETLIMITTEXT,3,0);
- SendDlgItemMessage(hwndDlg,IDC_SPIN_CONFIRMDLGCOUNTDOWN,UDM_SETPOS,0,MAKELPARAM(setting,0));
- SetDlgItemInt(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN,setting,FALSE);
- }
- CheckDlgButton(hwndDlg,IDC_CHECK_SMARTOFFLINECHECK,db_get_b(NULL,"AutoShutdown","SmartOfflineCheck",SETTING_SMARTOFFLINECHECK_DEFAULT)!=0);
- CheckDlgButton(hwndDlg,IDC_CHECK_REMEMBERONRESTART,db_get_b(NULL,"AutoShutdown","RememberOnRestart",SETTING_REMEMBERONRESTART_DEFAULT)!=0);
- CheckDlgButton(hwndDlg,IDC_CHECK_SHOWCONFIRMDLG,db_get_b(NULL,"AutoShutdown","ShowConfirmDlg",SETTING_SHOWCONFIRMDLG_DEFAULT)!=0);
- { BOOL enabled=ServiceIsTypeEnabled(SDSDT_SHUTDOWN,0);
- if(enabled) {
- if(ServiceExists(MS_SYSINFO_HDDTEMP)) {
- EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_HDDOVERHEAT),TRUE);
- CheckDlgButton(hwndDlg,IDC_CHECK_HDDOVERHEAT,db_get_b(NULL,"AutoShutdown","HddOverheatShutdown",SETTING_HDDOVERHEATSHUTDOWN_DEFAULT)!=0);
- }
- if(ServiceExists(MS_WEATHER_UPDATE)) {
- EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_WEATHER),TRUE);
- CheckDlgButton(hwndDlg,IDC_CHECK_WEATHER,db_get_b(NULL,"AutoShutdown","WeatherShutdown",SETTING_WEATHERSHUTDOWN_DEFAULT)!=0);
- }
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+ {
+ WORD setting=db_get_w(NULL,"AutoShutdown","ConfirmDlgCountdown",SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT);
+ if (setting<3) setting=SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT;
+ SendDlgItemMessage(hwndDlg,IDC_SPIN_CONFIRMDLGCOUNTDOWN,UDM_SETRANGE,0,MAKELPARAM(999,3));
+ SendDlgItemMessage(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN,EM_SETLIMITTEXT,3,0);
+ SendDlgItemMessage(hwndDlg,IDC_SPIN_CONFIRMDLGCOUNTDOWN,UDM_SETPOS,0,MAKELPARAM(setting,0));
+ SetDlgItemInt(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN,setting,FALSE);
+ }
+ CheckDlgButton(hwndDlg,IDC_CHECK_SMARTOFFLINECHECK,db_get_b(NULL,"AutoShutdown","SmartOfflineCheck",SETTING_SMARTOFFLINECHECK_DEFAULT) != 0);
+ CheckDlgButton(hwndDlg,IDC_CHECK_REMEMBERONRESTART,db_get_b(NULL,"AutoShutdown","RememberOnRestart",SETTING_REMEMBERONRESTART_DEFAULT) != 0);
+ CheckDlgButton(hwndDlg,IDC_CHECK_SHOWCONFIRMDLG,db_get_b(NULL,"AutoShutdown","ShowConfirmDlg",SETTING_SHOWCONFIRMDLG_DEFAULT) != 0);
+ {
+ BOOL enabled = ServiceIsTypeEnabled(SDSDT_SHUTDOWN,0);
+ if (enabled) {
+ if (ServiceExists(MS_SYSINFO_HDDTEMP)) {
+ EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_HDDOVERHEAT),TRUE);
+ CheckDlgButton(hwndDlg,IDC_CHECK_HDDOVERHEAT,db_get_b(NULL,"AutoShutdown","HddOverheatShutdown",SETTING_HDDOVERHEATSHUTDOWN_DEFAULT) != 0);
+ }
+ if (ServiceExists(MS_WEATHER_UPDATE)) {
+ EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_WEATHER),TRUE);
+ CheckDlgButton(hwndDlg,IDC_CHECK_WEATHER,db_get_b(NULL,"AutoShutdown","WeatherShutdown",SETTING_WEATHERSHUTDOWN_DEFAULT) != 0);
}
}
- SendMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0);
- return TRUE; /* default focus */
- case M_ENABLE_SUBCTLS:
- { BOOL checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_SHOWCONFIRMDLG)!=0;
- if(checked!=IsWindowEnabled(GetDlgItem(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN))) {
+ }
+ SendMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0);
+ return TRUE; /* default focus */
+
+ case M_ENABLE_SUBCTLS:
+ {
+ BOOL checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_SHOWCONFIRMDLG) != 0;
+ if (checked != IsWindowEnabled(GetDlgItem(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN))) {
EnableWindow(GetDlgItem(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN),checked);
EnableWindow(GetDlgItem(hwndDlg,IDC_SPIN_CONFIRMDLGCOUNTDOWN),checked);
EnableWindow(GetDlgItem(hwndDlg,IDC_TEXT_COUNTDOWNSTARTS),checked);
@@ -70,35 +74,37 @@ static INT_PTR CALLBACK ShutdownOptDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,L }
return TRUE;
}
- case WM_COMMAND:
- switch(LOWORD(wParam)) {
- case IDC_EDIT_CONFIRMDLGCOUNTDOWN:
- if(HIWORD(wParam)==EN_KILLFOCUS)
- if((int)GetDlgItemInt(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN,NULL,TRUE)<3) {
- SendDlgItemMessage(hwndDlg,IDC_SPIN_CONFIRMDLGCOUNTDOWN,UDM_SETPOS,0,MAKELPARAM(3,0));
- SetDlgItemInt(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN,3,FALSE);
- }
- if(HIWORD(wParam)!=EN_CHANGE || (HWND)lParam!=GetFocus())
- return TRUE; /* no apply */
- break;
- }
- PostMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0);
- PostMessage(GetParent(hwndDlg),PSM_CHANGED,0,0); /* enable apply */
- return FALSE;
- case WM_NOTIFY:
- switch(((NMHDR*)lParam)->code) {
- case PSN_APPLY:
- db_set_b(NULL,"AutoShutdown","ShowConfirmDlg",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SHOWCONFIRMDLG)!=0));
- db_set_w(NULL,"AutoShutdown","ConfirmDlgCountdown",(WORD)GetDlgItemInt(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN,NULL,FALSE));
- db_set_b(NULL,"AutoShutdown","RememberOnRestart",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_REMEMBERONRESTART)!=0));
- db_set_b(NULL,"AutoShutdown","SmartOfflineCheck",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SMARTOFFLINECHECK)!=0));
- if(IsWindowEnabled(GetDlgItem(hwndDlg,IDC_CHECK_WEATHER)))
- db_set_b(NULL,"AutoShutdown","WeatherShutdown",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_WEATHER)!=0));
- if(IsWindowEnabled(GetDlgItem(hwndDlg,IDC_CHECK_HDDOVERHEAT)))
- db_set_b(NULL,"AutoShutdown","HddOverheatShutdown",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_HDDOVERHEAT)!=0));
- return TRUE;
- }
- break;
+
+ case WM_COMMAND:
+ switch(LOWORD(wParam)) {
+ case IDC_EDIT_CONFIRMDLGCOUNTDOWN:
+ if (HIWORD(wParam)==EN_KILLFOCUS)
+ if ((int)GetDlgItemInt(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN,NULL,TRUE)<3) {
+ SendDlgItemMessage(hwndDlg,IDC_SPIN_CONFIRMDLGCOUNTDOWN,UDM_SETPOS,0,MAKELPARAM(3,0));
+ SetDlgItemInt(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN,3,FALSE);
+ }
+ if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())
+ return TRUE; /* no apply */
+ break;
+ }
+ PostMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0);
+ PostMessage(GetParent(hwndDlg),PSM_CHANGED,0,0); /* enable apply */
+ return FALSE;
+
+ case WM_NOTIFY:
+ switch(((NMHDR*)lParam)->code) {
+ case PSN_APPLY:
+ db_set_b(NULL,"AutoShutdown","ShowConfirmDlg",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SHOWCONFIRMDLG) != 0));
+ db_set_w(NULL,"AutoShutdown","ConfirmDlgCountdown",(WORD)GetDlgItemInt(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN,NULL,FALSE));
+ db_set_b(NULL,"AutoShutdown","RememberOnRestart",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_REMEMBERONRESTART) != 0));
+ db_set_b(NULL,"AutoShutdown","SmartOfflineCheck",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SMARTOFFLINECHECK) != 0));
+ if (IsWindowEnabled(GetDlgItem(hwndDlg,IDC_CHECK_WEATHER)))
+ db_set_b(NULL,"AutoShutdown","WeatherShutdown",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_WEATHER) != 0));
+ if (IsWindowEnabled(GetDlgItem(hwndDlg,IDC_CHECK_HDDOVERHEAT)))
+ db_set_b(NULL,"AutoShutdown","HddOverheatShutdown",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_HDDOVERHEAT) != 0));
+ return TRUE;
+ }
+ break;
}
return FALSE;
}
diff --git a/plugins/AutoShutdown/src/settingsdlg.cpp b/plugins/AutoShutdown/src/settingsdlg.cpp index 6e527eac22..f5a31ace20 100644 --- a/plugins/AutoShutdown/src/settingsdlg.cpp +++ b/plugins/AutoShutdown/src/settingsdlg.cpp @@ -36,14 +36,14 @@ const TCHAR *unitNames[]={LPGENT("Second(s)"), LPGENT("Minute(s)"), LPGENT("Hour static void EnableDlgItem(HWND hwndDlg,int idCtrl,BOOL fEnable)
{
hwndDlg=GetDlgItem(hwndDlg,idCtrl);
- if(hwndDlg!=NULL && IsWindowEnabled(hwndDlg)!=fEnable)
+ if (hwndDlg != NULL && IsWindowEnabled(hwndDlg) != fEnable)
EnableWindow(hwndDlg,fEnable);
}
static BOOL CALLBACK DisplayCpuUsageProc(BYTE nCpuUsage,LPARAM lParam)
{
/* dialog closed? */
- if(!IsWindow((HWND)lParam)) return FALSE; /* stop poll thread */
+ if (!IsWindow((HWND)lParam)) return FALSE; /* stop poll thread */
TCHAR str[64];
mir_sntprintf(str,SIZEOF(str),TranslateT("(current: %u%%)"),nCpuUsage);
SetWindowText((HWND)lParam,str);
@@ -54,9 +54,9 @@ static bool AnyProtoHasCaps(DWORD caps1) {
int nProtoCount;
PROTOACCOUNT **protos;
- if(!ProtoEnumAccounts(&nProtoCount, &protos))
+ if (!ProtoEnumAccounts(&nProtoCount, &protos))
for(int i=0;i<nProtoCount;++i)
- if(CallProtoService(protos[i]->szModuleName,PS_GETCAPS,(WPARAM)PFLAGNUM_1,0)&caps1)
+ if (CallProtoService(protos[i]->szModuleName,PS_GETCAPS,(WPARAM)PFLAGNUM_1,0)&caps1)
return true; /* CALLSERVICE_NOTFOUND also handled gracefully */
return false;
}
@@ -77,7 +77,7 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR {
HFONT hBoldFont;
LOGFONT lf;
- if(GetObject((HFONT)SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_GETFONT,0,0),sizeof(lf),&lf)) {
+ if (GetObject((HFONT)SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_GETFONT,0,0),sizeof(lf),&lf)) {
lf.lfWeight=FW_BOLD;
hBoldFont=CreateFontIndirect(&lf);
} else hBoldFont=NULL;
@@ -87,17 +87,17 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR {
WORD watcherType=db_get_w(NULL,"AutoShutdown","WatcherFlags",SETTING_WATCHERFLAGS_DEFAULT);
CheckRadioButton(hwndDlg,IDC_RADIO_STTIME,IDC_RADIO_STCOUNTDOWN,(watcherType&SDWTF_ST_TIME)?IDC_RADIO_STTIME:IDC_RADIO_STCOUNTDOWN);
- CheckDlgButton(hwndDlg,IDC_CHECK_SPECIFICTIME,(watcherType&SDWTF_SPECIFICTIME)!=0);
- CheckDlgButton(hwndDlg,IDC_CHECK_MESSAGE,(watcherType&SDWTF_MESSAGE)!=0);
- CheckDlgButton(hwndDlg,IDC_CHECK_FILETRANSFER,(watcherType&SDWTF_FILETRANSFER)!=0);
- CheckDlgButton(hwndDlg,IDC_CHECK_IDLE,(watcherType&SDWTF_IDLE)!=0);
- CheckDlgButton(hwndDlg,IDC_CHECK_STATUS,(watcherType&SDWTF_STATUS)!=0);
- CheckDlgButton(hwndDlg,IDC_CHECK_CPUUSAGE,(watcherType&SDWTF_CPUUSAGE)!=0);
+ CheckDlgButton(hwndDlg,IDC_CHECK_SPECIFICTIME,(watcherType&SDWTF_SPECIFICTIME) != 0);
+ CheckDlgButton(hwndDlg,IDC_CHECK_MESSAGE,(watcherType&SDWTF_MESSAGE) != 0);
+ CheckDlgButton(hwndDlg,IDC_CHECK_FILETRANSFER,(watcherType&SDWTF_FILETRANSFER) != 0);
+ CheckDlgButton(hwndDlg,IDC_CHECK_IDLE,(watcherType&SDWTF_IDLE) != 0);
+ CheckDlgButton(hwndDlg,IDC_CHECK_STATUS,(watcherType&SDWTF_STATUS) != 0);
+ CheckDlgButton(hwndDlg,IDC_CHECK_CPUUSAGE,(watcherType&SDWTF_CPUUSAGE) != 0);
}
/* read-in countdown val */
{
SYSTEMTIME st;
- if(!TimeStampToSystemTime((time_t)db_get_dw(NULL,"AutoShutdown","TimeStamp",SETTING_TIMESTAMP_DEFAULT),&st))
+ if (!TimeStampToSystemTime((time_t)db_get_dw(NULL,"AutoShutdown","TimeStamp",SETTING_TIMESTAMP_DEFAULT),&st))
GetLocalTime(&st);
DateTime_SetSystemtime(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),GDT_VALID,&st);
DateTime_SetSystemtime(GetDlgItem(hwndDlg,IDC_DATE_TIMESTAMP),GDT_VALID,&st);
@@ -105,7 +105,7 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR }
{
DWORD setting=db_get_dw(NULL,"AutoShutdown","Countdown",SETTING_COUNTDOWN_DEFAULT);
- if(setting<1) setting=SETTING_COUNTDOWN_DEFAULT;
+ if (setting<1) setting=SETTING_COUNTDOWN_DEFAULT;
SendDlgItemMessage(hwndDlg,IDC_SPIN_COUNTDOWN,UDM_SETRANGE,0,MAKELPARAM(UD_MAXVAL,1));
SendDlgItemMessage(hwndDlg,IDC_EDIT_COUNTDOWN,EM_SETLIMITTEXT,(WPARAM)10,0);
SendDlgItemMessage(hwndDlg,IDC_SPIN_COUNTDOWN,UDM_SETPOS,0,MAKELPARAM(setting,0));
@@ -118,19 +118,19 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR SendMessage(hwndCombo,CB_INITSTORAGE,SIZEOF(unitNames),SIZEOF(unitNames)*16); /* approx. */
for(int i=0;i<SIZEOF(unitNames);++i) {
int index=SendMessage(hwndCombo,CB_ADDSTRING,0,(LPARAM)TranslateTS(unitNames[i]));
- if(index!=LB_ERR) {
+ if (index != LB_ERR) {
SendMessage(hwndCombo,CB_SETITEMDATA,index,(LPARAM)unitValues[i]);
- if(i==0 || unitValues[i]==lastUnit) SendMessage(hwndCombo,CB_SETCURSEL,index,0);
+ if (i==0 || unitValues[i]==lastUnit) SendMessage(hwndCombo,CB_SETCURSEL,index,0);
}
}
}
{
DBVARIANT dbv;
- if(!db_get_ts(NULL,"AutoShutdown","Message",&dbv)) {
+ if (!db_get_ts(NULL,"AutoShutdown","Message",&dbv)) {
SetDlgItemText(hwndDlg,IDC_EDIT_MESSAGE,dbv.ptszVal);
mir_free(dbv.ptszVal);
}
- if(ServiceExists(MS_AUTOREPLACER_ADDWINHANDLE))
+ if (ServiceExists(MS_AUTOREPLACER_ADDWINHANDLE))
CallService(MS_AUTOREPLACER_ADDWINHANDLE,0,(LPARAM)GetDlgItem(hwndDlg,IDC_EDIT_MESSAGE));
}
/* cpuusage threshold */
@@ -149,29 +149,29 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR SendMessage(hwndCombo,CB_SETEXTENDEDUI,TRUE,0);
SendMessage(hwndCombo,CB_INITSTORAGE,SDSDT_MAX,SDSDT_MAX*32);
for(BYTE shutdownType=1;shutdownType<=SDSDT_MAX;++shutdownType)
- if(ServiceIsTypeEnabled(shutdownType,0)) {
+ if (ServiceIsTypeEnabled(shutdownType,0)) {
TCHAR *pszText=(TCHAR*)ServiceGetTypeDescription(shutdownType,GSTDF_TCHAR); /* never fails */
int index=SendMessage(hwndCombo,CB_ADDSTRING,0,(LPARAM)pszText);
- if(index!=LB_ERR) {
+ if (index != LB_ERR) {
SendMessage(hwndCombo,CB_SETITEMDATA,index,(LPARAM)shutdownType);
- if(shutdownType==1 || shutdownType==lastShutdownType) SendMessage(hwndCombo,CB_SETCURSEL,(WPARAM)index,0);
+ if (shutdownType==1 || shutdownType==lastShutdownType) SendMessage(hwndCombo,CB_SETCURSEL,(WPARAM)index,0);
}
}
SendMessage(hwndDlg,M_UPDATE_SHUTDOWNDESC,0,(LPARAM)hwndCombo);
}
/* check if proto is installed that supports instant messages and check if a message dialog plugin is installed */
- if(!AnyProtoHasCaps(PF1_IMRECV) || !ServiceExists(MS_MSG_SENDMESSAGE)) { /* no srmessage present? */
+ if (!AnyProtoHasCaps(PF1_IMRECV) || !ServiceExists(MS_MSG_SENDMESSAGE)) { /* no srmessage present? */
CheckDlgButton(hwndDlg,IDC_CHECK_MESSAGE,FALSE);
EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_MESSAGE),FALSE);
EnableWindow(GetDlgItem(hwndDlg,IDC_EDIT_MESSAGE),FALSE);
}
/* check if proto is installed that supports file transfers and check if a file transfer dialog is available */
- if((!AnyProtoHasCaps(PF1_FILESEND) && !AnyProtoHasCaps(PF1_FILERECV)) || !ServiceExists(MS_FILE_SENDFILE)) { /* no srfile present? */
+ if ((!AnyProtoHasCaps(PF1_FILESEND) && !AnyProtoHasCaps(PF1_FILERECV)) || !ServiceExists(MS_FILE_SENDFILE)) { /* no srfile present? */
CheckDlgButton(hwndDlg,IDC_CHECK_FILETRANSFER,FALSE);
EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_FILETRANSFER),FALSE);
}
/* check if cpu usage can be detected */
- if(!PollCpuUsage(DisplayCpuUsageProc,(LPARAM)GetDlgItem(hwndDlg,IDC_TEXT_CURRENTCPU),1800)) {
+ if (!PollCpuUsage(DisplayCpuUsageProc,(LPARAM)GetDlgItem(hwndDlg,IDC_TEXT_CURRENTCPU),1800)) {
CheckDlgButton(hwndDlg,IDC_CHECK_CPUUSAGE,FALSE);
EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_CPUUSAGE),FALSE);
}
@@ -181,13 +181,13 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR }
case WM_DESTROY:
{
- if(ServiceExists(MS_AUTOREPLACER_ADDWINHANDLE))
+ if (ServiceExists(MS_AUTOREPLACER_ADDWINHANDLE))
CallService(MS_AUTOREPLACER_REMWINHANDLE,0,(LPARAM)GetDlgItem(hwndDlg,IDC_EDIT_MESSAGE));
Utils_SaveWindowPosition(hwndDlg,NULL,"AutoShutdown","SettingsDlg_");
HICON hIcon=(HICON)SendDlgItemMessage(hwndDlg,IDC_ICON_HEADER,STM_SETIMAGE,IMAGE_ICON,0);
HFONT hFont=(HFONT)SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_GETFONT,0,0);
SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_SETFONT,0,FALSE); /* no return value */
- if(hFont!=NULL) DeleteObject(hFont);
+ if (hFont != NULL) DeleteObject(hFont);
hwndSettingsDlg=NULL;
}
return TRUE;
@@ -209,9 +209,9 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR case M_ENABLE_SUBCTLS:
{
- BOOL checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_MESSAGE)!=0;
+ BOOL checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_MESSAGE) != 0;
EnableDlgItem(hwndDlg,IDC_EDIT_MESSAGE,checked);
- checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME)!=0;
+ checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME) != 0;
EnableDlgItem(hwndDlg,IDC_RADIO_STTIME,checked);
EnableDlgItem(hwndDlg,IDC_RADIO_STCOUNTDOWN,checked);
checked=(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME) && IsDlgButtonChecked(hwndDlg,IDC_RADIO_STTIME));
@@ -221,9 +221,9 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR EnableDlgItem(hwndDlg,IDC_EDIT_COUNTDOWN,checked);
EnableDlgItem(hwndDlg,IDC_SPIN_COUNTDOWN,checked);
EnableDlgItem(hwndDlg,IDC_COMBO_COUNTDOWNUNIT,checked);
- checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_IDLE)!=0;
+ checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_IDLE) != 0;
EnableDlgItem(hwndDlg,IDC_URL_IDLE,checked);
- checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_CPUUSAGE)!=0;
+ checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_CPUUSAGE) != 0;
EnableDlgItem(hwndDlg,IDC_EDIT_CPUUSAGE,checked);
EnableDlgItem(hwndDlg,IDC_SPIN_CPUUSAGE,checked);
EnableDlgItem(hwndDlg,IDC_TEXT_PERCENT,checked);
@@ -256,16 +256,16 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR st.wMonth=stBuf.wMonth;
st.wYear=stBuf.wYear;
GetLocalTime(&stBuf);
- if(SystemTimeToTimeStamp(&st,×tamp)) {
+ if (SystemTimeToTimeStamp(&st,×tamp)) {
/* set to current date if earlier */
- if(timestamp<time(NULL)) {
+ if (timestamp<time(NULL)) {
st.wDay=stBuf.wDay;
st.wDayOfWeek=stBuf.wDayOfWeek;
st.wMonth=stBuf.wMonth;
st.wYear=stBuf.wYear;
- if(SystemTimeToTimeStamp(&st,×tamp)) {
+ if (SystemTimeToTimeStamp(&st,×tamp)) {
/* step one day up if still earlier */
- if(timestamp<time(NULL)) {
+ if (timestamp<time(NULL)) {
timestamp+=24*60*60;
TimeStampToSystemTime(timestamp,&st);
}
@@ -305,8 +305,8 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR return TRUE;
case IDC_EDIT_COUNTDOWN:
- if(HIWORD(wParam)==EN_KILLFOCUS) {
- if((int)GetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,NULL,TRUE)<1) {
+ if (HIWORD(wParam)==EN_KILLFOCUS) {
+ if ((int)GetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,NULL,TRUE)<1) {
SendDlgItemMessage(hwndDlg,IDC_SPIN_COUNTDOWN,UDM_SETPOS,0,MAKELPARAM(1,0));
SetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,1,FALSE);
}
@@ -315,10 +315,10 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR break;
case IDC_EDIT_CPUUSAGE:
- if(HIWORD(wParam)==EN_KILLFOCUS) {
+ if (HIWORD(wParam)==EN_KILLFOCUS) {
WORD val=(WORD)GetDlgItemInt(hwndDlg,IDC_EDIT_CPUUSAGE,NULL,FALSE);
- if(val<1) val=1;
- else if(val>100) val=100;
+ if (val<1) val=1;
+ else if (val>100) val=100;
SendDlgItemMessage(hwndDlg,IDC_SPIN_CPUUSAGE,UDM_SETPOS,0,MAKELPARAM(val,0));
SetDlgItemInt(hwndDlg,IDC_EDIT_CPUUSAGE,val,FALSE);
return TRUE;
@@ -337,7 +337,7 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR }
case IDC_COMBO_SHUTDOWNTYPE:
- if(HIWORD(wParam)==CBN_SELCHANGE)
+ if (HIWORD(wParam)==CBN_SELCHANGE)
SendMessage(hwndDlg,M_UPDATE_SHUTDOWNDESC,0,lParam);
return TRUE;
@@ -348,7 +348,7 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR HWND hwndEdit=GetDlgItem(hwndDlg,IDC_EDIT_MESSAGE);
int len=GetWindowTextLength(hwndEdit)+1;
TCHAR *pszText=(TCHAR*)mir_alloc(len*sizeof(TCHAR));
- if(pszText!=NULL && GetWindowText(hwndEdit,pszText,len+1)) {
+ if (pszText != NULL && GetWindowText(hwndEdit,pszText,len+1)) {
TrimString(pszText);
db_set_ts(NULL,"AutoShutdown","Message",pszText);
}
@@ -359,28 +359,28 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR SYSTEMTIME st;
time_t timestamp;
DateTime_GetSystemtime(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),&st); /* time gets synchronized */
- if(!SystemTimeToTimeStamp(&st,×tamp))
+ if (!SystemTimeToTimeStamp(&st,×tamp))
timestamp=time(NULL);
db_set_dw(NULL,"AutoShutdown","TimeStamp",(DWORD)timestamp);
}
/* shutdown type */
{
int index = SendDlgItemMessage(hwndDlg,IDC_COMBO_SHUTDOWNTYPE,CB_GETCURSEL,0,0);
- if(index!=LB_ERR) db_set_b(NULL,"AutoShutdown","ShutdownType",(BYTE)SendDlgItemMessage(hwndDlg,IDC_COMBO_SHUTDOWNTYPE,CB_GETITEMDATA,(WPARAM)index,0));
+ if (index != LB_ERR) db_set_b(NULL,"AutoShutdown","ShutdownType",(BYTE)SendDlgItemMessage(hwndDlg,IDC_COMBO_SHUTDOWNTYPE,CB_GETITEMDATA,(WPARAM)index,0));
index=SendDlgItemMessage(hwndDlg,IDC_COMBO_COUNTDOWNUNIT,CB_GETCURSEL,0,0);
- if(index!=LB_ERR) db_set_dw(NULL,"AutoShutdown","CountdownUnit",(DWORD)SendDlgItemMessage(hwndDlg,IDC_COMBO_COUNTDOWNUNIT,CB_GETITEMDATA,(WPARAM)index,0));
+ if (index != LB_ERR) db_set_dw(NULL,"AutoShutdown","CountdownUnit",(DWORD)SendDlgItemMessage(hwndDlg,IDC_COMBO_COUNTDOWNUNIT,CB_GETITEMDATA,(WPARAM)index,0));
db_set_dw(NULL,"AutoShutdown","Countdown",(DWORD)GetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,NULL,FALSE));
db_set_b(NULL,"AutoShutdown","CpuUsageThreshold",(BYTE)GetDlgItemInt(hwndDlg,IDC_EDIT_CPUUSAGE,NULL,FALSE));
}
/* watcher type */
{
WORD watcherType = (WORD)(IsDlgButtonChecked(hwndDlg,IDC_RADIO_STTIME)?SDWTF_ST_TIME:SDWTF_ST_COUNTDOWN);
- if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME)) watcherType|=SDWTF_SPECIFICTIME;
- if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_MESSAGE)) watcherType|=SDWTF_MESSAGE;
- if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_FILETRANSFER)) watcherType|=SDWTF_FILETRANSFER;
- if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_IDLE)) watcherType|=SDWTF_IDLE;
- if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_STATUS)) watcherType|=SDWTF_STATUS;
- if(IsDlgButtonChecked(hwndDlg,IDC_CHECK_CPUUSAGE)) watcherType|=SDWTF_CPUUSAGE;
+ if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME)) watcherType|=SDWTF_SPECIFICTIME;
+ if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_MESSAGE)) watcherType|=SDWTF_MESSAGE;
+ if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_FILETRANSFER)) watcherType|=SDWTF_FILETRANSFER;
+ if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_IDLE)) watcherType|=SDWTF_IDLE;
+ if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_STATUS)) watcherType|=SDWTF_STATUS;
+ if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_CPUUSAGE)) watcherType|=SDWTF_CPUUSAGE;
db_set_w(NULL,"AutoShutdown","WatcherFlags",watcherType);
ServiceStartWatcher(0,watcherType);
}
@@ -403,7 +403,7 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR static INT_PTR ServiceShowSettingsDialog(WPARAM wParam,LPARAM lParam)
{
- if(hwndSettingsDlg!=NULL) { /* already opened, bring to front */
+ if (hwndSettingsDlg != NULL) { /* already opened, bring to front */
SetForegroundWindow(hwndSettingsDlg);
return 0;
}
@@ -430,7 +430,7 @@ int ToolbarLoaded(WPARAM,LPARAM) void SetShutdownToolbarButton(bool fActive)
{
- if(hToolbarButton)
+ if (hToolbarButton)
CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hToolbarButton,fActive?TTBST_PUSHED:TTBST_RELEASED);
}
@@ -443,7 +443,7 @@ void SetShutdownMenuItem(bool fActive) /* main menu */
CLISTMENUITEM mi = { sizeof(mi) };
mi.position = 2001090000;
- if(fActive)
+ if (fActive)
{
mi.icolibItem = iconList[1].hIcolib;
mi.ptszName = LPGENT("Stop automatic &shutdown");
@@ -463,7 +463,7 @@ void SetShutdownMenuItem(bool fActive) /* tray menu */
mi.position = 899999;
- if(hTrayMenuItem != NULL) {
+ if (hTrayMenuItem != NULL) {
mi.flags |= CMIM_NAME | CMIM_ICON;
Menu_ModifyItem(hTrayMenuItem, &mi);
}
@@ -473,7 +473,7 @@ void SetShutdownMenuItem(bool fActive) static INT_PTR MenuItemCommand(WPARAM,LPARAM)
{
/* toggle between StopWatcher and ShowSettingsDdialog */
- if(ServiceIsWatcherEnabled(0,0))
+ if (ServiceIsWatcherEnabled(0,0))
ServiceStopWatcher(0,0);
else
ServiceShowSettingsDialog(0,0);
diff --git a/plugins/AutoShutdown/src/shutdownsvc.cpp b/plugins/AutoShutdown/src/shutdownsvc.cpp index c3f0a740ee..fb351ebef5 100644 --- a/plugins/AutoShutdown/src/shutdownsvc.cpp +++ b/plugins/AutoShutdown/src/shutdownsvc.cpp @@ -24,22 +24,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /* Shutdown Dialog */
static HWND hwndShutdownDlg;
extern HINSTANCE hInst;
-/* Services */
+
+/* Events */
static HANDLE hEventOkToShutdown,hEventShutdown;
-static HANDLE hServiceShutdown,hServiceIsTypeEnabled,hServiceGetTypeDesc;
/************************* Utils **************************************/
-TCHAR *desc[]={LPGENT("Miranda NG is going to be automatically closed in %u second(s)."),
- LPGENT("All Miranda NG protocols are going to be set to offline in %u second(s)."),
- LPGENT("You will be logged off automatically in %u second(s)."),
- LPGENT("The computer will automatically be restarted in %u second(s)."),
- LPGENT("The computer will automatically be set to standby mode in %u second(s)."),
- LPGENT("The computer will automatically be set to hibernate mode in %u second(s)."),
- LPGENT("The workstation will automatically get locked in %u second(s)."),
- LPGENT("All dialup connections will be closed in %u second(s)."),
- LPGENT("The computer will automatically be shut down in %u second(s).")};
-
+TCHAR *desc[] = {
+ LPGENT("Miranda NG is going to be automatically closed in %u second(s)."),
+ LPGENT("All Miranda NG protocols are going to be set to offline in %u second(s)."),
+ LPGENT("You will be logged off automatically in %u second(s)."),
+ LPGENT("The computer will automatically be restarted in %u second(s)."),
+ LPGENT("The computer will automatically be set to standby mode in %u second(s)."),
+ LPGENT("The computer will automatically be set to hibernate mode in %u second(s)."),
+ LPGENT("The workstation will automatically get locked in %u second(s)."),
+ LPGENT("All dialup connections will be closed in %u second(s)."),
+ LPGENT("The computer will automatically be shut down in %u second(s).")
+};
static BOOL WinNT_SetPrivilege(TCHAR *pszPrivName,BOOL bEnable)
{
@@ -47,10 +48,10 @@ static BOOL WinNT_SetPrivilege(TCHAR *pszPrivName,BOOL bEnable) HANDLE hToken;
TOKEN_PRIVILEGES tkp;
/* get a token for this process */
- if(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&hToken)) {
+ if (OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&hToken)) {
tkp.PrivilegeCount=1; /* one privilege is to set */
/* get the LUID for the shutdown privilege */
- if(LookupPrivilegeValue(NULL,pszPrivName,&tkp.Privileges[0].Luid)) {
+ if (LookupPrivilegeValue(NULL,pszPrivName,&tkp.Privileges[0].Luid)) {
tkp.Privileges[0].Attributes=bEnable?SE_PRIVILEGE_ENABLED:0;
/* get the shutdown privilege for this process */
bReturn=AdjustTokenPrivileges(hToken,FALSE,&tkp,0,(PTOKEN_PRIVILEGES)NULL,0);
@@ -65,19 +66,6 @@ static void BroadcastEndSession(DWORD dwRecipients,LPARAM lParam) BroadcastSystemMessage(BSF_FORCEIFHUNG,&dwRecipients,WM_ENDSESSION,TRUE,lParam);
}
-static BOOL WinNT_IsWorkStationLocked(void)
-{
- HDESK hDesk;
- TCHAR szName[8];
- DWORD cbName;
- BOOL bLocked;
- hDesk=OpenInputDesktop(0,FALSE,DESKTOP_READOBJECTS);
- if(hDesk==NULL) return TRUE;
- bLocked=(!GetUserObjectInformation(hDesk,UOI_NAME,szName,SIZEOF(szName),&cbName) || lstrcmpi(szName,_T("default"))!=0);
- CloseDesktop(hDesk);
- return bLocked;
-}
-
/************************* Workers ************************************/
static BOOL IsShutdownTypeEnabled(BYTE shutdownType)
{
@@ -86,17 +74,17 @@ static BOOL IsShutdownTypeEnabled(BYTE shutdownType) case SDSDT_HIBERNATE:
case SDSDT_STANDBY:
{ HMODULE hPowerDLL=LoadLibraryA("POWRPROF"); /* all ascii */
- if(hPowerDLL!=NULL) {
+ if (hPowerDLL != NULL) {
BOOLEAN (STDAPICALLTYPE *pfnIsPwrModeAllowed)(void);
*(PROC*)&pfnIsPwrModeAllowed=GetProcAddress(hPowerDLL,(shutdownType==SDSDT_HIBERNATE)?"IsPwrHibernateAllowed":"IsPwrSuspendAllowed");
- if(pfnIsPwrModeAllowed) bReturn=pfnIsPwrModeAllowed()!=0;
+ if (pfnIsPwrModeAllowed) bReturn=pfnIsPwrModeAllowed() != 0;
FreeLibrary(hPowerDLL);
}
}
/* test privilege */
- if(bReturn) {
+ if (bReturn) {
bReturn=WinNT_SetPrivilege(SE_SHUTDOWN_NAME,TRUE);
- if(bReturn) WinNT_SetPrivilege(SE_SHUTDOWN_NAME,FALSE);
+ if (bReturn) WinNT_SetPrivilege(SE_SHUTDOWN_NAME,FALSE);
}
break;
case SDSDT_LOGOFF:
@@ -104,10 +92,10 @@ static BOOL IsShutdownTypeEnabled(BYTE shutdownType) DWORD dwSetting,dwSize;
/* NoLogOff is BINARY on Win9x/ME and DWORD on Win2000+ */
bReturn=TRUE;
- if(RegOpenKeyEx(HKEY_CURRENT_USER,_T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"),0,KEY_QUERY_VALUE,&hKey)==ERROR_SUCCESS) {
+ if (RegOpenKeyEx(HKEY_CURRENT_USER,_T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"),0,KEY_QUERY_VALUE,&hKey)==ERROR_SUCCESS) {
dwSize=sizeof(dwSetting);
- if(RegQueryValueEx(hKey, _T("NoLogOff"), 0, NULL, (LPBYTE)&dwSetting, &dwSize) == ERROR_SUCCESS)
- if(dwSetting) bReturn=FALSE;
+ if (RegQueryValueEx(hKey, _T("NoLogOff"), 0, NULL, (LPBYTE)&dwSetting, &dwSize) == ERROR_SUCCESS)
+ if (dwSetting) bReturn=FALSE;
RegCloseKey(hKey);
}
}
@@ -118,10 +106,10 @@ static BOOL IsShutdownTypeEnabled(BYTE shutdownType) DWORD dwSize,dwSetting;
/* DisableLockWorkstation is DWORD on Win2000+ */
bReturn=TRUE;
- if(RegOpenKeyEx(HKEY_CURRENT_USER,_T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"),0,KEY_QUERY_VALUE,&hKey)==ERROR_SUCCESS) {
+ if (RegOpenKeyEx(HKEY_CURRENT_USER,_T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"),0,KEY_QUERY_VALUE,&hKey)==ERROR_SUCCESS) {
dwSize=sizeof(dwSetting);
- if(!RegQueryValueEx(hKey, _T("DisableLockWorkstation"), 0, NULL, (LPBYTE)&dwSetting, &dwSize))
- if(dwSetting)
+ if (!RegQueryValueEx(hKey, _T("DisableLockWorkstation"), 0, NULL, (LPBYTE)&dwSetting, &dwSize))
+ if (dwSetting)
bReturn=FALSE;
RegCloseKey(hKey);
}
@@ -129,7 +117,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=SearchPath(NULL,_T("RASAPI32"),_T(".DLL"),0,NULL,NULL) != 0;
break;
case SDSDT_SETMIRANDAOFFLINE:
case SDSDT_CLOSEMIRANDA:
@@ -139,7 +127,7 @@ static BOOL IsShutdownTypeEnabled(BYTE shutdownType) case SDSDT_SHUTDOWN:
/* test privileges */
bReturn=WinNT_SetPrivilege(SE_SHUTDOWN_NAME,TRUE);
- if(bReturn)
+ if (bReturn)
WinNT_SetPrivilege(SE_SHUTDOWN_NAME,FALSE);
break;
}
@@ -148,165 +136,179 @@ static BOOL IsShutdownTypeEnabled(BYTE shutdownType) static DWORD ShutdownNow(BYTE shutdownType)
{
- DWORD dwErrCode=ERROR_SUCCESS;
+ DWORD dwErrCode = ERROR_SUCCESS;
switch(shutdownType) {
- case SDSDT_CLOSEMIRANDA:
- if(!Miranda_Terminated()) {
- /* waiting for short until ready (but not too long...) */
- DWORD dwLastTickCount=GetTickCount();
- while(!CallService(MS_SYSTEM_OKTOEXIT,0,0)) {
- /* infinite loop protection (max 5 sec) */
- if(GetTickCount()-dwLastTickCount>=5000) { /* wraparound works */
- OutputDebugStringA("Timeout (5 sec)\n"); /* tell others, all ascii */
- break;
- }
- SleepEx(1000,TRUE);
- if(Miranda_Terminated()) break; /* someone else did it */
- OutputDebugStringA("Not ready to exit. Waiting...\n"); /* tell others, all ascii */
+ case SDSDT_CLOSEMIRANDA:
+ if (!Miranda_Terminated()) {
+ /* waiting for short until ready (but not too long...) */
+ DWORD dwLastTickCount=GetTickCount();
+ while(!CallService(MS_SYSTEM_OKTOEXIT,0,0)) {
+ /* infinite loop protection (max 5 sec) */
+ if (GetTickCount()-dwLastTickCount>=5000) { /* wraparound works */
+ OutputDebugStringA("Timeout (5 sec)\n"); /* tell others, all ascii */
+ break;
}
- /* shutdown service must be called from main thread anyway */
- if(!DestroyWindow((HWND)CallService(MS_CLUI_GETHWND,0,0)))
- dwErrCode=GetLastError();
+ SleepEx(1000,TRUE);
+ if (Miranda_Terminated()) break; /* someone else did it */
+ OutputDebugStringA("Not ready to exit. Waiting...\n"); /* tell others, all ascii */
}
- break;
- case SDSDT_SETMIRANDAOFFLINE:
- /* set global status mode to offline (is remembered by Miranda on exit) */
- CallService(MS_CLIST_SETSTATUSMODE,(WPARAM)ID_STATUS_OFFLINE,0);
- break;
- case SDSDT_STANDBY:
- case SDSDT_HIBERNATE:
- WinNT_SetPrivilege(SE_SHUTDOWN_NAME,TRUE);
- if(!SetSystemPowerState(shutdownType==SDSDT_STANDBY,TRUE))
+ /* shutdown service must be called from main thread anyway */
+ if (!DestroyWindow((HWND)CallService(MS_CLUI_GETHWND,0,0)))
dwErrCode=GetLastError();
- WinNT_SetPrivilege(SE_SHUTDOWN_NAME,FALSE);
- break;
- case SDSDT_LOCKWORKSTATION:
- {
- if(!WinNT_IsWorkStationLocked())
- dwErrCode=GetLastError();
- }
- break;
- case SDSDT_CLOSERASCONNECTIONS:
- 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;
+ }
+ break;
+
+ case SDSDT_SETMIRANDAOFFLINE:
+ /* set global status mode to offline (is remembered by Miranda on exit) */
+ CallService(MS_CLIST_SETSTATUSMODE,(WPARAM)ID_STATUS_OFFLINE,0);
+ break;
+
+ case SDSDT_STANDBY:
+ case SDSDT_HIBERNATE:
+ WinNT_SetPrivilege(SE_SHUTDOWN_NAME,TRUE);
+ if (!SetSystemPowerState(shutdownType == SDSDT_STANDBY, TRUE))
+ dwErrCode = GetLastError();
+ WinNT_SetPrivilege(SE_SHUTDOWN_NAME,FALSE);
+ break;
+
+ case SDSDT_LOCKWORKSTATION:
+ if ( !IsWorkstationLocked())
+ dwErrCode = GetLastError();
+ break;
+
+ case SDSDT_CLOSERASCONNECTIONS:
+ 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;
}
- if(dwErrCode==ERROR_SUCCESS || dwErrCode==ERROR_BUFFER_TOO_SMALL) {
+ paConn=paConnBuf;
+ }
+ if (dwErrCode==ERROR_SUCCESS || dwErrCode==ERROR_BUFFER_TOO_SMALL) {
for(dw=0;dw<dwConnItems;++dw) {
- if(dwErrCode) {
- if(pfnRasHangUp(paConn[dw].hrasconn))
+ if (dwErrCode) {
+ if (pfnRasHangUp(paConn[dw].hrasconn))
paConn[dw].hrasconn=NULL; /* do not wait for on error */
- } else {
+ }
+ else {
dwErrCode=pfnRasHangUp(paConn[dw].hrasconn);
- if(!dwErrCode) paConn[dw].hrasconn=NULL; /* do not wait for on error */
+ 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();
+ 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) {
+ 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 */
+ dwRetries = GetTickCount();
+ if (dwRetries - dwLastTickCount>3000)
+ break; /* wraparound works */
}
+ }
+ }
}
mir_free(paConn); /* does NULL check */
- } else dwErrCode=GetLastError();
- FreeLibrary(hRasApiDLL);
- } else dwErrCode=GetLastError();
+ }
+ }
+ else dwErrCode = GetLastError();
+ FreeLibrary(hRasApiDLL);
}
- /* set Miranda to offline again, to remain offline with reconnection plugins */
- ShutdownNow(SDSDT_SETMIRANDAOFFLINE);
+ else dwErrCode = GetLastError();
+ }
+ /* set Miranda to offline again, to remain offline with reconnection plugins */
+ ShutdownNow(SDSDT_SETMIRANDAOFFLINE);
+ break;
+
+ case SDSDT_REBOOT:
+ case SDSDT_SHUTDOWN:
+ if (GetSystemMetrics(SM_SHUTTINGDOWN)) { /* Win2000+, 0 on error */
+ dwErrCode=ERROR_SHUTDOWN_IN_PROGRESS;
break;
- case SDSDT_REBOOT:
- case SDSDT_SHUTDOWN:
- if(GetSystemMetrics(SM_SHUTTINGDOWN)) { /* Win2000+, 0 on error */
- dwErrCode=ERROR_SHUTDOWN_IN_PROGRESS;
- break;
- }
- /* WinNT4/2000/XP */
- {
- WinNT_SetPrivilege(SE_SHUTDOWN_NAME,TRUE);
+ }
+ /* WinNT4/2000/XP */
+ {
+ WinNT_SetPrivilege(SE_SHUTDOWN_NAME,TRUE);
- /* does not send out WM_ENDSESSION messages, so we do it manually to
- * give the applications the chance to save their data */
- WinNT_SetPrivilege(SE_TCB_NAME,TRUE); /* for BSM_ALLDESKTOPS */
- BroadcastEndSession(BSM_APPLICATIONS|BSM_ALLDESKTOPS,ENDSESSION_CLOSEAPP); /* app should close itself */
- WinNT_SetPrivilege(SE_TCB_NAME,FALSE);
+ /* does not send out WM_ENDSESSION messages, so we do it manually to
+ * give the applications the chance to save their data */
+ WinNT_SetPrivilege(SE_TCB_NAME,TRUE); /* for BSM_ALLDESKTOPS */
+ BroadcastEndSession(BSM_APPLICATIONS|BSM_ALLDESKTOPS,ENDSESSION_CLOSEAPP); /* app should close itself */
+ WinNT_SetPrivilege(SE_TCB_NAME,FALSE);
- if(!InitiateSystemShutdownEx(NULL,TranslateT("AutoShutdown"),0,TRUE,shutdownType==SDSDT_REBOOT,SHTDN_REASON_MAJOR_OTHER|SHTDN_REASON_MINOR_OTHER|SHTDN_REASON_FLAG_PLANNED))
- dwErrCode=GetLastError();
+ if (!InitiateSystemShutdownEx(NULL,TranslateT("AutoShutdown"),0,TRUE,shutdownType==SDSDT_REBOOT,SHTDN_REASON_MAJOR_OTHER|SHTDN_REASON_MINOR_OTHER|SHTDN_REASON_FLAG_PLANNED))
+ dwErrCode=GetLastError();
- /* cleanly close Miranda */
- if(!dwErrCode) ShutdownNow(SDSDT_CLOSEMIRANDA);
- break;
+ /* cleanly close Miranda */
+ if (!dwErrCode) ShutdownNow(SDSDT_CLOSEMIRANDA);
+ break;
+ }
+ /* fall through for Win9x */
+ case SDSDT_LOGOFF:
+ {
+ UINT flags;
+ switch(shutdownType) {
+ case SDSDT_LOGOFF: flags=EWX_LOGOFF; break;
+ case SDSDT_REBOOT: flags=EWX_REBOOT; break;
+ default: flags=EWX_SHUTDOWN|EWX_POWEROFF;
}
- /* fall through for Win9x */
- case SDSDT_LOGOFF:
- { UINT flags;
- switch(shutdownType) {
- case SDSDT_LOGOFF: flags=EWX_LOGOFF; break;
- case SDSDT_REBOOT: flags=EWX_REBOOT; break;
- default: flags=EWX_SHUTDOWN|EWX_POWEROFF;
- }
- if(shutdownType==SDSDT_LOGOFF && !WinNT_IsWorkStationLocked())
- flags|=EWX_FORCEIFHUNG; /* only considered for WM_ENDSESSION messages */
- else flags|=EWX_FORCE; /* must be used when workstation locked */
-
- if(flags&EWX_FORCE) {
- /* EWX_FORCE does not send out WM_ENDSESSION messages, so we do it
- * manually to give the applications the chance to save their data */
- BroadcastEndSession(BSM_APPLICATIONS,(shutdownType==SDSDT_LOGOFF)?ENDSESSION_LOGOFF:0);
-
- /* Windows Me/98/95 (msdn): Because of the design of the shell,
- * calling ExitWindowsEx with EWX_FORCE fails to completely log off
- * the user (the system terminates the applications and displays the
- * Enter Windows Password dialog box, however, the user's desktop remains.)
- * To log off the user forcibly, terminate the Explorer process before calling
- * ExitWindowsEx with EWX_LOGOFF and EWX_FORCE. */
- }
- if(!ExitWindowsEx(flags,SHTDN_REASON_MAJOR_OTHER|SHTDN_REASON_MINOR_OTHER|SHTDN_REASON_FLAG_PLANNED))
- dwErrCode=GetLastError();
- /* cleanly close Miranda */
- if(!dwErrCode) ShutdownNow(SDSDT_CLOSEMIRANDA);
+ if (shutdownType == SDSDT_LOGOFF && !IsWorkstationLocked())
+ flags |= EWX_FORCEIFHUNG; /* only considered for WM_ENDSESSION messages */
+ else
+ flags|= EWX_FORCE; /* must be used when workstation locked */
+
+ if (flags & EWX_FORCE) {
+ /* EWX_FORCE does not send out WM_ENDSESSION messages, so we do it
+ * manually to give the applications the chance to save their data */
+ BroadcastEndSession(BSM_APPLICATIONS,(shutdownType==SDSDT_LOGOFF)?ENDSESSION_LOGOFF:0);
+
+ /* Windows Me/98/95 (msdn): Because of the design of the shell,
+ * calling ExitWindowsEx with EWX_FORCE fails to completely log off
+ * the user (the system terminates the applications and displays the
+ * Enter Windows Password dialog box, however, the user's desktop remains.)
+ * To log off the user forcibly, terminate the Explorer process before calling
+ * ExitWindowsEx with EWX_LOGOFF and EWX_FORCE. */
}
- break;
+ if (!ExitWindowsEx(flags,SHTDN_REASON_MAJOR_OTHER|SHTDN_REASON_MINOR_OTHER|SHTDN_REASON_FLAG_PLANNED))
+ dwErrCode = GetLastError();
+ /* cleanly close Miranda */
+ if (!dwErrCode)
+ ShutdownNow(SDSDT_CLOSEMIRANDA);
+ }
+ break;
}
return dwErrCode;
}
@@ -321,40 +323,43 @@ static INT_PTR CALLBACK ShutdownDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR WORD countdown=(WORD)GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA);
switch(msg) {
- case WM_INITDIALOG:
- hwndShutdownDlg=hwndDlg;
- SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG)lParam);
- TranslateDialogDefault(hwndDlg);
-
- if(lParam==SDSDT_SHUTDOWN || lParam==SDSDT_REBOOT || lParam==SDSDT_LOGOFF)
- ShowWindow(GetDlgItem(hwndDlg,IDC_TEXT_UNSAVEDWARNING),SW_SHOW);
- SendDlgItemMessage(hwndDlg,IDC_ICON_HEADER,STM_SETIMAGE,IMAGE_ICON,(LPARAM)Skin_GetIcon("AutoShutdown_Header"));
- { HFONT hBoldFont;
- LOGFONT lf;
- if(GetObject((HFONT)SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_GETFONT,0,0),sizeof(lf),&lf)) {
- lf.lfWeight=FW_BOLD;
- hBoldFont=CreateFontIndirect(&lf);
- }
- else hBoldFont=NULL;
- SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_SETFONT,(WPARAM)hBoldFont,FALSE);
- SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA, (LONG)hBoldFont);
- }
- { WORD countdown=db_get_w(NULL,"AutoShutdown","ConfirmDlgCountdown",SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT);
- if(countdown<3) countdown=SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT;
- SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA, countdown);
- SendMessage(hwndDlg,M_UPDATE_COUNTDOWN,0,countdown);
+ case WM_INITDIALOG:
+ hwndShutdownDlg=hwndDlg;
+ SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG)lParam);
+ TranslateDialogDefault(hwndDlg);
+
+ if (lParam==SDSDT_SHUTDOWN || lParam==SDSDT_REBOOT || lParam==SDSDT_LOGOFF)
+ ShowWindow(GetDlgItem(hwndDlg,IDC_TEXT_UNSAVEDWARNING),SW_SHOW);
+ SendDlgItemMessage(hwndDlg,IDC_ICON_HEADER,STM_SETIMAGE,IMAGE_ICON,(LPARAM)Skin_GetIcon("AutoShutdown_Header"));
+ {
+ HFONT hBoldFont;
+ LOGFONT lf;
+ if (GetObject((HFONT)SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_GETFONT,0,0),sizeof(lf),&lf)) {
+ lf.lfWeight=FW_BOLD;
+ hBoldFont=CreateFontIndirect(&lf);
}
- SkinPlaySound("AutoShutdown_Countdown");
- if(!SetTimer(hwndDlg,1,1000,NULL)) PostMessage(hwndDlg,M_START_SHUTDOWN,0,0);
- Utils_RestoreWindowPositionNoSize(hwndDlg,NULL,"AutoShutdown","ConfirmDlg_");
+ else hBoldFont=NULL;
+ SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_SETFONT,(WPARAM)hBoldFont,FALSE);
+ SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA, (LONG)hBoldFont);
+ }
+ {
+ WORD countdown=db_get_w(NULL,"AutoShutdown","ConfirmDlgCountdown",SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT);
+ if (countdown<3) countdown=SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT;
+ SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA, countdown);
+ SendMessage(hwndDlg,M_UPDATE_COUNTDOWN,0,countdown);
+ }
+ SkinPlaySound("AutoShutdown_Countdown");
+ if (!SetTimer(hwndDlg,1,1000,NULL)) PostMessage(hwndDlg,M_START_SHUTDOWN,0,0);
+ Utils_RestoreWindowPositionNoSize(hwndDlg,NULL,"AutoShutdown","ConfirmDlg_");
+
+ /* disallow foreground window changes (WinMe/2000+) */
+ SetForegroundWindow(hwndDlg);
+ LockSetForegroundWindow(LSFW_LOCK);
- /* disallow foreground window changes (WinMe/2000+) */
- SetForegroundWindow(hwndDlg);
- LockSetForegroundWindow(LSFW_LOCK);
+ SendMessage(hwndDlg,WM_NEXTDLGCTL,(WPARAM)GetDlgItem(hwndDlg,IDCANCEL),TRUE);
+ return FALSE; /* focus set on cancel */
- SendMessage(hwndDlg,WM_NEXTDLGCTL,(WPARAM)GetDlgItem(hwndDlg,IDCANCEL),TRUE);
- return FALSE; /* focus set on cancel */
- case WM_DESTROY:
+ case WM_DESTROY:
{
hwndShutdownDlg=NULL;
ShowWindow(hwndDlg,SW_HIDE);
@@ -364,61 +369,66 @@ static INT_PTR CALLBACK ShutdownDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR HICON hIcon=(HICON)SendDlgItemMessage(hwndDlg,IDC_ICON_HEADER,STM_SETIMAGE,IMAGE_ICON,0);
HFONT hFont=(HFONT)SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_GETFONT,0,0);
SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_SETFONT,0,FALSE); /* no return value */
- if(hFont!=NULL) DeleteObject(hFont);
- return TRUE;
+ if (hFont != NULL) DeleteObject(hFont);
}
- case M_START_SHUTDOWN:
- if(IsWindowEnabled(GetDlgItem(hwndDlg,IDC_BUTTON_SHUTDOWNNOW))) {
- DWORD dwErrCode;
- EnableWindow(GetDlgItem(hwndDlg,IDC_BUTTON_SHUTDOWNNOW),FALSE);
- ShowWindow(hwndDlg,SW_HIDE); /* get rid of the dialog immediately */
- dwErrCode=ShutdownNow(shutdownType);
- if(dwErrCode!=ERROR_SUCCESS) {
- char *pszErr;
- pszErr=GetWinErrorDescription(dwErrCode);
- ShowInfoMessage(NIIF_ERROR,Translate("Automatic Shutdown Error"),Translate("The shutdown process failed!\nReason: %s"),(pszErr!=NULL)?pszErr:Translate("Unknown"));
- if(pszErr!=NULL) LocalFree(pszErr);
- }
- DestroyWindow(hwndDlg);
- }
- return TRUE;
- case WM_TIMER:
- if(countdown) {
- --countdown;
- SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA, countdown);
- if(countdown==27 || countdown==24 || countdown==21 || countdown==19 ||
- countdown==17 || countdown==15 || countdown==13 || countdown==11 ||
- countdown<=10)
- SkinPlaySound("AutoShutdown_Countdown");
+ return TRUE;
+
+ case M_START_SHUTDOWN:
+ if (IsWindowEnabled(GetDlgItem(hwndDlg,IDC_BUTTON_SHUTDOWNNOW))) {
+ DWORD dwErrCode;
+ EnableWindow(GetDlgItem(hwndDlg,IDC_BUTTON_SHUTDOWNNOW),FALSE);
+ ShowWindow(hwndDlg,SW_HIDE); /* get rid of the dialog immediately */
+ dwErrCode=ShutdownNow(shutdownType);
+ if (dwErrCode != ERROR_SUCCESS) {
+ char *pszErr;
+ pszErr=GetWinErrorDescription(dwErrCode);
+ ShowInfoMessage(NIIF_ERROR,Translate("Automatic Shutdown Error"),Translate("The shutdown process failed!\nReason: %s"),(pszErr != NULL)?pszErr:Translate("Unknown"));
+ if (pszErr != NULL) LocalFree(pszErr);
}
- else KillTimer(hwndDlg,wParam); /* countdown finished */
- PostMessage(hwndDlg,M_UPDATE_COUNTDOWN,0,countdown);
- return TRUE;
- case M_UPDATE_COUNTDOWN: /* lParam=(WORD)countdown */
+ DestroyWindow(hwndDlg);
+ }
+ return TRUE;
+
+ case WM_TIMER:
+ if (countdown) {
+ --countdown;
+ SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA, countdown);
+ if (countdown==27 || countdown==24 || countdown==21 || countdown==19 ||
+ countdown==17 || countdown==15 || countdown==13 || countdown==11 ||
+ countdown<=10)
+ SkinPlaySound("AutoShutdown_Countdown");
+ }
+ else KillTimer(hwndDlg,wParam); /* countdown finished */
+ PostMessage(hwndDlg,M_UPDATE_COUNTDOWN,0,countdown);
+ return TRUE;
+
+ case M_UPDATE_COUNTDOWN: /* lParam=(WORD)countdown */
{
TCHAR szText[256];
mir_sntprintf(szText,SIZEOF(szText),TranslateTS(desc[shutdownType-1]),lParam);
SetDlgItemText(hwndDlg,IDC_TEXT_HEADER,szText);
/* countdown finished */
- if(!lParam) PostMessage(hwndDlg,M_START_SHUTDOWN,0,0);
- return TRUE;
+ if (!lParam)
+ PostMessage(hwndDlg,M_START_SHUTDOWN,0,0);
}
- case WM_COMMAND:
- switch(LOWORD(wParam)) {
- case IDC_BUTTON_SHUTDOWNNOW:
- KillTimer(hwndDlg,1);
- SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA, 0);
- SendMessage(hwndDlg,M_UPDATE_COUNTDOWN,0,(LONG)0);
- PostMessage(hwndDlg,M_START_SHUTDOWN,0,0);
- return TRUE;
- case IDCANCEL: /* WM_CLOSE */
- if(countdown) {
- KillTimer(hwndDlg,1);
- DestroyWindow(hwndDlg);
- }
- return TRUE;
+ return TRUE;
+
+ case WM_COMMAND:
+ switch(LOWORD(wParam)) {
+ case IDC_BUTTON_SHUTDOWNNOW:
+ KillTimer(hwndDlg,1);
+ SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA, 0);
+ SendMessage(hwndDlg,M_UPDATE_COUNTDOWN,0,(LONG)0);
+ PostMessage(hwndDlg,M_START_SHUTDOWN,0,0);
+ return TRUE;
+ case IDCANCEL: /* WM_CLOSE */
+ if (countdown) {
+ KillTimer(hwndDlg,1);
+ DestroyWindow(hwndDlg);
}
- break;
+ return TRUE;
+ }
+ break;
}
return FALSE;
}
@@ -428,32 +438,32 @@ static INT_PTR CALLBACK ShutdownDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR INT_PTR ServiceShutdown(WPARAM wParam,LPARAM lParam)
{
/* passing 0 as wParam is only to be used internally, undocumented */
- if(!wParam) wParam=db_get_b(NULL,"AutoShutdown","ShutdownType",SETTING_SHUTDOWNTYPE_DEFAULT);
- if(!IsShutdownTypeEnabled((BYTE)wParam)) return 1; /* does shutdownType range check */
- if((BOOL)lParam && hwndShutdownDlg!=NULL) return 2;
+ if (!wParam) wParam=db_get_b(NULL,"AutoShutdown","ShutdownType",SETTING_SHUTDOWNTYPE_DEFAULT);
+ if (!IsShutdownTypeEnabled((BYTE)wParam)) return 1; /* does shutdownType range check */
+ if ((BOOL)lParam && hwndShutdownDlg != NULL) return 2;
/* ask others if allowed */
- if(NotifyEventHooks(hEventOkToShutdown,wParam,lParam)) {
+ if (NotifyEventHooks(hEventOkToShutdown,wParam,lParam)) {
OutputDebugStringA("automatic shutdown denied by event hook\n"); /* all ascii */
return 3;
}
/* tell others */
NotifyEventHooks(hEventShutdown,wParam,lParam);
/* show dialog */
- if(lParam && db_get_b(NULL,"AutoShutdown","ShowConfirmDlg",SETTING_SHOWCONFIRMDLG_DEFAULT))
- if(CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_SHUTDOWNNOW), NULL, ShutdownDlgProc, (LPARAM)(BYTE)wParam) != NULL)
+ if (lParam && db_get_b(NULL,"AutoShutdown","ShowConfirmDlg",SETTING_SHOWCONFIRMDLG_DEFAULT))
+ if (CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_SHUTDOWNNOW), NULL, ShutdownDlgProc, (LPARAM)(BYTE)wParam) != NULL)
return 0;
/* show error */
- { DWORD dwErrCode;
- dwErrCode=ShutdownNow((BYTE)wParam);
- if(dwErrCode!=ERROR_SUCCESS) {
- char *pszErr;
- pszErr=GetWinErrorDescription(dwErrCode);
- ShowInfoMessage(NIIF_ERROR,Translate("Automatic Shutdown Error"),Translate("Inititiating the shutdown process failed!\nReason: %s"),(pszErr!=NULL)?pszErr:Translate("Unknown"));
- if(pszErr!=NULL) LocalFree(pszErr);
- return 4;
- }
+
+ DWORD dwErrCode = ShutdownNow((BYTE)wParam);
+ if (dwErrCode != ERROR_SUCCESS) {
+ char *pszErr = GetWinErrorDescription(dwErrCode);
+ ShowInfoMessage(NIIF_ERROR,Translate("Automatic Shutdown Error"),Translate("Inititiating the shutdown process failed!\nReason: %s"),(pszErr != NULL)?pszErr:Translate("Unknown"));
+ if (pszErr != NULL)
+ LocalFree(pszErr);
+ return 4;
}
+
return 0;
}
@@ -462,33 +472,38 @@ INT_PTR ServiceIsTypeEnabled(WPARAM wParam,LPARAM) return IsShutdownTypeEnabled((BYTE)wParam); /* does shutdownType range check */
}
+const TCHAR *apszShort[] = {
+ LPGENT("Close Miranda NG"),LPGENT("Set Miranda NG offline"),LPGENT("Log off user"),
+ LPGENT("Restart computer"),LPGENT("Shutdown computer"),LPGENT("Standby mode"),LPGENT("Hibernate mode"),
+ LPGENT("Lock workstation"),LPGENT("Hang up dialup connections"),LPGENT("Close Miranda NG"),
+ LPGENT("Set Miranda NG offline"),LPGENT("Log off user"),LPGENT("Restart computer"),LPGENT("Shutdown computer"),
+ LPGENT("Standby mode"),LPGENT("Hibernate mode"),LPGENT("Lock workstation"),LPGENT("Hang up dialup connections")
+};
+
+const TCHAR *apszLong[] = {
+ LPGENT("Sets all Miranda NG protocols to offline and closes Miranda NG."),
+ LPGENT("Sets all Miranda NG protocols to offline."),
+ LPGENT("Logs the current Windows user off so that another user can log in."),
+ LPGENT("Shuts down Windows and then restarts Windows."),
+ LPGENT("Closes all running programs and shuts down Windows to a point at which it is safe to turn off the power."),
+ LPGENT("Saves the current Windows session in memory and sets the system to suspend mode."),
+ LPGENT("Saves the current Windows session on harddisc, so that the power can be turned off."),
+ LPGENT("Locks the computer. To unlock the computer, you must log in."),
+ LPGENT("Sets all protocols to offline and closes all RAS connections.")
+};
+
INT_PTR ServiceGetTypeDescription(WPARAM wParam,LPARAM lParam)
{
- TCHAR *pszDesc;
- const TCHAR *apszShort[]={LPGENT("Close Miranda NG"),LPGENT("Set Miranda NG offline"),LPGENT("Log off user"),
- LPGENT("Restart computer"),LPGENT("Shutdown computer"),LPGENT("Standby mode"),LPGENT("Hibernate mode"),
- LPGENT("Lock workstation"),LPGENT("Hang up dialup connections"),LPGENT("Close Miranda NG"),
- LPGENT("Set Miranda NG offline"),LPGENT("Log off user"),LPGENT("Restart computer"),LPGENT("Shutdown computer"),
- LPGENT("Standby mode"),LPGENT("Hibernate mode"),LPGENT("Lock workstation"),LPGENT("Hang up dialup connections")};
- const TCHAR *apszLong[]={LPGENT("Sets all Miranda NG protocols to offline and closes Miranda NG."),
- LPGENT("Sets all Miranda NG protocols to offline."),
- LPGENT("Logs the current Windows user off so that another user can log in."),
- LPGENT("Shuts down Windows and then restarts Windows."),
- LPGENT("Closes all running programs and shuts down Windows to a point at which it is safe to turn off the power."),
- LPGENT("Saves the current Windows session in memory and sets the system to suspend mode."),
- LPGENT("Saves the current Windows session on harddisc, so that the power can be turned off."),
- LPGENT("Locks the computer. To unlock the computer, you must log in."),
- LPGENT("Sets all protocols to offline and closes all RAS connections.")};
/* shutdownType range check */
- if(!wParam || (BYTE)wParam>SDSDT_MAX) return 0;
+ if (!wParam || (BYTE)wParam>SDSDT_MAX) return 0;
/* select description */
- pszDesc=(TCHAR*)((lParam&GSTDF_LONGDESC)?apszLong:apszShort)[wParam-1];
- if(!(lParam&GSTDF_UNTRANSLATED)) pszDesc=TranslateTS(pszDesc);
+ TCHAR *pszDesc=(TCHAR*)((lParam&GSTDF_LONGDESC)?apszLong:apszShort)[wParam-1];
+ if (!(lParam&GSTDF_UNTRANSLATED)) pszDesc=TranslateTS(pszDesc);
/* convert as needed */
- if(!(lParam&GSTDF_UNICODE)) {
+ if (!(lParam&GSTDF_UNICODE)) {
static char szConvBuf[128];
char *buf=u2a(pszDesc);
- if(buf==NULL) return 0;
+ if (buf==NULL) return 0;
lstrcpynA(szConvBuf,buf,sizeof(szConvBuf));
mir_free(buf);
return (INT_PTR)szConvBuf;
@@ -503,22 +518,24 @@ void InitShutdownSvc(void) /* Shutdown Dialog */
hwndShutdownDlg=NULL;
SkinAddNewSoundExT("AutoShutdown_Countdown",LPGENT("Alerts"),LPGENT("Automatic Shutdown Countdown"));
+
+ /* Events */
+ hEventOkToShutdown = CreateHookableEvent(ME_AUTOSHUTDOWN_OKTOSHUTDOWN);
+ hEventShutdown = CreateHookableEvent(ME_AUTOSHUTDOWN_SHUTDOWN);
+
/* Services */
- hEventOkToShutdown=CreateHookableEvent(ME_AUTOSHUTDOWN_OKTOSHUTDOWN);
- hEventShutdown=CreateHookableEvent(ME_AUTOSHUTDOWN_SHUTDOWN);
- hServiceShutdown = CreateServiceFunction(MS_AUTOSHUTDOWN_SHUTDOWN, ServiceShutdown);
- hServiceIsTypeEnabled = CreateServiceFunction(MS_AUTOSHUTDOWN_ISTYPEENABLED, ServiceIsTypeEnabled);
- hServiceGetTypeDesc = CreateServiceFunction(MS_AUTOSHUTDOWN_GETTYPEDESCRIPTION, ServiceGetTypeDescription);
+ CreateServiceFunction(MS_AUTOSHUTDOWN_SHUTDOWN, ServiceShutdown);
+ CreateServiceFunction(MS_AUTOSHUTDOWN_ISTYPEENABLED, ServiceIsTypeEnabled);
+ CreateServiceFunction(MS_AUTOSHUTDOWN_GETTYPEDESCRIPTION, ServiceGetTypeDescription);
}
void UninitShutdownSvc(void)
{
/* Shutdown Dialog */
- if(hwndShutdownDlg!=NULL) DestroyWindow(hwndShutdownDlg);
+ if (hwndShutdownDlg != NULL)
+ DestroyWindow(hwndShutdownDlg);
+
/* Services */
- DestroyServiceFunction(hServiceShutdown);
- DestroyServiceFunction(hServiceIsTypeEnabled);
- DestroyServiceFunction(hServiceGetTypeDesc);
DestroyHookableEvent(hEventOkToShutdown);
DestroyHookableEvent(hEventShutdown);
}
diff --git a/plugins/AutoShutdown/src/utils.cpp b/plugins/AutoShutdown/src/utils.cpp index b510fbd17c..75c65dc345 100644 --- a/plugins/AutoShutdown/src/utils.cpp +++ b/plugins/AutoShutdown/src/utils.cpp @@ -30,15 +30,15 @@ char* u2a(const WCHAR *pszUnicode) char *psz;
DWORD flags;
- if(pszUnicode==NULL) return NULL;
+ if (pszUnicode==NULL) return NULL;
codepage=CallService(MS_LANGPACK_GETCODEPAGE,0,0);
/* without WC_COMPOSITECHECK some characters might get out strange (see MS blog) */
cch=WideCharToMultiByte(codepage,flags=WC_COMPOSITECHECK,pszUnicode,-1,NULL,0,NULL,NULL);
- if(!cch) cch=WideCharToMultiByte(codepage,flags=0,pszUnicode,-1,NULL,0,NULL,NULL);
- if(!cch) return NULL;
+ if (!cch) cch=WideCharToMultiByte(codepage,flags=0,pszUnicode,-1,NULL,0,NULL,NULL);
+ if (!cch) return NULL;
psz=(char*)mir_alloc(cch);
- if(psz!=NULL && !WideCharToMultiByte(codepage,flags,pszUnicode,-1,psz,cch,NULL,NULL)){
+ if (psz != NULL && !WideCharToMultiByte(codepage,flags,pszUnicode,-1,psz,cch,NULL,NULL)){
mir_free(psz);
return NULL;
}
@@ -83,7 +83,7 @@ void ShowInfoMessage(BYTE flags,const char *pszTitle,const char *pszTextFmt,...) mir_vsnprintf(szText,SIZEOF(szText),pszTextFmt,va);
va_end(va);
- if(ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) {
+ if (ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) {
MIRANDASYSTRAYNOTIFY msn;
msn.cbSize=sizeof(msn);
msn.szProto=NULL;
@@ -91,12 +91,12 @@ void ShowInfoMessage(BYTE flags,const char *pszTitle,const char *pszTextFmt,...) msn.szInfo=(char*)szText;
msn.uTimeout=30000; /* max timeout */
msn.dwInfoFlags=flags;
- if(!CallServiceSync(MS_CLIST_SYSTRAY_NOTIFY,0,(LPARAM)&msn))
+ if (!CallServiceSync(MS_CLIST_SYSTRAY_NOTIFY,0,(LPARAM)&msn))
return; /* success */
}
mbp=(MSGBOXPARAMSA*)mir_calloc(sizeof(*mbp));
- if(mbp==NULL) return;
+ if (mbp==NULL) return;
mbp->cbSize=sizeof(*mbp);
mbp->lpszCaption=mir_strdup(pszTitle);
mbp->lpszText=mir_strdup(szText);
@@ -115,8 +115,8 @@ char* GetWinErrorDescription(DWORD dwLastError) {
char *buf=NULL;
DWORD flags=FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM;
- if(!FormatMessageA(flags,NULL,dwLastError,LANGIDFROMLCID((LCID)CallService(MS_LANGPACK_GETLOCALE,0,0)),(char*)&buf,0,NULL))
- if(GetLastError()==ERROR_RESOURCE_LANG_NOT_FOUND)
+ if (!FormatMessageA(flags,NULL,dwLastError,LANGIDFROMLCID((LCID)CallService(MS_LANGPACK_GETLOCALE,0,0)),(char*)&buf,0,NULL))
+ if (GetLastError()==ERROR_RESOURCE_LANG_NOT_FOUND)
FormatMessageA(flags,NULL,dwLastError,0,(char*)&buf,0,NULL);
return buf;
}
@@ -136,7 +136,7 @@ BOOL SystemTimeToTimeStamp(SYSTEMTIME *st,time_t *timestamp) ts.tm_year = st->wYear-1900; /* current year minus 1900 */
ts.tm_yday=0; /* 0-365 (Jan1=0) */
*timestamp = mktime(&ts);
- return (*timestamp!=-1);
+ return (*timestamp != -1);
}
BOOL TimeStampToSystemTime(time_t timestamp,SYSTEMTIME *st)
@@ -162,22 +162,22 @@ BOOL GetFormatedCountdown(TCHAR *pszOut,int nSize,time_t countdown) static BOOL fInited=FALSE;
static int (WINAPI *pfnGetDurationFormat)(LCID,DWORD,const SYSTEMTIME*,double,WCHAR*,WCHAR*,int);
/* Init */
- if(!fInited && IsWinVerVistaPlus()) {
+ if (!fInited && IsWinVerVistaPlus()) {
*(PROC*)&pfnGetDurationFormat=GetProcAddress(GetModuleHandleA("KERNEL32"),"GetDurationFormat");
fInited=TRUE;
}
/* WinVista */
- if(pfnGetDurationFormat!=NULL) {
+ if (pfnGetDurationFormat != NULL) {
SYSTEMTIME st;
LCID locale;
locale=(LCID)CallService(MS_LANGPACK_GETLOCALE,0,0);
- if(TimeStampToSystemTime(countdown,&st))
- if(pfnGetDurationFormat(locale,0,&st,0,NULL,pszOut,nSize))
+ if (TimeStampToSystemTime(countdown,&st))
+ if (pfnGetDurationFormat(locale,0,&st,0,NULL,pszOut,nSize))
return TRUE;
return FALSE;
} else
/* Win9x/NT/XP */
- return StrFromTimeInterval(pszOut,nSize,(countdown>(MAXDWORD/1000))?MAXDWORD:(countdown*1000),10)!=0;
+ return StrFromTimeInterval(pszOut,nSize,(countdown>(MAXDWORD/1000))?MAXDWORD:(countdown*1000),10) != 0;
return FALSE;
}
@@ -189,13 +189,13 @@ BOOL GetFormatedDateTime(TCHAR *pszOut,int nSize,time_t timestamp,BOOL fShowDate GetLocalTime(&stNow);
TimeStampToSystemTime(timestamp,&st);
/* today: no need to show the date */
- if(!fShowDateEvenToday && st.wDay==stNow.wDay && st.wMonth==stNow.wMonth && st.wYear==stNow.wYear)
- return GetTimeFormat(locale,((st.wSecond==0)?TIME_NOSECONDS:0)|TIME_FORCE24HOURFORMAT,&st,NULL,pszOut,nSize)!=0;
+ if (!fShowDateEvenToday && st.wDay==stNow.wDay && st.wMonth==stNow.wMonth && st.wYear==stNow.wYear)
+ return GetTimeFormat(locale,((st.wSecond==0)?TIME_NOSECONDS:0)|TIME_FORCE24HOURFORMAT,&st,NULL,pszOut,nSize) != 0;
/* show both date and time */
{ TCHAR szDate[128],szTime[128];
- if(!GetTimeFormat(locale,((st.wSecond==0)?TIME_NOSECONDS:0)|TIME_FORCE24HOURFORMAT,&st,NULL,szTime,SIZEOF(szTime)))
+ if (!GetTimeFormat(locale,((st.wSecond==0)?TIME_NOSECONDS:0)|TIME_FORCE24HOURFORMAT,&st,NULL,szTime,SIZEOF(szTime)))
return FALSE;
- if(!GetDateFormat(locale,DATE_SHORTDATE,&st,NULL,szDate,SIZEOF(szDate)))
+ if (!GetDateFormat(locale,DATE_SHORTDATE,&st,NULL,szDate,SIZEOF(szDate)))
return FALSE;
mir_sntprintf(pszOut,nSize,_T("%s %s"),szTime,szDate);
return TRUE;
@@ -216,16 +216,16 @@ int FontService_RegisterFont(const char *pszDbModule,const char *pszDbName,const lstrcpyn(fid.backgroundGroup,pszBackgroundGroup,SIZEOF(fid.backgroundGroup)); /* buffer safe */
lstrcpyn(fid.backgroundName,pszBackgroundName,SIZEOF(fid.backgroundName)); /* buffer safe */
fid.flags=FIDF_ALLOWREREGISTER;
- if(bAllowEffects) fid.flags|=FIDF_ALLOWEFFECTS;
+ if (bAllowEffects) fid.flags|=FIDF_ALLOWEFFECTS;
fid.order=position;
- if(plfDefault!=NULL) {
+ if (plfDefault != NULL) {
fid.flags|=FIDF_DEFAULTVALID;
fid.deffontsettings.colour=clrDefault;
fid.deffontsettings.size=(char)plfDefault->lfHeight;
- if(plfDefault->lfItalic) fid.deffontsettings.style|=DBFONTF_ITALIC;
- if(plfDefault->lfWeight!=FW_NORMAL) fid.deffontsettings.style|=DBFONTF_BOLD;
- if(plfDefault->lfUnderline) fid.deffontsettings.style|=DBFONTF_UNDERLINE;
- if(plfDefault->lfStrikeOut) fid.deffontsettings.style|=DBFONTF_STRIKEOUT;
+ if (plfDefault->lfItalic) fid.deffontsettings.style|=DBFONTF_ITALIC;
+ if (plfDefault->lfWeight != FW_NORMAL) fid.deffontsettings.style|=DBFONTF_BOLD;
+ if (plfDefault->lfUnderline) fid.deffontsettings.style|=DBFONTF_UNDERLINE;
+ if (plfDefault->lfStrikeOut) fid.deffontsettings.style|=DBFONTF_STRIKEOUT;
fid.deffontsettings.charset=plfDefault->lfCharSet;
lstrcpyn(fid.deffontsettings.szFace,plfDefault->lfFaceName,SIZEOF(fid.deffontsettings.szFace)); /* buffer safe */
}
diff --git a/plugins/AutoShutdown/src/watcher.cpp b/plugins/AutoShutdown/src/watcher.cpp index b4d9d89a05..71ea713e9a 100644 --- a/plugins/AutoShutdown/src/watcher.cpp +++ b/plugins/AutoShutdown/src/watcher.cpp @@ -48,16 +48,16 @@ static void __stdcall MainThreadMapping(void *param) HANDLE *phDoneEvent = (HANDLE*)param;
ServiceShutdown(0,TRUE); /* ensure main thread (for cpu usage shutdown) */
ServiceStopWatcher(0,0);
- if(*phDoneEvent!=NULL) SetEvent(*phDoneEvent);
+ if (*phDoneEvent != NULL) SetEvent(*phDoneEvent);
}
static void __inline ShutdownAndStopWatcher(void)
{
HANDLE hDoneEvent;
hDoneEvent=CreateEvent(NULL,FALSE,FALSE,NULL);
- if(CallFunctionAsync(MainThreadMapping, &hDoneEvent))
- if(hDoneEvent!=NULL) WaitForSingleObject(hDoneEvent,INFINITE);
- if(hDoneEvent!=NULL) CloseHandle(hDoneEvent);
+ if (CallFunctionAsync(MainThreadMapping, &hDoneEvent))
+ if (hDoneEvent != NULL) WaitForSingleObject(hDoneEvent,INFINITE);
+ if (hDoneEvent != NULL) CloseHandle(hDoneEvent);
}
/************************* Msg Shutdown *******************************/
@@ -65,28 +65,28 @@ static void __inline ShutdownAndStopWatcher(void) // ppBlob might get reallocated, must have been allocated using mir_alloc()
static TCHAR* GetMessageText(BYTE **ppBlob,DWORD *pcbBlob)
{
- DWORD cb;
(*ppBlob)[*pcbBlob]=0;
- cb=lstrlenA((char*)*ppBlob);
+ DWORD cb = lstrlenA((char*)*ppBlob);
/* use Unicode data if present */
- if(*pcbBlob>(cb+3)) {
+ if (*pcbBlob>(cb+3)) {
(*ppBlob)[*pcbBlob-1]=0;
return (WCHAR*)&(*ppBlob)[cb];
}
/* no Unicode data present, convert from ANSI */
- { int len;
- BYTE *buf;
- len=MultiByteToWideChar(CP_ACP,0,(char*)*ppBlob,-1,NULL,0);
- if(!len) return NULL;
- buf=(BYTE*)mir_realloc(*ppBlob,(*pcbBlob)+(len*sizeof(WCHAR)));
- if(buf==NULL) return NULL;
- *pcbBlob+=len*sizeof(WCHAR);
- *ppBlob=buf;
- buf=&(*ppBlob)[cb];
- MultiByteToWideChar(CP_ACP,0,(char*)*ppBlob,-1,(WCHAR*)buf,len);
- ((WCHAR*)buf)[len-1]=0;
- return (WCHAR*)buf;
- }
+ int len = MultiByteToWideChar(CP_ACP,0,(char*)*ppBlob,-1,NULL,0);
+ if (!len)
+ return NULL;
+
+ BYTE *buf=(BYTE*)mir_realloc(*ppBlob,(*pcbBlob)+(len*sizeof(WCHAR)));
+ if (buf == NULL)
+ return NULL;
+
+ *pcbBlob += len*sizeof(WCHAR);
+ *ppBlob = buf;
+ buf = &(*ppBlob)[cb];
+ MultiByteToWideChar(CP_ACP,0,(char*)*ppBlob,-1,(WCHAR*)buf,len);
+ ((WCHAR*)buf)[len-1] = 0;
+ return (WCHAR*)buf;
}
static int MsgEventAdded(WPARAM wParam,LPARAM lParam)
@@ -100,12 +100,12 @@ static int MsgEventAdded(WPARAM wParam,LPARAM lParam) if (dbe.pBlob == NULL)
return 0;
if (!db_event_get(hDbEvent, &dbe))
- if(dbe.eventType == EVENTTYPE_MESSAGE && !(dbe.flags & DBEF_SENT)) {
+ if (dbe.eventType == EVENTTYPE_MESSAGE && !(dbe.flags & DBEF_SENT)) {
DBVARIANT dbv;
- if(!db_get_ts(NULL,"AutoShutdown","Message",&dbv)) {
+ if (!db_get_ts(NULL,"AutoShutdown","Message",&dbv)) {
TrimString(dbv.ptszVal);
TCHAR *pszMsg = GetMessageText(&dbe.pBlob,&dbe.cbBlob);
- if(pszMsg!=NULL && _tcsstr(pszMsg,dbv.ptszVal)!=NULL)
+ if (pszMsg != NULL && _tcsstr(pszMsg,dbv.ptszVal) != NULL)
ShutdownAndStopWatcher(); /* msg with specified text recvd */
mir_free(dbv.ptszVal); /* does NULL check */
}
@@ -123,44 +123,44 @@ static int nTransfersCount; static int ProtoAck(WPARAM wParam,LPARAM lParam)
{
ACKDATA *ack=(ACKDATA*)lParam;
- if(ack->type==ACKTYPE_FILE)
- switch(ack->result) {
- case ACKRESULT_DATA:
- { int i;
- for(i=0;i<nTransfersCount;++i)
- if(transfers[i]==ack->hProcess)
- break; /* already in list */
- /* insert into list */
- { HANDLE *buf=(HANDLE*)mir_realloc(transfers,(nTransfersCount+1)*sizeof(HANDLE)); if(buf!=NULL) {
- transfers=buf;
- transfers[nTransfersCount]=ack->hProcess;
- ++nTransfersCount;
- }
- }
- break;
+ if (ack->type != ACKTYPE_FILE)
+ return 0;
+
+ switch(ack->result) {
+ case ACKRESULT_DATA:
+ {
+ for(int i=0; i < nTransfersCount; ++i)
+ if (transfers[i]==ack->hProcess)
+ break; /* already in list */
+ /* insert into list */
+ HANDLE *buf = (HANDLE*)mir_realloc(transfers,(nTransfersCount+1)*sizeof(HANDLE));
+ if (buf != NULL) {
+ transfers = buf;
+ transfers[nTransfersCount] = ack->hProcess;
+ ++nTransfersCount;
}
- case ACKRESULT_SUCCESS:
- case ACKRESULT_FAILED:
- case ACKRESULT_DENIED:
- { int i;
- for(i=0;i<nTransfersCount;++i)
- if(transfers[i]==ack->hProcess) {
- /* remove from list */
- HANDLE *buf;
- if(i<(nTransfersCount-1))
- MoveMemory(&transfers[i],&transfers[i+1],(nTransfersCount-i-1)*sizeof(HANDLE));
- --nTransfersCount;
- buf=(HANDLE*)mir_realloc(transfers,nTransfersCount*sizeof(HANDLE));
- if(buf!=NULL) transfers=buf;
- else if(!nTransfersCount) transfers=NULL;
- /* stop watcher */
- if(!nTransfersCount && (currentWatcherType&SDWTF_FILETRANSFER))
- ShutdownAndStopWatcher();
- break;
- }
+ break;
+ }
+ case ACKRESULT_SUCCESS:
+ case ACKRESULT_FAILED:
+ case ACKRESULT_DENIED:
+ for(int i=0;i<nTransfersCount;++i) {
+ if (transfers[i]==ack->hProcess) {
+ /* remove from list */
+ if (i<(nTransfersCount-1))
+ MoveMemory(&transfers[i],&transfers[i+1],(nTransfersCount-i-1)*sizeof(HANDLE));
+ --nTransfersCount;
+ HANDLE *buf = (HANDLE*)mir_realloc(transfers,nTransfersCount*sizeof(HANDLE));
+ if (buf != NULL) transfers=buf;
+ else if (!nTransfersCount) transfers=NULL;
+ /* stop watcher */
+ if (!nTransfersCount && (currentWatcherType&SDWTF_FILETRANSFER))
+ ShutdownAndStopWatcher();
break;
}
}
+ break;
+ }
return 0;
}
@@ -168,7 +168,7 @@ static int ProtoAck(WPARAM wParam,LPARAM lParam) static int IdleChanged(WPARAM,LPARAM lParam)
{
- if(currentWatcherType&SDWTF_IDLE && lParam&IDF_ISIDLE)
+ if (currentWatcherType&SDWTF_IDLE && lParam&IDF_ISIDLE)
ShutdownAndStopWatcher();
return 0;
}
@@ -181,12 +181,12 @@ static BOOL CheckAllContactsOffline(void) fSmartCheck=db_get_b(NULL,"AutoShutdown","SmartOfflineCheck",SETTING_SMARTOFFLINECHECK_DEFAULT);
for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
char *pszProto = GetContactProto(hContact);
- if(pszProto != NULL && CallProtoService(pszProto,PS_GETSTATUS,0,0)!=ID_STATUS_OFFLINE) {
- if(db_get_b(hContact,pszProto,"ChatRoom",0)) continue;
- if(db_get_w(hContact,pszProto,"Status",0)!=ID_STATUS_OFFLINE) {
- if(fSmartCheck) {
- if(db_get_b(hContact,"CList","Hidden",0)) continue;
- if(db_get_b(hContact,"CList","NotOnList",0)) continue;
+ if (pszProto != NULL && CallProtoService(pszProto,PS_GETSTATUS,0,0) != ID_STATUS_OFFLINE) {
+ if (db_get_b(hContact,pszProto,"ChatRoom",0)) continue;
+ if (db_get_w(hContact,pszProto,"Status",0) != ID_STATUS_OFFLINE) {
+ if (fSmartCheck) {
+ if (db_get_b(hContact,"CList","Hidden",0)) continue;
+ if (db_get_b(hContact,"CList","NotOnList",0)) continue;
}
fAllOffline=FALSE;
break;
@@ -198,12 +198,12 @@ static BOOL CheckAllContactsOffline(void) static int StatusSettingChanged(WPARAM wParam,LPARAM lParam)
{
- if(currentWatcherType&SDWTF_STATUS) {
+ if (currentWatcherType&SDWTF_STATUS) {
DBCONTACTWRITESETTING *dbcws=(DBCONTACTWRITESETTING*)lParam;
- if((HANDLE)wParam!=NULL && dbcws->value.wVal==ID_STATUS_OFFLINE && !lstrcmpA(dbcws->szSetting,"Status")) {
+ if ((HANDLE)wParam != NULL && dbcws->value.wVal==ID_STATUS_OFFLINE && !lstrcmpA(dbcws->szSetting,"Status")) {
char *pszProto = GetContactProto((HANDLE)wParam);
- if(pszProto!=NULL && !lstrcmpA(dbcws->szModule,pszProto))
- if(CheckAllContactsOffline())
+ if (pszProto != NULL && !lstrcmpA(dbcws->szModule,pszProto))
+ if (CheckAllContactsOffline())
ShutdownAndStopWatcher();
}
}
@@ -218,14 +218,14 @@ static BOOL CALLBACK CpuUsageWatcherProc(BYTE nCpuUsage,LPARAM lParam) {
static BYTE nTimesBelow=0; /* only one watcher thread */
/* terminated? */
- if(idCpuUsageThread!=GetCurrentThreadId()) {
+ if (idCpuUsageThread != GetCurrentThreadId()) {
nTimesBelow=0;
return FALSE; /* stop poll thread */
}
/* ignore random peaks */
- if(nCpuUsage<(BYTE)lParam) ++nTimesBelow;
+ if (nCpuUsage<(BYTE)lParam) ++nTimesBelow;
else nTimesBelow=0;
- if(nTimesBelow==3) {
+ if (nTimesBelow==3) {
nTimesBelow=0;
ShutdownAndStopWatcher();
return FALSE; /* stop poll thread */
@@ -238,8 +238,8 @@ static BOOL CALLBACK CpuUsageWatcherProc(BYTE nCpuUsage,LPARAM lParam) static int WeatherUpdated(WPARAM wParam,LPARAM lParam)
{
char *pszProto = GetContactProto((HANDLE)wParam);
- if((BOOL)lParam && pszProto!=NULL && CallProtoService(pszProto,PS_GETSTATUS,0,0)==THUNDER)
- if(db_get_b(NULL,"AutoShutdown","WeatherShutdown",SETTING_WEATHERSHUTDOWN_DEFAULT))
+ if ((BOOL)lParam && pszProto != NULL && CallProtoService(pszProto,PS_GETSTATUS,0,0)==THUNDER)
+ if (db_get_b(NULL,"AutoShutdown","WeatherShutdown",SETTING_WEATHERSHUTDOWN_DEFAULT))
ServiceShutdown(SDSDT_SHUTDOWN,TRUE);
return 0;
}
@@ -248,7 +248,7 @@ static int WeatherUpdated(WPARAM wParam,LPARAM lParam) static int HddOverheat(WPARAM wParam,LPARAM lParam)
{
- if(db_get_b(NULL,"AutoShutdown","HddOverheatShutdown",SETTING_HDDOVERHEATSHUTDOWN_DEFAULT))
+ if (db_get_b(NULL,"AutoShutdown","HddOverheatShutdown",SETTING_HDDOVERHEATSHUTDOWN_DEFAULT))
ServiceShutdown(SDSDT_SHUTDOWN,TRUE);
return 0;
}
@@ -258,21 +258,21 @@ static int HddOverheat(WPARAM wParam,LPARAM lParam) INT_PTR ServiceStartWatcher(WPARAM wParam,LPARAM lParam)
{
/* passing watcherType as lParam is only to be used internally, undocumented */
- if(lParam==0)
+ if (lParam==0)
lParam=(LPARAM)db_get_w(NULL,"AutoShutdown","WatcherFlags",0);
/* invalid flags or empty? */
- if(!(lParam&SDWTF_MASK))
+ if (!(lParam&SDWTF_MASK))
return 1;
/* no specific time choice? */
- if(lParam&SDWTF_SPECIFICTIME && !(lParam&SDWTF_ST_MASK))
+ if (lParam&SDWTF_SPECIFICTIME && !(lParam&SDWTF_ST_MASK))
return 2;
- if(currentWatcherType==(WORD)lParam)
+ if (currentWatcherType==(WORD)lParam)
return 3;
- if(currentWatcherType!=0) {
+ if (currentWatcherType != 0) {
/* Time Shutdown */
CloseCountdownFrame(); /* fails if not opened */
/* Cpu Shutdown */
@@ -284,26 +284,26 @@ INT_PTR ServiceStartWatcher(WPARAM wParam,LPARAM lParam) NotifyEventHooks(hEventWatcherChanged,TRUE,0);
/* Time Shutdown */
- if(currentWatcherType&SDWTF_SPECIFICTIME)
+ if (currentWatcherType&SDWTF_SPECIFICTIME)
ShowCountdownFrame(currentWatcherType); /* after modules loaded */
/* Cpu Shutdown */
- if(currentWatcherType&SDWTF_CPUUSAGE)
+ if (currentWatcherType&SDWTF_CPUUSAGE)
idCpuUsageThread=PollCpuUsage(CpuUsageWatcherProc,(LPARAM)DBGetContactSettingRangedByte(NULL,"AutoShutdown","CpuUsageThreshold",SETTING_CPUUSAGETHRESHOLD_DEFAULT,1,100),1500);
/* Transfer Shutdown */
- if(currentWatcherType&SDWTF_FILETRANSFER && !nTransfersCount)
+ if (currentWatcherType&SDWTF_FILETRANSFER && !nTransfersCount)
ShutdownAndStopWatcher();
/* Status Shutdown */
- if(currentWatcherType&SDWTF_STATUS && CheckAllContactsOffline())
+ if (currentWatcherType&SDWTF_STATUS && CheckAllContactsOffline())
ShutdownAndStopWatcher();
return 0;
}
INT_PTR ServiceStopWatcher(WPARAM,LPARAM)
{
- if(currentWatcherType==0) return 1;
+ if (currentWatcherType==0) return 1;
/* Time Shutdown */
- if(currentWatcherType&SDWTF_SPECIFICTIME)
+ if (currentWatcherType&SDWTF_SPECIFICTIME)
CloseCountdownFrame();
/* Cpu Shutdown */
idCpuUsageThread=0;
@@ -317,7 +317,7 @@ INT_PTR ServiceStopWatcher(WPARAM,LPARAM) INT_PTR ServiceIsWatcherEnabled(WPARAM,LPARAM)
{
- return currentWatcherType!=0;
+ return currentWatcherType != 0;
}
/************************* Misc ***********************************/
@@ -325,14 +325,14 @@ INT_PTR ServiceIsWatcherEnabled(WPARAM,LPARAM) void WatcherModulesLoaded(void)
{
/* Weather Shutdown */
- if(ServiceExists(MS_WEATHER_UPDATE))
+ if (ServiceExists(MS_WEATHER_UPDATE))
hHookWeatherUpdated=HookEvent(ME_WEATHER_UPDATED,WeatherUpdated);
/* Overheat Shutdown */
- if(ServiceExists(MS_SYSINFO_HDDTEMP))
+ if (ServiceExists(MS_SYSINFO_HDDTEMP))
hHookHddOverheat=HookEvent(ME_SYSINFO_HDDOVERHEAT,HddOverheat);
/* restore watcher if it was running on last exit */
- if(db_get_b(NULL,"AutoShutdown","RememberOnRestart",0)==SDROR_RUNNING) {
+ if (db_get_b(NULL,"AutoShutdown","RememberOnRestart",0)==SDROR_RUNNING) {
db_set_b(NULL,"AutoShutdown","RememberOnRestart",1);
ServiceStartWatcher(0,0); /* after modules loaded */
}
@@ -366,8 +366,8 @@ void InitWatcher(void) void UninitWatcher(void)
{
/* remember watcher if running */
- if(!ServiceStopWatcher(0,0))
- if(db_get_b(NULL,"AutoShutdown","RememberOnRestart",SETTING_REMEMBERONRESTART_DEFAULT))
+ if (!ServiceStopWatcher(0,0))
+ if (db_get_b(NULL,"AutoShutdown","RememberOnRestart",SETTING_REMEMBERONRESTART_DEFAULT))
db_set_b(NULL,"AutoShutdown","RememberOnRestart",SDROR_RUNNING);
/* Message Shutdown */
|