From b599a32b617386e5d9cb8df4540589612fae4fc3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 20 Aug 2018 19:11:40 +0300 Subject: patch for smile packs with remote files without valid extensions --- plugins/SmileyAdd/src/download.cpp | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'plugins/SmileyAdd') diff --git a/plugins/SmileyAdd/src/download.cpp b/plugins/SmileyAdd/src/download.cpp index 328bae9afd..7df7478090 100644 --- a/plugins/SmileyAdd/src/download.cpp +++ b/plugins/SmileyAdd/src/download.cpp @@ -161,20 +161,35 @@ void __cdecl SmileyDownloadThread(void*) bool GetSmileyFile(CMStringW &url, const CMStringW &packstr) { - MRegexp16 urlsplit(L".*/(.*)"); - urlsplit.match(url); + BYTE hash[MIR_SHA1_HASH_SIZE]; + mir_sha1_hash((BYTE*)url.c_str(), url.GetLength() * sizeof(wchar_t), hash); + wchar_t wszHash[MIR_SHA1_HASH_SIZE * 2 + 1]; + bin2hexW(hash, sizeof(hash), wszHash); CMStringW filename; filename.AppendFormat(L"%s\\%s\\", cachepath, packstr.c_str()); int pathpos = filename.GetLength(); - filename += urlsplit.getGroup(1); - bool needext = filename.Find('.') == -1; - if (needext) + MRegexp16 urlsplit(L".*/(.*)"); + urlsplit.match(url); + CMStringW urlFileName = urlsplit.getGroup(1); + + int iExtIdx = urlFileName.ReverseFind('.'); + if (iExtIdx != -1) { + CMStringW wszExt = urlFileName.Mid(iExtIdx); + if (ProtoGetAvatarFormat(wszExt) == PA_FORMAT_UNKNOWN) + iExtIdx = -1; + else + filename += urlFileName; + } + + if (iExtIdx == -1) { + filename += wszHash; filename += L".*"; + } _wfinddata_t c_file; - INT_PTR hFile = _wfindfirst((wchar_t*)filename.c_str(), &c_file); + INT_PTR hFile = _wfindfirst(filename, &c_file); if (hFile > -1) { _findclose(hFile); filename.Truncate(pathpos); @@ -182,11 +197,15 @@ bool GetSmileyFile(CMStringW &url, const CMStringW &packstr) url = filename; return false; } - if (needext) - filename.Truncate(filename.GetLength() - 1); + + if (iExtIdx == -1) { + filename.Truncate(pathpos); + filename += wszHash; + filename += L"."; + } WaitForSingleObject(g_hDlMutex, 3000); - dlQueue.insert(new QueueElem(url, filename, needext)); + dlQueue.insert(new QueueElem(url, filename, iExtIdx == -1)); ReleaseMutex(g_hDlMutex); if (!threadRunning) { -- cgit v1.2.3