Ejemplo n.º 1
0
wxString CStatTreeItemAverageSpeed::GetDisplayString() const
{
    uint64 time = m_timer->GetTimerSeconds();
    if (time) {
        return CFormat(wxGetTranslation(m_label)) % CastItoSpeed((*m_counter)/time);
    } else {
        return CFormat(wxGetTranslation(m_label)) % CastItoSpeed(0);
    }
}
Ejemplo n.º 2
0
void FormatValue(CFormat& format, const CECTag* tag)
{
	wxASSERT(tag->GetTagName() == EC_TAG_STAT_NODE_VALUE);

	wxString extra;
	const CECTag *tmp_tag = tag->GetTagByName(EC_TAG_STAT_NODE_VALUE);
	if (tmp_tag) {
		wxString tmp_fmt;
		const CECTag* tmp_vt = tmp_tag->GetTagByName(EC_TAG_STAT_VALUE_TYPE);
		EC_STATTREE_NODE_VALUE_TYPE tmp_valueType = tmp_vt != NULL ? (EC_STATTREE_NODE_VALUE_TYPE)tmp_vt->GetInt() : EC_VALUE_INTEGER;
		switch (tmp_valueType) {
			case EC_VALUE_INTEGER:
				tmp_fmt = wxT("%llu");
				break;
			case EC_VALUE_DOUBLE:
				tmp_fmt = wxT("%.2f%%");	// it's used for percentages
				break;
			default:
				tmp_fmt = wxT("%s");
		}
		CFormat tmp_format(wxT(" (") + tmp_fmt + wxT(")"));
		FormatValue(tmp_format, tmp_tag);
		extra = tmp_format.GetString();
	}

	const CECTag* vt = tag->GetTagByName(EC_TAG_STAT_VALUE_TYPE);
	EC_STATTREE_NODE_VALUE_TYPE valueType = vt != NULL ? (EC_STATTREE_NODE_VALUE_TYPE)vt->GetInt() : EC_VALUE_INTEGER;
	switch (valueType) {
		case EC_VALUE_INTEGER:
			format = format % tag->GetInt();
			break;
		case EC_VALUE_ISTRING:
			format = format % (CFormat(wxT("%u")) % tag->GetInt() + extra);
			break;
		case EC_VALUE_BYTES:
			format = format % (CastItoXBytes(tag->GetInt()) + extra);
			break;
		case EC_VALUE_ISHORT:
			format = format % (CastItoIShort(tag->GetInt()) + extra);
			break;
		case EC_VALUE_TIME:
			format = format % (CastSecondsToHM(tag->GetInt()) + extra);
			break;
		case EC_VALUE_SPEED:
			format = format % (CastItoSpeed(tag->GetInt()) + extra);
			break;
		case EC_VALUE_STRING:
			format = format % (wxGetTranslation(tag->GetStringData()) + extra);
			break;
		case EC_VALUE_DOUBLE:
			format = format % tag->GetDoubleData();
			break;
		default:
			wxFAIL;
	}
}
Ejemplo n.º 3
0
/*
 * Format EC packet into text form for output to console
 */
