diff options
author | George Hazan <ghazan@miranda.im> | 2019-05-30 19:21:30 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-05-30 19:21:30 +0300 |
commit | 502b684aba2c511bedae4b56a8d895d6c2ac5269 (patch) | |
tree | 046217973bb5951c5cb42abb1a49513b26324d7e /plugins/SmileyAdd | |
parent | 60e076f77663869a74ac2eb5e3c3989b5e185a64 (diff) |
fixes #1960 (SmileyAdd: Folders support)
Diffstat (limited to 'plugins/SmileyAdd')
-rw-r--r-- | plugins/SmileyAdd/src/customsmiley.cpp | 2 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/download.cpp | 17 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/general.cpp | 6 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/options.cpp | 21 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/richcall.cpp | 2 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/services.cpp | 6 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/services.h | 2 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/smileyroutines.cpp | 2 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/smileys.cpp | 38 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/smileys.h | 4 | ||||
-rw-r--r-- | plugins/SmileyAdd/src/stdafx.h | 2 |
11 files changed, 55 insertions, 47 deletions
diff --git a/plugins/SmileyAdd/src/customsmiley.cpp b/plugins/SmileyAdd/src/customsmiley.cpp index 624b016a7c..220b10f31d 100644 --- a/plugins/SmileyAdd/src/customsmiley.cpp +++ b/plugins/SmileyAdd/src/customsmiley.cpp @@ -72,7 +72,7 @@ bool SmileyCType::CreateTriggerText(char *text) size_t reslen;
ptrA res((char*)mir_base64_decode(mir_urlDecode(text), &reslen));
- if (res == NULL)
+ if (res == nullptr)
return false;
char save = res[reslen]; res[reslen] = 0; // safe because of mir_alloc
diff --git a/plugins/SmileyAdd/src/download.cpp b/plugins/SmileyAdd/src/download.cpp index 4042119869..5cbf42efc9 100644 --- a/plugins/SmileyAdd/src/download.cpp +++ b/plugins/SmileyAdd/src/download.cpp @@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h"
HNETLIBUSER hNetlibUser;
-static HANDLE hFolder;
+static HANDLE hFolderCache = 0, hFolderPacks = 0;
struct QueueElem
{
@@ -219,7 +219,8 @@ bool GetSmileyFile(CMStringW &url, const CMStringW &packstr) int FolderChanged(WPARAM, LPARAM)
{
- FoldersGetCustomPathT(hFolder, g_wszCachePath, MAX_PATH, L"");
+ FoldersGetCustomPathT(hFolderCache, g_wszCachePath, MAX_PATH, L"");
+ FoldersGetCustomPathT(hFolderPacks, g_plugin.wszDefaultPath, MAX_PATH, L"Smileys");
return 0;
}
@@ -231,12 +232,16 @@ void DownloadInit(void) nlu.szDescriptiveName.w = TranslateT("SmileyAdd HTTP connections");
hNetlibUser = Netlib_RegisterUser(&nlu);
- hFolder = FoldersRegisterCustomPathT(LPGEN("SmileyAdd"), LPGEN("Smiley cache"), MIRANDA_USERDATAT L"\\SmileyCache");
- if (hFolder) {
- FolderChanged(0, 0);
+ hFolderPacks = FoldersRegisterCustomPathT(LPGEN("SmileyAdd"), LPGEN("Smiley packs' folder"), L"Smileys");
+ if (hFolderPacks) {
+ hFolderCache = FoldersRegisterCustomPathT(LPGEN("SmileyAdd"), LPGEN("Smiley cache"), MIRANDA_USERDATAT L"\\SmileyCache");
+ FolderChanged(0, 0);
HookEvent(ME_FOLDERS_PATH_CHANGED, FolderChanged);
}
- else mir_wstrncpy(g_wszCachePath, VARSW(L"%miranda_userdata%\\SmileyCache"), MAX_PATH);
+ else {
+ wcsncpy_s(g_wszCachePath, VARSW(L"%miranda_userdata%\\SmileyCache"), _TRUNCATE);
+ wcsncpy_s(g_plugin.wszDefaultPath, L"Smileys", _TRUNCATE);
+ }
g_hDlMutex = CreateMutex(nullptr, FALSE, nullptr);
}
diff --git a/plugins/SmileyAdd/src/general.cpp b/plugins/SmileyAdd/src/general.cpp index 9456033e4c..9374f5e969 100644 --- a/plugins/SmileyAdd/src/general.cpp +++ b/plugins/SmileyAdd/src/general.cpp @@ -154,11 +154,11 @@ void DestroyGdiPlus(void) MCONTACT DecodeMetaContact(MCONTACT hContact)
{
- if (hContact == NULL)
- return NULL;
+ if (hContact == 0)
+ return 0;
MCONTACT hReal = db_mc_getMostOnline(hContact);
- if (hReal == NULL || (INT_PTR)hReal == CALLSERVICE_NOTFOUND)
+ if (hReal == 0 || (INT_PTR)hReal == CALLSERVICE_NOTFOUND)
hReal = hContact;
return hReal;
diff --git a/plugins/SmileyAdd/src/options.cpp b/plugins/SmileyAdd/src/options.cpp index 57bd307f8d..49a180b248 100644 --- a/plugins/SmileyAdd/src/options.cpp +++ b/plugins/SmileyAdd/src/options.cpp @@ -71,7 +71,14 @@ void OptionsType::ReadPackFileName(CMStringW &filename, const CMStringW &name, c CMStringW settingKey = name + L"-filename";
ptrW tszValue(g_plugin.getWStringA(_T2A(settingKey.c_str())));
- filename = (tszValue != NULL) ? (wchar_t*)tszValue : defaultFilename;
+ if (tszValue != nullptr)
+ filename = tszValue;
+ else {
+ if (defaultFilename.IsEmpty())
+ filename.Format(L"%s\\nova\\default.msl", g_plugin.wszDefaultPath);
+ else
+ filename = defaultFilename;
+ }
}
void OptionsType::WritePackFileName(const CMStringW &filename, const CMStringW &name)
@@ -83,7 +90,7 @@ void OptionsType::WritePackFileName(const CMStringW &filename, const CMStringW & void OptionsType::ReadCustomCategories(CMStringW &cats)
{
ptrW tszValue(g_plugin.getWStringA("CustomCategories"));
- if (tszValue != NULL)
+ if (tszValue != nullptr)
cats = tszValue;
}
@@ -98,7 +105,7 @@ void OptionsType::WriteCustomCategories(const CMStringW &cats) void OptionsType::ReadContactCategory(MCONTACT hContact, CMStringW &cats)
{
ptrW tszValue(g_plugin.getWStringA(hContact, "CustomCategory"));
- if (tszValue != NULL)
+ if (tszValue != nullptr)
cats = tszValue;
}
@@ -126,7 +133,7 @@ class COptionsDialog : public CDlgBase CMStringW inidir;
SmileyCategoryType *smc = tmpsmcat.GetSmileyCategory(item);
if (smc->GetFilename().IsEmpty())
- inidir = VARSW(L"Smileys");
+ inidir = g_plugin.wszDefaultPath;
else {
inidir = VARSW(smc->GetFilename());
inidir.Truncate(inidir.ReverseFind('\\'));
@@ -161,7 +168,7 @@ class COptionsDialog : public CDlgBase void PopulateSmPackList(void)
{
- categories.SelectItem(NULL);
+ categories.SelectItem(nullptr);
categories.DeleteAllItems();
UpdateVisibleSmPackList();
@@ -407,7 +414,7 @@ public: CMStringW catd = cat;
if (!catd.IsEmpty()) {
- tmpsmcat.AddCategory(cat, catd, smcCustom, DEFAULT_FILE_NAME);
+ tmpsmcat.AddCategory(cat, catd, smcCustom);
PopulateSmPackList();
NotifyChange();
@@ -444,7 +451,7 @@ public: stwp->xPosition = rect.left;
stwp->yPosition = rect.bottom + 4;
stwp->direction = 1;
- stwp->hContact = NULL;
+ stwp->hContact = 0;
mir_forkThread<SmileyToolWindowParam>(SmileyToolThread, stwp);
}
diff --git a/plugins/SmileyAdd/src/richcall.cpp b/plugins/SmileyAdd/src/richcall.cpp index ed87211546..0c3af9c77a 100644 --- a/plugins/SmileyAdd/src/richcall.cpp +++ b/plugins/SmileyAdd/src/richcall.cpp @@ -239,7 +239,7 @@ static LRESULT CALLBACK RichEditSubclass(HWND hwnd, UINT uMsg, WPARAM wParam, LP else if (wParam == VK_TAB && ((GetKeyState(VK_CONTROL) | GetKeyState(VK_SHIFT)) & 0x8000) == 0) {
sel.cpMax = LONG_MAX;
- bool hascont = rdt->hContact != NULL;
+ bool hascont = rdt->hContact != 0;
ReplaceContactSmileys(rdt, sel, false, hascont);
}
break;
diff --git a/plugins/SmileyAdd/src/services.cpp b/plugins/SmileyAdd/src/services.cpp index 2c2bbb398a..b7e7e3e066 100644 --- a/plugins/SmileyAdd/src/services.cpp +++ b/plugins/SmileyAdd/src/services.cpp @@ -34,7 +34,7 @@ SmileyPackType* GetSmileyPack(const char *proto, MCONTACT hContact, SmileyPackCT return nullptr;
CMStringW categoryName;
- if (hContact != NULL) {
+ if (hContact != 0) {
opt.ReadContactCategory(hContact, categoryName);
if (categoryName == L"<None>") return nullptr;
if (!categoryName.IsEmpty() && g_SmileyCategories.GetSmileyCategory(categoryName) == nullptr) {
@@ -99,7 +99,7 @@ INT_PTR ReplaceSmileysCommand(WPARAM, LPARAM lParam) (smrec.flags & (SAFLRE_OUTGOING | SAFLRE_NOCUSTOM)) ? nullptr : &smcp);
ReplaceSmileys(smre->hwndRichEditControl, SmileyPack, smcp, *smrec.rangeToReplace,
- smrec.hContact == NULL, false, false, (smre->flags & SAFLRE_FIREVIEW) ? true : false);
+ smrec.hContact == 0, false, false, (smre->flags & SAFLRE_FIREVIEW) ? true : false);
return TRUE;
}
@@ -419,7 +419,7 @@ int AccountListChanged(WPARAM wParam, LPARAM lParam) int DbSettingChanged(WPARAM hContact, LPARAM lParam)
{
- if (hContact == NULL)
+ if (hContact == 0)
return 0;
DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam;
diff --git a/plugins/SmileyAdd/src/services.h b/plugins/SmileyAdd/src/services.h index 6a877d63e8..eb88fdc5a7 100644 --- a/plugins/SmileyAdd/src/services.h +++ b/plugins/SmileyAdd/src/services.h @@ -39,7 +39,7 @@ int AccountListChanged(WPARAM wParam, LPARAM lParam); int DbSettingChanged(WPARAM wParam, LPARAM lParam);
int ReloadColour(WPARAM, LPARAM);
-SmileyPackType* GetSmileyPack(const char* proto, MCONTACT hContact = NULL, SmileyPackCType** smlc = nullptr);
+SmileyPackType* GetSmileyPack(const char* proto, MCONTACT hContact = 0, SmileyPackCType** smlc = nullptr);
#endif // SMILEYADD_SERVICES_H_
diff --git a/plugins/SmileyAdd/src/smileyroutines.cpp b/plugins/SmileyAdd/src/smileyroutines.cpp index 71c2e91e3a..0968fe10f3 100644 --- a/plugins/SmileyAdd/src/smileyroutines.cpp +++ b/plugins/SmileyAdd/src/smileyroutines.cpp @@ -231,7 +231,7 @@ void ReplaceSmileys(HWND hwnd, SmileyPackType *smp, SmileyPackCType *smcp, const GetClassName(hwnd, classname, _countof(classname));
bool ishpp = (wcsncmp(classname, L"THppRichEdit", 12) == 0) || fireView;
- SetRichCallback(hwnd, NULL, false, true);
+ SetRichCallback(hwnd, 0, false, true);
bool rdo = (GetWindowLongPtr(hwnd, GWL_STYLE) & ES_READONLY) != 0;
if (rdo)
diff --git a/plugins/SmileyAdd/src/smileys.cpp b/plugins/SmileyAdd/src/smileys.cpp index 9e70af2581..118bf70fa6 100644 --- a/plugins/SmileyAdd/src/smileys.cpp +++ b/plugins/SmileyAdd/src/smileys.cpp @@ -771,7 +771,7 @@ void SmileyCategoryListType::AddAndLoad(const CMStringW &name, const CMStringW & if (GetSmileyCategory(name) != nullptr) return; - AddCategory(name, displayName, smcExt, DEFAULT_FILE_NAME); + AddCategory(name, displayName, smcExt); // Load only if other smileys have been loaded already if (m_SmileyCategories.getCount() > 1) @@ -811,6 +811,7 @@ void SmileyCategoryListType::AddAccountAsCategory(PROTOACCOUNT *acc, const CMStr if (!PhysProtoName.IsEmpty()) paths = g_SmileyCategories.GetSmileyCategory(PhysProtoName) ? g_SmileyCategories.GetSmileyCategory(PhysProtoName)->GetFilename() : L""; + // assemble default path if (paths.IsEmpty()) { const char *packnam = acc->szProtoName; if (mir_strcmp(packnam, "JABBER") == 0) @@ -818,11 +819,9 @@ void SmileyCategoryListType::AddAccountAsCategory(PROTOACCOUNT *acc, const CMStr else if (strstr(packnam, "SIP") != nullptr) packnam = "MSN"; - char path[MAX_PATH]; - mir_snprintf(path, "Smileys\\nova\\%s.msl", packnam); - - CMStringW patha = VARSW(_A2T(path)); - if (_waccess(patha.c_str(), 0) != 0) + wchar_t path[MAX_PATH]; + mir_snwprintf(path, L"%s\\nova\\%S.msl", g_plugin.wszDefaultPath, packnam); + if (_waccess(path, 0) != 0) paths = defaultFile; } @@ -842,11 +841,10 @@ void SmileyCategoryListType::AddProtoAsCategory(char *acc, const CMStringW &defa else if (strstr(packnam, "SIP") != nullptr) packnam = "MSN"; - char path[MAX_PATH]; - mir_snprintf(path, "Smileys\\nova\\%s.msl", packnam); - - CMStringW paths = _A2T(path), patha = VARSW(paths); - if (_waccess(patha.c_str(), 0) != 0) + // assemble default path + CMStringW paths(FORMAT, L"%s\\nova\\%S.msl", g_plugin.wszDefaultPath, packnam); + paths = VARSW(paths); + if (_waccess(paths.c_str(), 0) != 0) paths = defaultFile; CMStringW dName(acc), displayName; @@ -911,18 +909,16 @@ void SmileyCategoryListType::AddContactTransportAsCategory(MCONTACT hContact, co mir_free(trsp); - CMStringW displayName = dbv.pwszVal; + CMStringW paths, displayName(dbv.pwszVal); if (packname != nullptr) { - char path[MAX_PATH]; - mir_snprintf(path, "Smileys\\nova\\%s.msl", packname); - - CMStringW paths = _A2T(path), patha = VARSW(paths); - if (_waccess(patha.c_str(), 0) != 0) + paths.Format(L"%s\\nova\\%S.msl", g_plugin.wszDefaultPath, packname); + paths = VARSW(paths); + if (_waccess(paths.c_str(), 0) != 0) paths = defaultFile; - - AddCategory(displayName, displayName, smcTransportProto, paths); } - else AddCategory(displayName, displayName, smcTransportProto, defaultFile); + else paths = defaultFile; + + AddCategory(displayName, displayName, smcTransportProto, defaultFile); db_free(&dbv); } @@ -932,7 +928,7 @@ void SmileyCategoryListType::AddAllProtocolsAsCategory(void) { CMStringW displayName = TranslateT("Standard"); CMStringW tname = L"Standard"; - AddCategory(tname, displayName, smcStd, DEFAULT_FILE_NAME); + AddCategory(tname, displayName, smcStd); const CMStringW &defaultFile = GetSmileyCategory(tname)->GetFilename(); diff --git a/plugins/SmileyAdd/src/smileys.h b/plugins/SmileyAdd/src/smileys.h index 00252e758f..56b5ffd8f9 100644 --- a/plugins/SmileyAdd/src/smileys.h +++ b/plugins/SmileyAdd/src/smileys.h @@ -23,8 +23,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define MS_SMILEYADD_CUSTOMCATMENU "SmileyAdd/CustomCatMenu"
-#define DEFAULT_FILE_NAME L"Smileys\\nova\\default.msl"
-
const unsigned HiddenSmiley = 1;
const unsigned RegExSmiley = 2;
const unsigned ServiceSmiley = 4;
@@ -306,7 +304,7 @@ public: int NumberOfSmileyCategories(void) { return m_SmileyCategories.getCount(); }
- void AddCategory(const CMStringW &name, const CMStringW &displayName, SmcType typ, const CMStringW &defaultFilename);
+ void AddCategory(const CMStringW &name, const CMStringW &displayName, SmcType typ, const CMStringW &defaultFilename = L"");
void AddAndLoad(const CMStringW &name, const CMStringW &displayName);
void AddAllProtocolsAsCategory(void);
void AddAccountAsCategory(PROTOACCOUNT *acc, const CMStringW &defaultFile);
diff --git a/plugins/SmileyAdd/src/stdafx.h b/plugins/SmileyAdd/src/stdafx.h index d0d2bc2fa1..c4d2a90015 100644 --- a/plugins/SmileyAdd/src/stdafx.h +++ b/plugins/SmileyAdd/src/stdafx.h @@ -101,6 +101,8 @@ struct CMPlugin : public PLUGIN<CMPlugin> int Load() override;
int Unload() override;
+
+ wchar_t wszDefaultPath[MAX_PATH];
};
#define DM_REMAKELOG (WM_USER + 11)
|