Skip to content

Commit

Permalink
Fixes a number of issues, found since the initial release of version …
Browse files Browse the repository at this point in the history
…0.60a.
  • Loading branch information
irwir committed Jan 17, 2021
1 parent 390156b commit 0c8a84c
Show file tree
Hide file tree
Showing 29 changed files with 128 additions and 111 deletions.
8 changes: 8 additions & 0 deletions srchybrid/CatDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,17 @@ void CCatDialog::OnBnClickedOk()
m_myCat->color = newcolor;
m_myCat->prio = m_prio.GetCurSel();
GetDlgItemText(IDC_AUTOCATEXT, m_myCat->autocat);
if (m_myCat->ac_regexpeval && !IsRegExpValid(m_myCat->autocat)) {
GetDlgItem(IDC_AUTOCATEXT)->SetFocus();
return;
}

GetDlgItemText(IDC_REGEXP, m_myCat->regexp);
if (m_myCat->regexp.GetLength() > 0) {
if (!IsRegExpValid(m_myCat->regexp)) {
GetDlgItem(IDC_REGEXP)->SetFocus();
return;
}
if (m_pacRegExp && m_pacRegExp->IsBound()) {
m_pacRegExp->AddItem(m_myCat->regexp, 0);
m_myCat->filter = 18;
Expand Down
39 changes: 20 additions & 19 deletions srchybrid/CommentDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ END_MESSAGE_MAP()

CCommentDialog::CCommentDialog()
: CResizablePage(CCommentDialog::IDD)
, m_iRating(-1)
, m_paFiles()
, m_bDataChanged()
, m_bMergedComment()
Expand Down Expand Up @@ -109,7 +110,7 @@ BOOL CCommentDialog::OnSetActive()
return FALSE;
if (m_bDataChanged) {
bool bContainsSharedKnownFile = false;
int iRating = -1;
m_iRating = -1;
m_bMergedComment = false;
CString strComment;
for (int i = 0; i < m_paFiles->GetSize(); ++i) {
Expand All @@ -124,20 +125,20 @@ BOOL CCommentDialog::OnSetActive()
bContainsSharedKnownFile = true;
if (i == 0) {
strComment = file->GetFileComment();
iRating = file->GetFileRating();
m_iRating = file->GetFileRating();
} else {
if (!m_bMergedComment && strComment.Compare(file->GetFileComment()) != 0) {
strComment.Empty();
m_bMergedComment = true;
}
if (iRating >= 0 && (UINT)iRating != file->GetFileRating())
iRating = -1;
if (m_iRating >= 0 && (UINT)m_iRating != file->GetFileRating())
m_iRating = -1;
}
}
m_bSelf = true;
SetDlgItemText(IDC_CMT_TEXT, strComment);
static_cast<CEdit*>(GetDlgItem(IDC_CMT_TEXT))->SetLimitText(MAXFILECOMMENTLEN);
m_ratebox.SetCurSel(iRating);
m_ratebox.SetCurSel(m_iRating);
m_bSelf = false;
EnableDialog(bContainsSharedKnownFile);

Expand Down Expand Up @@ -167,15 +168,15 @@ BOOL CCommentDialog::OnApply()
if (m_bEnabled && !m_bDataChanged) {
CString strComment;
GetDlgItemText(IDC_CMT_TEXT, strComment);
int iRating = m_ratebox.GetCurSel();
m_iRating = m_ratebox.GetCurSel();
for (int i = 0; i < m_paFiles->GetSize(); ++i)
if ((*m_paFiles)[i]->IsKindOf(RUNTIME_CLASS(CKnownFile))) {
CKnownFile *file = static_cast<CKnownFile*>((*m_paFiles)[i]);
if (theApp.sharedfiles->GetFileByID(file->GetFileHash()) != NULL) {
if (!strComment.IsEmpty() || !m_bMergedComment)
file->SetFileComment(strComment);
if (iRating >= 0)
file->SetFileRating(iRating);
if (m_iRating >= 0)
file->SetFileRating(m_iRating);
}
}
}
Expand Down Expand Up @@ -218,8 +219,8 @@ void CCommentDialog::Localize()
m_ratebox.AddItem(GetResString(IDS_CMT_FAIR), 3);
m_ratebox.AddItem(GetResString(IDS_CMT_GOOD), 4);
m_ratebox.AddItem(GetResString(IDS_CMT_EXCELLENT), 5);
UpdateHorzExtent(m_ratebox, 16); // adjust dropped width to ensure all strings are fully visible

UpdateHorzExtent(m_ratebox, 16); // adjust dropdown width to ensure all strings are fully visible
m_ratebox.SetCurSel(m_iRating);
RefreshData();
}

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

void CCommentDialog::EnableDialog(bool bEnabled)
{
if (m_bEnabled == bEnabled)
return;
m_bEnabled = bEnabled;
GetDlgItem(IDC_LST)->EnableWindow(static_cast<BOOL>(m_bEnabled));
GetDlgItem(IDC_CMT_TEXT)->EnableWindow(static_cast<BOOL>(m_bEnabled));
GetDlgItem(IDC_RATELIST)->EnableWindow(static_cast<BOOL>(m_bEnabled));
GetDlgItem(IDC_RESET)->EnableWindow(static_cast<BOOL>(m_bEnabled));
GetDlgItem(IDC_SEARCHKAD)->EnableWindow(static_cast<BOOL>(m_bEnabled));
if (m_bEnabled != bEnabled) {
m_bEnabled = bEnabled;
GetDlgItem(IDC_LST)->EnableWindow(bEnabled);
GetDlgItem(IDC_CMT_TEXT)->EnableWindow(bEnabled);
GetDlgItem(IDC_RATELIST)->EnableWindow(bEnabled);
GetDlgItem(IDC_RESET)->EnableWindow(bEnabled);
GetDlgItem(IDC_SEARCHKAD)->EnableWindow(bEnabled);
}
}
2 changes: 1 addition & 1 deletion srchybrid/CommentDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CCommentDialog : public CResizablePage
{
IDD = IDD_COMMENT
};

int m_iRating;
public:
CCommentDialog(); // standard constructor
virtual ~CCommentDialog() = default;
Expand Down
3 changes: 1 addition & 2 deletions srchybrid/CommentDialogLst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ BOOL CCommentDialogLst::OnSetActive()
if (!CResizablePage::OnSetActive())
return FALSE;
if (m_bDataChanged) {
RefreshData();
RefreshData();
m_bDataChanged = false;
}
Expand Down Expand Up @@ -197,7 +196,7 @@ void CCommentDialogLst::OnBnClickedFilter()
CString strNewCommentFilters;
for (int iPos = 0; iPos >= 0;) {
CString strFilter = strCommentFilters.Tokenize(_T("|"), iPos);
if (!strFilter.IsEmpty()) {
if (!strFilter.Trim().IsEmpty()) {
if (!strNewCommentFilters.IsEmpty())
strNewCommentFilters += _T('|');
strNewCommentFilters += strFilter.Trim();
Expand Down
2 changes: 1 addition & 1 deletion srchybrid/CreditsThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void CCreditsThread::InitText()

m_arCredits.Add(_T("03:00:eMule"));
m_arCredits.Add(_T("02:01:Version ") + theApp.m_strCurVersionLong);
m_arCredits.Add(_T("01:06:Copyright (C) 2002-2020 Merkur"));
m_arCredits.Add(_T("01:06:Copyright (C) 2002-2021 Merkur"));
m_arCredits.Add(_T("S:50"));
m_arCredits.Add(_T("02:04:Developers"));
m_arCredits.Add(_T("S:5"));
Expand Down
12 changes: 5 additions & 7 deletions srchybrid/DirectoryTreeCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,20 +342,18 @@ bool CDirectoryTreeCtrl::HasSubdirectories(const CString &strDir)

void CDirectoryTreeCtrl::GetSharedDirectories(CStringList &list)
{
for (POSITION pos = m_lstShared.GetHeadPosition(); pos != NULL; )
for (POSITION pos = m_lstShared.GetHeadPosition(); pos != NULL;)
list.AddTail(m_lstShared.GetNext(pos));
}

void CDirectoryTreeCtrl::SetSharedDirectories(CStringList &list)
{
m_lstShared.RemoveAll();

for (POSITION pos = list.GetHeadPosition(); pos != NULL; ) {
CString str = list.GetNext(pos);
if (str.Left(2) != _T("\\\\"))
slosh(str);
m_lstShared.AddTail(str);

for (POSITION pos = list.GetHeadPosition(); pos != NULL;) {
const CString &sDir(list.GetNext(pos));
if (!::PathIsUNC(sDir))
m_lstShared.AddTail(sDir);
}
Init();
}
Expand Down
41 changes: 20 additions & 21 deletions srchybrid/DownloadClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,12 @@ void CUpDownClient::DrawStatusBar(CDC *dc, const CRect &rect, bool onlygreyrect,
for (UINT i = 0; i < m_nPartCount; ++i) {
if (m_abyPartStatus[i]) {
uint64 uBegin = PARTSIZE * i;
uint64 uEnd = uBegin + PARTSIZE - 1;
if (uEnd >= (uint64)m_reqfile->GetFileSize())
uEnd = (uint64)m_reqfile->GetFileSize();
uint64 uEnd = min(uBegin + PARTSIZE, (uint64)m_reqfile->GetFileSize());

COLORREF colour;
if (m_reqfile->IsComplete(uBegin, uEnd - 1, false))
colour = crBoth;
else if (m_eDownloadState == DS_DOWNLOADING && GetSessionDown() > 0 && m_nLastBlockOffset >= uBegin && m_nLastBlockOffset <= uEnd)
else if (m_eDownloadState == DS_DOWNLOADING && GetSessionDown() && m_nLastBlockOffset >= uBegin && m_nLastBlockOffset < uEnd)
colour = crPending;
else if (pcNextPendingBlks != NULL && pcNextPendingBlks[i] == 'Y')
colour = crNextPending;
Expand Down Expand Up @@ -298,10 +296,11 @@ void CUpDownClient::SendFileRequest()
if (thePrefs.GetDebugClientTCPLevel() > 0)
DebugSend("OP_MPReqFileName", this, m_reqfile->GetFileHash());
dataFileReq.WriteUInt8(OP_REQUESTFILENAME);
if (GetExtendedRequestsVersion() > 0)
if (GetExtendedRequestsVersion() > 0) {
m_reqfile->WritePartStatus(&dataFileReq);
if (GetExtendedRequestsVersion() > 1)
m_reqfile->WriteCompleteSourcesCount(&dataFileReq);
if (GetExtendedRequestsVersion() > 1)
m_reqfile->WriteCompleteSourcesCount(&dataFileReq);
}

// OP_SETREQFILEID
if (thePrefs.GetDebugClientTCPLevel() > 0)
Expand Down Expand Up @@ -357,10 +356,11 @@ void CUpDownClient::SendFileRequest()
CSafeMemFile dataFileReq(96);
dataFileReq.WriteHash16(m_reqfile->GetFileHash());
//This is extended information
if (GetExtendedRequestsVersion() > 0)
if (GetExtendedRequestsVersion() > 0) {
m_reqfile->WritePartStatus(&dataFileReq);
if (GetExtendedRequestsVersion() > 1)
m_reqfile->WriteCompleteSourcesCount(&dataFileReq);
if (GetExtendedRequestsVersion() > 1)
m_reqfile->WriteCompleteSourcesCount(&dataFileReq);
}
if (thePrefs.GetDebugClientTCPLevel() > 0)
DebugSend("OP_FileRequest", this, m_reqfile->GetFileHash());
Packet *packet = new Packet(&dataFileReq);
Expand Down Expand Up @@ -640,7 +640,7 @@ void CUpDownClient::SetDownloadState(EDownloadState nNewState, LPCTSTR pszReason
}
break;
case DS_NONEEDEDPARTS:
// Since TCP asks never sets re-ask time if the result is DS_NONEEDEDPARTS
// Since TCP asks never set re-ask time if the result is DS_NONEEDEDPARTS
// If we set this, we will not re-ask for that file until some time has passed.
SetLastAskedTime();
//DontSwapTo(m_reqfile);
Expand Down Expand Up @@ -676,16 +676,15 @@ void CUpDownClient::SetDownloadState(EDownloadState nNewState, LPCTSTR pszReason
if (nNewState == DS_NONEEDEDPARTS)
pszReason = _T("NNP. You don't need any parts from this client.");

if (thePrefs.GetLogUlDlEvents())
AddDebugLogLine(DLP_VERYLOW, false
, _T("Download session ended: %s User: %s in SetDownloadState(). New State: %i, Length: %s, Payload: %s, Transferred: %s, Req blocks not yet completed: %i.")
, pszReason
, (LPCTSTR)DbgGetClientInfo()
, nNewState
, (LPCTSTR)CastSecondsToHM(GetDownTimeDifference(false) / SEC2MS(1))
, (LPCTSTR)CastItoXBytes(GetSessionPayloadDown())
, (LPCTSTR)CastItoXBytes(GetSessionDown())
, m_PendingBlocks_list.GetCount());
AddDebugLogLine(DLP_VERYLOW, false
, _T("Download session ended: %s User: %s in SetDownloadState(). New State: %i, Length: %s, Payload: %s, Transferred: %s, Req blocks not yet completed: %i.")
, pszReason
, (LPCTSTR)DbgGetClientInfo()
, nNewState
, (LPCTSTR)CastSecondsToHM(GetDownTimeDifference(false) / SEC2MS(1))
, (LPCTSTR)CastItoXBytes(GetSessionPayloadDown())
, (LPCTSTR)CastItoXBytes(GetSessionDown())
, m_PendingBlocks_list.GetCount());
}

ResetSessionDown();
Expand Down
2 changes: 1 addition & 1 deletion srchybrid/DownloadQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ void CDownloadQueue::ExportPartMetFilesOverview() const
file.printf(_T("--------------------------------------------------------------------------------\r\n"));
for (POSITION pos = filelist.GetHeadPosition(); pos != NULL;) {
const CPartFile *pPartFile = filelist.GetNext(pos);
if (pPartFile && pPartFile->GetStatus(true) != PS_COMPLETE) {
if (pPartFile->GetStatus(true) != PS_COMPLETE) {
CString strPartFilePath(pPartFile->GetFilePath());
TCHAR szNam[_MAX_FNAME];
TCHAR szExt[_MAX_EXT];
Expand Down
2 changes: 1 addition & 1 deletion srchybrid/ED2kLinkDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void CED2kLinkDlg::UpdateLink()

CString strLinks;
for (int i = 0; i != m_paFiles->GetSize(); ++i)
if ((*m_paFiles)[i] && (*m_paFiles)[i]->IsKindOf(RUNTIME_CLASS(CKnownFile))) {
if ((*m_paFiles)[i]->IsKindOf(RUNTIME_CLASS(CKnownFile))) {
if (!strLinks.IsEmpty())
strLinks += _T("\r\n\r\n");
const CKnownFile *file = static_cast<CKnownFile*>((*m_paFiles)[i]);
Expand Down
2 changes: 2 additions & 0 deletions srchybrid/FileDetailDialogInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ BOOL CFileDetailDialogInfo::OnInitDialog()
CResizablePage::OnInitDialog();
InitWindowStyles(this);

AddAnchor(IDC_FNAME, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_METFILE, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_FD_X0, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_FD_X6, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_FD_X8, TOP_LEFT, TOP_RIGHT);
Expand Down
4 changes: 2 additions & 2 deletions srchybrid/ListenSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,7 @@ bool CClientReqSocket::ProcessExtPacket(const BYTE *packet, uint32 size, UINT op
DebugRecv(sOp, client, (size >= 16) ? packet : NULL);
}

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

float CListenSocket::GetMaxConperFiveModifier()
{
Expand Down
22 changes: 18 additions & 4 deletions srchybrid/OtherFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3320,15 +3320,29 @@ bool IsUnicodeFile(LPCTSTR pszFilePath)
return bResult;
}

bool IsRegExpValid(const CString & regexpr)
{
try {
std::basic_regex<TCHAR> reFN(regexpr);
} catch (const std::regex_error&) {
return false;
}
return true;
}

bool RegularExpressionMatch(const CString &regexpr, const CString &teststring)
{
std::basic_regex<TCHAR> reFN(regexpr);
try {
std::basic_regex<TCHAR> reFN(regexpr);
#ifdef UNICODE
std::wcmatch mcUrl;
std::wcmatch mcUrl;
#else
std::cmatch mcUrl;
std::cmatch mcUrl;
#endif
return std::regex_match((LPCTSTR)teststring, mcUrl, reFN);
return std::regex_match((LPCTSTR)teststring, mcUrl, reFN);
} catch (const std::regex_error&) {
return false;
}
}

ULONGLONG GetModuleVersion(LPCTSTR pszFilePath)
Expand Down
1 change: 1 addition & 0 deletions srchybrid/OtherFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ CString GetFormatedUInt(ULONG ulVal);
CString GetFormatedUInt64(ULONGLONG ullVal);
void SecToTimeLength(unsigned long ulSec, CStringA &rstrTimeLength);
void SecToTimeLength(unsigned long ulSec, CStringW &rstrTimeLength);
bool IsRegExpValid(const CString &regexpr);
bool RegularExpressionMatch(const CString &regexpr, const CString &teststring);

// Print hash in a format which is similar to CertMgr's
Expand Down
2 changes: 2 additions & 0 deletions srchybrid/PartFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3649,6 +3649,8 @@ bool CPartFile::IsReadyForPreview() const
case PS_EMPTY:
case PS_PAUSED:
case PS_INSUFFICIENT:
break;
default:
return false;
}

Expand Down
Loading

0 comments on commit 0c8a84c

Please sign in to comment.