diff options
author | George Hazan <ghazan@miranda.im> | 2018-05-20 15:08:48 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-05-20 15:08:48 +0300 |
commit | 8a74e7495ce5ad39de4f5c25121a84d35df90c36 (patch) | |
tree | 03e5b4870f09a3163306740c2eebee47bc15b042 /plugins/AssocMgr | |
parent | c5bf7d6123dd1c3b82ccb8fdb1b068077e9d56d4 (diff) |
CMPlugin to receive a reference to PLUGININFOEX
Diffstat (limited to 'plugins/AssocMgr')
-rw-r--r-- | plugins/AssocMgr/src/assoclist.cpp | 36 | ||||
-rw-r--r-- | plugins/AssocMgr/src/main.cpp | 22 | ||||
-rw-r--r-- | plugins/AssocMgr/src/reg.cpp | 14 | ||||
-rw-r--r-- | plugins/AssocMgr/src/stdafx.h | 8 |
4 files changed, 41 insertions, 39 deletions
diff --git a/plugins/AssocMgr/src/assoclist.cpp b/plugins/AssocMgr/src/assoclist.cpp index 43c538eb2c..a71fca6050 100644 --- a/plugins/AssocMgr/src/assoclist.cpp +++ b/plugins/AssocMgr/src/assoclist.cpp @@ -49,7 +49,7 @@ static BOOL IsAssocEnabled(const ASSOCDATA *assoc) {
char szSetting[MAXMODULELABELLENGTH];
mir_snprintf(szSetting, "enabled_%s", assoc->pszClassName);
- return db_get_b(NULL, "AssocMgr", szSetting, (BYTE)!(assoc->flags&FTDF_DEFAULTDISABLED)) != 0;
+ return db_get_b(NULL, MODULENAME, szSetting, (BYTE)!(assoc->flags&FTDF_DEFAULTDISABLED)) != 0;
}
static void SetAssocEnabled(const ASSOCDATA *assoc, BOOL fEnabled)
@@ -57,13 +57,13 @@ static void SetAssocEnabled(const ASSOCDATA *assoc, BOOL fEnabled) char szSetting[MAXMODULELABELLENGTH];
wchar_t szDLL[MAX_PATH], szBuf[MAX_PATH];
mir_snprintf(szSetting, "enabled_%s", assoc->pszClassName);
- db_set_b(NULL, "AssocMgr", szSetting, (BYTE)fEnabled);
+ db_set_b(NULL, MODULENAME, szSetting, (BYTE)fEnabled);
// dll name for uninstall
if (assoc->hInstance != nullptr && assoc->hInstance != g_plugin.getInst() && assoc->hInstance != GetModuleHandle(nullptr))
if (GetModuleFileName(assoc->hInstance, szBuf, _countof(szBuf)))
if (PathToRelativeW(szBuf, szDLL)) {
mir_snprintf(szSetting, "module_%s", assoc->pszClassName);
- db_set_ws(NULL, "AssocMgr", szSetting, szDLL);
+ db_set_ws(NULL, MODULENAME, szSetting, szDLL);
}
}
@@ -71,10 +71,10 @@ static void DeleteAssocEnabledSetting(const ASSOCDATA *assoc) {
char szSetting[MAXMODULELABELLENGTH];
mir_snprintf(szSetting, "enabled_%s", assoc->pszClassName);
- db_unset(NULL, "AssocMgr", szSetting);
+ db_unset(NULL, MODULENAME, szSetting);
// dll name for uninstall
mir_snprintf(szSetting, "module_%s", assoc->pszClassName);
- db_unset(NULL, "AssocMgr", szSetting);
+ db_unset(NULL, MODULENAME, szSetting);
}
void CleanupAssocEnabledSettings(void)
@@ -88,18 +88,18 @@ void CleanupAssocEnabledSettings(void) char szSetting[MAXMODULELABELLENGTH];
// delete old enabled_* settings if associated plugin no longer present
- if (EnumDbPrefixSettings("AssocMgr", "enabled_", &ppszSettings, &nSettingsCount)) {
+ if (EnumDbPrefixSettings(MODULENAME, "enabled_", &ppszSettings, &nSettingsCount)) {
mir_cslock lck(csAssocList);
for (i = 0; i < nSettingsCount; ++i) {
pszSuffix = &ppszSettings[i][8];
mir_snprintf(szSetting, "module_%s", pszSuffix);
- if (!db_get_ws(NULL, "AssocMgr", szSetting, &dbv)) {
+ if (!db_get_ws(NULL, MODULENAME, szSetting, &dbv)) {
if (PathToAbsoluteW(dbv.ptszVal, szDLL)) {
// file still exists?
hFile = CreateFile(szDLL, 0, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
if (hFile == INVALID_HANDLE_VALUE) {
- db_unset(NULL, "AssocMgr", ppszSettings[i]);
- db_unset(NULL, "AssocMgr", szSetting);
+ db_unset(NULL, MODULENAME, ppszSettings[i]);
+ db_unset(NULL, MODULENAME, szSetting);
}
else CloseHandle(hFile);
}
@@ -117,8 +117,8 @@ static __inline void RememberMimeTypeAdded(const char *pszMimeType, const char * {
char szSetting[MAXMODULELABELLENGTH];
mir_snprintf(szSetting, "mime_%s", pszMimeType);
- if (fAdded) db_set_s(NULL, "AssocMgr", szSetting, pszFileExt);
- else db_unset(NULL, "AssocMgr", szSetting);
+ if (fAdded) db_set_s(NULL, MODULENAME, szSetting, pszFileExt);
+ else db_unset(NULL, MODULENAME, szSetting);
}
static __inline BOOL WasMimeTypeAdded(const char *pszMimeType)
@@ -127,7 +127,7 @@ static __inline BOOL WasMimeTypeAdded(const char *pszMimeType) DBVARIANT dbv;
BOOL fAdded = FALSE;
mir_snprintf(szSetting, "mime_%s", pszMimeType);
- if (!db_get(NULL, "AssocMgr", szSetting, &dbv)) fAdded = TRUE;
+ if (!db_get(NULL, MODULENAME, szSetting, &dbv)) fAdded = TRUE;
else db_free(&dbv);
return fAdded;
}
@@ -140,7 +140,7 @@ void CleanupMimeTypeAddedSettings(void) int i, j;
// delete old mime_* settings and unregister the associated mime type
- if (EnumDbPrefixSettings("AssocMgr", "mime_", &ppszSettings, &nSettingsCount)) {
+ if (EnumDbPrefixSettings(MODULENAME, "mime_", &ppszSettings, &nSettingsCount)) {
mir_cslock lck(csAssocList);
for (i = 0; i < nSettingsCount; ++i) {
pszSuffix = &ppszSettings[i][5];
@@ -148,12 +148,12 @@ void CleanupMimeTypeAddedSettings(void) if (!mir_strcmp(pszSuffix, pAssocList[j].pszMimeType))
break; // mime type in current list
if (j == nAssocListCount) { // mime type not in current list
- if (!db_get(NULL, "AssocMgr", ppszSettings[i], &dbv)) {
+ if (!db_get(NULL, MODULENAME, ppszSettings[i], &dbv)) {
if (dbv.type == DBVT_ASCIIZ)
RemoveRegMimeType(pszSuffix, dbv.pszVal);
db_free(&dbv);
}
- db_unset(NULL, "AssocMgr", ppszSettings[i]);
+ db_unset(NULL, MODULENAME, ppszSettings[i]);
}
mir_free(ppszSettings[i]);
}
@@ -737,7 +737,7 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara ListView_SetItemState(hwndList, lvi.iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE_USEHEADER); // size to fit window
// only while running
- CheckDlgButton(hwndDlg, IDC_ONLYWHILERUNNING, (BOOL)db_get_b(NULL, "AssocMgr", "OnlyWhileRunning", SETTING_ONLYWHILERUNNING_DEFAULT) ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_ONLYWHILERUNNING, (BOOL)db_get_b(NULL, MODULENAME, "OnlyWhileRunning", SETTING_ONLYWHILERUNNING_DEFAULT) ? BST_CHECKED : BST_UNCHECKED);
// autostart
wchar_t *pszRunCmd = MakeRunCommand(TRUE, TRUE);
@@ -864,7 +864,7 @@ static INT_PTR CALLBACK AssocListOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wPara BOOL fEnabled, fRegFailed = FALSE;
// only while running
- db_set_b(NULL, "AssocMgr", "OnlyWhileRunning", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_ONLYWHILERUNNING) != 0));
+ db_set_b(NULL, MODULENAME, "OnlyWhileRunning", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_ONLYWHILERUNNING) != 0));
// save enabled assoc items
HWND hwndList = GetDlgItem(hwndDlg, IDC_ASSOCLIST);
@@ -993,7 +993,7 @@ void UninitAssocList(void) UnhookEvent(hHookOptInit);
// Assoc List
- BYTE fOnlyWhileRunning = db_get_b(NULL, "AssocMgr", "OnlyWhileRunning", SETTING_ONLYWHILERUNNING_DEFAULT);
+ BYTE fOnlyWhileRunning = db_get_b(NULL, MODULENAME, "OnlyWhileRunning", SETTING_ONLYWHILERUNNING_DEFAULT);
for (int i = 0; i < nAssocListCount; ++i) {
ASSOCDATA *assoc = &pAssocList[i];
diff --git a/plugins/AssocMgr/src/main.cpp b/plugins/AssocMgr/src/main.cpp index a998291349..ad2702d0e8 100644 --- a/plugins/AssocMgr/src/main.cpp +++ b/plugins/AssocMgr/src/main.cpp @@ -23,11 +23,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #pragma comment(lib, "delayimp.lib")
-static HANDLE hHookModulesLoaded;
CMPlugin g_plugin;
int &hLangpack(g_plugin.m_hLang);
-PLUGININFOEX pluginInfo = {
+/////////////////////////////////////////////////////////////////////////////////////////
+
+PLUGININFOEX pluginInfoEx = {
sizeof(PLUGININFOEX),
__PLUGIN_NAME,
PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
@@ -40,31 +41,32 @@ PLUGININFOEX pluginInfo = { {0x52685cd7, 0xec7, 0x44c1, {0xa1, 0xa6, 0x38, 0x16, 0x12, 0x41, 0x82, 0x2}}
};
-static int AssocMgrModulesLoaded(WPARAM, LPARAM)
-{
- return 0;
-}
+CMPlugin::CMPlugin() :
+ PLUGIN<CMPlugin>(MODULENAME, pluginInfoEx)
+{}
extern "C" __declspec(dllexport) const PLUGININFOEX* MirandaPluginInfoEx(DWORD)
{
- return &pluginInfo;
+ return &pluginInfoEx;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
extern "C" __declspec(dllexport) int Load(void)
{
- mir_getLP(&pluginInfo);
+ mir_getLP(&pluginInfoEx);
InitAssocList();
InitDde();
- hHookModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, AssocMgrModulesLoaded);
return 0;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
extern "C" __declspec(dllexport) int Unload(void)
{
UninitDde();
UninitAssocList();
- UnhookEvent(hHookModulesLoaded);
return 0;
}
diff --git a/plugins/AssocMgr/src/reg.cpp b/plugins/AssocMgr/src/reg.cpp index ee7f8745b2..eb8db987b2 100644 --- a/plugins/AssocMgr/src/reg.cpp +++ b/plugins/AssocMgr/src/reg.cpp @@ -338,7 +338,7 @@ static void WriteDbBackupData(const char *pszSetting, DWORD dwType, BYTE *pData, if (buf) {
*(DWORD*)buf = dwType;
memcpy(buf + sizeof(DWORD), pData, cbData);
- db_set_blob(NULL, "AssocMgr", pszSetting, buf, (unsigned)cbLen);
+ db_set_blob(NULL, MODULENAME, pszSetting, buf, (unsigned)cbLen);
mir_free(buf);
}
}
@@ -347,7 +347,7 @@ static void WriteDbBackupData(const char *pszSetting, DWORD dwType, BYTE *pData, static BOOL ReadDbBackupData(const char *pszSetting, DWORD *pdwType, BYTE **ppData, DWORD *pcbData)
{
DBVARIANT dbv;
- if (!db_get(0, "AssocMgr", pszSetting, &dbv)) {
+ if (!db_get(0, MODULENAME, pszSetting, &dbv)) {
if (dbv.type == DBVT_BLOB && dbv.cpbVal >= sizeof(DWORD)) {
*pdwType = *(DWORD*)dbv.pbVal;
*ppData = dbv.pbVal;
@@ -454,7 +454,7 @@ static LONG RestoreRegTree(HKEY hKey, const char *pszSubKey, const char *pszDbPr if (pszPrefixWithSubKey != nullptr) {
int nSettingsCount;
char **ppszSettings;
- if (EnumDbPrefixSettings("AssocMgr", pszPrefixWithSubKey, &ppszSettings, &nSettingsCount)) {
+ if (EnumDbPrefixSettings(MODULENAME, pszPrefixWithSubKey, &ppszSettings, &nSettingsCount)) {
for (int i = 0; i < nSettingsCount; ++i) {
char *pszSuffix = &ppszSettings[i][nDbPrefixLen];
// key hierachy
@@ -486,7 +486,7 @@ static LONG RestoreRegTree(HKEY hKey, const char *pszSubKey, const char *pszDbPr }
else res = ERROR_INVALID_DATA;
if (res) break;
- db_unset(NULL, "AssocMgr", ppszSettings[i]);
+ db_unset(NULL, MODULENAME, ppszSettings[i]);
if (hSubKey != hKey) RegCloseKey(hSubKey);
}
mir_free(ppszSettings[i]);
@@ -507,9 +507,9 @@ static void DeleteRegTreeBackup(const char *pszSubKey, const char *pszDbPrefix) if (pszPrefixWithSubKey == nullptr) return;
mir_strcat(mir_strcat(mir_strcpy(pszPrefixWithSubKey, pszDbPrefix), pszSubKey), "\\"); // buffer safe
if (pszPrefixWithSubKey != nullptr) {
- if (EnumDbPrefixSettings("AssocMgr", pszPrefixWithSubKey, &ppszSettings, &nSettingsCount)) {
+ if (EnumDbPrefixSettings(MODULENAME, pszPrefixWithSubKey, &ppszSettings, &nSettingsCount)) {
for (i = 0; i < nSettingsCount; ++i) {
- db_unset(NULL, "AssocMgr", ppszSettings[i]);
+ db_unset(NULL, MODULENAME, ppszSettings[i]);
mir_free(ppszSettings[i]);
}
mir_free(ppszSettings);
@@ -523,7 +523,7 @@ void CleanupRegTreeBackupSettings(void) // delete old bak_* settings and try to restore backups
int nSettingsCount;
char **ppszSettings;
- if (!EnumDbPrefixSettings("AssocMgr", "bak_", &ppszSettings, &nSettingsCount))
+ if (!EnumDbPrefixSettings(MODULENAME, "bak_", &ppszSettings, &nSettingsCount))
return;
for (int i = 0; i < nSettingsCount; ++i) {
diff --git a/plugins/AssocMgr/src/stdafx.h b/plugins/AssocMgr/src/stdafx.h index b68cbfd6db..59108c7499 100644 --- a/plugins/AssocMgr/src/stdafx.h +++ b/plugins/AssocMgr/src/stdafx.h @@ -45,9 +45,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "resource.h"
#include "version.h"
+#define MODULENAME "AssocMgr"
+
struct CMPlugin : public PLUGIN<CMPlugin>
{
- CMPlugin() :
- PLUGIN<CMPlugin>("AssocMgr")
- {}
-};
\ No newline at end of file + CMPlugin();
+};
|