Exemple #1
0
LRESULT WaitingUsersFrame::onSpeaker(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	// [!] IRainman opt.
	TaskQueue::List t;
	m_tasks.get(t);
	
	if (t.empty())
		return 0;
		
	CFlyBusyBool l_busy(m_spoken);
	CLockRedraw<> lockCtrlList(m_ctrlList);
	CLockRedraw<> lockCtrlQueued(ctrlQueued);
	for (auto j = t.cbegin(); j != t.cend(); ++j)
	{
		switch (j->first)
		{
			case REMOVE_WAITING_ITEM:
			{
				RemoveFile(static_cast<UploadQueueTask&>(*j->second).getItem());
			}
			break;
			case REMOVE:
			{
				RemoveUser(static_cast<UserTask&>(*j->second).getUser());
			}
			break;
			case ADD_ITEM:
			{
				AddFile(static_cast<UploadQueueTask&>(*j->second).getItem());
				m_needsResort = true;
			}
			break;
			case UPDATE_ITEMS:
			{
				const int l_item_count = m_ctrlList.GetItemCount();
				if (l_item_count)
				{
					const int l_top_index = m_ctrlList.GetTopIndex();
					const int l_count_per_page = m_ctrlList.GetCountPerPage();
					int64_t itime = GET_TIME();
					for (int i = l_top_index; i < l_count_per_page; i++)
					{
						auto ii = m_ctrlList.getItemData(i);
						if (ii)
						{
							// https://drdump.com/DumpGroup.aspx?DumpGroupID=491521
							ii->setText(UploadQueueItem::COLUMN_TRANSFERRED, Util::formatBytesW(ii->getPos()) + _T(" (") + Util::toStringW((double)ii->getPos() * 100.0 / (double)ii->getSize()) + _T("%)"));
							ii->setText(UploadQueueItem::COLUMN_WAITING, Util::formatSecondsW(itime - ii->getTime()));
							m_ctrlList.updateItem(i, UploadQueueItem::COLUMN_TRANSFERRED);
							m_ctrlList.updateItem(i, UploadQueueItem::COLUMN_WAITING);
						}
					}
				}
				if (m_needsResort)
				{
					m_ctrlList.resort();
					m_needsResort = false;
				}
				if (m_needsUpdateStatus)
				{
					if (BOOLSETTING(BOLD_WAITING_USERS))
					{
						setDirty(0);
					}
					updateStatus();
					m_needsUpdateStatus = false;
				}
			}
			break;
			default:
				dcassert(0);
		}
		if (j->first != UPDATE_ITEMS)
		{
			m_needsUpdateStatus = true;
		}
		delete j->second;
	}
	return 0;
}
Exemple #2
0
LRESULT SpyFrame::onSpeaker(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	TaskQueue::List t;
	m_tasks.get(t);
	
	if (t.empty())
		return 0;
		
	CFlyBusyBool l_busy(m_spoken);
	CLockRedraw<> lockCtrlList(ctrlSearches);
	for (auto i = t.cbegin(); i != t.cend(); ++i)
	{
		switch (i->first)
		{
			case SEARCH:
			{
				SMTSearchInfo* si = (SMTSearchInfo*)i->second;
				//[+]IRainman refactoring SpyFrame
				if (m_needsUpdateTime)
				{
					m_CurrentTime = Text::toT(Util::formatDigitalClock(GET_TIME()));
					m_needsUpdateTime = false;
				}
				//[~]IRainman refactoring SpyFrame
				tstring l_SeekersNames;
				{
					auto& l_searh_item = m_spy_searches[si->s];
					if (m_showNick)// [+] IRainman
					{
						if (::strncmp(si->seeker.c_str(), "Hub:", 4))
						{
							const string::size_type l_twopt = si->seeker.find(':');
							if (l_twopt != string::npos)
							{
								const string l_ip = si->seeker.substr(0, l_twopt);
								const StringList l_users = ClientManager::getUserByIp(l_ip);
								if (!l_users.empty())
								{
									si->seeker = "[IP:" + l_ip + "] Users:" + Util::toString(l_users);
								}
							}
						}
					}
					if (m_log && m_LogFile)
					{
						m_log_txt += Text::fromT(m_CurrentTime) + "\t" +
						             si->seeker + "\t" +
						             si->s + "\r\n";
					}
					if (m_showNick)// [+] IRainman
					{
						size_t k;
						for (k = 0; k < NUM_SEEKERS; ++k)
							if (si->seeker == l_searh_item.m_seekers[k])
								break;          //that user's searching for file already noted
								
						if (k == NUM_SEEKERS)           //loop terminated normally
							l_searh_item.AddSeeker(si->seeker);
							
						for (k = 0; k < NUM_SEEKERS; ++k)
							l_SeekersNames += Text::toT(l_searh_item.m_seekers[k]) + _T("  ");
					}
					
					++m_total;
					++m_perSecond[m_current];
				}
				// !SMT!-S
				tstring hit;
				if (si->re == ClientManagerListener::SEARCH_PARTIAL_HIT)
					hit = _T('*');
				else if (si->re == ClientManagerListener::SEARCH_HIT)
					hit = _T('+');
					
				tstring l_search;
				l_search = Text::toT(si->s, l_search);
				const int j = ctrlSearches.find(l_search);
				if (j == -1)
				{
					TStringList a;
					a.reserve(5);
					a.push_back(l_search);
					a.push_back(_T("1"));
					a.push_back(l_SeekersNames);
					a.push_back(m_CurrentTime);
					a.push_back(hit);
					ctrlSearches.insert(a, 0, si->re);// !SMT!-S
					int l_Count = ctrlSearches.GetItemCount();
					if (l_Count > 500)
					{
						ctrlSearches.DeleteItem(--l_Count);
					}
				}
				else
				{
					TCHAR tmp[32];
					tmp[0] = 0;
					ctrlSearches.GetItemText(j, COLUMN_COUNT, tmp, 32);
					ctrlSearches.SetItemText(j, COLUMN_COUNT, Util::toStringW(Util::toInt(tmp) + 1).c_str());
					ctrlSearches.SetItemText(j, COLUMN_USERS, l_SeekersNames.c_str());
					ctrlSearches.SetItemText(j, COLUMN_TIME, m_CurrentTime.c_str());
					ctrlSearches.SetItemText(j, COLUMN_SHARE_HIT, hit.c_str()); // !SMT!-S
					ctrlSearches.SetItem(j, COLUMN_SHARE_HIT, LVIF_PARAM, NULL, 0, 0, 0, si->re); // !SMT!-S
					if (ctrlSearches.getSortColumn() == COLUMN_COUNT ||
					        ctrlSearches.getSortColumn() == COLUMN_TIME
					   )
						m_needsResort = true;
				}
				if (BOOLSETTING(BOLD_SEARCH))
				{
					setDirty(0);
				}
#ifdef FLYLINKDC_USE_SOUND_AND_POPUP_IN_SEARCH_SPY
				SHOW_POPUP(POPUP_SEARCH_SPY, m_CurrentTime + _T(" : ") + l_SeekersNames + _T("\r\n") + l_search, TSTRING(SEARCH_SPY)); // [+] SCALOlaz: Spy Popup. Thanks to tret2003 (NightOrion) with tstring
				PLAY_SOUND(SOUND_SEARCHSPY);
#endif
			}
			break;
			case TICK_AVG:
			{
				auto s = (Stats*)i->second;
				LocalArray<TCHAR, 50> buf;
				_snwprintf(buf.data(), buf.size(), CTSTRING(SEARCHES_PER), s->m_perS, s->m_perM);
				ctrlStatus.SetText(2, (TSTRING(TOTAL) + _T(' ') + Util::toStringW(m_total)).c_str());
				ctrlStatus.SetText(3, buf.data());
				ctrlStatus.SetText(4, (TSTRING(HITS) + _T(' ') + Util::toStringW((size_t)(ShareManager::getHits()))).c_str());
				const double ratio = m_total > 0 ? static_cast<double>(ShareManager::getHits()) / static_cast<double>(m_total) : 0.0;
				ctrlStatus.SetText(5, (TSTRING(HIT_RATIO) + _T(' ') + Util::toStringW(ratio)).c_str());
				if (m_needsResort)
				{
					m_needsResort = false;
					ctrlSearches.resort();
				}
			}
			break;
			case SAVE_LOG:
				if (m_log)
				{
					try
					{
						m_log->setEndPos(0);
						m_log->write(m_log_txt);
					}
					catch (const FileException& e)
					{
						LogManager::message("Error write file spylog.log error = " + e.getError());
					}
					m_log_txt.clear();
				}
				break;
		}
		delete i->second;
	}
	return 0;
}