summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/AVS/src/main.cpp15
-rw-r--r--plugins/AVS/src/options.cpp5
-rw-r--r--plugins/AVS/src/stdafx.h11
-rw-r--r--plugins/AVS/src/utils.cpp20
4 files changed, 22 insertions, 29 deletions
diff --git a/plugins/AVS/src/main.cpp b/plugins/AVS/src/main.cpp
index 3fec92cd3b..6761cdd781 100644
--- a/plugins/AVS/src/main.cpp
+++ b/plugins/AVS/src/main.cpp
@@ -122,11 +122,10 @@ static int MetaChanged(WPARAM hMeta, LPARAM hSubContact)
static void LoadDefaultInfo()
{
- protoPicCacheEntry *pce = new protoPicCacheEntry(PCE_TYPE_GLOBAL);
+ protoPicCacheEntry *pce = new protoPicCacheEntry(PCE_TYPE_GLOBAL, AVS_DEFAULT);
if (CreateAvatarInCache(0, pce, AVS_DEFAULT) != 1)
db_unset(0, PPICT_MODULE, AVS_DEFAULT);
- pce->szProtoname = mir_strdup(AVS_DEFAULT);
g_ProtoPictures.insert(pce);
}
@@ -138,28 +137,25 @@ static void LoadProtoInfo(PROTOCOLDESCRIPTOR *proto)
char protoName[MAX_PATH];
mir_snprintf(protoName, "Global avatar for %s accounts", proto->szName);
- protoPicCacheEntry *pce = new protoPicCacheEntry(PCE_TYPE_PROTO);
+ protoPicCacheEntry *pce = new protoPicCacheEntry(PCE_TYPE_PROTO, protoName);
if (CreateAvatarInCache(0, pce, protoName) != 1)
db_unset(0, PPICT_MODULE, protoName);
pce->pd = proto;
- pce->szProtoname = mir_strdup(protoName);
g_ProtoPictures.insert(pce);
}
static void LoadAccountInfo(PROTOACCOUNT *acc)
{
- protoPicCacheEntry *pce = new protoPicCacheEntry(PCE_TYPE_ACCOUNT);
+ protoPicCacheEntry *pce = new protoPicCacheEntry(PCE_TYPE_ACCOUNT, acc->szModuleName);
if (CreateAvatarInCache(0, pce, acc->szModuleName) != 1)
db_unset(0, PPICT_MODULE, acc->szModuleName);
pce->pa = acc;
- pce->szProtoname = mir_strdup(acc->szModuleName);
g_ProtoPictures.insert(pce);
- pce = new protoPicCacheEntry(PCE_TYPE_ACCOUNT);
+ pce = new protoPicCacheEntry(PCE_TYPE_ACCOUNT, acc->szModuleName);
CreateAvatarInCache(INVALID_CONTACT_ID, pce, acc->szModuleName);
- pce->szProtoname = mir_strdup(acc->szModuleName);
g_MyAvatars.insert(pce);
}
@@ -340,9 +336,8 @@ static int ModulesLoaded(WPARAM, LPARAM)
LoadAccountInfo(it);
// Load global avatar
- protoPicCacheEntry *pce = new protoPicCacheEntry(PCE_TYPE_GLOBAL);
+ protoPicCacheEntry *pce = new protoPicCacheEntry(PCE_TYPE_GLOBAL, "");
CreateAvatarInCache(INVALID_CONTACT_ID, pce, "");
- pce->szProtoname = mir_strdup("");
g_MyAvatars.insert(pce);
HookEvent(ME_PROTO_ACCLISTCHANGED, OnAccChanged);
diff --git a/plugins/AVS/src/options.cpp b/plugins/AVS/src/options.cpp
index eb0ea5756c..c041731de2 100644
--- a/plugins/AVS/src/options.cpp
+++ b/plugins/AVS/src/options.cpp
@@ -311,8 +311,7 @@ static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wPar
item.lParam = (LPARAM)p;
int newItem = ListView_InsertItem(hwndList, &item);
if (newItem >= 0)
- ListView_SetCheckState(hwndList, newItem,
- g_plugin.getByte(p->szProtoname, 1) ? TRUE : FALSE);
+ ListView_SetCheckState(hwndList, newItem, g_plugin.getByte(p->szProtoname, 1) ? TRUE : FALSE);
}
ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE);
ListView_Arrange(hwndList, LVA_ALIGNLEFT | LVA_ALIGNTOP);
@@ -347,7 +346,7 @@ static INT_PTR CALLBACK DlgProcOptionsProtos(HWND hwndDlg, UINT msg, WPARAM wPar
AVATARDRAWREQUEST avdrq = { 0 };
avdrq.hTargetDC = dis->hDC;
avdrq.dwFlags |= AVDRQ_PROTOPICT;
- avdrq.szProto = (g_selectedProto) ? g_selectedProto->szProtoname : 0;
+ avdrq.szProto = (g_selectedProto) ? g_selectedProto->szProtoname.get() : nullptr;
GetClientRect(GetDlgItem(hwndDlg, IDC_PROTOPIC), &avdrq.rcDraw);
CallService(MS_AV_DRAWAVATAR, 0, (LPARAM)&avdrq);
}
diff --git a/plugins/AVS/src/stdafx.h b/plugins/AVS/src/stdafx.h
index 88fd634691..be43639df5 100644
--- a/plugins/AVS/src/stdafx.h
+++ b/plugins/AVS/src/stdafx.h
@@ -95,15 +95,18 @@ struct CacheNode : public AVATARCACHEENTRY, public MZeroedObject
struct protoPicCacheEntry : public AVATARCACHEENTRY, public MZeroedObject
{
- protoPicCacheEntry(int _type) : cacheType(_type) {}
+ protoPicCacheEntry(int _type, const char *_szName) :
+ cacheType(_type),
+ szProtoname(mir_strdup(_szName))
+ {}
~protoPicCacheEntry();
void clear();
- char *szProtoname = nullptr;
- int cacheType = 0;
+ ptrA szProtoname;
+ int cacheType;
union {
- PROTOCOLDESCRIPTOR *pd;
+ PROTOCOLDESCRIPTOR *pd = 0;
PROTOACCOUNT *pa;
};
};
diff --git a/plugins/AVS/src/utils.cpp b/plugins/AVS/src/utils.cpp
index 2797eda433..cb15f3fd55 100644
--- a/plugins/AVS/src/utils.cpp
+++ b/plugins/AVS/src/utils.cpp
@@ -100,7 +100,7 @@ int CreateAvatarInCache(MCONTACT hContact, AVATARCACHEENTRY *ace, const char *sz
MyPathToAbsolute(tszValue, tszFilename);
if (!strstr(szProto, "Global avatar for")) {
- PROTOACCOUNT* pdescr = Proto_GetAccount(szProto);
+ PROTOACCOUNT *pdescr = Proto_GetAccount(szProto);
if (pdescr == nullptr)
return -1;
char key[MAX_PATH];
@@ -230,7 +230,7 @@ int CreateAvatarInCache(MCONTACT hContact, AVATARCACHEENTRY *ace, const char *sz
#define TOPBIT (1 << (WIDTH - 1)) /* MSB */
#define WIDTH 32
-int GetFileHash(wchar_t* filename)
+int GetFileHash(wchar_t *filename)
{
HANDLE hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr);
if (hFile == INVALID_HANDLE_VALUE)
@@ -257,8 +257,7 @@ int GetFileHash(wchar_t* filename)
remainder = (remainder << 1);
}
}
- }
- while (dwRead == 1024);
+ } while (dwRead == 1024);
CloseHandle(hFile);
@@ -271,7 +270,6 @@ protoPicCacheEntry::~protoPicCacheEntry()
{
if (hbmPic != nullptr)
DeleteObject(hbmPic);
- mir_free(szProtoname);
}
void protoPicCacheEntry::clear()
@@ -377,7 +375,7 @@ BOOL Proto_IsFetchingWhenContactOfflineAllowed(const char *proto)
/////////////////////////////////////////////////////////////////////////////////////////
-protoPicCacheEntry* GetProtoDefaultAvatar(MCONTACT hContact)
+protoPicCacheEntry *GetProtoDefaultAvatar(MCONTACT hContact)
{
char *szProto = Proto_GetBaseAccountName(hContact);
if (szProto)
@@ -420,21 +418,19 @@ int ChangeAvatar(MCONTACT hContact, bool fLoad, bool fNotifyHist, int pa_format)
PushAvatarRequest(node);
SetEvent(hLoaderEvent);
}
- else
- node->wipeInfo();
+ else node->wipeInfo();
return 0;
}
void DeleteGlobalUserAvatar()
{
- DBVARIANT dbv = { 0 };
- if (g_plugin.getWString("GlobalUserAvatarFile", &dbv))
+ ptrW wszPath(g_plugin.getWStringA("GlobalUserAvatarFile"));
+ if (!wszPath)
return;
wchar_t szFilename[MAX_PATH];
- MyPathToAbsolute(dbv.pwszVal, szFilename);
- db_free(&dbv);
+ MyPathToAbsolute(wszPath, szFilename);
DeleteFile(szFilename);
g_plugin.delSetting("GlobalUserAvatarFile");