diff options
-rw-r--r-- | include/newpluginapi.h | 7 | ||||
-rw-r--r-- | src/mir_app/src/menu_utils.cpp | 64 | ||||
-rw-r--r-- | src/mir_core/src/utils.cpp | 2 |
3 files changed, 40 insertions, 33 deletions
diff --git a/include/newpluginapi.h b/include/newpluginapi.h index e02d454caf..1226df7ccc 100644 --- a/include/newpluginapi.h +++ b/include/newpluginapi.h @@ -49,6 +49,13 @@ struct MUUID unsigned char d[8];
};
+__forceinline bool operator==(const MUUID &p1, const MUUID &p2)
+{ return memcmp(&p1, &p2, sizeof(MUUID)) == 0;
+}
+__forceinline bool operator!=(const MUUID &p1, const MUUID &p2)
+{ return memcmp(&p1, &p2, sizeof(MUUID)) != 0;
+}
+
MIR_APP_DLL(int) GetPluginLangId(const MUUID &uuid, int hLangpack);
MIR_APP_DLL(int) IsPluginLoaded(const MUUID &uuid);
diff --git a/src/mir_app/src/menu_utils.cpp b/src/mir_app/src/menu_utils.cpp index 3d6d498883..5572157cad 100644 --- a/src/mir_app/src/menu_utils.cpp +++ b/src/mir_app/src/menu_utils.cpp @@ -967,9 +967,7 @@ void ScheduleMenuUpdate() static int sttFindMenuItemByUid(TMO_IntMenuItem *pimi, void *pUid)
{
- char szUid[33];
- bin2hex(&pimi->mi.uid, sizeof(MUUID), szUid);
- return !strcmp(szUid, (char*)pUid);
+ return 0 == memcmp(&pimi->mi.uid, pUid, sizeof(MUUID));
}
int Menu_LoadFromDatabase(TMO_IntMenuItem *pimi, void *szModule)
@@ -988,21 +986,25 @@ int Menu_LoadFromDatabase(TMO_IntMenuItem *pimi, void *szModule) TCHAR *ptszToken = szValue, *pDelim = _tcschr(szValue, ';');
int bVisible = true, pos = 0;
TCHAR tszCustomName[201]; tszCustomName[0] = 0;
- char szCustomRoot[33]; szCustomRoot[0] = 0;
+ MUUID customRoot = {};
for (int i = 0; i < 4; i++) {
if (pDelim)
*pDelim = 0;
switch (i) {
- case 0: bVisible = _ttoi(ptszToken); break;
- case 1: pos = _ttoi(ptszToken); break;
- case 2: strncpy_s(szCustomRoot, _T2A(ptszToken), _TRUNCATE); break;
+ case 0: bVisible = _ttoi(ptszToken); break;
+ case 1: pos = _ttoi(ptszToken); break;
+ case 2:
+ hex2binT(ptszToken, &customRoot, sizeof(customRoot));
+ if (customRoot == pimi->mi.uid) // prevent a loop
+ memset(&customRoot, 0, sizeof(customRoot));
+ break;
}
ptszToken = pDelim + 1;
if ((pDelim = _tcschr(ptszToken, ';')) == NULL) {
if (i == 2 && *ptszToken != 0)
- _tcsncpy_s(tszCustomName, ptszToken, _TRUNCATE); break;
+ _tcsncpy_s(tszCustomName, ptszToken, _TRUNCATE);
break;
}
}
@@ -1017,32 +1019,30 @@ int Menu_LoadFromDatabase(TMO_IntMenuItem *pimi, void *szModule) if (tszCustomName[0])
replaceStrT(pimi->ptszCustomName, tszCustomName);
- if (szCustomRoot[0]) {
- char szCurrentUid[33];
- if (pimi->mi.root == NULL)
- szCurrentUid[0] = 0;
- else
- bin2hex(&pimi->mi.root->mi.uid, sizeof(pimi->mi.root->mi.uid), szCurrentUid);
+ MUUID currentUid;
+ if (pimi->mi.root == NULL)
+ memset(¤tUid, 0, sizeof(currentUid));
+ else
+ memcpy(¤tUid, &pimi->mi.root->mi.uid, sizeof(currentUid));
- if (0 != strcmp(szCurrentUid, szCustomRoot)) { // need to move menu item to another root
- TMO_LinkedList *pNew;
- if (szCustomRoot[0] != 0) {
- TMO_IntMenuItem *p = MO_RecursiveWalkMenu(pmo->m_items.first, sttFindMenuItemByUid, &szCustomRoot);
- if (p == NULL)
- return NULL;
-
- pimi->mi.root = p;
- pNew = &p->submenu;
- }
- else {
- pimi->mi.root = NULL;
- pNew = &pmo->m_items;
- }
-
- // relink menu item
- pimi->owner->remove(pimi);
- pNew->insert(pimi);
+ if (currentUid != customRoot) { // need to move menu item to another root
+ TMO_LinkedList *pNew;
+ if (customRoot != miid_last) {
+ TMO_IntMenuItem *p = MO_RecursiveWalkMenu(pmo->m_items.first, sttFindMenuItemByUid, &customRoot);
+ if (p == NULL)
+ return 0;
+
+ pimi->mi.root = p;
+ pNew = &p->submenu;
+ }
+ else {
+ pimi->mi.root = NULL;
+ pNew = &pmo->m_items;
}
+
+ // relink menu item
+ pimi->owner->remove(pimi);
+ pNew->insert(pimi);
}
return 0;
diff --git a/src/mir_core/src/utils.cpp b/src/mir_core/src/utils.cpp index a2f1ab0171..d065e8fa1b 100644 --- a/src/mir_core/src/utils.cpp +++ b/src/mir_core/src/utils.cpp @@ -317,7 +317,7 @@ MIR_CORE_DLL(bool) hex2binW(const wchar_t *pSrc, void *pData, size_t len) if (pSrc == NULL || pData == NULL || len == 0)
return false;
- size_t bufLen = wcslen(pSrc);
+ size_t bufLen = wcslen(pSrc)/2;
if (pSrc[bufLen * 2] != 0 || bufLen > len)
return false;
|