summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Plugins/emoticons/Docs/emoticons_changelog.txt3
-rw-r--r--Plugins/emoticons/commons.h5
-rw-r--r--Plugins/emoticons/data/Customize/Emoticons/Originals/Originals.mep89
-rw-r--r--Plugins/emoticons/data/Plugins/Emoticons/JGMAIL.emo16
-rw-r--r--Plugins/emoticons/data/Plugins/Emoticons/MSN.emo4
-rw-r--r--Plugins/emoticons/emoticons.cpp297
-rw-r--r--Plugins/emoticons/emoticons.vcproj8
7 files changed, 392 insertions, 30 deletions
diff --git a/Plugins/emoticons/Docs/emoticons_changelog.txt b/Plugins/emoticons/Docs/emoticons_changelog.txt
index e0090af..3faea7b 100644
--- a/Plugins/emoticons/Docs/emoticons_changelog.txt
+++ b/Plugins/emoticons/Docs/emoticons_changelog.txt
@@ -2,6 +2,9 @@ Emoticons
Changelog:
+. 0.0.1.6
+ + Allow URLs in emoticon packs
+
. 0.0.1.5
+ Added MySpace and AIM emoticons
* Fix for smileys after URL (closes issue 11)
diff --git a/Plugins/emoticons/commons.h b/Plugins/emoticons/commons.h
index f924b9d..84d0abe 100644
--- a/Plugins/emoticons/commons.h
+++ b/Plugins/emoticons/commons.h
@@ -74,6 +74,7 @@ using namespace std;
#include "../utils/mir_options.h"
#include "../utils/mir_icons.h"
#include "../utils/mir_buffer.h"
+#include "../utils/ContactAsyncQueue.h"
#include "resource.h"
#include "m_emoticons.h"
@@ -102,14 +103,16 @@ struct EmoticonImage
char *name;
char *relPath;
char *module;
+ char *url;
// For selection window
HBITMAP img;
BOOL transparent;
- EmoticonImage() : name(0), relPath(0), img(0), module(0) {}
+ EmoticonImage() : name(0), relPath(0), img(0), module(0), url(0) {}
~EmoticonImage();
+ void Download();
void Load(int &max_height, int &max_width);
void Release();
BOOL isAvaiable();
diff --git a/Plugins/emoticons/data/Customize/Emoticons/Originals/Originals.mep b/Plugins/emoticons/data/Customize/Emoticons/Originals/Originals.mep
new file mode 100644
index 0000000..c33a3ee
--- /dev/null
+++ b/Plugins/emoticons/data/Customize/Emoticons/Originals/Originals.mep
@@ -0,0 +1,89 @@
+Name: Original emoticons
+
+# Google Talk
+"JGMAIL\smile" = "http://mail.google.com/mail/im/emoticons/smile.gif"
+"JGMAIL\laugh" = "http://mail.google.com/mail/im/emoticons/grin.gif"
+"JGMAIL\wink" = "http://mail.google.com/mail/im/emoticons/wink.gif"
+"JGMAIL\crying" = "http://mail.google.com/mail/im/emoticons/cry.gif"
+"JGMAIL\shock" = "http://mail.google.com/mail/im/emoticons/shocked.gif"
+"JGMAIL\thinking" = "http://mail.google.com/mail/im/emoticons/slant.gif"
+"JGMAIL\dazed" = "http://mail.google.com/mail/im/emoticons/angry.gif"
+"JGMAIL\sad" = "http://mail.google.com/mail/im/emoticons/frown.gif"
+"JGMAIL\glass-cool" = "http://mail.google.com/mail/im/emoticons/cool.gif"
+"JGMAIL\tongue" = "http://mail.google.com/mail/im/emoticons/tongue.gif"
+"JGMAIL\love" = "http://mail.google.com/mail/im/emoticons/heart.gif"
+"JGMAIL\neutral" = "http://mail.google.com/mail/im/emoticons/straightface.gif"
+"JGMAIL\monkey" = "http://mail.google.com/mail/im/emoticons/monkey.gif"
+"JGMAIL\rock" = "http://mail.google.com/mail/im/emoticons/rockout.gif"
+
+# MSN
+# http://messenger.msn.com/Resource/Emoticons.aspx
+"MSN\smile" = "http://messenger.msn.com/Resource/emoticons/regular_smile.gif"
+"MSN\laugh" = "http://messenger.msn.com/Resource/emoticons/teeth_smile.gif"
+"MSN\shock" = "http://messenger.msn.com/Resource/emoticons/omg_smile.gif"
+"MSN\tongue" = "http://messenger.msn.com/Resource/emoticons/tongue_smile.gif"
+"MSN\wink" = "http://messenger.msn.com/Resource/emoticons/wink_smile.gif"
+"MSN\sad" = "http://messenger.msn.com/Resource/emoticons/sad_smile.gif"
+"MSN\confused" = "http://messenger.msn.com/Resource/emoticons/confused_smile.gif"
+"MSN\neutral" = "http://messenger.msn.com/Resource/emoticons/what_smile.gif"
+"MSN\crying" = "http://messenger.msn.com/Resource/emoticons/cry_smile.gif"
+"MSN\embarrassed" = "http://messenger.msn.com/Resource/emoticons/red_smile.gif"
+"MSN\glass-cool" = "http://messenger.msn.com/Resource/emoticons/shades_smile.gif"
+"MSN\angry" = "http://messenger.msn.com/Resource/emoticons/angry_smile.gif"
+"MSN\angel" = "http://messenger.msn.com/Resource/emoticons/angel_smile.gif"
+"MSN\devilish" = "http://messenger.msn.com/Resource/emoticons/devil_smile.gif"
+"MSN\quiet" = "http://messenger.msn.com/Resource/emoticons/47_47.gif"
+"MSN\teeth" = "http://messenger.msn.com/Resource/emoticons/48_48.gif"
+"MSN\glass-nerdy" = "http://messenger.msn.com/Resource/emoticons/49_49.gif"
+"MSN\sarcastic" = "http://messenger.msn.com/Resource/emoticons/50_50.gif"
+"MSN\secret" = "http://messenger.msn.com/Resource/emoticons/51_51.gif"
+"MSN\sick" = "http://messenger.msn.com/Resource/emoticons/52_52.gif"
+"MSN\dont-know" = "http://messenger.msn.com/Resource/emoticons/71_71.gif"
+"MSN\thinking" = "http://messenger.msn.com/Resource/emoticons/72_72.gif"
+"MSN\party" = "http://messenger.msn.com/Resource/emoticons/74_74.gif"
+"MSN\eyeroll" = "http://messenger.msn.com/Resource/emoticons/75_75.gif"
+"MSN\sleepy" = "http://messenger.msn.com/Resource/emoticons/77_77.gif"
+"MSN\coffee" = "http://messenger.msn.com/Resource/emoticons/coffee.gif"
+"MSN\yes" = "http://messenger.msn.com/Resource/emoticons/thumbs_up.gif"
+"MSN\no" = "http://messenger.msn.com/Resource/emoticons/thumbs_down.gif"
+"MSN\beer" = "http://messenger.msn.com/Resource/emoticons/beer_mug.gif"
+"MSN\drink" = "http://messenger.msn.com/Resource/emoticons/martini.gif"
+"MSN\female" = "http://messenger.msn.com/Resource/emoticons/girl.gif"
+"MSN\male" = "http://messenger.msn.com/Resource/emoticons/guy.gif"
+"MSN\hug-left" = "http://messenger.msn.com/Resource/emoticons/guy_hug.gif"
+"MSN\hug-right" = "http://messenger.msn.com/Resource/emoticons/girl_hug.gif"
+"MSN\vampire" = "http://messenger.msn.com/Resource/emoticons/bat.gif"
+"MSN\cake" = "http://messenger.msn.com/Resource/emoticons/cake.gif"
+"MSN\love" = "http://messenger.msn.com/Resource/emoticons/heart.gif"
+"MSN\love-over" = "http://messenger.msn.com/Resource/emoticons/broken_heart.gif"
+"MSN\kiss" = "http://messenger.msn.com/Resource/emoticons/kiss.gif"
+"MSN\present" = "http://messenger.msn.com/Resource/emoticons/present.gif"
+"MSN\rose" = "http://messenger.msn.com/Resource/emoticons/rose.gif"
+"MSN\rose-dead" = "http://messenger.msn.com/Resource/emoticons/wilted_rose.gif"
+"MSN\camera" = "http://messenger.msn.com/Resource/emoticons/camera.gif"
+"MSN\film" = "http://messenger.msn.com/Resource/emoticons/film.gif"
+"MSN\cat" = "http://messenger.msn.com/Resource/emoticons/cat.gif"
+"MSN\dog" = "http://messenger.msn.com/Resource/emoticons/dog.gif"
+"MSN\phone" = "http://messenger.msn.com/Resource/emoticons/phone.gif"
+"MSN\lamp" = "http://messenger.msn.com/Resource/emoticons/lightbulb.gif"
+"MSN\music" = "http://messenger.msn.com/Resource/emoticons/note.gif"
+"MSN\moon" = "http://messenger.msn.com/Resource/emoticons/moon.gif"
+"MSN\star" = "http://messenger.msn.com/Resource/emoticons/star.gif"
+"MSN\mail" = "http://messenger.msn.com/Resource/emoticons/envelope.gif"
+"MSN\clock" = "http://messenger.msn.com/Resource/emoticons/clock.gif"
+"MSN\msn" = "http://messenger.msn.com/Resource/emoticons/messenger.gif"
+"MSN\snail" = "http://messenger.msn.com/Resource/emoticons/53_53.gif"
+"MSN\sheep" = "http://messenger.msn.com/Resource/emoticons/70_70.gif"
+"MSN\plate" = "http://messenger.msn.com/Resource/emoticons/55_55.gif"
+"MSN\bowl" = "http://messenger.msn.com/Resource/emoticons/56_56.gif"
+"MSN\pizza" = "http://messenger.msn.com/Resource/emoticons/57_57.gif"
+"MSN\soccerball" = "http://messenger.msn.com/Resource/emoticons/58_58.gif"
+"MSN\car" = "http://messenger.msn.com/Resource/emoticons/59_59.gif"
+"MSN\airplane" = "http://messenger.msn.com/Resource/emoticons/60_60.gif"
+"MSN\umbrella" = "http://messenger.msn.com/Resource/emoticons/61_61.gif"
+"MSN\island" = "http://messenger.msn.com/Resource/emoticons/62_62.gif"
+"MSN\computer" = "http://messenger.msn.com/Resource/emoticons/63_63.gif"
+"MSN\mobile" = "http://messenger.msn.com/Resource/emoticons/64_64.gif"
+"MSN\rain" = "http://messenger.msn.com/Resource/emoticons/66_66.gif"
+"MSN\thunder" = "http://messenger.msn.com/Resource/emoticons/73_73.gif"
+"MSN\coins" = "http://messenger.msn.com/Resource/emoticons/69_69.gif"
diff --git a/Plugins/emoticons/data/Plugins/Emoticons/JGMAIL.emo b/Plugins/emoticons/data/Plugins/Emoticons/JGMAIL.emo
index 8f0f7e1..8da0fb3 100644
--- a/Plugins/emoticons/data/Plugins/Emoticons/JGMAIL.emo
+++ b/Plugins/emoticons/data/Plugins/Emoticons/JGMAIL.emo
@@ -1,5 +1,7 @@
# Google Talk protocol emoticons
+[Google Talk]
+
"smile" = "Smile", ":)" ":-)" "=)"
"laugh" = "Grin", ":D" ":-D" "=D"
"wink" = "Wink", ";)" ";-)" ";^)"
@@ -12,8 +14,16 @@
"tongue" = "Tongue", ":P" ":-P"
"love" = "Heart", "<3"
"neutral" = "Straight Face", ":-|"
-"monkey" = "It's a Monkey!", ":(|)"
-"rock" = "Rock out", "\\m/"
+
+[Hidden]
+
"bell" = "Cowbell", "+/'\\"
+"monkey" = "It's a Monkey!", ":(|)"
+"crab" = "Crab", "V.v.V"
+"pig" = "Pig", ":(:)"
"devilish" = "Devil", "}:-)" "}:)"
-"doh" = "Wince", ">.<" \ No newline at end of file
+"doh" = "Wince", ">.<"
+"rock" = "Rock out", "\\m/"
+"love-over" = "Broken Heart", "</3"
+"kiss" = "Kiss", ":*" ":-x"
+"mustache" = "Mustache", ":{"
diff --git a/Plugins/emoticons/data/Plugins/Emoticons/MSN.emo b/Plugins/emoticons/data/Plugins/Emoticons/MSN.emo
index 21cccff..c4dd7b6 100644
--- a/Plugins/emoticons/data/Plugins/Emoticons/MSN.emo
+++ b/Plugins/emoticons/data/Plugins/Emoticons/MSN.emo
@@ -45,7 +45,7 @@
"music" = "Note", "(8)"
"mail" = "E-mail", "(E)" "(e)"
"present" = "Gift with a bow", "(G)" "(g)"
-"cake" = "", "(^)"
+"cake" = "Birthday cake", "(^)"
"camera" = "Camera", "(P)" "(p)"
"lamp" = "Light bulb", "(I)" "(i)"
"coffee" = "Coffee cup", "(C)" "(c)"
@@ -56,7 +56,7 @@
"female" = "Girl", "(X)" "(x)"
"yes" = "Thumbs up", "(Y)" "(y)"
"no" = "Thumbs down", "(N)" "(n)"
-"vampire" = "", ":[" ":-["
+"vampire" = "Vampire bat", ":[" ":-["
"goat" = "Goat", "(nah)"
"turtle" = "Turtle", "(tu)"
"plate" = "Plate", "(pl)"
diff --git a/Plugins/emoticons/emoticons.cpp b/Plugins/emoticons/emoticons.cpp
index dabe53a..54f8175 100644
--- a/Plugins/emoticons/emoticons.cpp
+++ b/Plugins/emoticons/emoticons.cpp
@@ -52,6 +52,7 @@ PLUGINLINK *pluginLink;
HANDLE hHooks[3] = {0};
HANDLE hServices[4] = {0};
HANDLE hChangedEvent;
+HANDLE hNetlibUser = 0;
HANDLE hProtocolsFolder = NULL;
TCHAR protocolsFolder[1024];
@@ -74,11 +75,19 @@ LIST<Module> modules(10);
LIST<EmoticonPack> packs(10);
LIST<Contact> contacts(10);
+ContactAsyncQueue *downloadQueue;
+
BOOL LoadModule(Module *m);
void LoadModules();
BOOL LoadPack(EmoticonPack *p);
void LoadPacks();
+BOOL isValidExtension(char *name);
+#ifdef UNICODE
+BOOL isValidExtension(WCHAR *name);
+#endif
+void DownloadCallback(HANDLE hContact, void *param);
+void log(const char *fmt, ...);
void FillModuleImages(EmoticonPack *pack);
EmoticonPack *GetPack(char *name);
@@ -189,7 +198,6 @@ extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
return interfaces;
}
-
extern "C" int __declspec(dllexport) Load(PLUGINLINK *link)
{
pluginLink = link;
@@ -206,6 +214,8 @@ extern "C" int __declspec(dllexport) Load(PLUGINLINK *link)
hChangedEvent = CreateHookableEvent(ME_SMILEYADD_OPTIONSCHANGED);
+ downloadQueue = new ContactAsyncQueue(DownloadCallback, 1);
+
return 0;
}
@@ -302,6 +312,14 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam)
hServices[2] = CreateServiceFunction(MS_SMILEYADD_GETINFO2, GetInfo2Service);
hServices[3] = CreateServiceFunction(MS_SMILEYADD_SHOWSELECTION, ShowSelectionService);
+ NETLIBUSER nl_user = {0};
+ nl_user.cbSize = sizeof(nl_user);
+ nl_user.szSettingsModule = MODULE_NAME;
+ nl_user.flags = NUF_OUTGOING | NUF_HTTPCONNS;
+ nl_user.szDescriptiveName = Translate("Emoticon downloads");
+
+ hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nl_user);
+
loaded = TRUE;
return 0;
@@ -312,6 +330,9 @@ int PreShutdown(WPARAM wParam, LPARAM lParam)
{
int i;
+ delete downloadQueue;
+ downloadQueue = NULL;
+
// Delete packs
for(i = 0; i < packs.getCount(); i++)
{
@@ -334,6 +355,9 @@ int PreShutdown(WPARAM wParam, LPARAM lParam)
DeInitOptions();
+ if(hNetlibUser)
+ CallService(MS_NETLIB_CLOSEHANDLE, (WPARAM)hNetlibUser, 0);
+
return 0;
}
@@ -1191,6 +1215,28 @@ char *strtrim(char *str)
}
+BOOL HasProto(char *proto)
+{
+ PROTOCOLDESCRIPTOR **protos;
+ int count;
+ CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM)&count, (LPARAM)&protos);
+
+ for (int i = 0; i < count; i++)
+ {
+ if (protos[i]->type != PROTOTYPE_PROTOCOL)
+ continue;
+
+ if (protos[i]->szName == NULL || protos[i]->szName[0] == '\0')
+ continue;
+
+ if (stricmp(proto, protos[i]->szName) == 0)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
void LoadModules()
{
// Load the language files and create an array with then
@@ -1208,9 +1254,17 @@ void LoadModules()
if (!FileExists(file))
continue;
+ char *name = mir_t2a(ffd.cFileName);
+ name[strlen(name) - 4] = 0;
+
+ if (stricmp("Default", name) != 0 && !HasProto(name))
+ {
+ mir_free(name);
+ continue;
+ }
+
Module *m = new Module();
- m->name = mir_t2a(ffd.cFileName);
- m->name[strlen(m->name) - 4] = 0;
+ m->name = name;
m->path = mir_tstrdup(file);
modules.insert(m);
@@ -1364,6 +1418,38 @@ void LoadPacks()
}
+BOOL isValidExtension(char *name)
+{
+ char *p = strrchr(name, '.');
+ if (p == NULL)
+ return FALSE;
+ if (strcmp(p, ".jpg") != 0
+ && strcmp(p, ".jpeg") != 0
+ && strcmp(p, ".gif") != 0
+ && strcmp(p, ".png") != 0
+ /*&& strcmp(p, ".swf") != 0*/)
+ return FALSE;
+ return TRUE;
+}
+
+
+#ifdef UNICODE
+BOOL isValidExtension(WCHAR *name)
+{
+ WCHAR *p = wcsrchr(name, L'.');
+ if (p == NULL)
+ return FALSE;
+ if (lstrcmpW(p, L".jpg") != 0
+ && lstrcmpW(p, L".jpeg") != 0
+ && lstrcmpW(p, L".gif") != 0
+ && lstrcmpW(p, L".png") != 0
+ /*&& lstrcmpW(p, L".swf") != 0*/)
+ return FALSE;
+ return TRUE;
+}
+#endif
+
+
EmoticonImage * HandleMepLine(EmoticonPack *p, char *line)
{
int len = strlen(line);
@@ -1423,7 +1509,32 @@ EmoticonImage * HandleMepLine(EmoticonPack *p, char *line)
img->module = module;
break;
case 3:
- img->relPath = txt;
+ if (!isValidExtension(txt))
+ {
+ delete img;
+ img = NULL;
+ break;
+ }
+
+ if (strncmp("http://", txt, 7) == 0)
+ {
+ img->url = txt;
+
+ char *p = strrchr(txt, '//');
+ p++;
+
+ char tmp[1024];
+ if (img->module == NULL)
+ mir_snprintf(tmp, MAX_REGS(tmp), "cache\\%s", p);
+ else
+ mir_snprintf(tmp, MAX_REGS(tmp), "cache\\%s\\%s", img->module, p);
+
+ img->relPath = mir_strdup(tmp);
+ }
+ else
+ {
+ img->relPath = txt;
+ }
break;
}
@@ -1452,18 +1563,13 @@ BOOL LoadPack(EmoticonPack *pack)
if (!FileExists(filename))
continue;
- int len = strlen(ffd.cFileName);
- if (len < 5)
- continue;
- if (strcmp(&ffd.cFileName[len-4], ".jpg") != 0
- && strcmp(&ffd.cFileName[len-4], ".gif") != 0
- && strcmp(&ffd.cFileName[len-4], ".png"))
+ if (!isValidExtension(ffd.cFileName))
continue;
EmoticonImage *img = new EmoticonImage();
img->pack = pack;
img->name = mir_strdup(ffd.cFileName);
- img->name[strlen(img->name) - 4] = 0;
+ *strrchr(img->name, '.') = '\0';
img->relPath = mir_strdup(ffd.cFileName);
pack->images.insert(img);
}
@@ -1596,18 +1702,13 @@ EmoticonImage * GetEmoticomImageFromDisk(EmoticonPack *pack, Emoticon *e, Module
if (!FileExists(filename))
continue;
- int len = strlen(ffd.cFileName);
- if (len < 5)
- continue;
- if (strcmp(&ffd.cFileName[len-4], ".jpg") != 0
- && strcmp(&ffd.cFileName[len-4], ".gif") != 0
- && strcmp(&ffd.cFileName[len-4], ".png"))
+ if (!isValidExtension(ffd.cFileName))
continue;
img = new EmoticonImage();
img->pack = pack;
img->name = mir_strdup(ffd.cFileName);
- img->name[strlen(img->name) - 4] = 0;
+ *strrchr(img->name, '.') = '\0';
img->module = module->name;
mir_snprintf(filename, MAX_REGS(filename), "%s\\%s", module->name, ffd.cFileName);
img->relPath = mir_strdup(filename);
@@ -1646,7 +1747,10 @@ void FillModuleImages(EmoticonPack *pack)
}
}
if (e->img != NULL)
+ {
+ e->img->Download();
continue;
+ }
// Now try to load from disk
e->img = GetEmoticomImageFromDisk(pack, e, m);
@@ -1879,6 +1983,7 @@ EmoticonImage::~EmoticonImage()
MIR_FREE(name);
MIR_FREE(module);
MIR_FREE(relPath);
+ MIR_FREE(url);
}
@@ -1900,6 +2005,20 @@ BOOL EmoticonImage::isAvaiable()
}
+void EmoticonImage::Download()
+{
+ if (url == NULL)
+ return;
+
+ char tmp[1024];
+ mir_snprintf(tmp, MAX_REGS(tmp), "%s\\%s", pack->path, relPath);
+ if (FileExists(tmp))
+ return;
+
+ downloadQueue->AddIfDontHave(0, (HANDLE) this);
+}
+
+
void EmoticonImage::Load(int &max_height, int &max_width)
{
if (img != NULL)
@@ -2185,12 +2304,7 @@ int LoadContactSmileysService(WPARAM wParam, LPARAM lParam)
if (!FileExists(filename))
continue;
- int len = lstrlen(ffd.cFileName);
- if (len < 5)
- continue;
- if (lstrcmp(&ffd.cFileName[len-4], _T(".jpg")) != 0
- && lstrcmp(&ffd.cFileName[len-4], _T(".gif")) != 0
- && lstrcmp(&ffd.cFileName[len-4], _T(".png")))
+ if (!isValidExtension(ffd.cFileName))
continue;
CreateCustomSmiley(c, filename);
@@ -2208,3 +2322,138 @@ int LoadContactSmileysService(WPARAM wParam, LPARAM lParam)
return 0;
}
+
+
+BOOL CreatePath(const char *path)
+{
+ char folder[1024];
+ strncpy(folder, path, MAX_REGS(folder));
+ folder[MAX_REGS(folder)-1] = '\0';
+
+ char *p = folder;
+ if (p[0] && p[1] && p[1] == ':' && p[2] == '\\') p += 3; // skip drive letter
+
+ SetLastError(ERROR_SUCCESS);
+ while(p = strchr(p, '\\'))
+ {
+ *p = '\0';
+ CreateDirectoryA(folder, 0);
+ *p = '\\';
+ p++;
+ }
+ CreateDirectoryA(folder, 0);
+
+ DWORD lerr = GetLastError();
+ return (lerr == ERROR_SUCCESS || lerr == ERROR_ALREADY_EXISTS);
+}
+
+
+BOOL GetFile(char *url, char *dest, int recurse_count = 0)
+{
+ if(recurse_count > 5)
+ {
+ log("GetFile: error, too many redirects");
+ return FALSE;
+ }
+
+ // Assert path exists
+ char *p = strrchr(dest, '\\');
+ if (p != NULL)
+ {
+ *p = '\0';
+ if (!CreatePath(dest))
+ {
+ log("GetFile: error creating temp folder, code %d", (int) GetLastError());
+ *p = '\\';
+ return FALSE;
+ }
+ *p = '\\';
+ }
+
+ NETLIBHTTPREQUEST req = {0};
+
+ req.cbSize = sizeof(req);
+ req.requestType = REQUEST_GET;
+ req.szUrl = url;
+ req.flags = NLHRF_NODUMP;
+
+ NETLIBHTTPREQUEST *resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser, (LPARAM)&req);
+ if (resp == NULL)
+ {
+ log("GetFile: failed to download \"%s\" : error %d", url, (int) GetLastError());
+ return FALSE;
+ }
+
+ BOOL ret = FALSE;
+
+ if (resp->resultCode == 200)
+ {
+ HANDLE hSaveFile = CreateFileA(dest, GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
+ if (hSaveFile != INVALID_HANDLE_VALUE)
+ {
+ unsigned long bytes_written = 0;
+ if (WriteFile(hSaveFile, resp->pData, resp->dataLength, &bytes_written, NULL) == TRUE)
+ ret = TRUE;
+ else
+ log("GetFile: error writing file \"%s\", code %d", dest, (int) GetLastError());
+
+ CloseHandle(hSaveFile);
+ }
+ else
+ {
+ log("GetFile: error creating file \"%s\", code %d", dest, (int) GetLastError());
+ }
+ }
+ else if (resp->resultCode >= 300 && resp->resultCode < 400)
+ {
+ // get new location
+ for (int i = 0; i < resp->headersCount; i++)
+ {
+ if (strcmp(resp->headers[i].szName, "Location") == 0)
+ {
+ ret = GetFile(resp->headers[i].szValue, dest, recurse_count + 1);
+ break;
+ }
+ }
+ }
+ else
+ {
+ log("GetFile: failed to download \"%s\" : Invalid response, code %d", url, resp->resultCode);
+ }
+
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp);
+
+ return ret;
+}
+
+
+void DownloadCallback(HANDLE hContact, void *param)
+{
+ EmoticonImage *img = (EmoticonImage *) hContact;
+ if (img == NULL || img->url == NULL)
+ return;
+
+ char tmp[1024];
+ mir_snprintf(tmp, MAX_REGS(tmp), "%s\\%s", img->pack->path, img->relPath);
+ if (FileExists(tmp))
+ return;
+
+ if (!GetFile(img->url, tmp))
+ {
+ // Avoid further downloads
+ MIR_FREE(img->url);
+ }
+}
+
+
+void log(const char *fmt, ...)
+{
+ va_list va;
+ char text[1024];
+
+ va_start(va, fmt);
+ mir_vsnprintf(text, sizeof(text), fmt, va);
+ va_end(va);
+
+ CallService(MS_NETLIB_LOG, (WPARAM) hNetlibUser, (LPARAM) text);
+} \ No newline at end of file
diff --git a/Plugins/emoticons/emoticons.vcproj b/Plugins/emoticons/emoticons.vcproj
index 12423a7..f359277 100644
--- a/Plugins/emoticons/emoticons.vcproj
+++ b/Plugins/emoticons/emoticons.vcproj
@@ -427,6 +427,10 @@
>
</File>
<File
+ RelativePath="..\utils\ContactAsyncQueue.h"
+ >
+ </File>
+ <File
RelativePath="m_emoticons.h"
>
</File>
@@ -505,6 +509,10 @@
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
+ RelativePath="..\utils\ContactAsyncQueue.cpp"
+ >
+ </File>
+ <File
RelativePath="emoticons.cpp"
>
<FileConfiguration