diff options
author | George Hazan <ghazan@miranda.im> | 2018-05-10 15:30:27 +0200 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-05-10 15:30:27 +0200 |
commit | 32e1155026a444bc9aa753257b717bf0c81bc0d7 (patch) | |
tree | 60649b639beff1707595506c4e0b02be0b5998d8 | |
parent | ff3e3d685cc9fc8e924f57f0371dfc3a4d5c20d8 (diff) |
fixes #1335 (Reimplement XEP support in SmileyAdd again)
-rw-r--r-- | plugins/SmileyAdd/src/options.cpp | 4 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/smileys.cpp | 113 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/smileys.h | 3 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/stdafx.h | 1 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/version.h | 2 |
5 files changed, 115 insertions, 8 deletions
diff --git a/plugins/SmileyAdd/src/options.cpp b/plugins/SmileyAdd/src/options.cpp index 897982ade5..de31cf1b8a 100644 --- a/plugins/SmileyAdd/src/options.cpp +++ b/plugins/SmileyAdd/src/options.cpp @@ -482,9 +482,9 @@ bool OptionsDialogType::BrowseForSmileyPacks(int item) wchar_t filter[512], *pfilter;
mir_wstrcpy(filter, TranslateT("Smiley packs"));
- mir_wstrcat(filter, L" (*.msl;*.asl)");
+ mir_wstrcat(filter, L" (*.msl;*.asl;*.xep)");
pfilter = filter + mir_wstrlen(filter) + 1;
- mir_wstrcpy(pfilter, L"*.msl;*.asl");
+ mir_wstrcpy(pfilter, L"*.msl;*.asl;*.xep");
pfilter = pfilter + mir_wstrlen(pfilter) + 1;
mir_wstrcpy(pfilter, TranslateT("All files"));
mir_wstrcat(pfilter, L" (*.*)");
diff --git a/plugins/SmileyAdd/src/smileys.cpp b/plugins/SmileyAdd/src/smileys.cpp index 73a303a393..abb83b3db6 100644 --- a/plugins/SmileyAdd/src/smileys.cpp +++ b/plugins/SmileyAdd/src/smileys.cpp @@ -383,7 +383,6 @@ bool SmileyPackType::LoadSmileyFile(const CMStringW &filename, const CMStringW & _close(fh);
CMStringW tbuf;
-
if (len > 2 && *(wchar_t*)buf == 0xfeff)
tbuf = ((wchar_t*)buf + 1);
else if (len > 3 && buf[0] == '\xef' && buf[1] == '\xbb' && buf[2] == '\xbf')
@@ -393,6 +392,113 @@ bool SmileyPackType::LoadSmileyFile(const CMStringW &filename, const CMStringW & delete[] buf;
+ bool res;
+ if (filename.Find(L".xep") == -1)
+ res = LoadSmileyFileMSL(tbuf, onlyInfo, modpath);
+ else
+ res = LoadSmileyFileXEP(tbuf, onlyInfo);
+
+ if (errorFound)
+ ReportError(TranslateT("There were problems loading smiley pack (it should be corrected).\nSee network log for details."));
+
+ return res;
+}
+
+static IStream* DecodeBase64Data(const wchar_t *pString)
+{
+ size_t dataLen;
+ ptrA data((char*)mir_base64_decode(_T2A(pString), &dataLen));
+ if (data == nullptr)
+ return nullptr;
+
+ // Read image list
+ HGLOBAL hBuffer = GlobalAlloc(GMEM_MOVEABLE, dataLen);
+ if (!hBuffer)
+ return nullptr;
+
+ void *dst = GlobalLock(hBuffer);
+ memcpy(dst, data, dataLen);
+ GlobalUnlock(hBuffer);
+
+ IStream *pStream = nullptr;
+ CreateStreamOnHGlobal(hBuffer, TRUE, &pStream);
+ return pStream;
+}
+
+static CMStringW FilterQuotes(const wchar_t *pStr)
+{
+ CMStringW res(pStr);
+ int iStart = res.Find('\"', 0);
+ if (iStart != -1) {
+ int iEnd = res.Find('\"', ++iStart);
+ if (iEnd != -1)
+ res = res.Mid(iStart, iEnd - iStart);
+ }
+
+ return res;
+}
+
+bool SmileyPackType::LoadSmileyFileXEP(CMStringW &tbuf, bool onlyInfo)
+{
+ HXML node, xmlRoot = xmlParseString(tbuf, nullptr, nullptr);
+ if (!xmlRoot)
+ return false;
+
+ if (node = xmlGetChildByPath(xmlRoot, L"settings/DataBaseName", 0))
+ m_Name = xmlGetText(node);
+ if (node = xmlGetChildByPath(xmlRoot, L"settings/PackageAuthor", 0))
+ m_Author = xmlGetText(node);
+
+ if (!onlyInfo) {
+ const wchar_t *pStr = xmlGetClear(xmlGetChildByPath(xmlRoot, L"lists/images", 0), 0, 0, 0);
+ if (pStr) {
+ IStream *pStream = DecodeBase64Data(pStr);
+ if (pStream) {
+ if (m_hSmList != nullptr)
+ ImageList_Destroy(m_hSmList);
+ m_hSmList = ImageList_Read(pStream);
+ pStream->Release();
+ }
+ }
+
+ HXML nRec, dataRoot = xmlGetChildByPath(xmlRoot, L"dataroot", 0);
+ for (int i = 0; (nRec = xmlGetNthChild(dataRoot, L"record", i)) != 0; i++) {
+ pStr = xmlGetAttrValue(nRec, L"ImageIndex");
+ if (pStr == nullptr)
+ continue;
+
+ SmileyType *dat = new SmileyType;
+ dat->SetRegEx(true);
+ dat->SetImList(m_hSmList, _wtoi(pStr));
+ dat->m_ToolText = xmlGetText(nRec);
+
+ if (node = xmlGetChildByPath(nRec, L"Expression", 0))
+ dat->m_TriggerText = FilterQuotes(xmlGetText(node));
+ if (node = xmlGetChildByPath(nRec, L"PasteText", 0))
+ dat->m_InsertText = FilterQuotes(xmlGetText(node));
+
+ dat->SetHidden(dat->m_InsertText.IsEmpty());
+
+ if (node = xmlGetChildByPath(nRec, L"Image", 0)) {
+ IStream *pStream = DecodeBase64Data(xmlGetText(node));
+ if (pStream) {
+ dat->LoadFromImage(pStream);
+ pStream->Release();
+ }
+ }
+
+ m_SmileyList.insert(dat);
+ }
+ }
+
+ xmlDestroyNode(xmlRoot);
+
m_VisibleCount = m_SmileyList.getCount();
AddTriggersToSmileyLookup();
+ selec.x = selec.y = win.x = win.y = 0;
+ return true;
+}
+
+bool SmileyPackType::LoadSmileyFileMSL(CMStringW &tbuf, bool onlyInfo, CMStringW &modpath)
+{
CMStringW pathstr, packstr;
{
MRegexp16 pathsplit(L"(.*\\\\)(.*)\\.|$");
@@ -497,6 +603,7 @@ bool SmileyPackType::LoadSmileyFile(const CMStringW &filename, const CMStringW & ReplaceAllSpecials(dat->m_TriggerText, dat->m_ToolText);
}
+ bool noerr;
if (resname.IsEmpty()) {
dat->SetHidden(true);
dat->SetText(true);
@@ -523,10 +630,6 @@ bool SmileyPackType::LoadSmileyFile(const CMStringW &filename, const CMStringW & m_VisibleCount = m_SmileyList.getCount();
m_SmileyList.splice(hiddenSmileys);
AddTriggersToSmileyLookup();
-
- if (errorFound)
- ReportError(TranslateT("There were problems loading smiley pack (it should be corrected).\nSee network log for details."));
-
return true;
}
diff --git a/plugins/SmileyAdd/src/smileys.h b/plugins/SmileyAdd/src/smileys.h index d75d40c418..d0d7a0ef3c 100644 --- a/plugins/SmileyAdd/src/smileys.h +++ b/plugins/SmileyAdd/src/smileys.h @@ -203,6 +203,9 @@ public: bool LoadSmileyFile(const CMStringW &filename, const CMStringW &packname, bool onlyInfo, bool noerr = false);
+ bool LoadSmileyFileMSL(CMStringW &body, bool bOnlyInfo, CMStringW &modPath);
+ bool LoadSmileyFileXEP(CMStringW &body, bool bOnlyInfo);
+
void Clear(void);
};
diff --git a/plugins/SmileyAdd/src/stdafx.h b/plugins/SmileyAdd/src/stdafx.h index 3993c29660..db2cc70b63 100644 --- a/plugins/SmileyAdd/src/stdafx.h +++ b/plugins/SmileyAdd/src/stdafx.h @@ -68,6 +68,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <m_regexp.h>
#include <m_string.h>
#include <m_fontservice.h>
+#include <m_xml.h>
#include <m_metacontacts.h>
#include <m_smileyadd.h>
diff --git a/plugins/SmileyAdd/src/version.h b/plugins/SmileyAdd/src/version.h index 5c207eebfb..486043ea5f 100644 --- a/plugins/SmileyAdd/src/version.h +++ b/plugins/SmileyAdd/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 3
#define __RELEASE_NUM 0
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>
|