From 53452cdfd0f64b78eb91d80f2a266ecdcc4953c0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 26 Oct 2023 15:26:46 +0300 Subject: code simplification + cleaning --- plugins/SmileyAdd/src/services.cpp | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'plugins/SmileyAdd/src') diff --git a/plugins/SmileyAdd/src/services.cpp b/plugins/SmileyAdd/src/services.cpp index 1856f2b619..922f3289a6 100644 --- a/plugins/SmileyAdd/src/services.cpp +++ b/plugins/SmileyAdd/src/services.cpp @@ -338,33 +338,23 @@ static INT_PTR LoadContactSmileys(WPARAM, LPARAM lParam) SMADD_CONT *cont = (SMADD_CONT *)lParam; switch (cont->type) { - case 0: + case SMADD_SMILEPACK: g_SmileyPackCStore.AddSmileyPack(cont->pszModule, cont->path); NotifyEventHooks(g_hevOptionsChanged, 0, (WPARAM)cont->pszModule); break; - case 1: + case SMADD_FILE: g_SmileyPackCStore.AddSmiley(cont->pszModule, cont->path); NotifyEventHooks(g_hevOptionsChanged, 0, (WPARAM)cont->pszModule); break; - case 2: - WIN32_FIND_DATAW findData; - CMStringW wszPath(cont->path); - HANDLE hFind = FindFirstFileW(wszPath, &findData); - if (hFind != INVALID_HANDLE_VALUE) { - int idx = wszPath.ReverseFind('\\'); - if (idx != -1) - wszPath.Truncate(idx + 1); - - do { - if (!mir_wstrcmp(findData.cFileName, L".") || !mir_wstrcmp(findData.cFileName, L"..")) - continue; - - CMStringW wszFileName = wszPath + findData.cFileName; - g_SmileyPackCStore.AddSmiley(cont->pszModule, wszFileName); - } while (FindNextFileW(hFind, &findData)); - } + case SMADD_FOLDER: + auto *p = wcsrchr(cont->path, '\\'); + CMStringW wszPath(cont->path, (p == nullptr) ? lstrlen(cont->path) : p - cont->path + 1); + + for (auto &it : MFilePath(cont->path).search()) + if (mir_wstrcmp(it.getPath(), L".") && mir_wstrcmp(it.getPath(), L"..")) + g_SmileyPackCStore.AddSmiley(cont->pszModule, wszPath + it.getPath()); } return 0; } -- cgit v1.2.3