summaryrefslogtreecommitdiff
path: root/plugins/PluginUpdater/src/Notifications.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/PluginUpdater/src/Notifications.cpp')
-rw-r--r--plugins/PluginUpdater/src/Notifications.cpp264
1 files changed, 75 insertions, 189 deletions
diff --git a/plugins/PluginUpdater/src/Notifications.cpp b/plugins/PluginUpdater/src/Notifications.cpp
index 4a9108a5e8..9dbbf9a5a9 100644
--- a/plugins/PluginUpdater/src/Notifications.cpp
+++ b/plugins/PluginUpdater/src/Notifications.cpp
@@ -19,9 +19,27 @@ Boston, MA 02111-1307, USA.
#include "common.h"
-HANDLE hPipe = NULL;
+aPopups PopupsList[POPUPS];
-void PopupAction(HWND hWnd, BYTE action)
+void InitPopupList()
+{
+ int index = 0;
+ PopupsList[index].ID = index;
+ PopupsList[index].colorBack = db_get_dw(NULL, MODNAME, "Popups0Bg", COLOR_BG_FIRSTDEFAULT);
+ PopupsList[index].colorText = db_get_dw(NULL, MODNAME, "Popups0Tx", COLOR_TX_DEFAULT);
+
+ index = 1;
+ PopupsList[index].ID = index;
+ PopupsList[index].colorBack = db_get_dw(NULL, MODNAME, "Popups1Bg", COLOR_BG_SECONDDEFAULT);
+ PopupsList[index].colorText = db_get_dw(NULL, MODNAME, "Popups1Tx", COLOR_TX_DEFAULT);
+
+ index = 2;
+ PopupsList[index].ID = index;
+ PopupsList[index].colorBack = db_get_dw(NULL, MODNAME, "Popups2Bg", COLOR_BG_FIRSTDEFAULT);
+ PopupsList[index].colorText = db_get_dw(NULL, MODNAME, "Popups2Tx", COLOR_TX_DEFAULT);
+}
+
+void PopupAction(HWND hPopup, BYTE action)
{
switch (action) {
case PCA_CLOSEPOPUP:
@@ -29,108 +47,75 @@ void PopupAction(HWND hWnd, BYTE action)
case PCA_DONOTHING:
return;
}
- PUDeletePopup(hWnd);
+ PUDeletePopup(hPopup);
}
-static LRESULT CALLBACK PopupDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+static LRESULT CALLBACK PopupDlgProc(HWND hPopup, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
- case UM_POPUPACTION:
- if (HIWORD(wParam) == BN_CLICKED) {
- LPMSGPOPUPDATA pmpd = (LPMSGPOPUPDATA)PUGetPluginData(hDlg);
- if (pmpd) {
- switch (LOWORD(wParam)) {
- case IDYES:
- if (IsWindow(pmpd->hDialog))
- PostMessage(pmpd->hDialog, WM_CLOSE, 0, 0);
- PUDeletePopup(hDlg);
- break;
+ case WM_COMMAND:
+ PopupAction(hPopup, PopupOptions.LeftClickAction);
+ break;
- case IDNO:
- if (IsWindow(pmpd->hDialog))
- PostMessage(pmpd->hDialog, WM_CLOSE, 0, 0);
- PUDeletePopup(hDlg);
- break;
- }
- }
- }
+ case WM_CONTEXTMENU:
+ PopupAction(hPopup, PopupOptions.RightClickAction);
break;
case UM_FREEPLUGINDATA:
- {
- LPMSGPOPUPDATA pmpd = (LPMSGPOPUPDATA)PUGetPluginData(hDlg);
- if (pmpd > 0)
- mir_free(pmpd);
- return TRUE; //TRUE or FALSE is the same, it gets ignored.
- }
break;
}
- return DefWindowProc(hDlg, uMsg, wParam, lParam);
+ return DefWindowProc(hPopup, uMsg, wParam, lParam);
+}
+
+static void _stdcall RestartPrompt(void *) {
+ TCHAR tszText[200];
+ mir_sntprintf(tszText, SIZEOF(tszText), _T("%s\n\n%s"), TranslateT("You need to restart your Miranda to apply installed updates."), TranslateT("Would you like to restart it now?"));
+
+ if (MessageBox(0, tszText, TranslateT("Plugin Updater"), MB_YESNO | MB_ICONQUESTION | MB_TOPMOST) == IDYES)
+ CallService(MS_SYSTEM_RESTART, db_get_b(NULL,MODNAME,"RestartCurrentProfile",1) ? 1 : 0, 0);
}
-static LRESULT CALLBACK PopupDlgProc2(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+static LRESULT CALLBACK PopupDlgProcRestart(HWND hPopup, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
- case WM_COMMAND:
- PopupAction(hDlg, PopupOptions.LeftClickAction);
- break;
-
case WM_CONTEXTMENU:
- PopupAction(hDlg, PopupOptions.RightClickAction);
+ PUDeletePopup(hPopup);
break;
+ case WM_COMMAND:
+ PUDeletePopup(hPopup);
+ CallFunctionAsync(RestartPrompt,0);
- case UM_FREEPLUGINDATA:
- {
- LPMSGPOPUPDATA pmpd = (LPMSGPOPUPDATA)PUGetPluginData(hDlg);
- if (pmpd > 0)
- mir_free(pmpd);
- return TRUE; //TRUE or FALSE is the same, it gets ignored.
- }
break;
}
- return DefWindowProc(hDlg, uMsg, wParam, lParam);
+ return DefWindowProc(hPopup, uMsg, wParam, lParam);
}
-static void MakePopupAction(POPUPACTION &pa, int id)
+void ShowPopup(LPCTSTR ptszTitle, LPCTSTR ptszText, int Number)
{
- pa.cbSize = sizeof(POPUPACTION);
- pa.flags = PAF_ENABLED;
- pa.wParam = MAKEWORD(id, BN_CLICKED);
- pa.lParam = 0;
- switch (id) {
- case IDYES:
- pa.lchIcon = Skin_GetIcon("btn_ok");
- strncpy_s(pa.lpzTitle, MODNAME"/Yes", MAX_ACTIONTITLE);
- break;
-
- case IDNO:
- pa.lchIcon = Skin_GetIcon("btn_cancel");
- strncpy_s(pa.lpzTitle, MODNAME"/No", MAX_ACTIONTITLE);
- break;
+ if(Number != POPUP_TYPE_MSG) {
+ char setting[100];
+ mir_snprintf(setting, SIZEOF(setting), "Popups%d", Number);
+ if(!db_get_b(NULL, MODNAME, setting, DEFAULT_MESSAGE_ENABLED))
+ return;
}
-}
-void ShowPopup(HWND hDlg, LPCTSTR ptszTitle, LPCTSTR ptszText, int Number, int ActType, bool NoMessageBox)
-{
if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1)) {
- LPMSGPOPUPDATA pmpd = (LPMSGPOPUPDATA)mir_alloc(sizeof(MSGPOPUPDATA));
- if (!pmpd)
- return;
-
- POPUPDATAT_V2 pd = { 0 };
- pd.cbSize = sizeof(pd);
- pd.lchContact = NULL; //(HANDLE)wParam;
- pd.lchIcon = LoadSkinnedIcon(PopupsList[Number].Icon);
- pd.PluginWindowProc = (Number == 0 && ActType != 0) ? PopupDlgProc : PopupDlgProc2;
- pd.PluginData = pmpd;
- pd.iSeconds = (Number == 0) ? -1 : PopupOptions.Timeout;
- pd.hNotification = NULL;
- pd.lpActions = pmpd->pa;
+ POPUPDATAT pd = { 0 };
+ pd.lchContact = NULL;
+ pd.lchIcon = Skin_GetIcon("check_update");
+ if(Number == POPUP_TYPE_MSG) {
+ pd.PluginWindowProc = PopupDlgProcRestart;
+ pd.iSeconds = -1;
+ }
+ else {
+ pd.PluginWindowProc = PopupDlgProc;
+ pd.iSeconds = PopupOptions.Timeout;
+ }
- lstrcpyn(pd.lptzText, TranslateTS(ptszText), MAX_SECONDLINE);
- lstrcpyn(pd.lptzContactName, TranslateTS(ptszTitle), MAX_CONTACTNAME);
+ lstrcpyn(pd.lptzText, ptszText, MAX_SECONDLINE);
+ lstrcpyn(pd.lptzContactName, ptszTitle, MAX_CONTACTNAME);
switch (PopupOptions.DefColors) {
case byCOLOR_WINDOWS:
@@ -146,112 +131,25 @@ void ShowPopup(HWND hDlg, LPCTSTR ptszTitle, LPCTSTR ptszText, int Number, int A
break;
}
- pmpd->hDialog = hDlg;
-
- if (ActType == 1) {
- MakePopupAction(pmpd->pa[pd.actionCount++], IDYES);
- MakePopupAction(pmpd->pa[pd.actionCount++], IDNO);
+ PUAddPopupT(&pd);
+ } else {
+ if(Number != POPUP_TYPE_MSG) {
+ char setting[100];
+ mir_snprintf(setting, SIZEOF(setting), "Popups%dM", Number);
+ if (!db_get_b(NULL, MODNAME, setting, DEFAULT_MESSAGE_ENABLED))
+ return;
}
-
- CallService(MS_POPUP_ADDPOPUPT, (WPARAM)&pd, APF_NEWDATA);
- } else if (!NoMessageBox) {
- char setting[100];
- mir_snprintf(setting, SIZEOF(setting), "Popups%dM", Number);
- if (db_get_b(NULL, MODNAME, setting, DEFAULT_MESSAGE_ENABLED)) {
- int iMsgType;
- switch( Number ) {
- case 1: iMsgType = MB_ICONSTOP; break;
- case 2: iMsgType = MB_ICONINFORMATION; break;
- case 3: iMsgType = MB_ICONQUESTION; break;
- case 4: return;
- default: iMsgType = 0;
- }
- MessageBox(hDlg, TranslateTS(ptszText), TranslateTS(ptszTitle), iMsgType);
+ int iMsgType;
+ switch( Number ) {
+ case POPUP_TYPE_MSG: iMsgType = MB_ICONSTOP; break;
+ case POPUP_TYPE_ERROR: iMsgType = MB_ICONINFORMATION; break;
+ case POPUP_TYPE_INFO: iMsgType = MB_ICONQUESTION; break;
+ default: iMsgType = 0;
}
+ MessageBox(0, ptszText, ptszTitle, iMsgType);
}
}
-INT_PTR CALLBACK DlgDownload(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
-{
- switch (message) {
- case WM_INITDIALOG:
- SetWindowText(GetDlgItem(hDlg, IDC_LABEL), tszDialogMsg);
- SetWindowLongPtr(GetDlgItem(hDlg, IDC_PB), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hDlg, IDC_PB), GWL_STYLE) | PBS_MARQUEE);
- SendMessage(GetDlgItem(hDlg, IDC_PB), PBM_SETMARQUEE, 1, 50);
- return TRUE;
- }
- return FALSE;
-}
-
-INT_PTR CALLBACK DlgDownloadPop(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- switch (uMsg) {
- case WM_INITDIALOG:
- PopupDataText *temp = (PopupDataText*)lParam;
- ShowPopup(hDlg, temp->Title, temp->Text, 3, 0);
- return TRUE;
- }
- return FALSE;
-}
-
-bool PrepareEscalation()
-{
- // First try to create a file near Miranda32.exe
- TCHAR szPath[MAX_PATH];
- GetModuleFileName(NULL, szPath, SIZEOF(szPath));
- TCHAR *ext = _tcsrchr(szPath, '.');
- if (ext != NULL)
- *ext = '\0';
- _tcscat(szPath, _T(".test"));
- HANDLE hFile = CreateFile(szPath, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hFile != INVALID_HANDLE_VALUE) {
- // we are admins or UAC is disable, cool
- CloseHandle(hFile);
- DeleteFile(szPath);
- return true;
- }
-
- // Check the current process's "run as administrator" status.
- if ( IsRunAsAdmin())
- return true;
-
- // Elevate the process. Create a pipe for a stub first
- TCHAR tszPipeName[MAX_PATH];
- mir_sntprintf(tszPipeName, MAX_PATH, _T("\\\\.\\pipe\\Miranda_Pu_%d"), GetCurrentProcessId());
- hPipe = CreateNamedPipe(tszPipeName, PIPE_ACCESS_DUPLEX, PIPE_READMODE_BYTE | PIPE_WAIT, 1, 1024, 1024, NMPWAIT_USE_DEFAULT_WAIT, NULL);
- if (hPipe == INVALID_HANDLE_VALUE) {
- hPipe = NULL;
- return false;
- }
-
- TCHAR cmdLine[100], *p;
- GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath));
- if ((p = _tcsrchr(szPath, '\\')) != 0)
- _tcscpy(p+1, _T("pu_stub.exe"));
- mir_sntprintf(cmdLine, SIZEOF(cmdLine), _T("%d"), GetCurrentProcessId());
-
- // Launch a stub
- SHELLEXECUTEINFO sei = { sizeof(sei) };
- sei.lpVerb = L"runas";
- sei.lpFile = szPath;
- sei.lpParameters = cmdLine;
- sei.hwnd = NULL;
- sei.nShow = SW_NORMAL;
- if (ShellExecuteEx(&sei)) {
- if (hPipe != NULL)
- ConnectNamedPipe(hPipe, NULL);
- return true;
- }
-
- DWORD dwError = GetLastError();
- if (dwError == ERROR_CANCELLED)
- {
- // The user refused to allow privileges elevation.
- // Do nothing ...
- }
- return false;
-}
-
int ImageList_AddIconFromIconLib(HIMAGELIST hIml, const char *name)
{
HICON icon = Skin_GetIconByHandle(Skin_GetIconHandle(name));
@@ -259,15 +157,3 @@ int ImageList_AddIconFromIconLib(HIMAGELIST hIml, const char *name)
Skin_ReleaseIcon(icon);
return res;
}
-
-INT_PTR CALLBACK DlgMsgPop(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- switch (uMsg) {
- case WM_INITDIALOG:
- PopupDataText *temp = (PopupDataText*)lParam;
- ShowPopup(hDlg, temp->Title, temp->Text, 0, 1);
- return TRUE;
- }
- ShowWindow(hDlg, SW_HIDE);
- return FALSE;
-}