summaryrefslogtreecommitdiff
path: root/plugins/AutoRun/src
diff options
context:
space:
mode:
authorVadim Dashevskiy <watcherhd@gmail.com>2012-07-05 10:15:32 +0000
committerVadim Dashevskiy <watcherhd@gmail.com>2012-07-05 10:15:32 +0000
commit9ee9547340e785ca4eb38294d975d6e1a3a567f2 (patch)
tree65fe6c30298656e053a743ce560f8bb341a0b680 /plugins/AutoRun/src
parent1927dce5b48f9f5b77bca38ca01c8ce6f25097f3 (diff)
AutoRun: changed folder structure
git-svn-id: http://svn.miranda-ng.org/main/trunk@766 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/AutoRun/src')
-rw-r--r--plugins/AutoRun/src/autorun.h23
-rw-r--r--plugins/AutoRun/src/main.cpp144
-rw-r--r--plugins/AutoRun/src/resource.h17
3 files changed, 184 insertions, 0 deletions
diff --git a/plugins/AutoRun/src/autorun.h b/plugins/AutoRun/src/autorun.h
new file mode 100644
index 0000000000..4d0900fcf0
--- /dev/null
+++ b/plugins/AutoRun/src/autorun.h
@@ -0,0 +1,23 @@
+#define _CRT_SECURE_NO_WARNINGS
+#define MIRANDA_VER 0x0A00
+
+#include <windows.h>
+
+#include <newpluginapi.h>
+#include <m_langpack.h>
+#include <m_options.h>
+#include <m_database.h>
+#include <win2k.h>
+
+#include "resource.h"
+
+#define SUB_KEY _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run")
+#define ModuleName "Autorun"
+
+// Plugin UUID for New plugin loader
+// req. 0.7.18+ core
+// {EB0465E2-CEEE-11DB-83EF-C1BF55D89593}
+
+#define MIID_AUTORUN {0xeb0465e2, 0xceee, 0x11db, { 0x83, 0xef, 0xc1, 0xbf, 0x55, 0xd8, 0x95, 0x93}}
+
+HKEY ROOT_KEY = HKEY_CURRENT_USER;
diff --git a/plugins/AutoRun/src/main.cpp b/plugins/AutoRun/src/main.cpp
new file mode 100644
index 0000000000..36eebd47f2
--- /dev/null
+++ b/plugins/AutoRun/src/main.cpp
@@ -0,0 +1,144 @@
+#include "autorun.h"
+
+HINSTANCE hInst;
+HANDLE hHookOptionInit = NULL;
+int hLangpack;
+
+PLUGININFOEX pluginInfoEx=
+{ // about plugin
+ sizeof(PLUGININFOEX),
+ "Autorun",
+ PLUGIN_MAKE_VERSION(0,1,0,1),
+ "This plugin is a simple way to enable/disable to launch Miranda IM with system startup.",
+ "Sergey V. Gershovich a.k.a. Jazzy$ (fixed by Wolfram3D)",
+ "",
+ "Copyright © 2002-2007 Sergey V. Gershovich a.k.a. Jazzy$",
+ "http://miranda-im.org/download/index.php?action=viewfile&id=285",
+ UNICODE_AWARE,
+ MIID_AUTORUN
+};
+
+BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
+{
+ hInst = hinstDLL;
+ return TRUE;
+}
+void GetProfilePath(TCHAR *res)
+{
+ TCHAR dbname[MAX_PATH], dbpath[MAX_PATH], exename[MAX_PATH];
+ CallService(MS_DB_GETPROFILENAMET, SIZEOF(dbname), (LPARAM)(TCHAR*) dbname);
+ CallService(MS_DB_GETPROFILEPATHT, SIZEOF(dbpath), (LPARAM)(TCHAR*) dbpath);
+ GetModuleFileName(NULL,exename, SIZEOF(exename));
+ lstrcat(dbpath, _T("\\"));
+ lstrcpyn(dbpath + lstrlen(dbpath), dbname, lstrlen(dbname)-3);
+ lstrcat(dbpath, _T("\\"));
+ lstrcat(dbpath, dbname); // path + profile name
+ mir_sntprintf(res, lstrlen(exename) + lstrlen(dbpath) + 5, _T("\"%s\" \"%s\""), exename, dbpath);
+}
+
+static void SetAutorun(BOOL autorun)
+{
+ HKEY hKey;
+ DWORD dw;
+ switch (autorun)
+ {
+ case TRUE:
+ if (RegCreateKeyEx(ROOT_KEY, SUB_KEY, 0, NULL, 0, KEY_CREATE_SUB_KEY|KEY_SET_VALUE,NULL,&hKey,&dw) == ERROR_SUCCESS)
+ {
+ TCHAR result[MAX_PATH];
+ GetProfilePath(result);
+ RegSetValueEx(hKey, _T("MirandaIM"), 0, REG_SZ, (BYTE*)result, lstrlen(result)+1);
+ RegCloseKey(hKey);
+ break;
+ }
+ case FALSE:
+ if (RegOpenKey(ROOT_KEY, SUB_KEY, &hKey) == ERROR_SUCCESS)
+ {
+ RegDeleteValue(hKey, _T("MirandaIM"));
+ RegCloseKey(hKey);
+ break;
+ }
+ }
+}
+
+static BOOL CmpCurrentAndRegistry()
+{
+ HKEY hKey;
+ DWORD dwBufLen = MAX_PATH;
+ TCHAR result[MAX_PATH], dbpath[MAX_PATH];
+ GetProfilePath(result);
+
+ if (RegOpenKeyEx(ROOT_KEY, SUB_KEY, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
+ {
+ if (RegQueryValueEx(hKey, _T("MirandaIM"), NULL, NULL, (LPBYTE)dbpath, &dwBufLen) == ERROR_SUCCESS)
+ {
+ return (lstrcmpi(result,dbpath) == 0 ? TRUE : FALSE);
+ }
+ else
+ return FALSE;
+ }
+ else
+ return FALSE;
+}
+
+static INT_PTR CALLBACK DlgProcAutorunOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+ CheckDlgButton(hwndDlg,IDC_AUTORUN,CmpCurrentAndRegistry()); // Check chekbox if Registry value exists
+ return TRUE;
+ case WM_COMMAND:
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); // Send message to activate "Apply" button
+ return TRUE;
+ break;
+ case WM_NOTIFY:
+ switch(((LPNMHDR)lParam)->idFrom) {
+ case 0:
+ switch (((LPNMHDR)lParam)->code)
+ {
+ case PSN_APPLY: // if "Apply" pressed then...
+ SetAutorun(IsDlgButtonChecked(hwndDlg,IDC_AUTORUN)); //Save changes to registry;
+ return TRUE;
+ }
+ break;
+ }
+ break;
+ }
+ return FALSE;
+}
+
+static int AutorunOptInitialise(WPARAM wParam,LPARAM lParam)
+{
+ OPTIONSDIALOGPAGE odp = { 0 };
+ odp.cbSize = sizeof(odp);
+ odp.position = 100100000;
+ odp.hInstance = hInst;
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_AUTORUN);
+ odp.pszTitle = LPGEN(ModuleName);
+ odp.pszGroup = LPGEN("Plugins");
+ odp.pfnDlgProc = DlgProcAutorunOpts;
+ odp.flags = ODPF_BOLDGROUPS;
+ Options_AddPage(wParam, &odp);
+ return 0;
+}
+
+extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
+{
+ return &pluginInfoEx;
+}
+
+extern "C" __declspec(dllexport) int Load(void)
+{
+ mir_getLP(&pluginInfoEx);
+ hHookOptionInit = HookEvent(ME_OPT_INITIALISE, AutorunOptInitialise);
+ return 0;
+}
+
+extern "C" __declspec(dllexport) int Unload(void)
+{
+ if (hHookOptionInit)
+ UnhookEvent(hHookOptionInit);
+ return 0;
+} \ No newline at end of file
diff --git a/plugins/AutoRun/src/resource.h b/plugins/AutoRun/src/resource.h
new file mode 100644
index 0000000000..75fd39b582
--- /dev/null
+++ b/plugins/AutoRun/src/resource.h
@@ -0,0 +1,17 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Developer Studio generated include file.
+// Used by autorun.rc
+//
+#define IDD_OPT_AUTORUN 101
+#define IDC_AUTORUN 102
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 101
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1000
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif