diff options
author | George Hazan <ghazan@miranda.im> | 2018-10-17 17:28:58 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-10-17 17:28:58 +0300 |
commit | 2a24763dc13f729f41f6909d9e74e9bc7d6243a8 (patch) | |
tree | 892207d8d0b2fb622524fb1d5321b7efb6651ab1 /protocols/IRCG | |
parent | b80bf9c6208115addd64726fc6904f1543c63952 (diff) |
IRC:
- useless variable m_evWndCreate removed;
- fixes #1628 (IRC channel list window crashes when closed prematurely);
- code cleaning;
- version bump
Diffstat (limited to 'protocols/IRCG')
-rw-r--r-- | protocols/IRCG/src/commandmonitor.cpp | 175 | ||||
-rw-r--r-- | protocols/IRCG/src/input.cpp | 9 | ||||
-rw-r--r-- | protocols/IRCG/src/irclib.cpp | 2 | ||||
-rw-r--r-- | protocols/IRCG/src/ircproto.cpp | 3 | ||||
-rw-r--r-- | protocols/IRCG/src/ircproto.h | 5 | ||||
-rw-r--r-- | protocols/IRCG/src/services.cpp | 9 | ||||
-rw-r--r-- | protocols/IRCG/src/version.h | 2 | ||||
-rw-r--r-- | protocols/IRCG/src/windows.cpp | 4 |
8 files changed, 107 insertions, 102 deletions
diff --git a/protocols/IRCG/src/commandmonitor.cpp b/protocols/IRCG/src/commandmonitor.cpp index 2d84403b90..1e7b262430 100644 --- a/protocols/IRCG/src/commandmonitor.cpp +++ b/protocols/IRCG/src/commandmonitor.cpp @@ -240,7 +240,7 @@ void __cdecl CIrcProto::ResolveIPThread(void *di) Thread_SetName("IRC: ResolveIPThread");
IPRESOLVE* ipr = (IPRESOLVE *)di;
{
- mir_cslock lock(m_resolve);
+ mir_cslock lock(m_csResolve);
if (ipr != nullptr && (ipr->iType == IP_AUTO && mir_strlen(m_myHost) == 0 || ipr->iType == IP_MANUAL)) {
hostent* myhost = gethostbyname(ipr->sAddr);
@@ -1447,21 +1447,22 @@ bool CIrcProto::OnIrc_TOPIC(const CIrcMessage *pmsg) return true;
}
-static void __stdcall sttShowDlgList(void* param)
+static INT_PTR __stdcall sttShowDlgList(void* param)
{
CIrcProto *ppro = (CIrcProto*)param;
+
+ mir_cslock lck(ppro->m_csList);
if (ppro->m_listDlg == nullptr) {
ppro->m_listDlg = new CListDlg(ppro);
ppro->m_listDlg->Show();
}
- SetEvent(ppro->m_evWndCreate);
+ return 0;
}
bool CIrcProto::OnIrc_LISTSTART(const CIrcMessage *pmsg)
{
if (pmsg->m_bIncoming) {
- CallFunctionAsync(sttShowDlgList, this);
- WaitForSingleObject(m_evWndCreate, INFINITE);
+ CallFunctionSync(sttShowDlgList, this);
m_channelNumber = 0;
}
@@ -1471,81 +1472,92 @@ bool CIrcProto::OnIrc_LISTSTART(const CIrcMessage *pmsg) bool CIrcProto::OnIrc_LIST(const CIrcMessage *pmsg)
{
- if (pmsg->m_bIncoming == 1 && m_listDlg && pmsg->parameters.getCount() > 2) {
- m_channelNumber++;
- LVITEM lvItem;
- HWND hListView = GetDlgItem(m_listDlg->GetHwnd(), IDC_INFO_LISTVIEW);
- lvItem.iItem = ListView_GetItemCount(hListView);
- lvItem.mask = LVIF_TEXT | LVIF_PARAM;
- lvItem.iSubItem = 0;
- lvItem.pszText = pmsg->parameters[1].GetBuffer();
- lvItem.lParam = lvItem.iItem;
- lvItem.iItem = ListView_InsertItem(hListView, &lvItem);
- lvItem.mask = LVIF_TEXT;
- lvItem.iSubItem = 1;
- lvItem.pszText = pmsg->parameters[pmsg->parameters.getCount() - 2].GetBuffer();
- ListView_SetItem(hListView, &lvItem);
-
- wchar_t* temp = mir_wstrdup(pmsg->parameters[pmsg->parameters.getCount() - 1]);
- wchar_t* find = wcsstr(temp, L"[+");
- wchar_t* find2 = wcsstr(temp, L"]");
- wchar_t* save = temp;
- if (find == temp && find2 != nullptr && find + 8 >= find2) {
- temp = wcsstr(temp, L"]");
- if (mir_wstrlen(temp) > 1) {
- temp++;
- temp[0] = 0;
- lvItem.iSubItem = 2;
- lvItem.pszText = save;
- ListView_SetItem(hListView, &lvItem);
- temp[0] = ' ';
- temp++;
- }
- else temp = save;
- }
+ if (!pmsg->m_bIncoming || pmsg->parameters.getCount() <= 2)
+ return true;
- lvItem.iSubItem = 3;
- CMStringW S = DoColorCodes(temp, TRUE, FALSE);
- lvItem.pszText = S.GetBuffer();
- ListView_SetItem(hListView, &lvItem);
- temp = save;
- mir_free(temp);
+ mir_cslockfull lck(m_csList);
+ if (!m_listDlg)
+ return true;
+
+ m_channelNumber++;
+
+ HWND hListView = GetDlgItem(m_listDlg->GetHwnd(), IDC_INFO_LISTVIEW);
+ HWND hStatusWnd = m_listDlg->m_status.GetHwnd();
+ lck.unlock();
+
+ LVITEM lvItem;
+ lvItem.iItem = ListView_GetItemCount(hListView);
+ lvItem.mask = LVIF_TEXT | LVIF_PARAM;
+ lvItem.iSubItem = 0;
+ lvItem.pszText = pmsg->parameters[1].GetBuffer();
+ lvItem.lParam = lvItem.iItem;
+ lvItem.iItem = ListView_InsertItem(hListView, &lvItem);
+ lvItem.mask = LVIF_TEXT;
+ lvItem.iSubItem = 1;
+ lvItem.pszText = pmsg->parameters[pmsg->parameters.getCount() - 2].GetBuffer();
+ ListView_SetItem(hListView, &lvItem);
+
+ wchar_t* temp = mir_wstrdup(pmsg->parameters[pmsg->parameters.getCount() - 1]);
+ wchar_t* find = wcsstr(temp, L"[+");
+ wchar_t* find2 = wcsstr(temp, L"]");
+ wchar_t* save = temp;
+ if (find == temp && find2 != nullptr && find + 8 >= find2) {
+ temp = wcsstr(temp, L"]");
+ if (mir_wstrlen(temp) > 1) {
+ temp++;
+ temp[0] = 0;
+ lvItem.iSubItem = 2;
+ lvItem.pszText = save;
+ ListView_SetItem(hListView, &lvItem);
+ temp[0] = ' ';
+ temp++;
+ }
+ else temp = save;
+ }
- int percent = 100;
- if (m_noOfChannels > 0)
- percent = (int)(m_channelNumber * 100) / m_noOfChannels;
+ lvItem.iSubItem = 3;
+ CMStringW S = DoColorCodes(temp, TRUE, FALSE);
+ lvItem.pszText = S.GetBuffer();
+ ListView_SetItem(hListView, &lvItem);
+ temp = save;
+ mir_free(temp);
- wchar_t text[100];
- if (percent < 100)
- mir_snwprintf(text, TranslateT("Downloading list (%u%%) - %u channels"), percent, m_channelNumber);
- else
- mir_snwprintf(text, TranslateT("Downloading list - %u channels"), m_channelNumber);
- m_listDlg->m_status.SetText(text);
- }
+ int percent = 100;
+ if (m_noOfChannels > 0)
+ percent = (int)(m_channelNumber * 100) / m_noOfChannels;
+ wchar_t text[100];
+ if (percent < 100)
+ mir_snwprintf(text, TranslateT("Downloading list (%u%%) - %u channels"), percent, m_channelNumber);
+ else
+ mir_snwprintf(text, TranslateT("Downloading list - %u channels"), m_channelNumber);
+ SetWindowText(hStatusWnd, text);
return true;
}
bool CIrcProto::OnIrc_LISTEND(const CIrcMessage *pmsg)
{
- if (pmsg->m_bIncoming && m_listDlg) {
- EnableWindow(GetDlgItem(m_listDlg->GetHwnd(), IDC_JOIN), true);
- ListView_SetSelectionMark(GetDlgItem(m_listDlg->GetHwnd(), IDC_INFO_LISTVIEW), 0);
- ListView_SetColumnWidth(GetDlgItem(m_listDlg->GetHwnd(), IDC_INFO_LISTVIEW), 1, LVSCW_AUTOSIZE);
- ListView_SetColumnWidth(GetDlgItem(m_listDlg->GetHwnd(), IDC_INFO_LISTVIEW), 2, LVSCW_AUTOSIZE);
- ListView_SetColumnWidth(GetDlgItem(m_listDlg->GetHwnd(), IDC_INFO_LISTVIEW), 3, LVSCW_AUTOSIZE);
- m_listDlg->UpdateList();
-
- wchar_t text[100];
- mir_snwprintf(text, TranslateT("Done: %u channels"), m_channelNumber);
- int percent = 100;
- if (m_noOfChannels > 0)
- percent = (int)(m_channelNumber * 100) / m_noOfChannels;
- if (percent < 70) {
- mir_wstrcat(text, L" ");
- mir_wstrcat(text, TranslateT("(probably truncated by server)"));
+ if (pmsg->m_bIncoming) {
+ mir_cslock lck(m_csList);
+ if (m_listDlg) {
+ EnableWindow(GetDlgItem(m_listDlg->GetHwnd(), IDC_JOIN), true);
+ ListView_SetSelectionMark(GetDlgItem(m_listDlg->GetHwnd(), IDC_INFO_LISTVIEW), 0);
+ ListView_SetColumnWidth(GetDlgItem(m_listDlg->GetHwnd(), IDC_INFO_LISTVIEW), 1, LVSCW_AUTOSIZE);
+ ListView_SetColumnWidth(GetDlgItem(m_listDlg->GetHwnd(), IDC_INFO_LISTVIEW), 2, LVSCW_AUTOSIZE);
+ ListView_SetColumnWidth(GetDlgItem(m_listDlg->GetHwnd(), IDC_INFO_LISTVIEW), 3, LVSCW_AUTOSIZE);
+ m_listDlg->UpdateList();
+
+ wchar_t text[100];
+ mir_snwprintf(text, TranslateT("Done: %u channels"), m_channelNumber);
+ int percent = 100;
+ if (m_noOfChannels > 0)
+ percent = (int)(m_channelNumber * 100) / m_noOfChannels;
+ if (percent < 70) {
+ mir_wstrcat(text, L" ");
+ mir_wstrcat(text, TranslateT("(probably truncated by server)"));
+ }
+ SetDlgItemText(m_listDlg->GetHwnd(), IDC_TEXT, text);
}
- SetDlgItemText(m_listDlg->GetHwnd(), IDC_TEXT, text);
}
ShowMessage(pmsg);
return true;
@@ -1603,7 +1615,7 @@ bool CIrcProto::OnIrc_BANLISTEND(const CIrcMessage *pmsg) return true;
}
-static void __stdcall sttShowWhoisWnd(void* param)
+static INT_PTR __stdcall sttShowWhoisWnd(void* param)
{
CIrcMessage* pmsg = (CIrcMessage*)param;
CIrcProto *ppro = (CIrcProto*)pmsg->m_proto;
@@ -1611,18 +1623,16 @@ static void __stdcall sttShowWhoisWnd(void* param) ppro->m_whoisDlg = new CWhoisDlg(ppro);
ppro->m_whoisDlg->Show();
}
- SetEvent(ppro->m_evWndCreate);
ppro->m_whoisDlg->ShowMessage(pmsg);
- delete pmsg;
+ return 0;
}
bool CIrcProto::OnIrc_WHOIS_NAME(const CIrcMessage *pmsg)
{
- if (pmsg->m_bIncoming && pmsg->parameters.getCount() > 5 && m_manualWhoisCount > 0) {
- CallFunctionAsync(sttShowWhoisWnd, new CIrcMessage(*pmsg));
- WaitForSingleObject(m_evWndCreate, INFINITE);
- }
+ if (pmsg->m_bIncoming && pmsg->parameters.getCount() > 5 && m_manualWhoisCount > 0)
+ CallFunctionSync(sttShowWhoisWnd, (void*)pmsg);
+
ShowMessage(pmsg);
return true;
}
@@ -1766,7 +1776,7 @@ bool CIrcProto::OnIrc_WHOIS_NO_USER(const CIrcMessage *pmsg) return true;
}
-static void __stdcall sttShowNickWnd(void* param)
+static INT_PTR __stdcall sttShowNickWnd(void* param)
{
CIrcMessage* pmsg = (CIrcMessage*)param;
CIrcProto *ppro = pmsg->m_proto;
@@ -1774,12 +1784,12 @@ static void __stdcall sttShowNickWnd(void* param) ppro->m_nickDlg = new CNickDlg(ppro);
ppro->m_nickDlg->Show();
}
- SetEvent(ppro->m_evWndCreate);
+
SetDlgItemText(ppro->m_nickDlg->GetHwnd(), IDC_CAPTION, TranslateT("Change nickname"));
SetDlgItemText(ppro->m_nickDlg->GetHwnd(), IDC_TEXT, pmsg->parameters.getCount() > 2 ? pmsg->parameters[2] : L"");
ppro->m_nickDlg->m_Enick.SetText(pmsg->parameters[1]);
ppro->m_nickDlg->m_Enick.SendMsg(CB_SETEDITSEL, 0, MAKELPARAM(0, -1));
- delete pmsg;
+ return 0;
}
bool CIrcProto::OnIrc_NICK_ERR(const CIrcMessage *pmsg)
@@ -1791,10 +1801,7 @@ bool CIrcProto::OnIrc_NICK_ERR(const CIrcMessage *pmsg) if (IsConnected())
SendIrcMessage(m);
}
- else {
- CallFunctionAsync(sttShowNickWnd, new CIrcMessage(*pmsg));
- WaitForSingleObject(m_evWndCreate, INFINITE);
- }
+ else CallFunctionSync(sttShowNickWnd, (void*)pmsg);
}
ShowMessage(pmsg);
diff --git a/protocols/IRCG/src/input.cpp b/protocols/IRCG/src/input.cpp index f7cf3b6f84..934d56abd5 100644 --- a/protocols/IRCG/src/input.cpp +++ b/protocols/IRCG/src/input.cpp @@ -477,9 +477,12 @@ BOOL CIrcProto::DoHardcodedCommand(CMStringW text, wchar_t *window, MCONTACT hCo }
if (command == L"/list") {
- if (m_listDlg == nullptr) {
- m_listDlg = new CListDlg(this);
- m_listDlg->Show();
+ {
+ mir_cslock lck(m_csList);
+ if (m_listDlg == nullptr) {
+ m_listDlg = new CListDlg(this);
+ m_listDlg->Show();
+ }
}
SetActiveWindow(m_listDlg->GetHwnd());
int minutes = (int)m_noOfChannels / 4000;
diff --git a/protocols/IRCG/src/irclib.cpp b/protocols/IRCG/src/irclib.cpp index 96426b287e..04b26ec02f 100644 --- a/protocols/IRCG/src/irclib.cpp +++ b/protocols/IRCG/src/irclib.cpp @@ -270,7 +270,6 @@ void CIrcProto::Disconnect(void) Netlib_Shutdown(con); m_info.Reset(); - return; } void CIrcProto::Notify(const CIrcMessage* pmsg) @@ -340,7 +339,6 @@ void CIrcProto::InsertIncomingEvent(wchar_t* pszRaw) { CIrcMessage msg(this, pszRaw, true); Notify(&msg); - return; } void CIrcProto::createMessageFromPchar(const char* p) diff --git a/protocols/IRCG/src/ircproto.cpp b/protocols/IRCG/src/ircproto.cpp index 9c45c532ee..3fa02e20b1 100644 --- a/protocols/IRCG/src/ircproto.cpp +++ b/protocols/IRCG/src/ircproto.cpp @@ -39,8 +39,6 @@ CIrcProto::CIrcProto(const char* szModuleName, const wchar_t* tszUserName) : vUserhostReasons(10),
vWhoInProgress(10)
{
- m_evWndCreate = ::CreateEvent(nullptr, FALSE, FALSE, nullptr);
-
CreateProtoService(PS_GETMYAWAYMSG, &CIrcProto::GetMyAwayMsg);
CreateProtoService(PS_CREATEACCMGRUI, &CIrcProto::SvcCreateAccMgrUI);
@@ -157,7 +155,6 @@ CIrcProto::~CIrcProto() mir_free(m_alias);
- CloseHandle(m_evWndCreate);
KillChatTimer(OnlineNotifTimer);
KillChatTimer(OnlineNotifTimer3);
}
diff --git a/protocols/IRCG/src/ircproto.h b/protocols/IRCG/src/ircproto.h index 473ec06359..559a919a34 100644 --- a/protocols/IRCG/src/ircproto.h +++ b/protocols/IRCG/src/ircproto.h @@ -165,10 +165,7 @@ struct CIrcProto : public PROTO<CIrcProto> OBJLIST<CMStringW> vUserhostReasons; OBJLIST<CMStringW> vWhoInProgress; - mir_cs cs; - mir_cs m_gchook; - mir_cs m_resolve; - HANDLE m_evWndCreate; + mir_cs m_csSession, m_csGcHook, m_csResolve, m_csList; CMStringW m_statusMessage; int m_iTempCheckTime; diff --git a/protocols/IRCG/src/services.cpp b/protocols/IRCG/src/services.cpp index d1d79044e8..7d622ca3a0 100644 --- a/protocols/IRCG/src/services.cpp +++ b/protocols/IRCG/src/services.cpp @@ -458,7 +458,7 @@ int __cdecl CIrcProto::GCEventHook(WPARAM, LPARAM lParam) GCHOOK *gch = (GCHOOK*)lParam;
CMStringW S = L"";
- mir_cslock lock(m_gchook);
+ mir_cslock lock(m_csGcHook);
// handle the hook
if (gch) {
@@ -839,7 +839,7 @@ int __cdecl CIrcProto::GCMenuHook(WPARAM, LPARAM lParam) void CIrcProto::OnShutdown()
{
- mir_cslock lock(cs);
+ mir_cslock lock(m_csSession);
if (m_perform && IsConnected())
if (DoPerform("Event: Disconnect"))
@@ -944,7 +944,7 @@ void __cdecl CIrcProto::ConnectServerThread(void*) ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)Temp, ID_STATUS_CONNECTING);
Sleep(100);
{
- mir_cslock lock(cs);
+ mir_cslock lock(m_csSession);
Connect(si);
}
if (IsConnected()) {
@@ -969,10 +969,9 @@ void __cdecl CIrcProto::DisconnectServerThread(void*) {
Thread_SetName("IRC: DisconnectServer");
- mir_cslock lck(cs);
+ mir_cslock lck(m_csSession);
if (IsConnected())
Disconnect();
- return;
}
void CIrcProto::ConnectToServer(void)
diff --git a/protocols/IRCG/src/version.h b/protocols/IRCG/src/version.h index 392dcb951f..1475e0a058 100644 --- a/protocols/IRCG/src/version.h +++ b/protocols/IRCG/src/version.h @@ -1,6 +1,6 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 95
-#define __RELEASE_NUM 9
+#define __RELEASE_NUM 10
#define __BUILD_NUM 1
#include <stdver.h>
diff --git a/protocols/IRCG/src/windows.cpp b/protocols/IRCG/src/windows.cpp index 947bc7b5c7..252417b914 100644 --- a/protocols/IRCG/src/windows.cpp +++ b/protocols/IRCG/src/windows.cpp @@ -405,9 +405,13 @@ void CListDlg::OnDestroy() if (m_timer)
::KillTimer(m_hwnd, m_timer);
Utils_SaveWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, "channelList_");
+
+ mir_cslock lck(m_proto->m_csList);
m_proto->m_listDlg = nullptr;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
struct ListViewSortParam
{
CCtrlListView* pList;
|