summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Dashevskiy <watcherhd@gmail.com>2012-10-22 09:40:44 +0000
committerVadim Dashevskiy <watcherhd@gmail.com>2012-10-22 09:40:44 +0000
commita8a2a1e55b5ae4ba2b770d02cb6909d9d2ff4387 (patch)
tree10e4581d1cbcc054d9a7af3e3c17334405354c0e
parent9f88cd559f7d5929a4a48b0ebf57b3fc5e689405 (diff)
ProfileManager and Restar plugin's services now restart Miranda to the same profile they where called from
git-svn-id: http://svn.miranda-ng.org/main/trunk@2040 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--plugins/ProfileManager/src/pmanagerEx.cpp21
-rw-r--r--plugins/Restart/src/restart.cpp22
2 files changed, 39 insertions, 4 deletions
diff --git a/plugins/ProfileManager/src/pmanagerEx.cpp b/plugins/ProfileManager/src/pmanagerEx.cpp
index 8565faab30..5009d4b898 100644
--- a/plugins/ProfileManager/src/pmanagerEx.cpp
+++ b/plugins/ProfileManager/src/pmanagerEx.cpp
@@ -16,6 +16,7 @@ There is no warranty.
#include <m_skin.h>
#include <m_langpack.h>
#include <m_system.h>
+#include <m_utils.h>
#include <win2k.h>
#include "resource.h"
@@ -26,7 +27,7 @@ TCHAR fn[MAX_PATH];
TCHAR lmn[MAX_PATH];
TCHAR* pathn;
int hLangpack;
-HANDLE hLoadPM, hChangePM, hDbchecker;
+HANDLE hLoadPM, hChangePM, hDbchecker, hRestartMe;
PLUGININFOEX pluginInfo={
sizeof(PLUGININFOEX),
@@ -82,6 +83,21 @@ static INT_PTR CheckDb(WPARAM wParam, LPARAM lParam)
return 0;
}
+static INT_PTR RestartMe(WPARAM wParam, LPARAM lParam)
+{
+ TCHAR mirandaPath[MAX_PATH], cmdLine[100];
+ PROCESS_INFORMATION pi;
+ STARTUPINFO si = {0};
+ si.cb = sizeof(si);
+ GetModuleFileName(NULL, mirandaPath, SIZEOF(mirandaPath));
+ TCHAR *profilename = Utils_ReplaceVarsT(_T("%miranda_profilename%"));
+ mir_sntprintf(cmdLine, SIZEOF(cmdLine), _T("\"%s\" /restart:%d /profile=%s"), mirandaPath, GetCurrentProcessId(), profilename);
+ CallService("CloseAction", 0, 0);
+ CreateProcess(mirandaPath, cmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
+ mir_free(profilename);
+ return 0;
+}
+
extern "C" __declspec(dllexport) int Load(void)
{
CLISTMENUITEM mi;
@@ -121,6 +137,7 @@ extern "C" __declspec(dllexport) int Load(void)
mi.pszService = "Database/CheckDb";
Menu_AddMainMenuItem(&mi);
+ hRestartMe = CreateServiceFunction("System/RestartMe", RestartMe);
ZeroMemory(&mi, sizeof(mi));
mi.cbSize = sizeof(mi);
mi.position = -500200000;
@@ -128,7 +145,7 @@ extern "C" __declspec(dllexport) int Load(void)
mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_Restart));
mi.ptszPopupName = NULL;
mi.ptszName = _T("Restart");
- mi.pszService = MS_SYSTEM_RESTART;
+ mi.pszService = "System/RestartMe";
Menu_AddMainMenuItem(&mi);
return 0;
diff --git a/plugins/Restart/src/restart.cpp b/plugins/Restart/src/restart.cpp
index 07c15b60e7..c4215794a2 100644
--- a/plugins/Restart/src/restart.cpp
+++ b/plugins/Restart/src/restart.cpp
@@ -6,11 +6,13 @@
#include <m_langpack.h>
#include <m_system.h>
#include <m_genmenu.h>
+#include <m_utils.h>
+#include <win2k.h>
#include "resource.h"
HINSTANCE hInst;
-HANDLE hIconHandle;
int hLangpack;
+HANDLE hIconHandle, hRestartMe;
PLUGININFOEX pluginInfo={
sizeof(PLUGININFOEX),
@@ -36,6 +38,21 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD miranda
return &pluginInfo;
}
+static INT_PTR RestartMe(WPARAM wParam, LPARAM lParam)
+{
+ TCHAR mirandaPath[MAX_PATH], cmdLine[100];
+ PROCESS_INFORMATION pi;
+ STARTUPINFO si = {0};
+ si.cb = sizeof(si);
+ GetModuleFileName(NULL, mirandaPath, SIZEOF(mirandaPath));
+ TCHAR *profilename = Utils_ReplaceVarsT(_T("%miranda_profilename%"));
+ mir_sntprintf(cmdLine, SIZEOF(cmdLine), _T("\"%s\" /restart:%d /profile=%s"), mirandaPath, GetCurrentProcessId(), profilename);
+ CallService("CloseAction", 0, 0);
+ CreateProcess(mirandaPath, cmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
+ mir_free(profilename);
+ return 0;
+}
+
extern "C" __declspec(dllexport) int Load(void)
{
mir_getLP( &pluginInfo );
@@ -53,12 +70,13 @@ extern "C" __declspec(dllexport) int Load(void)
sid.iDefaultIndex = -IDI_RESTARTICON;
hIconHandle = Skin_AddIcon(&sid);
+ hRestartMe = CreateServiceFunction("System/RestartMe", RestartMe);
CLISTMENUITEM mi = { sizeof(mi) };
mi.position = -0x7FFFFFFF;
mi.flags = CMIF_ICONFROMICOLIB | CMIF_TCHAR;
mi.icolibItem = hIconHandle;
mi.ptszName = _T("Restart");
- mi.pszService = MS_SYSTEM_RESTART;
+ mi.pszService = "System/RestartMe";
Menu_AddMainMenuItem(&mi);
Menu_AddTrayMenuItem(&mi);
return 0;