From 8a74e7495ce5ad39de4f5c25121a84d35df90c36 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 20 May 2018 15:08:48 +0300 Subject: CMPlugin to receive a reference to PLUGININFOEX --- plugins/AutoShutdown/src/frame.cpp | 14 +++++++------- plugins/AutoShutdown/src/main.cpp | 32 ++++++++++++++++++++------------ plugins/AutoShutdown/src/options.cpp | 20 ++++++++++---------- plugins/AutoShutdown/src/settingsdlg.cpp | 32 ++++++++++++++++---------------- plugins/AutoShutdown/src/shutdownsvc.cpp | 12 ++++++------ plugins/AutoShutdown/src/stdafx.h | 6 +++--- plugins/AutoShutdown/src/watcher.cpp | 18 +++++++++--------- 7 files changed, 71 insertions(+), 63 deletions(-) (limited to 'plugins/AutoShutdown/src') diff --git a/plugins/AutoShutdown/src/frame.cpp b/plugins/AutoShutdown/src/frame.cpp index c8a279189b..ab4baad2b9 100644 --- a/plugins/AutoShutdown/src/frame.cpp +++ b/plugins/AutoShutdown/src/frame.cpp @@ -288,14 +288,14 @@ static LRESULT CALLBACK FrameWndProc(HWND hwndFrame, UINT msg, WPARAM wParam, LP } case M_SET_COUNTDOWN: if (dat->fTimeFlags&SDWTF_ST_TIME) { - dat->settingLastTime = (time_t)db_get_dw(NULL, "AutoShutdown", "TimeStamp", SETTING_TIMESTAMP_DEFAULT); + dat->settingLastTime = (time_t)db_get_dw(NULL, MODULENAME, "TimeStamp", SETTING_TIMESTAMP_DEFAULT); dat->countdown = time(0); if (dat->settingLastTime > dat->countdown) dat->countdown = dat->settingLastTime - dat->countdown; else dat->countdown = 0; } 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); + dat->countdown = (time_t)db_get_dw(NULL, MODULENAME, "Countdown", SETTING_COUNTDOWN_DEFAULT); + dat->countdown *= (time_t)db_get_dw(NULL, MODULENAME, "CountdownUnit", SETTING_COUNTDOWNUNIT_DEFAULT); } dat->flags &= ~FWPDF_COUNTDOWNINVALID; /* commctl 4.70+, Win95: 1-100 will work fine (wrap around) */ @@ -499,7 +499,7 @@ void ShowCountdownFrame(WORD fTimeFlags) clf.align = alBottom; clf.height = GetSystemMetrics(SM_CYICON); clf.Flags = F_VISIBLE | F_SHOWTBTIP | F_NOBORDER | F_SKINNED; - clf.name = Translate("AutoShutdown"); + clf.name = Translate(MODULENAME); clf.TBname = Translate("Automatic shutdown"); clf.hWnd = hwndCountdownFrame; hFrame = (WORD)CallService(MS_CLIST_FRAMES_ADDFRAME, (WPARAM)&clf, 0); @@ -553,13 +553,13 @@ static int FrameModulesLoaded(WPARAM, LPARAM) LOGFONT lf; /* built-in font module is not available before this hook */ COLORREF clr = GetDefaultColor(FRAMEELEMENT_TEXT); - FontService_RegisterFont("AutoShutdown", "CountdownFont", LPGENW("Automatic shutdown"), LPGENW("Countdown on frame"), LPGENW("Automatic shutdown"), LPGENW("Background"), 0, FALSE, GetDefaultFont(&lf), clr); + FontService_RegisterFont(MODULENAME, "CountdownFont", LPGENW("Automatic shutdown"), LPGENW("Countdown on frame"), LPGENW("Automatic shutdown"), LPGENW("Background"), 0, FALSE, GetDefaultFont(&lf), clr); clr = GetDefaultColor(FRAMEELEMENT_BKGRND); - FontService_RegisterColor("AutoShutdown", "BkgColor", LPGENW("Automatic shutdown"), LPGENW("Background"), clr); + FontService_RegisterColor(MODULENAME, "BkgColor", LPGENW("Automatic shutdown"), LPGENW("Background"), clr); 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); + FontService_RegisterColor(MODULENAME, "ProgressColor", TranslateT("Automatic shutdown"), TranslateT("Progress bar"), clr); } } return 0; diff --git a/plugins/AutoShutdown/src/main.cpp b/plugins/AutoShutdown/src/main.cpp index dfeeb8df16..bffd3d22fd 100644 --- a/plugins/AutoShutdown/src/main.cpp +++ b/plugins/AutoShutdown/src/main.cpp @@ -24,7 +24,16 @@ CLIST_INTERFACE *pcli; CMPlugin g_plugin; int &hLangpack(g_plugin.m_hLang); -PLUGININFOEX pluginInfo = { +IconItem iconList[] = +{ + { LPGEN("Header"), "AutoShutdown_Header", IDI_HEADER }, + { LPGEN("Active"), "AutoShutdown_Active", IDI_ACTIVE }, + { LPGEN("Inactive"), "AutoShutdown_Inactive", IDI_INACTIVE }, +}; + +///////////////////////////////////////////////////////////////////////////////////////// + +PLUGININFOEX pluginInfoEx = { sizeof(PLUGININFOEX), __PLUGIN_NAME, PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), @@ -37,12 +46,16 @@ PLUGININFOEX pluginInfo = { {0x9de24579, 0x5c5c, 0x49aa, {0x80, 0xe8, 0x4d, 0x38, 0xe4, 0x34, 0x4e, 0x63}} }; -IconItem iconList[] = +CMPlugin::CMPlugin() : + PLUGIN(MODULENAME, pluginInfoEx) +{} + +extern "C" __declspec(dllexport) const PLUGININFOEX* MirandaPluginInfoEx(DWORD) { - { LPGEN("Header"), "AutoShutdown_Header", IDI_HEADER }, - { LPGEN("Active"), "AutoShutdown_Active", IDI_ACTIVE }, - { LPGEN("Inactive"), "AutoShutdown_Inactive", IDI_INACTIVE }, -}; + return &pluginInfoEx; +} + +///////////////////////////////////////////////////////////////////////////////////////// static int ShutdownModulesLoaded(WPARAM, LPARAM) { @@ -53,14 +66,9 @@ static int ShutdownModulesLoaded(WPARAM, LPARAM) return 0; } -extern "C" __declspec(dllexport) const PLUGININFOEX* MirandaPluginInfoEx(DWORD) -{ - return &pluginInfo; -} - extern "C" __declspec(dllexport) int Load(void) { - mir_getLP(&pluginInfo); + mir_getLP(&pluginInfoEx); pcli = Clist_GetInterface(); INITCOMMONCONTROLSEX icc; diff --git a/plugins/AutoShutdown/src/options.cpp b/plugins/AutoShutdown/src/options.cpp index f0b2255566..df9cc47f9b 100644 --- a/plugins/AutoShutdown/src/options.cpp +++ b/plugins/AutoShutdown/src/options.cpp @@ -36,7 +36,7 @@ static INT_PTR CALLBACK ShutdownOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); { - WORD setting = db_get_w(NULL, "AutoShutdown", "ConfirmDlgCountdown", SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT); + WORD setting = db_get_w(NULL, MODULENAME, "ConfirmDlgCountdown", SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT); if (setting < 3) setting = SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT; SendDlgItemMessage(hwndDlg, IDC_SPIN_CONFIRMDLGCOUNTDOWN, UDM_SETRANGE, 0, MAKELPARAM(999, 3)); @@ -44,15 +44,15 @@ static INT_PTR CALLBACK ShutdownOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam 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 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CHECK_REMEMBERONRESTART, db_get_b(NULL, "AutoShutdown", "RememberOnRestart", SETTING_REMEMBERONRESTART_DEFAULT) != 0 ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_CHECK_SHOWCONFIRMDLG, db_get_b(NULL, "AutoShutdown", "ShowConfirmDlg", SETTING_SHOWCONFIRMDLG_DEFAULT) != 0 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_CHECK_SMARTOFFLINECHECK, db_get_b(NULL, MODULENAME, "SmartOfflineCheck", SETTING_SMARTOFFLINECHECK_DEFAULT) != 0 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_CHECK_REMEMBERONRESTART, db_get_b(NULL, MODULENAME, "RememberOnRestart", SETTING_REMEMBERONRESTART_DEFAULT) != 0 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_CHECK_SHOWCONFIRMDLG, db_get_b(NULL, MODULENAME, "ShowConfirmDlg", SETTING_SHOWCONFIRMDLG_DEFAULT) != 0 ? BST_CHECKED : BST_UNCHECKED); { BOOL enabled = ServiceIsTypeEnabled(SDSDT_SHUTDOWN, 0); if (enabled) { 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 ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_CHECK_WEATHER, db_get_b(NULL, MODULENAME, "WeatherShutdown", SETTING_WEATHERSHUTDOWN_DEFAULT) != 0 ? BST_CHECKED : BST_UNCHECKED); } } } @@ -90,12 +90,12 @@ static INT_PTR CALLBACK ShutdownOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam 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, nullptr, 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)); + db_set_b(NULL, MODULENAME, "ShowConfirmDlg", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_CHECK_SHOWCONFIRMDLG) != 0)); + db_set_w(NULL, MODULENAME, "ConfirmDlgCountdown", (WORD)GetDlgItemInt(hwndDlg, IDC_EDIT_CONFIRMDLGCOUNTDOWN, nullptr, FALSE)); + db_set_b(NULL, MODULENAME, "RememberOnRestart", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_CHECK_REMEMBERONRESTART) != 0)); + db_set_b(NULL, MODULENAME, "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)); + db_set_b(NULL, MODULENAME, "WeatherShutdown", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_CHECK_WEATHER) != 0)); return TRUE; } break; diff --git a/plugins/AutoShutdown/src/settingsdlg.cpp b/plugins/AutoShutdown/src/settingsdlg.cpp index 2e7b6003ec..2c82d7d4df 100644 --- a/plugins/AutoShutdown/src/settingsdlg.cpp +++ b/plugins/AutoShutdown/src/settingsdlg.cpp @@ -81,7 +81,7 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L } /* read-in watcher flags */ { - WORD watcherType = db_get_w(NULL, "AutoShutdown", "WatcherFlags", SETTING_WATCHERFLAGS_DEFAULT); + WORD watcherType = db_get_w(NULL, MODULENAME, "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 ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_CHECK_MESSAGE, (watcherType&SDWTF_MESSAGE) != 0 ? BST_CHECKED : BST_UNCHECKED); @@ -93,14 +93,14 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L /* 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, MODULENAME, "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); SendMessage(hwndDlg, M_CHECK_DATETIME, 0, 0); } { - DWORD setting = db_get_dw(NULL, "AutoShutdown", "Countdown", SETTING_COUNTDOWN_DEFAULT); + DWORD setting = db_get_dw(NULL, MODULENAME, "Countdown", 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); @@ -109,7 +109,7 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L } { HWND hwndCombo = GetDlgItem(hwndDlg, IDC_COMBO_COUNTDOWNUNIT); - DWORD lastUnit = db_get_dw(NULL, "AutoShutdown", "CountdownUnit", SETTING_COUNTDOWNUNIT_DEFAULT); + DWORD lastUnit = db_get_dw(NULL, MODULENAME, "CountdownUnit", SETTING_COUNTDOWNUNIT_DEFAULT); SendMessage(hwndCombo, CB_SETLOCALE, (WPARAM)locale, 0); /* sort order */ SendMessage(hwndCombo, CB_INITSTORAGE, _countof(unitNames), _countof(unitNames) * 16); /* approx. */ for (int i = 0; i < _countof(unitNames); ++i) { @@ -122,14 +122,14 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L } { DBVARIANT dbv; - if (!db_get_ws(NULL, "AutoShutdown", "Message", &dbv)) { + if (!db_get_ws(NULL, MODULENAME, "Message", &dbv)) { SetDlgItemText(hwndDlg, IDC_EDIT_MESSAGE, dbv.ptszVal); mir_free(dbv.ptszVal); } } /* cpuusage threshold */ { - BYTE setting = DBGetContactSettingRangedByte(NULL, "AutoShutdown", "CpuUsageThreshold", SETTING_CPUUSAGETHRESHOLD_DEFAULT, 1, 100); + BYTE setting = DBGetContactSettingRangedByte(NULL, MODULENAME, "CpuUsageThreshold", SETTING_CPUUSAGETHRESHOLD_DEFAULT, 1, 100); SendDlgItemMessage(hwndDlg, IDC_SPIN_CPUUSAGE, UDM_SETRANGE, 0, MAKELPARAM(100, 1)); SendDlgItemMessage(hwndDlg, IDC_EDIT_CPUUSAGE, EM_SETLIMITTEXT, (WPARAM)3, 0); SendDlgItemMessage(hwndDlg, IDC_SPIN_CPUUSAGE, UDM_SETPOS, 0, MAKELPARAM(setting, 0)); @@ -138,7 +138,7 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L /* shutdown types */ { HWND hwndCombo = GetDlgItem(hwndDlg, IDC_COMBO_SHUTDOWNTYPE); - BYTE lastShutdownType = db_get_b(NULL, "AutoShutdown", "ShutdownType", SETTING_SHUTDOWNTYPE_DEFAULT); + BYTE lastShutdownType = db_get_b(NULL, MODULENAME, "ShutdownType", SETTING_SHUTDOWNTYPE_DEFAULT); SendMessage(hwndCombo, CB_SETLOCALE, (WPARAM)locale, 0); /* sort order */ SendMessage(hwndCombo, CB_SETEXTENDEDUI, TRUE, 0); SendMessage(hwndCombo, CB_INITSTORAGE, SDSDT_MAX, SDSDT_MAX * 32); @@ -171,11 +171,11 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L } } SendMessage(hwndDlg, M_ENABLE_SUBCTLS, 0, 0); - Utils_RestoreWindowPositionNoSize(hwndDlg, NULL, "AutoShutdown", "SettingsDlg_"); + Utils_RestoreWindowPositionNoSize(hwndDlg, NULL, MODULENAME, "SettingsDlg_"); return TRUE; /* default focus */ case WM_DESTROY: - Utils_SaveWindowPosition(hwndDlg, NULL, "AutoShutdown", "SettingsDlg_"); + Utils_SaveWindowPosition(hwndDlg, NULL, MODULENAME, "SettingsDlg_"); { HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_TEXT_HEADER, WM_GETFONT, 0, 0); SendDlgItemMessage(hwndDlg, IDC_TEXT_HEADER, WM_SETFONT, 0, FALSE); /* no return value */ @@ -340,7 +340,7 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L wchar_t *pszText = (wchar_t*)mir_alloc(len*sizeof(wchar_t)); if (pszText != nullptr && GetWindowText(hwndEdit, pszText, len + 1)) { TrimString(pszText); - db_set_ws(NULL, "AutoShutdown", "Message", pszText); + db_set_ws(NULL, MODULENAME, "Message", pszText); } mir_free(pszText); /* does NULL check */ } @@ -351,18 +351,18 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_TIME_TIMESTAMP), &st); /* time gets synchronized */ if (!SystemTimeToTimeStamp(&st, ×tamp)) timestamp = time(0); - db_set_dw(NULL, "AutoShutdown", "TimeStamp", (DWORD)timestamp); + db_set_dw(NULL, MODULENAME, "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)); + db_set_b(NULL, MODULENAME, "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)); - db_set_dw(NULL, "AutoShutdown", "Countdown", (DWORD)GetDlgItemInt(hwndDlg, IDC_EDIT_COUNTDOWN, nullptr, FALSE)); - db_set_b(NULL, "AutoShutdown", "CpuUsageThreshold", (BYTE)GetDlgItemInt(hwndDlg, IDC_EDIT_CPUUSAGE, nullptr, FALSE)); + db_set_dw(NULL, MODULENAME, "CountdownUnit", (DWORD)SendDlgItemMessage(hwndDlg, IDC_COMBO_COUNTDOWNUNIT, CB_GETITEMDATA, (WPARAM)index, 0)); + db_set_dw(NULL, MODULENAME, "Countdown", (DWORD)GetDlgItemInt(hwndDlg, IDC_EDIT_COUNTDOWN, nullptr, FALSE)); + db_set_b(NULL, MODULENAME, "CpuUsageThreshold", (BYTE)GetDlgItemInt(hwndDlg, IDC_EDIT_CPUUSAGE, nullptr, FALSE)); } /* watcher type */ { @@ -373,7 +373,7 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L 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); + db_set_w(NULL, MODULENAME, "WatcherFlags", watcherType); ServiceStartWatcher(0, watcherType); } DestroyWindow(hwndDlg); diff --git a/plugins/AutoShutdown/src/shutdownsvc.cpp b/plugins/AutoShutdown/src/shutdownsvc.cpp index 699820190c..b120727a7a 100644 --- a/plugins/AutoShutdown/src/shutdownsvc.cpp +++ b/plugins/AutoShutdown/src/shutdownsvc.cpp @@ -247,7 +247,7 @@ static DWORD ShutdownNow(BYTE shutdownType) BroadcastEndSession(BSM_APPLICATIONS | BSM_ALLDESKTOPS, ENDSESSION_CLOSEAPP); /* app should close itself */ WinNT_SetPrivilege(SE_TCB_NAME, FALSE); - if (!InitiateSystemShutdownEx(nullptr, TranslateT("AutoShutdown"), 0, TRUE, shutdownType == SDSDT_REBOOT, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER | SHTDN_REASON_FLAG_PLANNED)) + if (!InitiateSystemShutdownEx(nullptr, TranslateT(MODULENAME), 0, TRUE, shutdownType == SDSDT_REBOOT, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER | SHTDN_REASON_FLAG_PLANNED)) dwErrCode = GetLastError(); /* cleanly close Miranda */ @@ -321,7 +321,7 @@ static INT_PTR CALLBACK ShutdownDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA, (LONG_PTR)hBoldFont); } { - countdown = db_get_w(NULL, "AutoShutdown", "ConfirmDlgCountdown", SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT); + countdown = db_get_w(NULL, MODULENAME, "ConfirmDlgCountdown", SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT); if (countdown < 3) countdown = SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT; SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA, countdown); @@ -331,7 +331,7 @@ static INT_PTR CALLBACK ShutdownDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L if (!SetTimer(hwndDlg, 1, 1000, nullptr)) PostMessage(hwndDlg, M_START_SHUTDOWN, 0, 0); - Utils_RestoreWindowPositionNoSize(hwndDlg, NULL, "AutoShutdown", "ConfirmDlg_"); + Utils_RestoreWindowPositionNoSize(hwndDlg, NULL, MODULENAME, "ConfirmDlg_"); /* disallow foreground window changes (WinMe/2000+) */ SetForegroundWindow(hwndDlg); @@ -346,7 +346,7 @@ static INT_PTR CALLBACK ShutdownDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L ShowWindow(hwndDlg, SW_HIDE); /* reallow foreground window changes (WinMe/2000+) */ LockSetForegroundWindow(LSFW_UNLOCK); - Utils_SaveWindowPosition(hwndDlg, NULL, "AutoShutdown", "ConfirmDlg_"); + Utils_SaveWindowPosition(hwndDlg, NULL, MODULENAME, "ConfirmDlg_"); 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 != nullptr) DeleteObject(hFont); @@ -416,7 +416,7 @@ static INT_PTR CALLBACK ShutdownDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L 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 (!wParam) wParam = db_get_b(NULL, MODULENAME, "ShutdownType", SETTING_SHUTDOWNTYPE_DEFAULT); if (!IsShutdownTypeEnabled((BYTE)wParam)) return 1; /* does shutdownType range check */ if ((BOOL)lParam && hwndShutdownDlg != nullptr) return 2; @@ -428,7 +428,7 @@ INT_PTR ServiceShutdown(WPARAM wParam, LPARAM lParam) /* tell others */ NotifyEventHooks(hEventShutdown, wParam, lParam); /* show dialog */ - if (lParam && db_get_b(NULL, "AutoShutdown", "ShowConfirmDlg", SETTING_SHOWCONFIRMDLG_DEFAULT)) + if (lParam && db_get_b(NULL, MODULENAME, "ShowConfirmDlg", SETTING_SHOWCONFIRMDLG_DEFAULT)) if (CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_SHUTDOWNNOW), nullptr, ShutdownDlgProc, (BYTE)wParam) != nullptr) return 0; /* show error */ diff --git a/plugins/AutoShutdown/src/stdafx.h b/plugins/AutoShutdown/src/stdafx.h index c0b60f6181..13f1bcd976 100644 --- a/plugins/AutoShutdown/src/stdafx.h +++ b/plugins/AutoShutdown/src/stdafx.h @@ -74,11 +74,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "resource.h" #include "version.h" +#define MODULENAME "AutoShutdown" + struct CMPlugin : public PLUGIN { - CMPlugin() : - PLUGIN("AutoShutdown") - {} + CMPlugin(); }; extern IconItem iconList[]; \ No newline at end of file diff --git a/plugins/AutoShutdown/src/watcher.cpp b/plugins/AutoShutdown/src/watcher.cpp index 9c55326902..fbd2987e8b 100644 --- a/plugins/AutoShutdown/src/watcher.cpp +++ b/plugins/AutoShutdown/src/watcher.cpp @@ -99,7 +99,7 @@ static int MsgEventAdded(WPARAM, LPARAM hDbEvent) if (!db_event_get(hDbEvent, &dbe)) if (dbe.eventType == EVENTTYPE_MESSAGE && !(dbe.flags & DBEF_SENT)) { DBVARIANT dbv; - if (!db_get_ws(NULL, "AutoShutdown", "Message", &dbv)) { + if (!db_get_ws(NULL, MODULENAME, "Message", &dbv)) { TrimString(dbv.ptszVal); wchar_t *pszMsg = GetMessageText(&dbe.pBlob, &dbe.cbBlob); if (pszMsg != nullptr && wcsstr(pszMsg, dbv.ptszVal) != nullptr) @@ -175,7 +175,7 @@ static int IdleChanged(WPARAM, LPARAM lParam) static BOOL CheckAllContactsOffline(void) { BOOL fSmartCheck, fAllOffline = TRUE; /* tentatively */ - fSmartCheck = db_get_b(NULL, "AutoShutdown", "SmartOfflineCheck", SETTING_SMARTOFFLINECHECK_DEFAULT); + fSmartCheck = db_get_b(NULL, MODULENAME, "SmartOfflineCheck", SETTING_SMARTOFFLINECHECK_DEFAULT); for (auto &hContact : Contacts()) { char *pszProto = GetContactProto(hContact); if (pszProto != nullptr && Proto_GetStatus(pszProto) != ID_STATUS_OFFLINE) { @@ -236,7 +236,7 @@ static int WeatherUpdated(WPARAM wParam, LPARAM lParam) { char *pszProto = GetContactProto(wParam); if ((BOOL)lParam && pszProto != nullptr && Proto_GetStatus(pszProto) == THUNDER) - if (db_get_b(NULL, "AutoShutdown", "WeatherShutdown", SETTING_WEATHERSHUTDOWN_DEFAULT)) + if (db_get_b(NULL, MODULENAME, "WeatherShutdown", SETTING_WEATHERSHUTDOWN_DEFAULT)) ServiceShutdown(SDSDT_SHUTDOWN, TRUE); return 0; } @@ -247,7 +247,7 @@ INT_PTR ServiceStartWatcher(WPARAM, LPARAM lParam) { /* passing watcherType as lParam is only to be used internally, undocumented */ if (lParam == 0) - lParam = (LPARAM)db_get_w(NULL, "AutoShutdown", "WatcherFlags", 0); + lParam = (LPARAM)db_get_w(NULL, MODULENAME, "WatcherFlags", 0); /* invalid flags or empty? */ if (!(lParam&SDWTF_MASK)) @@ -276,7 +276,7 @@ INT_PTR ServiceStartWatcher(WPARAM, LPARAM lParam) ShowCountdownFrame(currentWatcherType); /* after modules loaded */ /* Cpu Shutdown */ if (currentWatcherType&SDWTF_CPUUSAGE) - idCpuUsageThread = PollCpuUsage(CpuUsageWatcherProc, (LPARAM)DBGetContactSettingRangedByte(NULL, "AutoShutdown", "CpuUsageThreshold", SETTING_CPUUSAGETHRESHOLD_DEFAULT, 1, 100), 1500); + idCpuUsageThread = PollCpuUsage(CpuUsageWatcherProc, (LPARAM)DBGetContactSettingRangedByte(NULL, MODULENAME, "CpuUsageThreshold", SETTING_CPUUSAGETHRESHOLD_DEFAULT, 1, 100), 1500); /* Transfer Shutdown */ if (currentWatcherType&SDWTF_FILETRANSFER && !nTransfersCount) ShutdownAndStopWatcher(); @@ -317,8 +317,8 @@ void WatcherModulesLoaded(void) hHookWeatherUpdated = HookEvent(ME_WEATHER_UPDATED, WeatherUpdated); /* restore watcher if it was running on last exit */ - if (db_get_b(NULL, "AutoShutdown", "RememberOnRestart", 0) == SDROR_RUNNING) { - db_set_b(NULL, "AutoShutdown", "RememberOnRestart", 1); + if (db_get_b(NULL, MODULENAME, "RememberOnRestart", 0) == SDROR_RUNNING) { + db_set_b(NULL, MODULENAME, "RememberOnRestart", 1); ServiceStartWatcher(0, 0); /* after modules loaded */ } } @@ -350,8 +350,8 @@ void UninitWatcher(void) { /* remember watcher if running */ if (!ServiceStopWatcher(0, 0)) - if (db_get_b(NULL, "AutoShutdown", "RememberOnRestart", SETTING_REMEMBERONRESTART_DEFAULT)) - db_set_b(NULL, "AutoShutdown", "RememberOnRestart", SDROR_RUNNING); + if (db_get_b(NULL, MODULENAME, "RememberOnRestart", SETTING_REMEMBERONRESTART_DEFAULT)) + db_set_b(NULL, MODULENAME, "RememberOnRestart", SDROR_RUNNING); /* Message Shutdown */ UnhookEvent(hHookEventAdded); -- cgit v1.2.3