void CamulecmdApp::Process_Answer_v2(const CECPacket *response)
{
	wxString s;
	wxString msgFailedUnknown(_("Request failed with an unknown error."));
	wxASSERT(response);
	switch (response->GetOpCode()) {
		case EC_OP_NOOP:
			s << _("Operation was successful.");
			break;
		case EC_OP_FAILED:
			{
				const CECTag *tag = response->GetFirstTagSafe();
				if (tag->IsString()) {
					s <<	CFormat(_("Request failed with the following error: %s")) % wxGetTranslation(tag->GetStringData());
				} else {
					s << msgFailedUnknown;
				}
			}
			break;
		case EC_OP_SET_PREFERENCES:
			{
				const CECTag *tab = response->GetTagByNameSafe(EC_TAG_PREFS_SECURITY);
				const CECTag *ipfilterLevel = tab->GetTagByName(EC_TAG_IPFILTER_LEVEL);
				if (ipfilterLevel) {
					if (m_last_cmd_id == CMD_ID_GET_IPFILTER ||
					    m_last_cmd_id == CMD_ID_GET_IPFILTER_STATE ||
					    m_last_cmd_id == CMD_ID_GET_IPFILTER_STATE_CLIENTS) {
						s += CFormat(_("IP filtering for clients is %s.\n"))
								% ((tab->GetTagByName(EC_TAG_IPFILTER_CLIENTS) == NULL) ? _("OFF") : _("ON"));
					}
					if (m_last_cmd_id == CMD_ID_GET_IPFILTER ||
					    m_last_cmd_id == CMD_ID_GET_IPFILTER_STATE ||
					    m_last_cmd_id == CMD_ID_GET_IPFILTER_STATE_SERVERS) {
						s += CFormat(_("IP filtering for servers is %s.\n"))
								% ((tab->GetTagByName(EC_TAG_IPFILTER_SERVERS) == NULL) ? _("OFF") : _("ON"));
					}
					if (m_last_cmd_id == CMD_ID_GET_IPFILTER ||
					    m_last_cmd_id == CMD_ID_GET_IPFILTER_LEVEL) {
						s << CFormat(_("Current IPFilter Level is %d.\n")) % ipfilterLevel->GetInt();
					}
				}
				tab = response->GetTagByNameSafe(EC_TAG_PREFS_CONNECTIONS);
				const CECTag *connMaxUL = tab->GetTagByName(EC_TAG_CONN_MAX_UL);
				const CECTag *connMaxDL = tab->GetTagByName(EC_TAG_CONN_MAX_DL);
				if (connMaxUL && connMaxDL) {
					s << CFormat(_("Bandwidth limits: Up: %u kB/s, Down: %u kB/s.\n"))
						% connMaxUL->GetInt() % connMaxDL->GetInt();
				}
			}
			break;
		case EC_OP_STRINGS:
			for (CECPacket::const_iterator it = response->begin(); it != response->end(); ++it) {
				const CECTag &tag = *it;
				s << tag.GetStringData() << wxT("\n");
			}
			break;
		case EC_OP_STATS: {
			const CEC_ConnState_Tag *connState = static_cast<const CEC_ConnState_Tag*>(response->GetTagByName(EC_TAG_CONNSTATE));
			if (connState) {
				s << _("eD2k") << wxT(": ");
				if (connState->IsConnectedED2K()) {
					const CECTag *server = connState->GetTagByName(EC_TAG_SERVER);
					const CECTag *serverName = server ? server->GetTagByName(EC_TAG_SERVER_NAME) : NULL;
					if (server && serverName) {
						s << CFormat(_("Connected to %s %s %s")) %
						 serverName->GetStringData() %
						 server->GetIPv4Data().StringIP() %
						 (connState->HasLowID() ? _("with LowID") : _("with HighID"));
					}
				} else if (connState->IsConnectingED2K()) {
					s << _("Now connecting");
				} else {
					s << _("Not connected");
				}
				s << wxT('\n') << _("Kad") << wxT(": ");
				if (connState->IsKadRunning()) {
					if (connState->IsConnectedKademlia()) {
						s << _("Connected") << wxT(" (");
						if (connState->IsKadFirewalled()) {
							s << _("firewalled");
						} else {
							s << _("ok");
						}
						s << wxT(')');
					} else {
						s << _("Not connected");
					}
				} else {
					s << _("Not running");
				}
				s << wxT('\n');
			}
			const CECTag *tmpTag;
			if ((tmpTag = response->GetTagByName(EC_TAG_STATS_DL_SPEED)) != 0) {
				s <<	CFormat(_("\nDownload:\t%s")) % CastItoSpeed(tmpTag->GetInt());
			}
			if ((tmpTag = response->GetTagByName(EC_TAG_STATS_UL_SPEED)) != 0) {
				s <<	CFormat(_("\nUpload:\t%s")) % CastItoSpeed(tmpTag->GetInt());
			}
			if ((tmpTag = response->GetTagByName(EC_TAG_STATS_UL_QUEUE_LEN)) != 0) {
				s <<	CFormat(_("\nClients in queue:\t%d\n")) % tmpTag->GetInt();
			}
			if ((tmpTag = response->GetTagByName(EC_TAG_STATS_TOTAL_SRC_COUNT)) != 0) {
				s <<	CFormat(_("\nTotal sources:\t%d\n")) % tmpTag->GetInt();
			}
			break;
		}
		case EC_OP_DLOAD_QUEUE:
			for (CECPacket::const_iterator it = response->begin(); it != response->end(); ++it) {
				const CEC_PartFile_Tag *tag = static_cast<const CEC_PartFile_Tag *>(&*it);
				uint64 filesize, donesize;
				filesize = tag->SizeFull();
				donesize = tag->SizeDone();
				s <<	tag->FileHashString() << wxT(" ") <<
					tag->FileName() <<
					(CFormat(wxT("\n\t [%.1f%%] %4i/%4i "))
						% ((float)donesize / ((float)filesize)*100.0)
						% ((int)tag->SourceCount() - (int)tag->SourceNotCurrCount())
						% (int)tag->SourceCount()) <<
					((int)tag->SourceCountA4AF() ? wxString(CFormat(wxT("+%2.2i ")) % (int)tag->SourceCountA4AF()) : wxString(wxT("    "))) <<
					((int)tag->SourceXferCount() ? wxString(CFormat(wxT("(%2.2i) - ")) % (int)tag->SourceXferCount()) : wxString(wxT("     - "))) <<
					tag->GetFileStatusString();
				s << wxT(" - ") << tag->PartMetName();
				if (tag->DownPrio() < 10) {
					s << wxT(" - ") << PriorityToStr((int)tag->DownPrio(), 0);
				} else {
					s << wxT(" - ") << PriorityToStr((tag->DownPrio() - 10), 1);
				}
				if ( tag->SourceXferCount() > 0) {
					s << wxT(" - ") + CastItoSpeed(tag->Speed());
				}
				s << wxT("\n");
			}
			break;
		case EC_OP_ULOAD_QUEUE:
			for (CECPacket::const_iterator it = response->begin(); it != response->end(); ++it) {
				const CECTag *tag = & *it;
				const CECTag *clientName = tag->GetTagByName(EC_TAG_CLIENT_NAME);
				const CECTag *partfileName = tag->GetTagByName(EC_TAG_PARTFILE_NAME);
				const CECTag *partfileSizeXfer = tag->GetTagByName(EC_TAG_PARTFILE_SIZE_XFER);
				const CECTag *partfileSpeed = tag->GetTagByName(EC_TAG_CLIENT_UP_SPEED);
				if (clientName && partfileName && partfileSizeXfer && partfileSpeed) {
					s <<	wxT("\n") <<
						CFormat(wxT("%10u ")) % tag->GetInt() <<
						clientName->GetStringData() << wxT(" ") <<
						partfileName->GetStringData() << wxT(" ") <<
						CastItoXBytes(partfileSizeXfer->GetInt()) << wxT(" ") <<
						CastItoSpeed(partfileSpeed->GetInt());
				}
			}
			break;
		case EC_OP_LOG:
			for (CECPacket::const_iterator it = response->begin(); it != response->end(); ++it) {
				const CECTag &tag = *it;
				s << tag.GetStringData() << wxT("\n");
			}
			break;
		case EC_OP_SERVER_LIST:
			for (CECPacket::const_iterator it = response->begin(); it != response->end(); ++it) {
				const CECTag &tag = *it;
				const CECTag *serverName = tag.GetTagByName(EC_TAG_SERVER_NAME);
				if (serverName) {
					wxString ip = tag.GetIPv4Data().StringIP();
					ip.Append(' ', 24 - ip.Length());
					s << ip << serverName->GetStringData() << wxT("\n");
				}
			}
			break;

		case EC_OP_SHARED_FILES:
			for (CECPacket::const_iterator it = response->begin(); it != response->end(); ++it) {
				const CEC_SharedFile_Tag *tag = static_cast<const CEC_SharedFile_Tag *>(&*it);
				s << tag->FileHashString() << wxT(" ");
				wxString filePath = tag->FilePath();
				bool ispartfile = true;
				if (filePath.EndsWith(wxT(".part"))) {
					for (unsigned i = 0; i < filePath.Length() - 5; i++) {
						if (filePath[i] < wxT('0') || filePath[i] > wxT('9')) {
							ispartfile = false;
							break;
						}
					}
				} else {
					ispartfile = false;
				}
				if (ispartfile) {
					s << _("[PartFile]") << wxT(" ");
				} else {
					s << filePath
#ifdef __WINDOWS__
					  << wxT('\\');
#else
					  << wxT('/');
#endif
				}
				s << tag->FileName()
				  << wxT("\n\t") << PriorityToStr(tag->UpPrio() % 10, tag->UpPrio() >= 10) << wxT(" - ") << CFormat(wxT("%i(%i) / %i(%i) - %s (%s) - %.2f\n"))
					% tag->GetRequests() % tag->GetAllRequests()
					% tag->GetAccepts() % tag->GetAllAccepts()
					% CastItoXBytes(tag->GetXferred()) % CastItoXBytes(tag->GetAllXferred())
					% (static_cast<float>(tag->GetAllXferred()) / static_cast<float>(tag->SizeFull()));
			}
			break;

		case EC_OP_STATSTREE:
			s << StatTree2Text(static_cast<const CEC_StatTree_Node_Tag*>(response->GetTagByName(EC_TAG_STATTREE_NODE)), 0);
			break;

		case EC_OP_SEARCH_RESULTS:
		{
			int i = 0;
			m_Results_map.clear();
			s += CFormat(_("Number of search results: %i\n")) % response->GetTagCount();
			for (CECPacket::const_iterator it = response->begin(); it != response->end(); ++it) {
				const CEC_SearchFile_Tag *tag = static_cast<const CEC_SearchFile_Tag *>(&*it);
				//printf("Tag FileName: %s \n",(const char*)unicode2char(tag->FileName()));
				m_Results_map[i++] = new SearchFile(tag);
			}
			ShowResults(m_Results_map);
			break;
		}
		case EC_OP_SEARCH_PROGRESS:
		{
			const CECTag *tab = response->GetTagByNameSafe(EC_TAG_SEARCH_STATUS);
			uint32 progress = tab->GetInt();
			if (progress <= 100) {
				s += CFormat(_("Search progress: %u %% \n")) % progress;
			} else {
				s += _("Search progress not available");
			}
			break;
		}
		default:
			s += CFormat(_("Received an unknown reply from the server, OpCode = %#x.")) % response->GetOpCode();
	}