Skip to content

Commit 0c8a84c

Browse files
committed
Fixes a number of issues, found since the initial release of version 0.60a.
1 parent 390156b commit 0c8a84c

29 files changed

+128
-111
lines changed

srchybrid/CatDialog.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,17 @@ void CCatDialog::OnBnClickedOk()
180180
m_myCat->color = newcolor;
181181
m_myCat->prio = m_prio.GetCurSel();
182182
GetDlgItemText(IDC_AUTOCATEXT, m_myCat->autocat);
183+
if (m_myCat->ac_regexpeval && !IsRegExpValid(m_myCat->autocat)) {
184+
GetDlgItem(IDC_AUTOCATEXT)->SetFocus();
185+
return;
186+
}
183187

184188
GetDlgItemText(IDC_REGEXP, m_myCat->regexp);
185189
if (m_myCat->regexp.GetLength() > 0) {
190+
if (!IsRegExpValid(m_myCat->regexp)) {
191+
GetDlgItem(IDC_REGEXP)->SetFocus();
192+
return;
193+
}
186194
if (m_pacRegExp && m_pacRegExp->IsBound()) {
187195
m_pacRegExp->AddItem(m_myCat->regexp, 0);
188196
m_myCat->filter = 18;

srchybrid/CommentDialog.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ END_MESSAGE_MAP()
5353

5454
CCommentDialog::CCommentDialog()
5555
: CResizablePage(CCommentDialog::IDD)
56+
, m_iRating(-1)
5657
, m_paFiles()
5758
, m_bDataChanged()
5859
, m_bMergedComment()
@@ -109,7 +110,7 @@ BOOL CCommentDialog::OnSetActive()
109110
return FALSE;
110111
if (m_bDataChanged) {
111112
bool bContainsSharedKnownFile = false;
112-
int iRating = -1;
113+
m_iRating = -1;
113114
m_bMergedComment = false;
114115
CString strComment;
115116
for (int i = 0; i < m_paFiles->GetSize(); ++i) {
@@ -124,20 +125,20 @@ BOOL CCommentDialog::OnSetActive()
124125
bContainsSharedKnownFile = true;
125126
if (i == 0) {
126127
strComment = file->GetFileComment();
127-
iRating = file->GetFileRating();
128+
m_iRating = file->GetFileRating();
128129
} else {
129130
if (!m_bMergedComment && strComment.Compare(file->GetFileComment()) != 0) {
130131
strComment.Empty();
131132
m_bMergedComment = true;
132133
}
133-
if (iRating >= 0 && (UINT)iRating != file->GetFileRating())
134-
iRating = -1;
134+
if (m_iRating >= 0 && (UINT)m_iRating != file->GetFileRating())
135+
m_iRating = -1;
135136
}
136137
}
137138
m_bSelf = true;
138139
SetDlgItemText(IDC_CMT_TEXT, strComment);
139140
static_cast<CEdit*>(GetDlgItem(IDC_CMT_TEXT))->SetLimitText(MAXFILECOMMENTLEN);
140-
m_ratebox.SetCurSel(iRating);
141+
m_ratebox.SetCurSel(m_iRating);
141142
m_bSelf = false;
142143
EnableDialog(bContainsSharedKnownFile);
143144

@@ -167,15 +168,15 @@ BOOL CCommentDialog::OnApply()
167168
if (m_bEnabled && !m_bDataChanged) {
168169
CString strComment;
169170
GetDlgItemText(IDC_CMT_TEXT, strComment);
170-
int iRating = m_ratebox.GetCurSel();
171+
m_iRating = m_ratebox.GetCurSel();
171172
for (int i = 0; i < m_paFiles->GetSize(); ++i)
172173
if ((*m_paFiles)[i]->IsKindOf(RUNTIME_CLASS(CKnownFile))) {
173174
CKnownFile *file = static_cast<CKnownFile*>((*m_paFiles)[i]);
174175
if (theApp.sharedfiles->GetFileByID(file->GetFileHash()) != NULL) {
175176
if (!strComment.IsEmpty() || !m_bMergedComment)
176177
file->SetFileComment(strComment);
177-
if (iRating >= 0)
178-
file->SetFileRating(iRating);
178+
if (m_iRating >= 0)
179+
file->SetFileRating(m_iRating);
179180
}
180181
}
181182
}
@@ -218,8 +219,8 @@ void CCommentDialog::Localize()
218219
m_ratebox.AddItem(GetResString(IDS_CMT_FAIR), 3);
219220
m_ratebox.AddItem(GetResString(IDS_CMT_GOOD), 4);
220221
m_ratebox.AddItem(GetResString(IDS_CMT_EXCELLENT), 5);
221-
UpdateHorzExtent(m_ratebox, 16); // adjust dropped width to ensure all strings are fully visible
222-
222+
UpdateHorzExtent(m_ratebox, 16); // adjust dropdown width to ensure all strings are fully visible
223+
m_ratebox.SetCurSel(m_iRating);
223224
RefreshData();
224225
}
225226

@@ -263,7 +264,7 @@ void CCommentDialog::RefreshData(bool deleteOld)
263264
for (int i = 0; i < m_paFiles->GetSize(); ++i) {
264265
CAbstractFile *file = static_cast<CAbstractFile*>((*m_paFiles)[i]);
265266
if (file->IsPartFile()) {
266-
for (POSITION pos = static_cast<CPartFile*>(file)->srclist.GetHeadPosition(); pos != NULL; ) {
267+
for (POSITION pos = static_cast<CPartFile*>(file)->srclist.GetHeadPosition(); pos != NULL;) {
267268
CUpDownClient *cur_src = static_cast<CPartFile*>(file)->srclist.GetNext(pos);
268269
if (cur_src->HasFileRating() || !cur_src->GetFileComment().IsEmpty())
269270
m_lstComments.AddItem(cur_src);
@@ -318,12 +319,12 @@ void CCommentDialog::OnBnClickedSearchKad()
318319

319320
void CCommentDialog::EnableDialog(bool bEnabled)
320321
{
321-
if (m_bEnabled == bEnabled)
322-
return;
323-
m_bEnabled = bEnabled;
324-
GetDlgItem(IDC_LST)->EnableWindow(static_cast<BOOL>(m_bEnabled));
325-
GetDlgItem(IDC_CMT_TEXT)->EnableWindow(static_cast<BOOL>(m_bEnabled));
326-
GetDlgItem(IDC_RATELIST)->EnableWindow(static_cast<BOOL>(m_bEnabled));
327-
GetDlgItem(IDC_RESET)->EnableWindow(static_cast<BOOL>(m_bEnabled));
328-
GetDlgItem(IDC_SEARCHKAD)->EnableWindow(static_cast<BOOL>(m_bEnabled));
322+
if (m_bEnabled != bEnabled) {
323+
m_bEnabled = bEnabled;
324+
GetDlgItem(IDC_LST)->EnableWindow(bEnabled);
325+
GetDlgItem(IDC_CMT_TEXT)->EnableWindow(bEnabled);
326+
GetDlgItem(IDC_RATELIST)->EnableWindow(bEnabled);
327+
GetDlgItem(IDC_RESET)->EnableWindow(bEnabled);
328+
GetDlgItem(IDC_SEARCHKAD)->EnableWindow(bEnabled);
329+
}
329330
}

srchybrid/CommentDialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CCommentDialog : public CResizablePage
1717
{
1818
IDD = IDD_COMMENT
1919
};
20-
20+
int m_iRating;
2121
public:
2222
CCommentDialog(); // standard constructor
2323
virtual ~CCommentDialog() = default;

srchybrid/CommentDialogLst.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ BOOL CCommentDialogLst::OnSetActive()
9595
if (!CResizablePage::OnSetActive())
9696
return FALSE;
9797
if (m_bDataChanged) {
98-
RefreshData();
9998
RefreshData();
10099
m_bDataChanged = false;
101100
}
@@ -197,7 +196,7 @@ void CCommentDialogLst::OnBnClickedFilter()
197196
CString strNewCommentFilters;
198197
for (int iPos = 0; iPos >= 0;) {
199198
CString strFilter = strCommentFilters.Tokenize(_T("|"), iPos);
200-
if (!strFilter.IsEmpty()) {
199+
if (!strFilter.Trim().IsEmpty()) {
201200
if (!strNewCommentFilters.IsEmpty())
202201
strNewCommentFilters += _T('|');
203202
strNewCommentFilters += strFilter.Trim();

srchybrid/CreditsThread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ void CCreditsThread::InitText()
388388

389389
m_arCredits.Add(_T("03:00:eMule"));
390390
m_arCredits.Add(_T("02:01:Version ") + theApp.m_strCurVersionLong);
391-
m_arCredits.Add(_T("01:06:Copyright (C) 2002-2020 Merkur"));
391+
m_arCredits.Add(_T("01:06:Copyright (C) 2002-2021 Merkur"));
392392
m_arCredits.Add(_T("S:50"));
393393
m_arCredits.Add(_T("02:04:Developers"));
394394
m_arCredits.Add(_T("S:5"));

srchybrid/DirectoryTreeCtrl.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,20 +342,18 @@ bool CDirectoryTreeCtrl::HasSubdirectories(const CString &strDir)
342342

343343
void CDirectoryTreeCtrl::GetSharedDirectories(CStringList &list)
344344
{
345-
for (POSITION pos = m_lstShared.GetHeadPosition(); pos != NULL; )
345+
for (POSITION pos = m_lstShared.GetHeadPosition(); pos != NULL;)
346346
list.AddTail(m_lstShared.GetNext(pos));
347347
}
348348

349349
void CDirectoryTreeCtrl::SetSharedDirectories(CStringList &list)
350350
{
351351
m_lstShared.RemoveAll();
352352

353-
for (POSITION pos = list.GetHeadPosition(); pos != NULL; ) {
354-
CString str = list.GetNext(pos);
355-
if (str.Left(2) != _T("\\\\"))
356-
slosh(str);
357-
m_lstShared.AddTail(str);
358-
353+
for (POSITION pos = list.GetHeadPosition(); pos != NULL;) {
354+
const CString &sDir(list.GetNext(pos));
355+
if (!::PathIsUNC(sDir))
356+
m_lstShared.AddTail(sDir);
359357
}
360358
Init();
361359
}

srchybrid/DownloadClient.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,12 @@ void CUpDownClient::DrawStatusBar(CDC *dc, const CRect &rect, bool onlygreyrect,
103103
for (UINT i = 0; i < m_nPartCount; ++i) {
104104
if (m_abyPartStatus[i]) {
105105
uint64 uBegin = PARTSIZE * i;
106-
uint64 uEnd = uBegin + PARTSIZE - 1;
107-
if (uEnd >= (uint64)m_reqfile->GetFileSize())
108-
uEnd = (uint64)m_reqfile->GetFileSize();
106+
uint64 uEnd = min(uBegin + PARTSIZE, (uint64)m_reqfile->GetFileSize());
109107

110108
COLORREF colour;
111109
if (m_reqfile->IsComplete(uBegin, uEnd - 1, false))
112110
colour = crBoth;
113-
else if (m_eDownloadState == DS_DOWNLOADING && GetSessionDown() > 0 && m_nLastBlockOffset >= uBegin && m_nLastBlockOffset <= uEnd)
111+
else if (m_eDownloadState == DS_DOWNLOADING && GetSessionDown() && m_nLastBlockOffset >= uBegin && m_nLastBlockOffset < uEnd)
114112
colour = crPending;
115113
else if (pcNextPendingBlks != NULL && pcNextPendingBlks[i] == 'Y')
116114
colour = crNextPending;
@@ -298,10 +296,11 @@ void CUpDownClient::SendFileRequest()
298296
if (thePrefs.GetDebugClientTCPLevel() > 0)
299297
DebugSend("OP_MPReqFileName", this, m_reqfile->GetFileHash());
300298
dataFileReq.WriteUInt8(OP_REQUESTFILENAME);
301-
if (GetExtendedRequestsVersion() > 0)
299+
if (GetExtendedRequestsVersion() > 0) {
302300
m_reqfile->WritePartStatus(&dataFileReq);
303-
if (GetExtendedRequestsVersion() > 1)
304-
m_reqfile->WriteCompleteSourcesCount(&dataFileReq);
301+
if (GetExtendedRequestsVersion() > 1)
302+
m_reqfile->WriteCompleteSourcesCount(&dataFileReq);
303+
}
305304

306305
// OP_SETREQFILEID
307306
if (thePrefs.GetDebugClientTCPLevel() > 0)
@@ -357,10 +356,11 @@ void CUpDownClient::SendFileRequest()
357356
CSafeMemFile dataFileReq(96);
358357
dataFileReq.WriteHash16(m_reqfile->GetFileHash());
359358
//This is extended information
360-
if (GetExtendedRequestsVersion() > 0)
359+
if (GetExtendedRequestsVersion() > 0) {
361360
m_reqfile->WritePartStatus(&dataFileReq);
362-
if (GetExtendedRequestsVersion() > 1)
363-
m_reqfile->WriteCompleteSourcesCount(&dataFileReq);
361+
if (GetExtendedRequestsVersion() > 1)
362+
m_reqfile->WriteCompleteSourcesCount(&dataFileReq);
363+
}
364364
if (thePrefs.GetDebugClientTCPLevel() > 0)
365365
DebugSend("OP_FileRequest", this, m_reqfile->GetFileHash());
366366
Packet *packet = new Packet(&dataFileReq);
@@ -640,7 +640,7 @@ void CUpDownClient::SetDownloadState(EDownloadState nNewState, LPCTSTR pszReason
640640
}
641641
break;
642642
case DS_NONEEDEDPARTS:
643-
// Since TCP asks never sets re-ask time if the result is DS_NONEEDEDPARTS
643+
// Since TCP asks never set re-ask time if the result is DS_NONEEDEDPARTS
644644
// If we set this, we will not re-ask for that file until some time has passed.
645645
SetLastAskedTime();
646646
//DontSwapTo(m_reqfile);
@@ -676,16 +676,15 @@ void CUpDownClient::SetDownloadState(EDownloadState nNewState, LPCTSTR pszReason
676676
if (nNewState == DS_NONEEDEDPARTS)
677677
pszReason = _T("NNP. You don't need any parts from this client.");
678678

679-
if (thePrefs.GetLogUlDlEvents())
680-
AddDebugLogLine(DLP_VERYLOW, false
681-
, _T("Download session ended: %s User: %s in SetDownloadState(). New State: %i, Length: %s, Payload: %s, Transferred: %s, Req blocks not yet completed: %i.")
682-
, pszReason
683-
, (LPCTSTR)DbgGetClientInfo()
684-
, nNewState
685-
, (LPCTSTR)CastSecondsToHM(GetDownTimeDifference(false) / SEC2MS(1))
686-
, (LPCTSTR)CastItoXBytes(GetSessionPayloadDown())
687-
, (LPCTSTR)CastItoXBytes(GetSessionDown())
688-
, m_PendingBlocks_list.GetCount());
679+
AddDebugLogLine(DLP_VERYLOW, false
680+
, _T("Download session ended: %s User: %s in SetDownloadState(). New State: %i, Length: %s, Payload: %s, Transferred: %s, Req blocks not yet completed: %i.")
681+
, pszReason
682+
, (LPCTSTR)DbgGetClientInfo()
683+
, nNewState
684+
, (LPCTSTR)CastSecondsToHM(GetDownTimeDifference(false) / SEC2MS(1))
685+
, (LPCTSTR)CastItoXBytes(GetSessionPayloadDown())
686+
, (LPCTSTR)CastItoXBytes(GetSessionDown())
687+
, m_PendingBlocks_list.GetCount());
689688
}
690689

691690
ResetSessionDown();

srchybrid/DownloadQueue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,7 @@ void CDownloadQueue::ExportPartMetFilesOverview() const
16601660
file.printf(_T("--------------------------------------------------------------------------------\r\n"));
16611661
for (POSITION pos = filelist.GetHeadPosition(); pos != NULL;) {
16621662
const CPartFile *pPartFile = filelist.GetNext(pos);
1663-
if (pPartFile && pPartFile->GetStatus(true) != PS_COMPLETE) {
1663+
if (pPartFile->GetStatus(true) != PS_COMPLETE) {
16641664
CString strPartFilePath(pPartFile->GetFilePath());
16651665
TCHAR szNam[_MAX_FNAME];
16661666
TCHAR szExt[_MAX_EXT];

srchybrid/ED2kLinkDlg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void CED2kLinkDlg::UpdateLink()
181181

182182
CString strLinks;
183183
for (int i = 0; i != m_paFiles->GetSize(); ++i)
184-
if ((*m_paFiles)[i] && (*m_paFiles)[i]->IsKindOf(RUNTIME_CLASS(CKnownFile))) {
184+
if ((*m_paFiles)[i]->IsKindOf(RUNTIME_CLASS(CKnownFile))) {
185185
if (!strLinks.IsEmpty())
186186
strLinks += _T("\r\n\r\n");
187187
const CKnownFile *file = static_cast<CKnownFile*>((*m_paFiles)[i]);

srchybrid/FileDetailDialogInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ BOOL CFileDetailDialogInfo::OnInitDialog()
7272
CResizablePage::OnInitDialog();
7373
InitWindowStyles(this);
7474

75+
AddAnchor(IDC_FNAME, TOP_LEFT, TOP_RIGHT);
76+
AddAnchor(IDC_METFILE, TOP_LEFT, TOP_RIGHT);
7577
AddAnchor(IDC_FD_X0, TOP_LEFT, TOP_RIGHT);
7678
AddAnchor(IDC_FD_X6, TOP_LEFT, TOP_RIGHT);
7779
AddAnchor(IDC_FD_X8, TOP_LEFT, TOP_RIGHT);

srchybrid/ListenSocket.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ bool CClientReqSocket::ProcessExtPacket(const BYTE *packet, uint32 size, UINT op
17441744
DebugRecv(sOp, client, (size >= 16) ? packet : NULL);
17451745
}
17461746

1747-
theStats.AddDownDataOverheadFileRequest(16 + 2 * (opcode == OP_COMPRESSEDPART ? 4 : 8));
1747+
theStats.AddDownDataOverheadFileRequest(16 + (opcode == OP_COMPRESSEDPART ? 4 : 8) + (opcode == OP_SENDINGPART_I64 ? 8 : 4));
17481748
client->CheckHandshakeFinished();
17491749
const CPartFile *creqfile = client->GetRequestFile();
17501750
if (creqfile && !creqfile->IsStopped() && (creqfile->GetStatus() == PS_READY || creqfile->GetStatus() == PS_EMPTY)) {
@@ -2367,7 +2367,7 @@ void CListenSocket::UpdateConnectionsStatus()
23672367
if (averageconnections < 0.001f)
23682368
averageconnections = 0.001f; // avoid floating point underflow
23692369
}
2370-
}
2370+
}
23712371

23722372
float CListenSocket::GetMaxConperFiveModifier()
23732373
{

srchybrid/OtherFunctions.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,15 +3320,29 @@ bool IsUnicodeFile(LPCTSTR pszFilePath)
33203320
return bResult;
33213321
}
33223322

3323+
bool IsRegExpValid(const CString & regexpr)
3324+
{
3325+
try {
3326+
std::basic_regex<TCHAR> reFN(regexpr);
3327+
} catch (const std::regex_error&) {
3328+
return false;
3329+
}
3330+
return true;
3331+
}
3332+
33233333
bool RegularExpressionMatch(const CString &regexpr, const CString &teststring)
33243334
{
3325-
std::basic_regex<TCHAR> reFN(regexpr);
3335+
try {
3336+
std::basic_regex<TCHAR> reFN(regexpr);
33263337
#ifdef UNICODE
3327-
std::wcmatch mcUrl;
3338+
std::wcmatch mcUrl;
33283339
#else
3329-
std::cmatch mcUrl;
3340+
std::cmatch mcUrl;
33303341
#endif
3331-
return std::regex_match((LPCTSTR)teststring, mcUrl, reFN);
3342+
return std::regex_match((LPCTSTR)teststring, mcUrl, reFN);
3343+
} catch (const std::regex_error&) {
3344+
return false;
3345+
}
33323346
}
33333347

33343348
ULONGLONG GetModuleVersion(LPCTSTR pszFilePath)

srchybrid/OtherFunctions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ CString GetFormatedUInt(ULONG ulVal);
132132
CString GetFormatedUInt64(ULONGLONG ullVal);
133133
void SecToTimeLength(unsigned long ulSec, CStringA &rstrTimeLength);
134134
void SecToTimeLength(unsigned long ulSec, CStringW &rstrTimeLength);
135+
bool IsRegExpValid(const CString &regexpr);
135136
bool RegularExpressionMatch(const CString &regexpr, const CString &teststring);
136137

137138
// Print hash in a format which is similar to CertMgr's

srchybrid/PartFile.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3649,6 +3649,8 @@ bool CPartFile::IsReadyForPreview() const
36493649
case PS_EMPTY:
36503650
case PS_PAUSED:
36513651
case PS_INSUFFICIENT:
3652+
break;
3653+
default:
36523654
return false;
36533655
}
36543656

0 commit comments

Comments
 (0)