diff options
author | George Hazan <george.hazan@gmail.com> | 2014-07-31 17:50:56 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-07-31 17:50:56 +0000 |
commit | 9631bfe941ed0cbba6e720b7efd92966e0c6a670 (patch) | |
tree | 7b76ef132a0afb2e7185923d368a7fc328358b76 | |
parent | 83a45d3e3f7bccff5b32dc0cb2d0e81340ec6ec2 (diff) |
old ugly trash removed from AVS
git-svn-id: http://svn.miranda-ng.org/main/trunk@10005 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | plugins/AVS/src/acc.cpp | 2 | ||||
-rw-r--r-- | plugins/AVS/src/cache.cpp | 266 | ||||
-rw-r--r-- | plugins/AVS/src/commonheaders.h | 17 | ||||
-rw-r--r-- | plugins/AVS/src/main.cpp | 3 | ||||
-rw-r--r-- | plugins/AVS/src/options.cpp | 4 | ||||
-rw-r--r-- | plugins/AVS/src/poll.cpp | 29 | ||||
-rw-r--r-- | plugins/AVS/src/services.cpp | 9 | ||||
-rw-r--r-- | plugins/AVS/src/utils.cpp | 22 | ||||
-rw-r--r-- | plugins/AVS/src/version.h | 4 |
9 files changed, 160 insertions, 196 deletions
diff --git a/plugins/AVS/src/acc.cpp b/plugins/AVS/src/acc.cpp index a99c3a2e59..3d79469baf 100644 --- a/plugins/AVS/src/acc.cpp +++ b/plugins/AVS/src/acc.cpp @@ -75,7 +75,7 @@ typedef struct } ACCData;
-BOOL AnimatedGifGetData(ACCData* data)
+BOOL AnimatedGifGetData(ACCData *data)
{
FIBITMAP *page = fei->FI_LockPage(data->ag.multi, 0);
if (page == NULL)
diff --git a/plugins/AVS/src/cache.cpp b/plugins/AVS/src/cache.cpp index ead84e1aa8..73f39892c9 100644 --- a/plugins/AVS/src/cache.cpp +++ b/plugins/AVS/src/cache.cpp @@ -19,65 +19,54 @@ Boston, MA 02111-1307, USA. #include "commonheaders.h"
-static int g_maxBlock = 0, g_curBlock = 0;
-static CacheNode **g_cacheBlocks = NULL;
-
-static CacheNode *g_Cache = 0;
-static mir_cs alloccs, cachecs;
-
-// allocate a cache block and add it to the list of blocks
-// does not link the new block with the old block(s) - caller needs to do this
-
-static CacheNode* AllocCacheBlock()
+CacheNode::CacheNode()
{
- CacheNode *allocedBlock = (CacheNode*)malloc(CACHE_BLOCKSIZE * sizeof(struct CacheNode));
- ZeroMemory((void *)allocedBlock, sizeof(CacheNode) * CACHE_BLOCKSIZE);
-
- for (int i = 0; i < CACHE_BLOCKSIZE - 1; i++)
- allocedBlock[i].pNextNode = &allocedBlock[i + 1]; // pre-link the alloced block
-
- if (g_Cache == NULL) // first time only...
- g_Cache = allocedBlock;
-
- // add it to the list of blocks
- if (g_curBlock == g_maxBlock) {
- g_maxBlock += 10;
- g_cacheBlocks = (CacheNode**)realloc(g_cacheBlocks, g_maxBlock * sizeof(CacheNode*));
- }
- g_cacheBlocks[g_curBlock++] = allocedBlock;
-
- return(allocedBlock);
}
-void InitCache(void)
+CacheNode::~CacheNode()
{
- AllocCacheBlock();
+ if (hbmPic != 0)
+ DeleteObject(hbmPic);
}
-void UnloadCache(void)
+void CacheNode::wipeInfo()
{
- for (CacheNode *cc = g_Cache; cc; cc = cc->pNextNode)
- if (cc->ace.hbmPic != 0)
- DeleteObject(cc->ace.hbmPic);
+ MCONTACT saveContact = hContact;
+ if (hbmPic)
+ DeleteObject(hbmPic);
+ memset(this, 0, sizeof(CacheNode));
+ hContact = saveContact;
+}
- for (int i = 0; i < g_curBlock; i++)
- free(g_cacheBlocks[i]);
- free(g_cacheBlocks);
+static int CompareNodes(const CacheNode *p1, const CacheNode *p2)
+{
+ return INT_PTR(p1->hContact) - INT_PTR(p2->hContact);
}
-// link a new cache block with the already existing chain of blocks
+static OBJLIST<CacheNode> arCache(100, CompareNodes);
+static LIST<CacheNode> arQueue(10);
+static mir_cs alloccs, cachecs;
-static CacheNode* AddToList(CacheNode *node)
+// allocate a cache block and add it to the list of blocks
+// does not link the new block with the old block(s) - caller needs to do this
+
+void UnloadCache(void)
{
- CacheNode *pCurrent = g_Cache;
- while (pCurrent->pNextNode != 0)
- pCurrent = pCurrent->pNextNode;
+ arCache.destroy();
+}
- pCurrent->pNextNode = node;
- return pCurrent;
+void PushAvatarRequest(CacheNode *cc)
+{
+ mir_cslock lck(alloccs);
+ int idx = arQueue.getCount();
+ if (idx > 0)
+ idx--;
+ arQueue.insert(cc, idx);
}
-CacheNode* FindAvatarInCache(MCONTACT hContact, BOOL add, BOOL findAny)
+// link a new cache block with the already existing chain of blocks
+
+CacheNode* FindAvatarInCache(MCONTACT hContact, bool add, bool findAny)
{
if (g_shutDown)
return NULL;
@@ -86,38 +75,28 @@ CacheNode* FindAvatarInCache(MCONTACT hContact, BOOL add, BOOL findAny) if (szProto == NULL || !db_get_b(NULL, AVS_MODULE, szProto, 1))
return NULL;
- mir_cslock lck(cachecs);
-
- CacheNode *cc = g_Cache, *foundNode = NULL;
- while (cc) {
- if (cc->ace.hContact == hContact) {
- cc->ace.t_lastAccess = time(NULL);
- foundNode = cc->loaded || findAny ? cc : NULL;
- return foundNode;
- }
+ avatarCacheEntry tmp;
+ tmp.hContact = hContact;
- // found an empty and usable node
- if (foundNode == NULL && cc->ace.hContact == 0)
- foundNode = cc;
+ mir_cslock lck(cachecs);
- cc = cc->pNextNode;
+ CacheNode *cc = arCache.find((CacheNode*)&tmp);
+ if (cc) {
+ cc->t_lastAccess = time(NULL);
+ return (cc->loaded || findAny) ? cc : NULL;
}
// not found
if (!add)
return NULL;
- if (foundNode == NULL) { // no free entry found, create a new and append it to the list
- mir_cslock all(alloccs); // protect memory block allocation
- CacheNode *newNode = AllocCacheBlock();
- AddToList(newNode);
- foundNode = newNode;
- }
+ cc = new CacheNode();
+ cc->hContact = hContact;
+ arCache.insert(cc);
+
+ PushAvatarRequest(cc);
- foundNode->ace.hContact = hContact;
- foundNode->loaded = FALSE;
- foundNode->mustLoad = 1; // pic loader will watch this and load images
- SetEvent(hLoaderEvent); // wake him up
+ SetEvent(hLoaderEvent); // wake him up
return NULL;
}
@@ -134,7 +113,7 @@ void NotifyMetaAware(MCONTACT hContact, CacheNode *node = NULL, AVATARCACHEENTRY return;
if (ace == (AVATARCACHEENTRY*)-1)
- ace = &node->ace;
+ ace = node;
NotifyEventHooks(hEventChanged, hContact, (LPARAM)ace);
@@ -145,12 +124,12 @@ void NotifyMetaAware(MCONTACT hContact, CacheNode *node = NULL, AVATARCACHEENTRY if (node->dwFlags & AVH_MUSTNOTIFY) {
// Fire the event for avatar history
node->dwFlags &= ~AVH_MUSTNOTIFY;
- if (node->ace.szFilename[0] != '\0') {
+ if (node->szFilename[0] != '\0') {
CONTACTAVATARCHANGEDNOTIFICATION cacn = { 0 };
cacn.cbSize = sizeof(CONTACTAVATARCHANGEDNOTIFICATION);
cacn.hContact = hContact;
cacn.format = node->pa_format;
- _tcsncpy(cacn.filename, node->ace.szFilename, MAX_PATH);
+ _tcsncpy(cacn.filename, node->szFilename, MAX_PATH);
cacn.filename[MAX_PATH - 1] = 0;
// Get hash
@@ -182,22 +161,28 @@ void NotifyMetaAware(MCONTACT hContact, CacheNode *node = NULL, AVATARCACHEENTRY // An cache entry is never deleted. What is deleted is the image handle inside it
// This is done this way to keep track of which avatars avs have to keep track
-void DeleteAvatarFromCache(MCONTACT hContact, BOOL forever)
+void DeleteAvatarFromCache(MCONTACT hContact, bool bForever)
{
if (g_shutDown)
return;
- hContact = GetContactThatHaveTheAvatar(hContact);
- CacheNode *node = FindAvatarInCache(hContact, FALSE);
- if (node == NULL) {
- CacheNode temp_node = { 0 };
+ avatarCacheEntry tmp;
+ tmp.hContact = GetContactThatHaveTheAvatar(hContact);
+
+ mir_cslock lck(cachecs);
+ int idx = arCache.getIndex((CacheNode*)&tmp);
+ if (idx == -1) {
+ CacheNode temp_node;
+ memset(&temp_node, 0, sizeof(temp_node));
NotifyMetaAware(hContact, &temp_node, (AVATARCACHEENTRY *)GetProtoDefaultAvatar(hContact));
- return;
}
- node->mustLoad = -1; // mark for deletion
- if (forever)
- node->dwFlags |= AVS_DELETENODEFOREVER;
- SetEvent(hLoaderEvent);
+ else {
+ NotifyMetaAware(hContact, &arCache[idx], (AVATARCACHEENTRY*)GetProtoDefaultAvatar(hContact));
+ if (!bForever)
+ arCache[idx].wipeInfo();
+ else
+ arCache.remove(idx);
+ }
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -207,15 +192,16 @@ int SetAvatarAttribute(MCONTACT hContact, DWORD attrib, int mode) if (g_shutDown)
return 0;
- for (CacheNode *cc = g_Cache; cc; cc = cc->pNextNode) {
- if (cc->ace.hContact != hContact)
- continue;
+ avatarCacheEntry tmp;
+ tmp.hContact = hContact;
- DWORD dwFlags = cc->ace.dwFlags;
- cc->ace.dwFlags = mode ? (cc->ace.dwFlags | attrib) : (cc->ace.dwFlags & ~attrib);
- if (cc->ace.dwFlags != dwFlags)
+ mir_cslock lck(cachecs);
+ CacheNode *cc = arCache.find((CacheNode*)&tmp);
+ if (cc != NULL) {
+ DWORD dwFlags = cc->dwFlags;
+ cc->dwFlags = mode ? (cc->dwFlags | attrib) : (cc->dwFlags & ~attrib);
+ if (cc->dwFlags != dwFlags)
NotifyMetaAware(hContact, cc);
- break;
}
return 0;
}
@@ -224,7 +210,7 @@ int SetAvatarAttribute(MCONTACT hContact, DWORD attrib, int mode) // nodes where mustLoad is < 0 (must be deleted).
// its waken up by the event and tries to lock the cache only when absolutely necessary.
-void PicLoader(LPVOID param)
+void PicLoader(LPVOID)
{
DWORD dwDelay = db_get_dw(NULL, AVS_MODULE, "picloader_sleeptime", 80);
@@ -234,75 +220,57 @@ void PicLoader(LPVOID param) dwDelay = 100;
while (!g_shutDown) {
- CacheNode *node = g_Cache;
-
- while (!g_shutDown && node) {
- if (node->mustLoad > 0 && node->ace.hContact) {
- node->mustLoad = 0;
- AVATARCACHEENTRY ace_temp;
-
- if (db_get_b(node->ace.hContact, "ContactPhoto", "NeedUpdate", 0))
- QueueAdd(node->ace.hContact);
-
- CopyMemory(&ace_temp, &node->ace, sizeof(AVATARCACHEENTRY));
- ace_temp.hbmPic = 0;
-
- int result = CreateAvatarInCache(node->ace.hContact, &ace_temp, NULL);
- if (result == -2) {
- char *szProto = GetContactProto(node->ace.hContact);
- if (szProto == NULL || Proto_NeedDelaysForAvatars(szProto))
- QueueAdd(node->ace.hContact);
- else if (FetchAvatarFor(node->ace.hContact, szProto) == GAIR_SUCCESS) // Try to create again
- result = CreateAvatarInCache(node->ace.hContact, &ace_temp, NULL);
- }
+ while (!g_shutDown) {
+ CacheNode *node;
+ {
+ mir_cslock all(alloccs);
+ node = arQueue[0];
+ if (node)
+ arQueue.remove(0);
+ }
+ if (node == NULL)
+ break;
+
+ if (db_get_b(node->hContact, "ContactPhoto", "NeedUpdate", 0))
+ QueueAdd(node->hContact);
+
+ AVATARCACHEENTRY ace_temp;
+ CopyMemory(&ace_temp, node, sizeof(AVATARCACHEENTRY));
+ ace_temp.hbmPic = 0;
+
+ int result = CreateAvatarInCache(node->hContact, &ace_temp, NULL);
+ if (result == -2) {
+ char *szProto = GetContactProto(node->hContact);
+ if (szProto == NULL || Proto_NeedDelaysForAvatars(szProto))
+ QueueAdd(node->hContact);
+ else if (FetchAvatarFor(node->hContact, szProto) == GAIR_SUCCESS) // Try to create again
+ result = CreateAvatarInCache(node->hContact, &ace_temp, NULL);
+ }
- if (result == 1 && ace_temp.hbmPic != 0) { // Loaded
- HBITMAP oldPic = node->ace.hbmPic;
- {
- mir_cslock l(cachecs);
- CopyMemory(&node->ace, &ace_temp, sizeof(AVATARCACHEENTRY));
- node->loaded = TRUE;
- }
- if (oldPic)
- DeleteObject(oldPic);
- NotifyMetaAware(node->ace.hContact, node);
- }
- else if (result == 0 || result == -3) { // Has no avatar
- HBITMAP oldPic = node->ace.hbmPic;
- {
- mir_cslock l(cachecs);
- CopyMemory(&node->ace, &ace_temp, sizeof(AVATARCACHEENTRY));
- node->loaded = FALSE;
- node->mustLoad = 0;
- }
- if (oldPic)
- DeleteObject(oldPic);
- NotifyMetaAware(node->ace.hContact, node);
+ if (result == 1 && ace_temp.hbmPic != 0) { // Loaded
+ HBITMAP oldPic = node->hbmPic;
+ {
+ mir_cslock l(cachecs);
+ CopyMemory(node, &ace_temp, sizeof(AVATARCACHEENTRY));
+ node->loaded = TRUE;
}
-
- mir_sleep(dwDelay);
+ if (oldPic)
+ DeleteObject(oldPic);
+ NotifyMetaAware(node->hContact, node);
}
- else if (node->mustLoad < 0 && node->ace.hContact) { // delete this picture
- MCONTACT hContact = node->ace.hContact;
+ else if (result == 0 || result == -3) { // Has no avatar
+ HBITMAP oldPic = node->hbmPic;
{
mir_cslock l(cachecs);
- node->mustLoad = 0;
- node->loaded = 0;
- if (node->ace.hbmPic)
- DeleteObject(node->ace.hbmPic);
- ZeroMemory(&node->ace, sizeof(AVATARCACHEENTRY));
- if (node->dwFlags & AVS_DELETENODEFOREVER)
- node->dwFlags &= ~AVS_DELETENODEFOREVER;
- else
- node->ace.hContact = hContact;
+ CopyMemory(node, &ace_temp, sizeof(AVATARCACHEENTRY));
+ node->loaded = FALSE;
}
- NotifyMetaAware(hContact, node, (AVATARCACHEENTRY *)GetProtoDefaultAvatar(hContact));
+ if (oldPic)
+ DeleteObject(oldPic);
+ NotifyMetaAware(node->hContact, node);
}
- // protect this by changes from the cache block allocator as it can cause inconsistencies while working
- // on allocating a new block.
- mir_cslock all(alloccs); // protect memory block allocation
- node = node->pNextNode;
+ mir_sleep(dwDelay);
}
WaitForSingleObject(hLoaderEvent, INFINITE);
ResetEvent(hLoaderEvent);
diff --git a/plugins/AVS/src/commonheaders.h b/plugins/AVS/src/commonheaders.h index c44fb6b08a..8ea2caab56 100644 --- a/plugins/AVS/src/commonheaders.h +++ b/plugins/AVS/src/commonheaders.h @@ -65,15 +65,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-struct CacheNode
+struct CacheNode : public avatarCacheEntry, public MZeroedObject
{
- CacheNode *pNextNode;
- avatarCacheEntry ace;
+ CacheNode();
+ ~CacheNode();
BOOL loaded;
- int mustLoad;
DWORD dwFlags;
int pa_format;
+
+ void wipeInfo();
};
// The same fields as avatarCacheEntry + proto name
@@ -127,18 +128,18 @@ void MakePathRelative(MCONTACT hContact, TCHAR *dest); HBITMAP LoadPNG(struct avatarCacheEntry *ace, char *szFilename);
-void InitCache(void);
void UnloadCache(void);
int CreateAvatarInCache(MCONTACT hContact, avatarCacheEntry *ace, char *szProto);
-void DeleteAvatarFromCache(MCONTACT hContact, BOOL);
+void DeleteAvatarFromCache(MCONTACT hContact, bool bForever);
void PicLoader(LPVOID param);
void InternalDrawAvatar(AVATARDRAWREQUEST *r, HBITMAP hbm, LONG bmWidth, LONG bmHeight, DWORD dwFlags);
-int ChangeAvatar(MCONTACT hContact, BOOL fLoad, BOOL fNotifyHist = FALSE, int pa_format = 0);
+int ChangeAvatar(MCONTACT hContact, bool fLoad, bool fNotifyHist = false, int pa_format = 0);
void DeleteGlobalUserAvatar();
int FetchAvatarFor(MCONTACT hContact, char *szProto = NULL);
-CacheNode* FindAvatarInCache(MCONTACT hContact, BOOL add, BOOL findAny = FALSE);
+CacheNode* FindAvatarInCache(MCONTACT hContact, bool add, bool findAny = false);
+void PushAvatarRequest(CacheNode *cc);
int SetAvatarAttribute(MCONTACT hContact, DWORD attrib, int mode);
void SetIgnoreNotify(char *protocol, BOOL ignore);
diff --git a/plugins/AVS/src/main.cpp b/plugins/AVS/src/main.cpp index d921c7fb30..42ebac3b36 100644 --- a/plugins/AVS/src/main.cpp +++ b/plugins/AVS/src/main.cpp @@ -138,7 +138,7 @@ static int MetaChanged(WPARAM hMeta, LPARAM hSubContact) ace = (AVATARCACHEENTRY*)GetProtoDefaultAvatar(hSubContact);
QueueAdd(hSubContact);
}
- else ace = &node->ace;
+ else ace = node;
NotifyEventHooks(hEventChanged, hMeta, (LPARAM)ace);
return 0;
@@ -411,7 +411,6 @@ static int LoadAvatarModule() hMyAvatarChanged = CreateHookableEvent(ME_AV_MYAVATARCHANGED);
InitServices();
- InitCache();
InitPolls();
_tcsncpy_s(g_szDataPath, SIZEOF(g_szDataPath), VARST(_T("%miranda_userdata%\\")), _TRUNCATE);
diff --git a/plugins/AVS/src/options.cpp b/plugins/AVS/src/options.cpp index aabdfa1479..9cade6f3d3 100644 --- a/plugins/AVS/src/options.cpp +++ b/plugins/AVS/src/options.cpp @@ -695,7 +695,7 @@ INT_PTR CALLBACK DlgProcAvatarOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPA case DM_REALODAVATAR:
SaveTransparentData(hwndDlg, hContact, IsDlgButtonChecked(hwndDlg, IDC_PROTECTAVATAR));
- ChangeAvatar(hContact, TRUE);
+ ChangeAvatar(hContact, true);
InvalidateRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), NULL, TRUE);
break;
@@ -880,7 +880,7 @@ static INT_PTR CALLBACK DlgProcAvatarUserInfo(HWND hwndDlg, UINT msg, WPARAM wPa case DM_REALODAVATAR:
SaveTransparentData(hwndDlg, hContact, IsDlgButtonChecked(hwndDlg, IDC_PROTECTAVATAR));
- ChangeAvatar(hContact, TRUE);
+ ChangeAvatar(hContact, true);
break;
case WM_NCDESTROY:
diff --git a/plugins/AVS/src/poll.cpp b/plugins/AVS/src/poll.cpp index 08c3170edc..159aef797d 100644 --- a/plugins/AVS/src/poll.cpp +++ b/plugins/AVS/src/poll.cpp @@ -60,13 +60,12 @@ static int QueueSortItems(const QueueItem *p1, const QueueItem *p2) }
static OBJLIST<QueueItem> queue(20, QueueSortItems);
-static CRITICAL_SECTION cs;
+static mir_cs cs;
static int waitTime;
void InitPolls()
{
waitTime = REQUEST_WAIT_TIME;
- InitializeCriticalSection(&cs);
// Init request queue
mir_forkthread(RequestThread, NULL);
@@ -74,7 +73,6 @@ void InitPolls() void UninitPolls()
{
- DeleteCriticalSection(&cs);
queue.destroy();
}
@@ -163,10 +161,10 @@ void ProcessAvatarInfo(MCONTACT hContact, int type, PROTO_AVATAR_INFORMATIONT *p || pai->format == PA_FORMAT_GIF) {
// We can load it!
MakePathRelative(hContact, pai->filename);
- ChangeAvatar(hContact, TRUE, TRUE, pai->format);
+ ChangeAvatar(hContact, true, true, pai->format);
}
else // As we can't load it, notify but don't load
- ChangeAvatar(hContact, FALSE, TRUE, pai->format);
+ ChangeAvatar(hContact, false, true, pai->format);
}
else if (type == GAIR_NOAVATAR) {
db_unset(hContact, "ContactPhoto", "NeedUpdate");
@@ -180,7 +178,7 @@ void ProcessAvatarInfo(MCONTACT hContact, int type, PROTO_AVATAR_INFORMATIONT *p db_unset(hContact, "ContactPhoto", "Format");
// Fix cache
- ChangeAvatar(hContact, FALSE, TRUE, 0);
+ ChangeAvatar(hContact, false, true, 0);
}
}
else if (type == GAIR_FAILED) {
@@ -231,20 +229,20 @@ int FetchAvatarFor(MCONTACT hContact, char *szProto) static void RequestThread(void *vParam)
{
while (!g_shutDown) {
- EnterCriticalSection(&cs);
+ mir_cslockfull lck(cs);
if (queue.getCount() == 0) {
// No items, so suspend thread
- LeaveCriticalSection(&cs);
+ lck.unlock();
mir_sleep(POOL_DELAY);
continue;
}
// Take a look at first item
- QueueItem& qi = queue[queue.getCount() - 1];
+ QueueItem &qi = queue[queue.getCount() - 1];
if (qi.check_time > GetTickCount()) {
// Not time to request yet, wait...
- LeaveCriticalSection(&cs);
+ lck.unlock();
mir_sleep(POOL_DELAY);
continue;
}
@@ -253,15 +251,14 @@ static void RequestThread(void *vParam) MCONTACT hContact = qi.hContact;
queue.remove(queue.getCount() - 1);
QueueRemove(hContact);
- LeaveCriticalSection(&cs);
+ lck.unlock();
if (FetchAvatarFor(hContact) == GAIR_WAITFOR) {
// Mark to not request this contact avatar for more 30 min
- {
- mir_cslock lock(cs);
- QueueRemove(hContact);
- QueueAdd(hContact, REQUEST_WAITFOR_WAIT_TIME);
- }
+ lck.lock();
+ QueueRemove(hContact);
+ QueueAdd(hContact, REQUEST_WAITFOR_WAIT_TIME);
+ lck.unlock();
// Wait a little until requesting again
mir_sleep(REQUEST_DELAY);
diff --git a/plugins/AVS/src/services.cpp b/plugins/AVS/src/services.cpp index 24d4579e6b..cd1ac0fd72 100644 --- a/plugins/AVS/src/services.cpp +++ b/plugins/AVS/src/services.cpp @@ -37,8 +37,7 @@ INT_PTR GetAvatarBitmap(WPARAM hContact, LPARAM lParam) CacheNode *node = FindAvatarInCache(hContact, TRUE);
if (node == NULL || !node->loaded)
return (INT_PTR)GetProtoDefaultAvatar(hContact);
- else
- return (INT_PTR)&node->ace;
+ return (INT_PTR)node;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -56,7 +55,7 @@ INT_PTR ProtectAvatar(WPARAM hContact, LPARAM lParam) db_set_b(hContact, "ContactPhoto", "Locked", lParam ? 1 : 0);
if (lParam == 0)
MakePathRelative(hContact);
- ChangeAvatar(hContact, TRUE);
+ ChangeAvatar(hContact, true);
}
return 0;
}
@@ -179,9 +178,9 @@ static INT_PTR avSetAvatar(MCONTACT hContact, TCHAR *tszPath) db_set_b(hContact, "ContactPhoto", "Locked", is_locked);
db_set_ts(hContact, "ContactPhoto", "File", szFinalName);
MakePathRelative(hContact, szFinalName);
- // Fix cache
- ChangeAvatar(hContact, TRUE);
+ // Fix cache
+ ChangeAvatar(hContact, true);
return 0;
}
diff --git a/plugins/AVS/src/utils.cpp b/plugins/AVS/src/utils.cpp index a57bf998f0..ba1f67abc2 100644 --- a/plugins/AVS/src/utils.cpp +++ b/plugins/AVS/src/utils.cpp @@ -48,11 +48,9 @@ void MakePathRelative(MCONTACT hContact, TCHAR *path) void MakePathRelative(MCONTACT hContact)
{
- DBVARIANT dbv;
- if (!db_get_ts(hContact, "ContactPhoto", "File", &dbv)) {
- MakePathRelative(hContact, dbv.ptszVal);
- db_free(&dbv);
- }
+ ptrT tszPath(db_get_tsa(hContact, "ContactPhoto", "File"));
+ if (tszPath)
+ MakePathRelative(hContact, tszPath);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -81,8 +79,7 @@ int CreateAvatarInCache(MCONTACT hContact, avatarCacheEntry *ace, char *szProto) if (proto == NULL || !db_get_b(NULL, AVS_MODULE, proto, 1))
return -1;
- if (db_get_b(hContact, "ContactPhoto", "Locked", 0)
- && !db_get_ts(hContact, "ContactPhoto", "Backup", &dbv)) {
+ if (db_get_b(hContact, "ContactPhoto", "Locked", 0) && !db_get_ts(hContact, "ContactPhoto", "Backup", &dbv)) {
PathToAbsoluteT(dbv.ptszVal, tszFilename, g_szDataPath);
db_free(&dbv);
}
@@ -401,7 +398,7 @@ BOOL Proto_IsFetchingWhenContactOfflineAllowed(const char *proto) /////////////////////////////////////////////////////////////////////////////////////////
-protoPicCacheEntry *GetProtoDefaultAvatar(MCONTACT hContact)
+protoPicCacheEntry* GetProtoDefaultAvatar(MCONTACT hContact)
{
char *szProto = GetContactProto(hContact);
if (szProto) {
@@ -426,7 +423,7 @@ MCONTACT GetContactThatHaveTheAvatar(MCONTACT hContact, int locked) return hContact;
}
-int ChangeAvatar(MCONTACT hContact, BOOL fLoad, BOOL fNotifyHist, int pa_format)
+int ChangeAvatar(MCONTACT hContact, bool fLoad, bool fNotifyHist, int pa_format)
{
if (g_shutDown)
return 0;
@@ -441,9 +438,12 @@ int ChangeAvatar(MCONTACT hContact, BOOL fLoad, BOOL fNotifyHist, int pa_format) if (fNotifyHist)
node->dwFlags |= AVH_MUSTNOTIFY;
- node->mustLoad = fLoad ? 1 : -1;
node->pa_format = pa_format;
- SetEvent(hLoaderEvent);
+ if (fLoad) {
+ PushAvatarRequest(node);
+ SetEvent(hLoaderEvent);
+ }
+ else node->wipeInfo();
return 0;
}
diff --git a/plugins/AVS/src/version.h b/plugins/AVS/src/version.h index 466fcb6aa4..77245e34bf 100644 --- a/plugins/AVS/src/version.h +++ b/plugins/AVS/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 95
-#define __RELEASE_NUM 2
-#define __BUILD_NUM 2
+#define __RELEASE_NUM 3
+#define __BUILD_NUM 1
#include <stdver.h>
|