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/ExternalAPI/m_smileyadd.h | 6 +++++- plugins/SmileyAdd/src/services.cpp | 28 +++++++++------------------- 2 files changed, 14 insertions(+), 20 deletions(-) (limited to 'plugins') diff --git a/plugins/ExternalAPI/m_smileyadd.h b/plugins/ExternalAPI/m_smileyadd.h index cfb46fb509..8b832479fd 100644 --- a/plugins/ExternalAPI/m_smileyadd.h +++ b/plugins/ExternalAPI/m_smileyadd.h @@ -209,9 +209,13 @@ struct FVCNDATA_NMHDR // wParam = (WPARAM) 0; not used // lParam = (LPARAM) (SMADD_CONT*) &dir; // pointer to directory to load smiley from +#define SMADD_SMILEPACK 0 +#define SMADD_FILE 1 +#define SMADD_FOLDER 2 + struct SMADD_CONT { - int type; // 0 - directory, 1 - file; + int type; // SMADD_* constant const char *pszModule; // module name const wchar_t *path; // smiley category name for reference }; 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