From 50664544a36dfcd81534ba98c2e6740a4d961e73 Mon Sep 17 00:00:00 2001 From: upstream svn Date: Mon, 20 Sep 2010 20:54:03 +0000 Subject: [PATCH] Format string mayhem wxString::Format is not type safe, that's why CFormat was invented. After getting two Format string crashes with wx 2.9 64 bit (which is kind of sensitive regarding the matter) just opening/closing the app I had enough and swept out almost all wxString::Format calls, further cleaning up some format strings in the process. Most were innocent enough, but there were several instances of passing 64 bit ints to %u. Also CFormat(wxT("%c")) % ('A' + 5) now works as it should (allowing pass of an int instead of a wxChar to %c now). --- .svn-revision | 2 +- src/BaseClient.cpp | 34 +++++++-------- src/ChatSelector.cpp | 2 +- src/ClientCreditsList.cpp | 4 +- src/ClientDetailDialog.cpp | 19 +++----- src/ClientList.cpp | 2 +- src/ClientTCPSocket.cpp | 34 ++++++--------- src/ClientUDPSocket.cpp | 2 +- src/CommentDialogLst.cpp | 2 +- src/DirectoryTreeCtrl.cpp | 2 +- src/DownloadClient.cpp | 9 ++-- src/DownloadListCtrl.cpp | 15 +++---- src/DownloadQueue.cpp | 6 +-- src/ExternalConn.cpp | 11 +++-- src/FileDetailDialog.cpp | 22 +++++----- src/GenericClientListCtrl.cpp | 14 +++--- src/KadDlg.cpp | 2 +- src/KnownFile.cpp | 2 +- src/KnownFileList.cpp | 5 +-- src/MuleTrayIcon.cpp | 17 ++++---- src/MuleUDPSocket.cpp | 5 +-- src/NetworkFunctions.h | 9 ++-- src/OtherFunctions.cpp | 68 ++++++++++++----------------- src/PartFile.cpp | 42 +++++++++--------- src/PartFileConvert.cpp | 4 +- src/PartFileConvertDlg.cpp | 2 +- src/Preferences.cpp | 10 ++--- src/PrefsUnifiedDlg.cpp | 18 ++++---- src/SHAHashSet.cpp | 4 +- src/SearchDlg.cpp | 4 +- src/SearchList.cpp | 2 +- src/SearchListCtrl.cpp | 22 ++++++---- src/Server.cpp | 2 +- src/ServerConnect.cpp | 4 +- src/ServerList.cpp | 6 +-- src/ServerListCtrl.cpp | 15 +++---- src/ServerSocket.cpp | 32 +++++++------- src/ServerUDPSocket.cpp | 17 +++----- src/ServerWnd.cpp | 2 +- src/SharedFileList.cpp | 4 +- src/SharedFilesCtrl.cpp | 26 +++++------ src/StatTree.cpp | 17 +++----- src/Statistics.cpp | 2 +- src/StatisticsDlg.cpp | 4 +- src/Tag.cpp | 24 +++++----- src/TextClient.cpp | 55 ++++++++++++----------- src/ThreadTasks.cpp | 2 +- src/TransferWnd.cpp | 4 +- src/amule-gui.cpp | 4 +- src/amule.cpp | 22 +++++----- src/amuleDlg.cpp | 6 +-- src/amuled.cpp | 2 +- src/kademlia/kademlia/Entry.cpp | 9 ++-- src/kademlia/kademlia/Indexed.cpp | 8 ++-- src/kademlia/kademlia/Kademlia.cpp | 8 ++-- src/kademlia/kademlia/Prefs.cpp | 11 ++--- src/kademlia/kademlia/Search.cpp | 10 ++--- src/kademlia/kademlia/UDPFirewallTester.cpp | 2 +- src/kademlia/net/KademliaUDPListener.cpp | 39 +++++++++-------- src/kademlia/net/PacketTracking.cpp | 6 +-- src/kademlia/routing/RoutingZone.cpp | 22 +++++----- src/kademlia/utils/UInt128.cpp | 9 ++-- src/libs/common/FileFunctions.cpp | 4 +- src/libs/common/Format.cpp | 22 +++++++--- src/libs/common/Format.h | 1 - src/libs/common/MD5Sum.cpp | 3 +- src/libs/common/MuleDebug.cpp | 9 ++-- src/libs/ec/cpp/ECSpecialTags.cpp | 2 +- src/webserver/src/WebServer.cpp | 4 +- 69 files changed, 398 insertions(+), 417 deletions(-) diff --git a/.svn-revision b/.svn-revision index 11896afe..4c314813 100644 --- a/.svn-revision +++ b/.svn-revision @@ -1 +1 @@ -10288 +10290 diff --git a/src/BaseClient.cpp b/src/BaseClient.cpp index 4339543b..72dd9d30 100644 --- a/src/BaseClient.cpp +++ b/src/BaseClient.cpp @@ -1487,7 +1487,7 @@ bool CUpDownClient::TryToConnect(bool bIgnoreMaxCon) // we already check above with !theApp->CanDoCallback(this) if any callback is possible at all m_dwDirectCallbackTimeout = ::GetTickCount() + SEC2MS(45); theApp->clientlist->AddDirectCallbackClient(this); - AddDebugLogLineN(logClient, wxString::Format(wxT("Direct Callback on port %u to client on ip "), GetKadPort()) + Uint32toStringIP(GetConnectIP())); + AddDebugLogLineN(logClient, CFormat(wxT("Direct Callback on port %u to client on ip %s")) % GetKadPort() % Uint32toStringIP(GetConnectIP())); CMemFile data; data.WriteUInt16(thePrefs::GetPort()); // needs to know our port @@ -1551,7 +1551,7 @@ bool CUpDownClient::TryToConnect(bool bIgnoreMaxCon) CPacket* packet = new CPacket(bio, OP_KADEMLIAHEADER, KADEMLIA_CALLBACK_REQ); // eMule FIXME: We don't know which kadversion the buddy has, so we need to send unencrypted theApp->clientudp->SendPacket(packet, GetBuddyIP(), GetBuddyPort(), false, NULL, true, 0); - AddDebugLogLineN(logClientKadUDP, wxString::Format(wxT("KadCallbackReq (size=%i) to "),packet->GetPacketSize()) + Uint32_16toStringIP_Port(GetBuddyIP(), GetBuddyPort())); + AddDebugLogLineN(logClientKadUDP, CFormat(wxT("KadCallbackReq (size=%i) to %s")) % packet->GetPacketSize() % Uint32_16toStringIP_Port(GetBuddyIP(), GetBuddyPort())); theStats::AddUpOverheadKad(packet->GetRealPacketSize()); SetDownloadState(DS_WAITCALLBACKKAD); } else { @@ -1767,7 +1767,7 @@ void CUpDownClient::ReGetClientSoft() } // Isn't xMule annoying? if ((m_clientSoft == SO_LXMULE) && (GetMuleVersion() > 0x26) && (GetMuleVersion() != 0x99)) { - m_clientSoftString += wxString::Format(_(" (Fake eMule version %#x)"),GetMuleVersion()); + m_clientSoftString += CFormat(_(" (Fake eMule version %#x)")) % GetMuleVersion(); } if ((m_clientSoft == SO_EMULE) && ( @@ -1802,7 +1802,7 @@ void CUpDownClient::ReGetClientSoft() AddLogLineNS(CFormat(wxT("Compatible client found with ET_COMPATIBLECLIENT of %x")) % m_byCompatibleClient); } #endif - m_clientSoftString = GetSoftName(m_clientSoft) + wxString::Format(wxT("(%#x)"),m_byCompatibleClient); + m_clientSoftString = CFormat(wxT("%s(%#x)")) % GetSoftName(m_clientSoft) % m_byCompatibleClient; } else { // If we step here, it might mean 2 things: // a eMule @@ -1819,14 +1819,14 @@ void CUpDownClient::ReGetClientSoft() m_nClientVersion = MAKE_CLIENT_VERSION(0,nClientMinVersion,0); switch (m_clientSoft) { case SO_AMULE: - m_clientVerString = wxString::Format(_("1.x (based on eMule v0.%u)"), nClientMinVersion); + m_clientVerString = CFormat(_("1.x (based on eMule v0.%u)")) % nClientMinVersion; break; case SO_LPHANT: m_clientVerString = wxT("< v0.05"); break; default: clientModString = GetClientModString(); - m_clientVerString = wxString::Format(wxT("v0.%u"), nClientMinVersion); + m_clientVerString = CFormat(wxT("v0.%u")) % nClientMinVersion; break; } } else { @@ -1848,23 +1848,23 @@ void CUpDownClient::ReGetClientSoft() // eMule+ developers, so I think they're slowly getting smarter. // They are based on our implementation, so we use the same format // for the version string. - m_clientVerString = wxString::Format(wxT("v%u.%u.%u"), nClientMajVersion, nClientMinVersion, nClientUpVersion); + m_clientVerString = CFormat(wxT("v%u.%u.%u")) % nClientMajVersion % nClientMinVersion % nClientUpVersion; break; case SO_LPHANT: - m_clientVerString = wxString::Format(wxT(" v%u.%.2u%c"), nClientMajVersion-1, nClientMinVersion, 'a' + nClientUpVersion); + m_clientVerString = CFormat(wxT(" v%u.%.2u%c")) % (nClientMajVersion-1) % nClientMinVersion % ('a' + nClientUpVersion); break; case SO_EMULEPLUS: - m_clientVerString = wxString::Format(wxT("v%u"), nClientMajVersion); + m_clientVerString = CFormat(wxT("v%u")) % nClientMajVersion; if(nClientMinVersion != 0) { - m_clientVerString += wxString::Format(wxT(".%u"), nClientMinVersion); + m_clientVerString += CFormat(wxT(".%u")) % nClientMinVersion; } if(nClientUpVersion != 0) { - m_clientVerString += wxString::Format(wxT("%c"), 'a' + nClientUpVersion - 1); + m_clientVerString += CFormat(wxT("%c")) % ('a' + nClientUpVersion - 1); } break; default: clientModString = GetClientModString(); - m_clientVerString = wxString::Format(wxT("v%u.%u%c"), nClientMajVersion, nClientMinVersion, 'a' + nClientUpVersion); + m_clientVerString = CFormat(wxT("v%u.%u%c")) % nClientMajVersion % nClientMinVersion % ('a' + nClientUpVersion); break; } } @@ -1912,27 +1912,27 @@ void CUpDownClient::ReGetClientSoft() } m_nClientVersion = MAKE_CLIENT_VERSION(nClientMajVersion, nClientMinVersion, nClientUpVersion); if (nClientUpVersion) { - m_clientVerString = wxString::Format(wxT("v%u.%u.%u"), nClientMajVersion, nClientMinVersion, nClientUpVersion); + m_clientVerString = CFormat(wxT("v%u.%u.%u")) % nClientMajVersion % nClientMinVersion % nClientUpVersion; } else { - m_clientVerString = wxString::Format(wxT("v%u.%u"), nClientMajVersion, nClientMinVersion); + m_clientVerString = CFormat(wxT("v%u.%u")) % nClientMajVersion % nClientMinVersion; } } else if (m_bIsML || (iHashType == SO_MLDONKEY)) { m_clientSoft = SO_MLDONKEY; m_clientSoftString = GetSoftName(m_clientSoft); uint32 nClientMinVersion = m_nClientVersion; m_nClientVersion = MAKE_CLIENT_VERSION(0, nClientMinVersion, 0); - m_clientVerString = wxString::Format(wxT("v0.%u"), nClientMinVersion); + m_clientVerString = CFormat(wxT("v0.%u")) % nClientMinVersion; } else if (iHashType == SO_OLDEMULE) { m_clientSoft = SO_OLDEMULE; m_clientSoftString = GetSoftName(m_clientSoft); uint32 nClientMinVersion = m_nClientVersion; m_nClientVersion = MAKE_CLIENT_VERSION(0, nClientMinVersion, 0); - m_clientVerString = wxString::Format(wxT("v0.%u"), nClientMinVersion); + m_clientVerString = CFormat(wxT("v0.%u")) % nClientMinVersion; } else { m_clientSoft = SO_EDONKEY; m_clientSoftString = GetSoftName(m_clientSoft); m_nClientVersion *= 10; - m_clientVerString = wxString::Format(wxT("v%u.%u"), m_nClientVersion / 100000, (m_nClientVersion / 1000) % 100); + m_clientVerString = CFormat(wxT("v%u.%u")) % (m_nClientVersion / 100000) % ((m_nClientVersion / 1000) % 100); } m_clientVersionString = m_clientVerString; diff --git a/src/ChatSelector.cpp b/src/ChatSelector.cpp index 3c97614e..b1e889f5 100644 --- a/src/ChatSelector.cpp +++ b/src/ChatSelector.cpp @@ -193,7 +193,7 @@ bool CChatSelector::ProcessMessage(uint64 sender_id, const wxString& message) // This must NOT happen. // Build a client name based on the ID uint32 ip = IP_FROM_GUI_ID(sender_id); - client_name = wxString::Format(wxT("IP: %u.%u.%u.%u Port: %u"),(uint8)ip,(uint8)(ip>>8),(uint8)(ip>>16),(uint8)(ip>>24),(unsigned)PORT_FROM_GUI_ID(sender_id)); + client_name = CFormat(wxT("IP: %s Port: %u")) % Uint32toStringIP(ip) % PORT_FROM_GUI_ID(sender_id); } session = StartSession( sender_id, client_name, true ); diff --git a/src/ClientCreditsList.cpp b/src/ClientCreditsList.cpp index b7a96c5b..0e65aee0 100644 --- a/src/ClientCreditsList.cpp +++ b/src/ClientCreditsList.cpp @@ -155,10 +155,10 @@ void CClientCreditsList::LoadList() m_mapClients[newcredits->GetKey()] = newcredits; } - AddLogLineM(false, wxString::Format(wxPLURAL("Creditfile loaded, %u client is known", "Creditfile loaded, %u clients are known", count - cDeleted), count - cDeleted)); + AddLogLineN(CFormat(wxPLURAL("Creditfile loaded, %u client is known", "Creditfile loaded, %u clients are known", count - cDeleted)) % (count - cDeleted)); if (cDeleted) { - AddLogLineM(false, wxString::Format(wxPLURAL(" - Credits expired for %u client!", " - Credits expired for %u clients!", cDeleted), cDeleted)); + AddLogLineN(CFormat(wxPLURAL(" - Credits expired for %u client!", " - Credits expired for %u clients!", cDeleted)) % cDeleted); } } catch (const CSafeIOException& e) { AddDebugLogLineC(logCredits, wxT("IO error while loading clients.met file: ") + e.what()); diff --git a/src/ClientDetailDialog.cpp b/src/ClientDetailDialog.cpp index e032517f..75c1e1db 100644 --- a/src/ClientDetailDialog.cpp +++ b/src/ClientDetailDialog.cpp @@ -102,15 +102,13 @@ bool CClientDetailDialog::OnInitDialog() { // Client IP/Port CastChild(ID_DIP, wxStaticText)->SetLabel( - m_client->GetFullIP() + - wxString::Format(wxT(":%i"), m_client->GetUserPort())); + CFormat(wxT("%s:%i")) % m_client->GetFullIP() % m_client->GetUserPort()); // Server IP/Port/Name if (m_client->GetServerIP()) { wxString srvaddr = Uint32toStringIP(m_client->GetServerIP()); CastChild(ID_DSIP, wxStaticText)->SetLabel( - srvaddr + - wxString::Format(wxT(":%i"),m_client->GetServerPort())); + CFormat(wxT("%s:%i")) % srvaddr % m_client->GetServerPort()); CastChild(ID_DSNAME, wxStaticText)->SetLabel( m_client->GetServerName()); } else { @@ -155,13 +153,11 @@ bool CClientDetailDialog::OnInitDialog() { // Average Upload Rate CastChild(ID_DAVUR, wxStaticText)->SetLabel( - wxString::Format(_("%.1f kB/s"), - m_client->GetKBpsDown())); + CFormat(_("%.1f kB/s")) % m_client->GetKBpsDown()); // Average Download Rate CastChild(ID_DAVDR, wxStaticText)->SetLabel( - wxString::Format(_("%.1f kB/s"), - m_client->GetUploadDatarate() / 1024.0f)); + CFormat(_("%.1f kB/s")) % (m_client->GetUploadDatarate() / 1024.0f)); // Total Upload CastChild(ID_DUPTOTAL, wxStaticText)->SetLabel( @@ -173,8 +169,7 @@ bool CClientDetailDialog::OnInitDialog() { // DL/UP Modifier CastChild(ID_DRATIO, wxStaticText)->SetLabel( - wxString::Format(wxT("%.1f"), - (float)m_client->GetScoreRatio())); + CFormat(wxT("%.1f")) % m_client->GetScoreRatio()); // Secure Ident if (theApp->CryptoAvailable()) { @@ -202,9 +197,9 @@ bool CClientDetailDialog::OnInitDialog() { // Queue Score if (m_client->GetUploadState() != US_NONE) { CastChild(ID_QUEUERANK, wxStaticText)->SetLabel( - wxString::Format(wxT("%u"), m_client->GetUploadQueueWaitingPosition())); + CFormat(wxT("%u")) % m_client->GetUploadQueueWaitingPosition()); CastChild(ID_DSCORE, wxStaticText)->SetLabel( - wxString::Format(wxT("%u"), m_client->GetScore())); + CFormat(wxT("%u")) % m_client->GetScore()); } else { CastChild(ID_QUEUERANK, wxStaticText)->SetLabel(wxT("-")); CastChild(ID_DSCORE, wxStaticText)->SetLabel(wxT("-")); diff --git a/src/ClientList.cpp b/src/ClientList.cpp index 2a6d45fb..62145662 100644 --- a/src/ClientList.cpp +++ b/src/ClientList.cpp @@ -1064,7 +1064,7 @@ void CClientList::CleanUpClientList() #endif } } - AddDebugLogLineN(logClient, wxString::Format(wxT("Cleaned ClientList, removed %i not used known clients"), cDeleted)); + AddDebugLogLineN(logClient, CFormat(wxT("Cleaned ClientList, removed %i not used known clients")) % cDeleted); } } diff --git a/src/ClientTCPSocket.cpp b/src/ClientTCPSocket.cpp index 68756159..58ffab9b 100644 --- a/src/ClientTCPSocket.cpp +++ b/src/ClientTCPSocket.cpp @@ -243,7 +243,7 @@ void CClientTCPSocket::OnClose(int nErrorCode) wxASSERT(theApp->listensocket->IsValidSocket(this)); CEMSocket::OnClose(nErrorCode); if (nErrorCode) { - Disconnect(wxString::Format(wxT("Closed: %u"), nErrorCode)); + Disconnect(CFormat(wxT("Closed: %u")) % nErrorCode); } else { Disconnect(wxT("Close")); } @@ -1068,7 +1068,7 @@ bool CClientTCPSocket::ProcessPacket(const byte* buffer, uint32 size, uint8 opco default: theStats::AddDownOverheadOther(size); - AddDebugLogLineN( logRemoteClient, wxString::Format(wxT("Edonkey packet: unknown opcode: %i %x from "), opcode, opcode) + m_client->GetFullIP()); + AddDebugLogLineN(logRemoteClient, CFormat(wxT("Edonkey packet: unknown opcode: %i %x from %s")) % opcode % opcode % m_client->GetFullIP()); return false; } @@ -1870,7 +1870,7 @@ bool CClientTCPSocket::ProcessExtPacket(const byte* buffer, uint32 size, uint8 o } default: theStats::AddDownOverheadOther(size); - AddDebugLogLineN( logRemoteClient, wxString::Format(wxT("eMule packet : unknown opcode: %i %x from "),opcode,opcode) + m_client->GetFullIP()); + AddDebugLogLineN(logRemoteClient, CFormat(wxT("eMule packet : unknown opcode: %i %x from %s")) % opcode % opcode % m_client->GetFullIP()); break; } @@ -1915,10 +1915,10 @@ bool CClientTCPSocket::ProcessED2Kv2Packet(const byte* buffer, uint32 size, uint default: theStats::AddDownOverheadOther(size); - AddDebugLogLineN( logRemoteClient, wxString::Format(wxT("ED2Kv2 packet : unknown opcode: %i %x from "), opcode, opcode) + m_client->GetFullIP()); + AddDebugLogLineN(logRemoteClient, CFormat(wxT("ED2Kv2 packet : unknown opcode: %i %x from %s")) % opcode % opcode % m_client->GetFullIP()); } } catch (...) { - AddDebugLogLineN( logRemoteClient, wxString::Format(wxT("ED2Kv2 packet is corrupt at pos %i! opcode: %i %x from "),data.GetPosition(), opcode, opcode) + m_client->GetFullIP()); + AddDebugLogLineN(logRemoteClient, CFormat(wxT("ED2Kv2 packet is corrupt at pos %i! opcode: %i %x from %s")) % data.GetPosition() % opcode % opcode % m_client->GetFullIP()); throw; } @@ -1996,17 +1996,15 @@ void CClientTCPSocket::OnError(int nErrorCode) // 107 -> Transport endpoint is not connected if (m_client) { if (!m_client->GetUserName().IsEmpty()) { - strError = wxT("OnError: Client '") + m_client->GetUserName() + - wxT("' (IP:") + m_client->GetFullIP() + - wxString::Format(wxT(") caused an error: %u. Disconnecting client!"), nErrorCode); + strError = CFormat(wxT("OnError: Client '%s' (IP:%s) caused an error: %u. Disconnecting client!")) + % m_client->GetUserName() % m_client->GetFullIP() % nErrorCode; } else { - strError = wxT("OnError: Unknown client (IP:") + - m_client->GetFullIP() + - wxString::Format(wxT(") caused an error: %u. Disconnecting client!"), nErrorCode); + strError = CFormat(wxT("OnError: Unknown client (IP:%s) caused an error: %u. Disconnecting client!")) + % m_client->GetFullIP() % nErrorCode; } } else { - strError = wxString::Format(wxT("OnError: A client caused an error or did something bad (error %u). Disconnecting client !"), - nErrorCode); + strError = CFormat(wxT("OnError: A client caused an error or did something bad (error %u). Disconnecting client !")) + % nErrorCode; } } else { strError = wxT("Error 107 (Transport endpoint is not connected)"); @@ -2040,16 +2038,12 @@ bool CClientTCPSocket::PacketReceived(CPacket* packet) (packet->GetProtocol() == OP_ED2KV2PACKEDPROT)) { if (!packet->UnPackPacket()) { - AddDebugLogLineN( logZLib, wxT("Failed to decompress client TCP packet.")); + AddDebugLogLineN(logZLib, wxT("Failed to decompress client TCP packet.")); bResult = false; process = false; } else { - AddDebugLogLineN(logRemoteClient, - wxString::Format(wxT("Packet unpacked, new protocol %x, opcode %x, size %u"), - packet->GetProtocol(), - packet->GetOpCode(), - packet->GetPacketSize()) - ); + AddDebugLogLineN(logRemoteClient, CFormat(wxT("Packet unpacked, new protocol %x, opcode %x, size %u")) + % packet->GetProtocol() % packet->GetOpCode() % packet->GetPacketSize()); } } diff --git a/src/ClientUDPSocket.cpp b/src/ClientUDPSocket.cpp index d539d2bc..5f802bc1 100644 --- a/src/ClientUDPSocket.cpp +++ b/src/ClientUDPSocket.cpp @@ -124,7 +124,7 @@ void CClientUDPSocket::OnPacketReceived(uint32 ip, uint16 port, byte* buffer, si break; default: - AddDebugLogLineN(logClientUDP, wxString::Format(wxT("Unknown opcode on received packet: 0x%x"), protocol)); + AddDebugLogLineN(logClientUDP, CFormat(wxT("Unknown opcode on received packet: 0x%x")) % protocol); } } catch (const wxString& e) { AddDebugLogLineN(logClientUDP, wxT("Error while parsing UDP packet: ") + e); diff --git a/src/CommentDialogLst.cpp b/src/CommentDialogLst.cpp index 4ef2979e..2df863f9 100644 --- a/src/CommentDialogLst.cpp +++ b/src/CommentDialogLst.cpp @@ -102,7 +102,7 @@ void CCommentDialogLst::UpdateList() if (count == 0) { info = _("No comments"); } else { - info = wxString::Format(wxPLURAL("%u comment", "%u comments", count), count); + info = CFormat(wxPLURAL("%u comment", "%u comments", count)) % count; } FindWindow(IDC_CMSTATUS)->SetLabel(info); diff --git a/src/DirectoryTreeCtrl.cpp b/src/DirectoryTreeCtrl.cpp index 85839012..41810a07 100644 --- a/src/DirectoryTreeCtrl.cpp +++ b/src/DirectoryTreeCtrl.cpp @@ -117,7 +117,7 @@ void CDirectoryTreeCtrl::Init() if (! (drives & 1)) { // skip non existant drives continue; } - wxString driveStr = wxString::Format(wxT("%c:"), drive); + wxString driveStr = CFormat(wxT("%c:")) % drive; uint32 type = GetDriveType(driveStr + wxT("\\")); // skip removable/undefined drives, share only fixed or remote drives diff --git a/src/DownloadClient.cpp b/src/DownloadClient.cpp index d862be2f..3adbd654 100644 --- a/src/DownloadClient.cpp +++ b/src/DownloadClient.cpp @@ -266,7 +266,8 @@ void CUpDownClient::SendFileRequest() } CPacket* packet = new CPacket(dataFileReq, OP_EMULEPROT, (SupportExtMultiPacket() ? OP_MULTIPACKET_EXT : OP_MULTIPACKET)); theStats::AddUpOverheadFileRequest(packet->GetPacketSize()); - AddDebugLogLineN(logLocalClient, wxString::Format(wxT("Local Client: %s "), (SupportExtMultiPacket() ? wxT("OP_MULTIPACKET_EXT (") : wxT("OP_MULTIPACKET (") )) + sent_opcodes + wxT(") to ") + GetFullIP()); + AddDebugLogLineN(logLocalClient, CFormat(wxT("Local Client: %s (%s) to %s")) + % (SupportExtMultiPacket() ? wxT("OP_MULTIPACKET_EXT") : wxT("OP_MULTIPACKET")) % sent_opcodes % GetFullIP()); SendPacket(packet, true); } else { //This is extended information @@ -809,7 +810,7 @@ void CUpDownClient::SendBlockRequests() } } packet = new CPacket(data, (bHasLongBlocks ? OP_EMULEPROT : OP_EDONKEYPROT), (bHasLongBlocks ? (uint8)OP_REQUESTPARTS_I64 : (uint8)OP_REQUESTPARTS)); - AddDebugLogLineN( logLocalClient, wxString::Format(wxT("Local Client: %s to "),(bHasLongBlocks ? wxT("OP_REQUESTPARTS_I64") : wxT("OP_REQUESTPARTS"))) + GetFullIP() ); + AddDebugLogLineN(logLocalClient, CFormat(wxT("Local Client: %s to %s")) % (bHasLongBlocks ? wxT("OP_REQUESTPARTS_I64") : wxT("OP_REQUESTPARTS")) % GetFullIP()); break; } default: @@ -1148,9 +1149,9 @@ int CUpDownClient::unzip(Pending_Block_Struct *block, byte *zipped, uint32 lenZi wxString strZipError; if ( zS->msg ) { - strZipError = wxString::Format(wxT(" %d '"), err) + wxString::FromAscii(zS->msg) + wxT("'"); + strZipError = CFormat(wxT(" %d '%s'")) % err % wxString::FromAscii(zS->msg); } else if (err != Z_OK) { - strZipError = wxString::Format(wxT(" %d"), err); + strZipError = CFormat(wxT(" %d")) % err; } AddDebugLogLineN(logZLib, diff --git a/src/DownloadListCtrl.cpp b/src/DownloadListCtrl.cpp index eb2bd1b8..96b05df7 100644 --- a/src/DownloadListCtrl.cpp +++ b/src/DownloadListCtrl.cpp @@ -925,8 +925,7 @@ void CDownloadListCtrl::DrawFileItem( wxDC* dc, int nColumn, const wxRect& rect, // Speed case ColumnSpeed: if ( file->GetTransferingSrcCount() ) { - text = wxString::Format( wxT("%.1f "), file->GetKBpsDown() ) + - _("kB/s"); + text = CFormat(_("%.1f kB/s")) % file->GetKBpsDown(); } break; @@ -977,7 +976,7 @@ void CDownloadListCtrl::DrawFileItem( wxDC* dc, int nColumn, const wxRect& rect, // to avoid Format doing roundings float percent = floor( file->GetPercentCompleted() * 10.0f ) / 10.0f; - wxString buffer = wxString::Format( wxT("%.1f%%"), percent ); + wxString buffer = CFormat(wxT("%.1f%%")) % percent; int middlex = (2*rect.GetX() + rect.GetWidth()) >> 1; int middley = (2*rect.GetY() + rect.GetHeight()) >> 1; @@ -1003,17 +1002,17 @@ void CDownloadListCtrl::DrawFileItem( wxDC* dc, int nColumn, const wxRect& rect, uint16 sc = file->GetSourceCount(); uint16 ncsc = file->GetNotCurrentSourcesCount(); if ( ncsc ) { - text = wxString::Format( wxT("%i/%i" ), sc - ncsc, sc ); + text = CFormat(wxT("%i/%i")) % (sc - ncsc) % sc; } else { - text = wxString::Format( wxT("%i"), sc ); + text = CFormat(wxT("%i")) % sc; } if ( file->GetSrcA4AFCount() ) { - text += wxString::Format( wxT("+%i"), file->GetSrcA4AFCount() ); + text += CFormat(wxT("+%i")) % file->GetSrcA4AFCount(); } if ( file->GetTransferingSrcCount() ) { - text += wxString::Format( wxT(" (%i)"), file->GetTransferingSrcCount() ); + text += CFormat(wxT(" (%i)")) % file->GetTransferingSrcCount(); } break; @@ -1227,7 +1226,7 @@ void CDownloadListCtrl::ShowFilesCount( int diff ) wxStaticText* label = CastByName( wxT("downloadsLabel"), GetParent(), wxStaticText ); - label->SetLabel( wxString::Format( _("Downloads (%i)"), m_filecount ) ); + label->SetLabel(CFormat(_("Downloads (%i)")) % m_filecount); label->GetParent()->Layout(); } diff --git a/src/DownloadQueue.cpp b/src/DownloadQueue.cpp index 45c28847..21fba3a5 100644 --- a/src/DownloadQueue.cpp +++ b/src/DownloadQueue.cpp @@ -159,9 +159,9 @@ void CDownloadQueue::LoadMetFiles(const CPath& path) AddLogLineNS(_("All PartFiles Loaded.")); if ( GetFileCount() == 0 ) { - AddLogLineM(false, _("No part files found")); + AddLogLineN(_("No part files found")); } else { - AddLogLineM(false, wxString::Format(wxPLURAL("Found %u part file", "Found %u part files", GetFileCount()), GetFileCount()) ); + AddLogLineN(CFormat(wxPLURAL("Found %u part file", "Found %u part files", GetFileCount())) % GetFileCount()); DoSortByPriority(); CheckDiskspace( path ); @@ -1427,7 +1427,7 @@ void CDownloadQueue::ObserverAdded( ObserverType* o ) void CDownloadQueue::KademliaSearchFile(uint32_t searchID, const Kademlia::CUInt128* pcontactID, const Kademlia::CUInt128* pbuddyID, uint8_t type, uint32_t ip, uint16_t tcp, uint16_t udp, uint32_t buddyip, uint16_t buddyport, uint8_t byCryptOptions) { - AddDebugLogLineN(logKadSearch, wxString::Format(wxT("Search result sources (type %i)"),type)); + AddDebugLogLineN(logKadSearch, CFormat(wxT("Search result sources (type %i)")) % type); //Safety measure to make sure we are looking for these sources CPartFile* temp = GetFileByKadFileSearchID(searchID); diff --git a/src/ExternalConn.cpp b/src/ExternalConn.cpp index f4c1e122..3779a06c 100644 --- a/src/ExternalConn.cpp +++ b/src/ExternalConn.cpp @@ -322,13 +322,11 @@ ExternalConn::ExternalConn(amuleIPV4Address addr, wxString *msg) int port = addr.Service(); wxString ip = addr.IPAddress(); if (m_ECServer->Ok()) { - msgLocal = wxT("*** TCP socket (ECServer) listening on ") + ip + - wxString::Format(wxT(":%d"), port); + msgLocal = CFormat(wxT("*** TCP socket (ECServer) listening on %s:%d")) % ip % port; *msg += msgLocal + wxT("\n"); AddLogLineM(false, msgLocal); } else { - msgLocal = wxT("Could not listen for external connections at ") + ip + - wxString::Format(wxT(":%d!"), port); + msgLocal = CFormat(wxT("Could not listen for external connections at %s:%d!")) % ip % port; *msg += msgLocal + wxT("\n"); AddLogLineM(false, msgLocal); } @@ -458,7 +456,8 @@ const CECPacket *CECServerSocket::Authenticate(const CECPacket *request) % (m_haveNotificationSupport ? wxT("yes") : wxT("no"))); } else { response = new CECPacket(EC_OP_AUTH_FAIL); - response->AddTag(CECTag(EC_TAG_STRING, wxTRANSLATE("Invalid protocol version.") + wxString::Format(wxT("( %i != %i )"),proto_version,EC_CURRENT_PROTOCOL_VERSION))); + response->AddTag(CECTag(EC_TAG_STRING, wxTRANSLATE("Invalid protocol version.") + + CFormat(wxT("( %i != %i )")) % proto_version % EC_CURRENT_PROTOCOL_VERSION)); } } else { response = new CECPacket(EC_OP_AUTH_FAIL); @@ -1663,7 +1662,7 @@ CECPacket *CECServerSocket::ProcessRequest2(const CECPacket *request) break; } if (!response) { - AddLogLineM(false, wxString::Format(_("External Connection: invalid opcode received: %#x"), request->GetOpCode())); + AddLogLineN(CFormat(_("External Connection: invalid opcode received: %#x")) % request->GetOpCode()); wxFAIL; response = new CECPacket(EC_OP_FAILED); response->AddTag(CECTag(EC_TAG_STRING, wxTRANSLATE("Invalid opcode (wrong protocol version?)"))); diff --git a/src/FileDetailDialog.cpp b/src/FileDetailDialog.cpp index 2f0901a4..89846c06 100644 --- a/src/FileDetailDialog.cpp +++ b/src/FileDetailDialog.cpp @@ -98,29 +98,27 @@ void CFileDetailDialog::UpdateData() } CastChild(IDC_FHASH,wxStaticText)->SetLabel(m_file->GetFileHash().Encode()); - bufferS = wxString::Format(wxT("%llu bytes ("), m_file->GetFileSize()) - + CastItoXBytes(m_file->GetFileSize()) - + wxT(")"); + bufferS = CFormat(wxT("%u bytes (%s)")) % m_file->GetFileSize() % CastItoXBytes(m_file->GetFileSize()); CastChild(IDC_FSIZE,wxControl)->SetLabel(bufferS); CastChild(IDC_PFSTATUS,wxControl)->SetLabel(m_file->getPartfileStatus()); - bufferS = wxString::Format(wxT("%i (%i)"),m_file->GetPartCount(),m_file->GetHashCount()); + bufferS = CFormat(wxT("%i (%i)")) % m_file->GetPartCount() % m_file->GetHashCount(); CastChild(IDC_PARTCOUNT,wxControl)->SetLabel(bufferS); CastChild(IDC_TRANSFERRED,wxControl)->SetLabel(CastItoXBytes(m_file->GetTransferred())); CastChild(IDC_FD_STATS1,wxControl)->SetLabel(CastItoXBytes(m_file->GetLostDueToCorruption())); CastChild(IDC_FD_STATS2,wxControl)->SetLabel(CastItoXBytes(m_file->GetGainDueToCompression())); CastChild(IDC_FD_STATS3,wxControl)->SetLabel(CastItoIShort(m_file->TotalPacketsSavedDueToICH())); CastChild(IDC_COMPLSIZE,wxControl)->SetLabel(CastItoXBytes(m_file->GetCompletedSize())); - bufferS = wxString::Format(_("%.2f%% done"),m_file->GetPercentCompleted()); + bufferS = CFormat(_("%.2f%% done")) % m_file->GetPercentCompleted(); CastChild(IDC_PROCCOMPL,wxControl)->SetLabel(bufferS); - bufferS = wxString::Format(_("%.2f kB/s"),(float)m_file->GetKBpsDown()); + bufferS = CFormat(_("%.2f kB/s")) % m_file->GetKBpsDown(); CastChild(IDC_DATARATE,wxControl)->SetLabel(bufferS); - bufferS = wxString::Format(wxT("%i"),m_file->GetSourceCount()); + bufferS = CFormat(wxT("%i")) % m_file->GetSourceCount(); CastChild(IDC_SOURCECOUNT,wxControl)->SetLabel(bufferS); - bufferS = wxString::Format(wxT("%i"),m_file->GetTransferingSrcCount()); + bufferS = CFormat(wxT("%i")) % m_file->GetTransferingSrcCount(); CastChild(IDC_SOURCECOUNT2,wxControl)->SetLabel(bufferS); - bufferS = wxString::Format(wxT("%i (%.1f%%)"), - m_file->GetAvailablePartCount(), - ((m_file->GetAvailablePartCount() * 100.0f)/ m_file->GetPartCount())); + bufferS = CFormat(wxT("%i (%.1f%%)")) + % m_file->GetAvailablePartCount() + % ((m_file->GetAvailablePartCount() * 100.0)/ m_file->GetPartCount()); CastChild(IDC_PARTAVAILABLE,wxControl)->SetLabel(bufferS); bufferS = CastSecondsToHM(m_file->GetDlActiveTime()); CastChild(IDC_DLACTIVETIME, wxControl)->SetLabel(bufferS); @@ -214,7 +212,7 @@ void CFileDetailDialog::FillSourcenameList() pmyListCtrl->DeleteItem(i); i--; // PA: one step back is enough, no need to go back to 0 } else { - pmyListCtrl->SetItem(i, 1, wxString::Format(wxT("%li"), item->count)); + pmyListCtrl->SetItem(i, 1, CFormat(wxT("%i")) % item->count); } } diff --git a/src/GenericClientListCtrl.cpp b/src/GenericClientListCtrl.cpp index 7bb52044..6964eda5 100644 --- a/src/GenericClientListCtrl.cpp +++ b/src/GenericClientListCtrl.cpp @@ -775,16 +775,14 @@ void CGenericClientListCtrl::DrawClientItem( break; case ColumnUserSpeedDown: if (item->GetType() != A4AF_SOURCE && client->GetKBpsDown() > 0.001) { - buffer = wxString::Format(wxT("%.1f "), - client->GetKBpsDown()) + _("kB/s"); + buffer = CFormat(_("%.1f kB/s")) % client->GetKBpsDown(); dc->DrawText(buffer, rect.GetX(), rect.GetY()); } break; case ColumnUserSpeedUp: // Datarate is in bytes. if (item->GetType() != A4AF_SOURCE && client->GetUploadDatarate() > 1024) { - buffer = wxString::Format(wxT("%.1f "), - client->GetUploadDatarate() / 1024.0f) + _("kB/s"); + buffer = CFormat(_("%.1f kB/s")) % (client->GetUploadDatarate() / 1024.0); dc->DrawText(buffer, rect.GetX(), rect.GetY()); } break; @@ -886,7 +884,7 @@ void CGenericClientListCtrl::DrawClientItem( if ( qrDiff > 0 ) { dc->SetTextForeground(*wxRED); } - buffer = wxString::Format(_("QR: %u (%i)"), client->GetRemoteQueueRank(), qrDiff); + buffer = CFormat(_("QR: %u (%i)")) % client->GetRemoteQueueRank() % qrDiff; } else { buffer = _("QR: ???"); } @@ -905,7 +903,7 @@ void CGenericClientListCtrl::DrawClientItem( if (nRank == 0) { buffer = _("Waiting for upload slot"); } else { - buffer = wxString::Format(_("QR: %u"), nRank); + buffer = CFormat(_("QR: %u")) % nRank; } } else if (client->GetUploadState() == US_UPLOADING) { buffer = _("Uploading"); @@ -1160,9 +1158,7 @@ void CGenericClientListCtrl::ShowSourcesCount( int diff ) wxStaticText* label = CastByID( ID_CLIENTCOUNT, GetParent(), wxStaticText ); if (label) { - wxString str = wxString::Format(wxT("%i"), m_clientcount ); - - label->SetLabel( str ); + label->SetLabel(CFormat(wxT("%i")) % m_clientcount); label->GetParent()->Layout(); } } diff --git a/src/KadDlg.cpp b/src/KadDlg.cpp index 7cc8ca03..8d430b3c 100644 --- a/src/KadDlg.cpp +++ b/src/KadDlg.cpp @@ -143,7 +143,7 @@ void CKadDlg::UpdateGraph(const GraphUpdateInfo& update) wxStaticText* label = CastChild( wxT("nodesListLabel"), wxStaticText ); wxCHECK_RET(label, wxT("Failed to find kad-nodes label")); - label->SetLabel(wxString::Format(_("Nodes (%u)"), nodeCount)); + label->SetLabel(CFormat(_("Nodes (%u)")) % nodeCount); label->GetParent()->Layout(); } diff --git a/src/KnownFile.cpp b/src/KnownFile.cpp index 3551f242..78c5ec37 100644 --- a/src/KnownFile.cpp +++ b/src/KnownFile.cpp @@ -1406,7 +1406,7 @@ wxString CKnownFile::GetFeedback() const { return wxString(_("File name")) + wxT(": ") + GetFileName().GetPrintable() + wxT("\n") + _("File size") + wxT(": ") + CastItoXBytes(GetFileSize()) + wxT("\n") - + _("Share ratio") + wxString::Format(wxT(": %.2f%%\n"), (((double)statistic.GetAllTimeTransferred() / (double)GetFileSize()) * 100.0)) + + _("Share ratio") + CFormat(wxT(": %.2f%%\n")) % (((double)statistic.GetAllTimeTransferred() / (double)GetFileSize()) * 100.0) + _("Uploaded") + wxT(": ") + CastItoXBytes(statistic.GetTransferred()) + wxT(" (") + CastItoXBytes(statistic.GetAllTimeTransferred()) + wxT(")\n") + _("Requested") + CFormat(wxT(": %u (%u)\n")) % statistic.GetRequests() % statistic.GetAllTimeRequests() + _("Accepted") + CFormat(wxT(": %u (%u)\n")) % statistic.GetAccepts() % statistic.GetAllTimeAccepts() diff --git a/src/KnownFileList.cpp b/src/KnownFileList.cpp index d7855367..ff7403b8 100644 --- a/src/KnownFileList.cpp +++ b/src/KnownFileList.cpp @@ -94,9 +94,8 @@ bool CKnownFileList::Init() wxMutexLocker sLock(list_mut); uint32 RecordsNumber = file.ReadUInt32(); - AddDebugLogLineN(logKnownFiles, - wxString::Format(wxT("Reading %i known files from file format 0x%2.2x."), - RecordsNumber, version)); + AddDebugLogLineN(logKnownFiles, CFormat(wxT("Reading %i known files from file format 0x%2.2x.")) + % RecordsNumber % version); for (uint32 i = 0; i < RecordsNumber; i++) { CScopedPtr record(new CKnownFile()); if (record->LoadFromFile(&file)) { diff --git a/src/MuleTrayIcon.cpp b/src/MuleTrayIcon.cpp index c9e62541..5a5239ee 100644 --- a/src/MuleTrayIcon.cpp +++ b/src/MuleTrayIcon.cpp @@ -103,7 +103,7 @@ END_EVENT_TABLE() long GetSpeedFromString(wxString label){ long temp; - label.Replace(wxT("kB/s"),wxT(""),TRUE); + label.Replace(_("kB/s"),wxT(""),TRUE); label.Trim(FALSE); label.Trim(TRUE); label.ToLong(&temp); @@ -325,7 +325,7 @@ wxMenu* CMuleTrayIcon::CreatePopupMenu() label += _("UL: None"); } else { - label += wxString::Format(_("UL: %u"), max_upload); + label += CFormat(_("UL: %u")) % max_upload; } label += wxT(", "); @@ -335,13 +335,13 @@ wxMenu* CMuleTrayIcon::CreatePopupMenu() label += _("DL: None"); } else { - label += wxString::Format(_("DL: %u"), max_download); + label += CFormat(_("DL: %u")) % max_download; } traymenu->Append(TRAY_MENU_INFO, label); - label = wxString::Format(_("Download speed: %.1f"), theStats::GetDownloadRate() / 1024.0); + label = CFormat(_("Download speed: %.1f")) % (theStats::GetDownloadRate() / 1024.0); traymenu->Append(TRAY_MENU_INFO, label); - label = wxString::Format(_("Upload speed: %.1f"), theStats::GetUploadRate() / 1024.0); + label = CFormat(_("Upload speed: %.1f")) % (theStats::GetUploadRate() / 1024.0); traymenu->Append(TRAY_MENU_INFO, label); traymenu->AppendSeparator(); @@ -361,8 +361,7 @@ wxMenu* CMuleTrayIcon::CreatePopupMenu() wxString temp = _("ClientID: "); if (theApp->IsConnectedED2K()) { - unsigned long id = theApp->GetED2KID(); - temp += wxString::Format(wxT("%lu"), id); + temp += CFormat(wxT("%u")) % theApp->GetED2KID(); } else { temp += _("Not connected"); } @@ -486,7 +485,7 @@ wxMenu* CMuleTrayIcon::CreatePopupMenu() for ( int i = 0; i < 5; i++ ) { unsigned int tempspeed = (unsigned int)((double)max_ul_speed / 5) * (5 - i); - wxString temp = wxString::Format(wxT("%u kB/s"), tempspeed); + wxString temp = CFormat(wxT("%u %s")) % tempspeed % _("kB/s"); UploadSpeedMenu->Append((int)UPLOAD_ITEM1+i+1,temp); } } @@ -507,7 +506,7 @@ wxMenu* CMuleTrayIcon::CreatePopupMenu() for ( int i = 0; i < 5; i++ ) { unsigned int tempspeed = (unsigned int)((double)max_dl_speed / 5) * (5 - i); - wxString temp = wxString::Format(wxT("%d kB/s"), tempspeed); + wxString temp = CFormat(wxT("%d %s")) % tempspeed % _("kB/s"); DownloadSpeedMenu->Append((int)DOWNLOAD_ITEM1+i+1,temp); } } diff --git a/src/MuleUDPSocket.cpp b/src/MuleUDPSocket.cpp index 6e23cbea..6211513d 100644 --- a/src/MuleUDPSocket.cpp +++ b/src/MuleUDPSocket.cpp @@ -134,9 +134,8 @@ const unsigned UDP_BUFFER_SIZE = 16384; void CMuleUDPSocket::OnReceive(int errorCode) { - AddDebugLogLineN(logMuleUDP, wxString::Format( - wxT("Got UDP callback for read: Error %i Socket state %i"), - errorCode, Ok() ? 1 : 0)); + AddDebugLogLineN(logMuleUDP, CFormat(wxT("Got UDP callback for read: Error %i Socket state %i")) + % errorCode % Ok()); char buffer[UDP_BUFFER_SIZE]; wxIPV4address addr; diff --git a/src/NetworkFunctions.h b/src/NetworkFunctions.h index c78950f5..57a552d5 100644 --- a/src/NetworkFunctions.h +++ b/src/NetworkFunctions.h @@ -28,6 +28,7 @@ #define NETWORK_FUNCTIONS_H #include "Types.h" // Needed for uint16 and uint32 +#include // Needed for CFormat #include // Network ip/host handling functions @@ -35,23 +36,23 @@ inline wxString Uint32toStringIP(uint32 ip) { - return wxString::Format(wxT("%u.%u.%u.%u"),(uint8)ip,(uint8)(ip>>8),(uint8)(ip>>16),(uint8)(ip>>24)); + return CFormat(wxT("%u.%u.%u.%u")) % (uint8)ip % (uint8)(ip>>8) % (uint8)(ip>>16) % (uint8)(ip>>24); } inline wxString Uint32_16toStringIP_Port(uint32 ip, uint16 port) { - return wxString::Format(wxT("%u.%u.%u.%u:%u"),(uint8)ip,(uint8)(ip>>8),(uint8)(ip>>16),(uint8)(ip>>24),port); + return CFormat(wxT("%u.%u.%u.%u:%u")) % (uint8)ip % (uint8)(ip>>8) % (uint8)(ip>>16) % (uint8)(ip>>24) % port; } // These functions take IPs in host-order inline wxString KadIPToString(uint32_t ip) { - return wxString::Format(wxT("%u.%u.%u.%u"), (uint8_t)(ip >> 24), (uint8_t)(ip >> 16), (uint8_t)(ip >> 8), (uint8_t)ip); + return CFormat(wxT("%u.%u.%u.%u")) % (uint8_t)(ip >> 24) % (uint8_t)(ip >> 16) % (uint8_t)(ip >> 8) % (uint8_t)ip; } inline wxString KadIPPortToString(uint32_t ip, uint16_t port) { - return wxString::Format(wxT("%u.%u.%u.%u:%u"), (uint8_t)(ip >> 24), (uint8_t)(ip >> 16), (uint8_t)(ip >> 8), (uint8_t)ip, port); + return CFormat(wxT("%u.%u.%u.%u:%u")) % (uint8_t)(ip >> 24) % (uint8_t)(ip >> 16) % (uint8_t)(ip >> 8) % (uint8_t)ip % port; } /** diff --git a/src/OtherFunctions.cpp b/src/OtherFunctions.cpp index 2bc8484c..443338a3 100644 --- a/src/OtherFunctions.cpp +++ b/src/OtherFunctions.cpp @@ -84,14 +84,14 @@ wxString GetMuleVersion() ver += wxT("wxMSW"); #endif - ver += wxString::Format(wxT(" v%d.%d.%d"), wxMAJOR_VERSION, wxMINOR_VERSION, wxRELEASE_NUMBER ); + ver += CFormat(wxT(" v%d.%d.%d")) % wxMAJOR_VERSION % wxMINOR_VERSION % wxRELEASE_NUMBER; #ifdef __WXDEBUG__ ver += wxT(" (Debugging)"); #endif #ifdef SVNDATE - ver += wxString::Format( wxT(" (Snapshot: %s)"), wxT(SVNDATE)); + ver += CFormat(wxT(" (Snapshot: %s)")) % wxT(SVNDATE); #endif return ver; @@ -103,15 +103,15 @@ wxString CastItoXBytes( uint64 count ) { if (count < 1024) - return wxString::Format( wxT("%u "), (unsigned)count) + wxPLURAL("byte", "bytes", count) ; + return CFormat(wxT("%u ")) % count + wxPLURAL("byte", "bytes", count) ; else if (count < 1048576) - return wxString::Format( wxT("%u "), (unsigned)count >> 10) + _("kB") ; + return CFormat(wxT("%u ")) % (count >> 10) + _("kB") ; else if (count < 1073741824) - return wxString::Format( wxT("%.2f "), (float)(uint32)count/1048576) + _("MB") ; + return CFormat(wxT("%.2f ")) % ((float)(uint32)count/1048576) + _("MB") ; else if (count < 1099511627776LL) - return wxString::Format( wxT("%.3f "), (float)((uint32)(count/1024))/1048576) + _("GB") ; + return CFormat(wxT("%.3f ")) % ((float)((uint32)(count/1024))/1048576) + _("GB") ; else - return wxString::Format( wxT("%.3f "), (float)count/1099511627776LL) + _("TB") ; + return CFormat(wxT("%.3f ")) % ((float)count/1099511627776LL) + _("TB") ; } @@ -119,26 +119,26 @@ wxString CastItoIShort(uint64 count) { if (count < 1000) - return wxString::Format(wxT("%u"), (uint32)count); + return CFormat(wxT("%u")) % count; else if (count < 1000000) - return wxString::Format(wxT("%.0f"),(float)(uint32)count/1000) + _("k") ; + return CFormat(wxT("%.0f")) % ((float)(uint32)count/1000) + _("k") ; else if (count < 1000000000) - return wxString::Format(wxT("%.2f"),(float)(uint32)count/1000000) + _("M") ; + return CFormat(wxT("%.2f")) % ((float)(uint32)count/1000000) + _("M") ; else if (count < 1000000000000LL) - return wxString::Format(wxT("%.2f"),(float)((uint32)(count/1000))/1000000) + _("G") ; + return CFormat(wxT("%.2f")) % ((float)((uint32)(count/1000))/1000000) + _("G") ; else - return wxString::Format(wxT("%.2f"),(float)count/1000000000000LL) + _("T"); + return CFormat(wxT("%.2f")) % ((float)count/1000000000000LL) + _("T"); } wxString CastItoSpeed(uint32 bytes) { if (bytes < 1024) - return wxString::Format(wxT("%u "), bytes) + wxPLURAL("byte/sec", "bytes/sec", bytes); + return CFormat(wxT("%u ")) % bytes + wxPLURAL("byte/sec", "bytes/sec", bytes); else if (bytes < 1048576) - return wxString::Format(wxT("%.2f "), bytes / 1024.0) + _("kB/s"); + return CFormat(wxT("%.2f ")) % (bytes / 1024.0) + _("kB/s"); else - return wxString::Format(wxT("%.2f "), bytes / 1048576.0) + _("MB/s"); + return CFormat(wxT("%.2f ")) % (bytes / 1048576.0) + _("MB/s"); } @@ -147,33 +147,21 @@ wxString CastSecondsToHM(uint32 count, uint16 msecs) { if (count < 60) { if (!msecs) { - return wxString::Format( - wxT("%02u %s"), count, _("secs")); + return CFormat(wxT("%02u %s")) % count % _("secs"); } else { - return wxString::Format( - wxT("%.3f %s"), - (count + ((float)msecs/1000)), _("secs")); + return CFormat(wxT("%.3f %s")) + % (count + ((float)msecs/1000)) % _("secs"); } } else if (count < 3600) { - return wxString::Format( - wxT("%u:%02u %s"), - count/60, - (count % 60), - _("mins")); + return CFormat(wxT("%u:%02u %s")) + % (count/60) % (count % 60) % _("mins"); } else if (count < 86400) { - return wxString::Format( - wxT("%u:%02u %s"), - count/3600, - (count % 3600)/60, - _("hours")); + return CFormat(wxT("%u:%02u %s")) + % (count/3600) % ((count % 3600)/60) % _("hours"); } else { - return wxString::Format( - wxT("%u %s %02u:%02u %s"), - count/86400, - _("Days"), - (count % 86400)/3600, - (count % 3600)/60, - _("hours")); + return CFormat(wxT("%u %s %02u:%02u %s")) + % (count/86400) % _("Days") + % ((count % 86400)/3600) % ((count % 3600)/60) % _("hours"); } } @@ -1017,10 +1005,10 @@ wxString DumpMemToStr(const void *buff, int n, const wxString& msg, bool ok) result += msg + wxT(" - ok=") + ( ok ? wxT("true, ") : wxT("false, ") ); } - result += wxString::Format( wxT("%d bytes\n"), n ); + result += CFormat(wxT("%d bytes\n")) % n; for ( int i = 0; i < lines; ++i) { // Show address - result += wxString::Format( wxT("%08x "), i * 16 ); + result += CFormat(wxT("%08x ")) % (i * 16); // Show two columns of hex-values for ( int j = 0; j < 2; ++j) { @@ -1028,7 +1016,7 @@ wxString DumpMemToStr(const void *buff, int n, const wxString& msg, bool ok) int pos = 16 * i + 8 * j + k; if ( pos < n ) { - result += wxString::Format( wxT("%02x "), p[pos] ); + result += CFormat(wxT("%02x ")) % p[pos]; } else { result += wxT(" "); } diff --git a/src/PartFile.cpp b/src/PartFile.cpp index 7593492b..286b4b5e 100644 --- a/src/PartFile.cpp +++ b/src/PartFile.cpp @@ -267,7 +267,7 @@ void CPartFile::CreatePartFile() int i = 0; do { ++i; - m_partmetfilename = CPath(wxString::Format(wxT("%03i.part.met"), i)); + m_partmetfilename = CPath(CFormat(wxT("%03i.part.met")) % i); m_fullname = thePrefs::GetTempDir().JoinPaths(m_partmetfilename); } while (m_fullname.FileExists()); @@ -846,7 +846,7 @@ bool CPartFile::SavePartFile(bool Initial) if (!strCorruptedParts.IsEmpty()) { strCorruptedParts += wxT(","); } - strCorruptedParts += wxString::Format(wxT("%u"), (unsigned)uCorruptedPart); + strCorruptedParts += CFormat(wxT("%u")) % uCorruptedPart; } wxASSERT( !strCorruptedParts.IsEmpty() ); @@ -878,12 +878,12 @@ bool CPartFile::SavePartFile(bool Initial) // gaps unsigned i_pos = 0; for (CGapList::const_iterator it = m_gaplist.begin(); it != m_gaplist.end(); ++it) { - wxString tagName = wxString::Format(wxT(" %u"), i_pos); + wxString tagName = CFormat(wxT(" %u")) % i_pos; // gap start = first missing byte but gap ends = first non-missing byte // in edonkey but I think its easier to user the real limits tagName[0] = FT_GAPSTART; - CTagIntSized(tagName, it.start() , IsLargeFile() ? 64 : 32).WriteTagToFile( &file ); + CTagIntSized(tagName, it.start(), IsLargeFile() ? 64 : 32).WriteTagToFile( &file ); tagName[0] = FT_GAPEND; CTagIntSized(tagName, it.end() + 1, IsLargeFile() ? 64 : 32).WriteTagToFile( &file ); @@ -1658,9 +1658,9 @@ void CPartFile::AddSources(CMemFile& sources,uint32 serverip, uint16 serverport, if ((thePrefs::IsClientCryptLayerRequested() && (byCryptOptions & 0x01/*supported*/) > 0 && (byCryptOptions & 0x80) == 0) || (thePrefs::IsClientCryptLayerSupported() && (byCryptOptions & 0x02/*requested*/) > 0 && (byCryptOptions & 0x80) == 0)) { - AddDebugLogLineN(logPartFile, wxString::Format(wxT("Server didn't provide UserHash for source %u, even if it was expected to (or local obfuscationsettings changed during serverconnect"), userid)); + AddDebugLogLineN(logPartFile, CFormat(wxT("Server didn't provide UserHash for source %u, even if it was expected to (or local obfuscationsettings changed during serverconnect")) % userid); } else if (!thePrefs::IsClientCryptLayerRequested() && (byCryptOptions & 0x02/*requested*/) == 0 && (byCryptOptions & 0x80) != 0) { - AddDebugLogLineN(logPartFile, wxString::Format(wxT("Server provided UserHash for source %u, even if it wasn't expected to (or local obfuscationsettings changed during serverconnect"), userid)); + AddDebugLogLineN(logPartFile, CFormat(wxT("Server provided UserHash for source %u, even if it wasn't expected to (or local obfuscationsettings changed during serverconnect")) % userid); } } @@ -3350,9 +3350,8 @@ void CPartFile::AICHRecoveryDataAvailable(uint16 nPart) FlushBuffer(true); uint32 length = GetPartSize(nPart); // if the part was already ok, it would now be complete - if (IsComplete(nPart)){ - AddDebugLogLineN( logAICHRecovery, - wxString::Format( wxT("Processing AICH Recovery data: The part (%u) is already complete, canceling"), nPart ) ); + if (IsComplete(nPart)) { + AddDebugLogLineN(logAICHRecovery, CFormat(wxT("Processing AICH Recovery data: The part (%u) is already complete, canceling")) % nPart); return; } @@ -3405,30 +3404,29 @@ void CPartFile::AICHRecoveryDataAvailable(uint16 nPart) m_CorruptionBlackBox->EvaluateData(); // ok now some sanity checks - if (IsComplete(nPart)){ + if (IsComplete(nPart)) { // this is bad, but it could probably happen under some rare circumstances // make sure that MD4 agrees to this fact too - if (!HashSinglePart(nPart)){ - AddDebugLogLineN( logAICHRecovery, - wxString::Format(wxT("Processing AICH Recovery data: The part (%u) got completed while recovering - but MD4 says it corrupt! Setting hashset to error state, deleting part"), nPart)); + if (!HashSinglePart(nPart)) { + AddDebugLogLineN(logAICHRecovery, + CFormat(wxT("Processing AICH Recovery data: The part (%u) got completed while recovering - but MD4 says it corrupt! Setting hashset to error state, deleting part")) % nPart); // now we are fu... unhappy m_pAICHHashSet->SetStatus(AICH_ERROR); AddGap(nPart); wxFAIL; return; - } - else{ - AddDebugLogLineN( logAICHRecovery, wxString::Format( - wxT("Processing AICH Recovery data: The part (%u) got completed while recovering and MD4 agrees"), nPart) ); - if (status == PS_EMPTY && theApp->IsRunning()){ - if (GetHashCount() == GetED2KPartHashCount() && !m_hashsetneeded){ + } else { + AddDebugLogLineN(logAICHRecovery, + CFormat(wxT("Processing AICH Recovery data: The part (%u) got completed while recovering and MD4 agrees")) % nPart); + if (status == PS_EMPTY && theApp->IsRunning()) { + if (GetHashCount() == GetED2KPartHashCount() && !m_hashsetneeded) { // Successfully recovered part, make it available for sharing SetStatus(PS_READY); theApp->sharedfiles->SafeAddKFile(this); } } - if (theApp->IsRunning()){ + if (theApp->IsRunning()) { // Is this file finished? if (m_gaplist.IsComplete()) { CompleteFile(false); @@ -3764,8 +3762,8 @@ wxString CPartFile::GetFeedback() const { wxString retval = CKnownFile::GetFeedback(); if (GetStatus() != PS_COMPLETE) { - retval += wxString(_("Downloaded")) + wxT(": ") + CastItoXBytes(GetCompletedSize()) + wxString::Format(wxT(" (%.2f%%)\n"), GetPercentCompleted()) - + _("Sources") + CFormat(wxT(": %u\n")) % GetSourceCount(); + retval += CFormat(wxT("%s: %s (%.2f%%)\n%s: %u\n")) + % _("Downloaded") % CastItoXBytes(GetCompletedSize()) % GetPercentCompleted() % _("Sources") % GetSourceCount(); } return retval + _("Status") + wxT(": ") + getPartfileStatus() + wxT("\n"); } diff --git a/src/PartFileConvert.cpp b/src/PartFileConvert.cpp index 43deae1a..8bf63bd0 100644 --- a/src/PartFileConvert.cpp +++ b/src/PartFileConvert.cpp @@ -324,7 +324,7 @@ ConvStatus CPartFileConvert::performConvertToeMule(const CPath& fileName) while (filename.IsOk()) { // stats ++curindex; - buffer = wxString::Format(_("Loading data from old download file (%u of %u)"), curindex, partfilecount); + buffer = CFormat(_("Loading data from old download file (%u of %u)")) % curindex % partfilecount; Notify_ConvertUpdateProgress(10 + (curindex * stepperpart), buffer); @@ -344,7 +344,7 @@ ConvStatus CPartFileConvert::performConvertToeMule(const CPath& fileName) inputfile.Read(ba, toReadWrite); inputfile.Close(); - buffer = wxString::Format(_("Saving data block into new single download file (%u of %u)"), curindex, partfilecount); + buffer = CFormat(_("Saving data block into new single download file (%u of %u)")) % curindex % partfilecount; Notify_ConvertUpdateProgress(10 + (curindex * stepperpart), buffer); diff --git a/src/PartFileConvertDlg.cpp b/src/PartFileConvertDlg.cpp index c5ec0073..9e1db540 100644 --- a/src/PartFileConvertDlg.cpp +++ b/src/PartFileConvertDlg.cpp @@ -130,7 +130,7 @@ void CPartFileConvertDlg::UpdateProgress(float percent, wxString text, wxString { if (s_convertgui) { s_convertgui->m_pb_current->SetValue((int)percent); - wxString buffer = wxString::Format(wxT("%.2f %%"), percent); + wxString buffer = CFormat(wxT("%.2f %%")) % percent; wxStaticText* percentlabel = dynamic_cast(s_convertgui->FindWindow(IDC_CONV_PROZENT)); percentlabel->SetLabel(buffer); diff --git a/src/Preferences.cpp b/src/Preferences.cpp index 082b960c..c15868a5 100644 --- a/src/Preferences.cpp +++ b/src/Preferences.cpp @@ -1277,7 +1277,7 @@ void CPreferences::BuildItemList( const wxString& appdir ) #ifndef AMULE_DAEMON // Colors have been moved from global prefs to CStatisticsDlg for ( int i = 0; i < cntStatColors; i++ ) { - wxString str = wxString::Format(wxT("/eMule/StatColor%i"),i); + wxString str = CFormat(wxT("/eMule/StatColor%i")) % i; s_MiscList.push_back( new Cfg_Colour( str, CStatisticsDlg::acrStat[i] ) ); } #endif @@ -1557,7 +1557,7 @@ void CPreferences::SaveCats() cfg->Write( wxT("Title"), m_CatList[i]->title ); cfg->Write( wxT("Incoming"), CPath::ToUniv(m_CatList[i]->path) ); cfg->Write( wxT("Comment"), m_CatList[i]->comment ); - cfg->Write( wxT("Color"), wxString::Format(wxT("%u"), m_CatList[i]->color) ); + cfg->Write( wxT("Color"), wxString(CFormat(wxT("%u")) % m_CatList[i]->color)); cfg->Write( wxT("Priority"), (int)m_CatList[i]->prio ); } // remove deleted cats from config @@ -1588,7 +1588,7 @@ void CPreferences::LoadCats() long max = cfg->Read( wxT("/General/Count"), 0l ); for ( int i = 1; i <= max ; i++ ) { - cfg->SetPath( wxString::Format(wxT("/Cat#%i"), i) ); + cfg->SetPath(CFormat(wxT("/Cat#%i")) % i); Category_Struct* newcat = new Category_Struct; @@ -1772,8 +1772,8 @@ void CPreferences::SetPort(uint16 val) // Warning: Check for +3, because server UDP is TCP+3 if (val +3 > 65535) { - AddLogLineM(true, _("TCP port can't be higher than 65532 due to server UDP socket being TCP+3")); - AddLogLineM(false, wxString::Format(_("Default port will be used (%d)"),DEFAULT_TCP_PORT)); + AddLogLineC(_("TCP port can't be higher than 65532 due to server UDP socket being TCP+3")); + AddLogLineN(CFormat(_("Default port will be used (%d)")) % DEFAULT_TCP_PORT); s_port = DEFAULT_TCP_PORT; } else { s_port = val; diff --git a/src/PrefsUnifiedDlg.cpp b/src/PrefsUnifiedDlg.cpp index 11a023de..ce01cb42 100644 --- a/src/PrefsUnifiedDlg.cpp +++ b/src/PrefsUnifiedDlg.cpp @@ -1022,47 +1022,47 @@ void PrefsUnifiedDlg::OnScrollBarChange( wxScrollEvent& event ) switch ( event.GetId() ) { case IDC_SLIDER: id = IDC_SLIDERINFO; - label = wxString::Format( wxPLURAL("Update delay: %d second", "Update delay: %d seconds", event.GetPosition()), event.GetPosition() ); + label = CFormat(wxPLURAL("Update delay: %d second", "Update delay: %d seconds", event.GetPosition())) % event.GetPosition(); theApp->amuledlg->m_statisticswnd->SetUpdatePeriod(event.GetPosition()); theApp->amuledlg->m_kademliawnd->SetUpdatePeriod(event.GetPosition()); break; case IDC_SLIDER3: id = IDC_SLIDERINFO3; - label = wxString::Format( wxPLURAL("Time for average graph: %d minute", "Time for average graph: %d minutes", event.GetPosition()), event.GetPosition() ); + label = CFormat(wxPLURAL("Time for average graph: %d minute", "Time for average graph: %d minutes", event.GetPosition())) % event.GetPosition(); theApp->m_statistics->SetAverageMinutes(event.GetPosition()); break; case IDC_SLIDER4: id = IDC_SLIDERINFO4; - label = wxString::Format( _("Connections Graph Scale: %d"), event.GetPosition() ); - theApp->amuledlg->m_statisticswnd->GetConnScope()->SetRanges(0,event.GetPosition()); + label = CFormat(_("Connections Graph Scale: %d")) % event.GetPosition(); + theApp->amuledlg->m_statisticswnd->GetConnScope()->SetRanges(0, event.GetPosition()); break; case IDC_SLIDER2: id = IDC_SLIDERINFO2; - label = wxString::Format( wxPLURAL("Update delay : %d second", "Update delay : %d seconds", event.GetPosition()), event.GetPosition() ); + label = CFormat(wxPLURAL("Update delay : %d second", "Update delay : %d seconds", event.GetPosition())) % event.GetPosition(); break; case IDC_FILEBUFFERSIZE: id = IDC_FILEBUFFERSIZE_STATIC; // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation - label = wxString::Format( wxPLURAL("File Buffer Size: %d byte", "File Buffer Size: %d bytes", event.GetPosition() * 15000), event.GetPosition() * 15000 ); + label = CFormat(wxPLURAL("File Buffer Size: %d byte", "File Buffer Size: %d bytes", event.GetPosition() * 15000)) % (event.GetPosition() * 15000); break; case IDC_QUEUESIZE: id = IDC_QUEUESIZE_STATIC; // Yes, it seems odd to add the singular form here, but other languages might need to know the number to select the appropriate translation - label = wxString::Format( wxPLURAL("Upload Queue Size: %d client", "Upload Queue Size: %d clients", event.GetPosition() * 100), event.GetPosition() * 100 ); + label = CFormat(wxPLURAL("Upload Queue Size: %d client", "Upload Queue Size: %d clients", event.GetPosition() * 100)) % (event.GetPosition() * 100); break; case IDC_SERVERKEEPALIVE: id = IDC_SERVERKEEPALIVE_LABEL; if ( event.GetPosition() ) { - label = wxString::Format( wxPLURAL("Server connection refresh interval: %d minute", "Server connection refresh interval: %d minutes", event.GetPosition()), event.GetPosition() ); + label = CFormat(wxPLURAL("Server connection refresh interval: %d minute", "Server connection refresh interval: %d minutes", event.GetPosition())) % event.GetPosition(); } else { - label = wxString::Format( _("Server connection refresh interval: Disabled") ); + label = _("Server connection refresh interval: Disabled"); } break; diff --git a/src/SHAHashSet.cpp b/src/SHAHashSet.cpp index 248a9040..1ff3d67a 100644 --- a/src/SHAHashSet.cpp +++ b/src/SHAHashSet.cpp @@ -651,7 +651,7 @@ bool CAICHHashSet::SaveHashSet() return false; } - AddDebugLogLineN(logSHAHashSet, wxString::Format(wxT("Met file is version 0x%2.2x."),header)); + AddDebugLogLineN(logSHAHashSet, CFormat(wxT("Met file is version 0x%2.2x.")) % header); } else { file.WriteUInt8(KNOWN2_MET_VERSION); // Update the recorded size, in order for the sanity check below to work. @@ -694,7 +694,7 @@ bool CAICHHashSet::SaveHashSet() AddDebugLogLineC(logSHAHashSet, wxT("Failed to save HashSet: Calculated and real size of hashset differ!")); return false; } - AddDebugLogLineN(logSHAHashSet, wxString::Format(wxT("Sucessfully saved eMuleAC Hashset, %u Hashes + 1 Masterhash written"), nHashCount)); + AddDebugLogLineN(logSHAHashSet, CFormat(wxT("Successfully saved eMuleAC Hashset, %u Hashs + 1 Masterhash written")) % nHashCount); } catch (const CSafeIOException& e) { AddDebugLogLineC(logSHAHashSet, wxT("IO error while saving AICH HashSet: ") + e.what()); return false; diff --git a/src/SearchDlg.cpp b/src/SearchDlg.cpp index e303a01c..4ffd16f3 100644 --- a/src/SearchDlg.cpp +++ b/src/SearchDlg.cpp @@ -589,9 +589,9 @@ void CSearchDlg::UpdateHitCount(CSearchListCtrl* page) size_t hidden = page->GetHiddenItemCount(); if (hidden) { - searchtxt += wxString::Format(wxT(" (%u/%u)"), shown, shown + hidden); + searchtxt += CFormat(wxT(" (%u/%u)")) % shown % (shown + hidden); } else { - searchtxt += wxString::Format(wxT(" (%u)"), shown); + searchtxt += CFormat(wxT(" (%u)")) % shown; } m_notebook->SetPageText(i, searchtxt); diff --git a/src/SearchList.cpp b/src/SearchList.cpp index 8af4041f..847e16f5 100644 --- a/src/SearchList.cpp +++ b/src/SearchList.cpp @@ -685,7 +685,7 @@ CSearchList::CMemFilePtr CSearchList::CreateSearchData(const CSearchParams& para } if (iParseResult != 0) { - _astrParserErrors.Add(wxString::Format(wxT("Undefined error %i on search expression"),iParseResult)); + _astrParserErrors.Add(CFormat(wxT("Undefined error %i on search expression")) % iParseResult); return CMemFilePtr(NULL); } diff --git a/src/SearchListCtrl.cpp b/src/SearchListCtrl.cpp index f891fcb2..db06f7de 100644 --- a/src/SearchListCtrl.cpp +++ b/src/SearchListCtrl.cpp @@ -202,18 +202,21 @@ void CSearchListCtrl::AddResult(CSearchFile* toshow) SetItem(newid, ID_SEARCH_COL_SIZE, CastItoXBytes( toshow->GetFileSize() ) ); // Source count - wxString temp = wxString::Format(wxT("%d"), toshow->GetSourceCount()); + wxString temp = CFormat(wxT("%d")) % toshow->GetSourceCount(); if (toshow->GetCompleteSourceCount()) { - temp += wxString::Format(wxT(" (%d)"), toshow->GetCompleteSourceCount()); + temp += CFormat(wxT(" (%d)")) % toshow->GetCompleteSourceCount(); } if (toshow->GetClientsCount()) { - temp += wxString::Format(wxT(" [%d]"), toshow->GetClientsCount()); + temp += CFormat(wxT(" [%d]")) % toshow->GetClientsCount(); } #if defined(__DEBUG__) && !defined(CLIENT_GUI) if (toshow->GetKadPublishInfo() == 0) { temp += wxT(" | -"); } else { - temp += wxString::Format(wxT(" | N:%u, P:%u, T:%0.2f"), (toshow->GetKadPublishInfo() & 0xFF000000) >> 24, (toshow->GetKadPublishInfo() & 0x00FF0000) >> 16, (toshow->GetKadPublishInfo() & 0x0000FFFF) / 100.0); + temp += CFormat(wxT(" | N:%u, P:%u, T:%0.2f")) + % ((toshow->GetKadPublishInfo() & 0xFF000000) >> 24) + % ((toshow->GetKadPublishInfo() & 0x00FF0000) >> 16) + % ((toshow->GetKadPublishInfo() & 0x0000FFFF) / 100.0); } #endif SetItem( newid, ID_SEARCH_COL_SOURCES, temp ); @@ -255,18 +258,21 @@ void CSearchListCtrl::UpdateResult(CSearchFile* toupdate) // Update the filename, which may be changed in case of multiple variants. SetItem(index, ID_SEARCH_COL_NAME, toupdate->GetFileName().GetPrintable()); - wxString temp = wxString::Format(wxT("%d"), toupdate->GetSourceCount()); + wxString temp = CFormat(wxT("%d")) % toupdate->GetSourceCount(); if (toupdate->GetCompleteSourceCount()) { - temp += wxString::Format(wxT(" (%d)"), toupdate->GetCompleteSourceCount()); + temp += CFormat(wxT(" (%d)")) % toupdate->GetCompleteSourceCount(); } if (toupdate->GetClientsCount()) { - temp += wxString::Format(wxT(" [%d]"), toupdate->GetClientsCount()); + temp += CFormat(wxT(" [%d]")) % toupdate->GetClientsCount(); } #if defined(__DEBUG__) && !defined(CLIENT_GUI) if (toupdate->GetKadPublishInfo() == 0) { temp += wxT(" | -"); } else { - temp += wxString::Format(wxT(" | N:%u, P:%u, T:%0.2f"), (toupdate->GetKadPublishInfo() & 0xFF000000) >> 24, (toupdate->GetKadPublishInfo() & 0x00FF0000) >> 16, (toupdate->GetKadPublishInfo() & 0x0000FFFF) / 100.0); + temp += CFormat(wxT(" | N:%u, P:%u, T:%0.2f")) + % ((toupdate->GetKadPublishInfo() & 0xFF000000) >> 24) + % ((toupdate->GetKadPublishInfo() & 0x00FF0000) >> 16) + % ((toupdate->GetKadPublishInfo() & 0x0000FFFF) / 100.0); } #endif SetItem(index, ID_SEARCH_COL_SOURCES, temp); diff --git a/src/Server.cpp b/src/Server.cpp index abe2b455..bb615c16 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -232,7 +232,7 @@ bool CServer::AddTagFromFile(CFileDataIO* servermet) m_strVersion = tag.GetStr(); } } else if (tag.IsInt()) { - m_strVersion = wxString::Format(wxT("%u.%u"), tag.GetInt() >> 16, tag.GetInt() & 0xFFFF); + m_strVersion = CFormat(wxT("%u.%u")) % (tag.GetInt() >> 16) % (tag.GetInt() & 0xFFFF); } else { wxFAIL; } diff --git a/src/ServerConnect.cpp b/src/ServerConnect.cpp index 523b497f..e539c663 100644 --- a/src/ServerConnect.cpp +++ b/src/ServerConnect.cpp @@ -388,8 +388,8 @@ void CServerConnect::ConnectionFailed(CServerSocket* sender) case CS_FATALERROR:{ bool autoretry= !singleconnecting; StopConnectionTry(); - if ((thePrefs::Reconnect()) && (autoretry) && (!m_idRetryTimer.IsRunning())){ - AddLogLineM(false, wxString::Format(wxPLURAL("Automatic connection to server will retry in %d second", "Automatic connection to server will retry in %d seconds", CS_RETRYCONNECTTIME), CS_RETRYCONNECTTIME)); + if ((thePrefs::Reconnect()) && (autoretry) && (!m_idRetryTimer.IsRunning())) { + AddLogLineN(CFormat(wxPLURAL("Automatic connection to server will retry in %d second", "Automatic connection to server will retry in %d seconds", CS_RETRYCONNECTTIME)) % CS_RETRYCONNECTTIME); m_idRetryTimer.Start(1000*CS_RETRYCONNECTTIME); } break; diff --git a/src/ServerList.cpp b/src/ServerList.cpp index 6b0d9484..280648cb 100644 --- a/src/ServerList.cpp +++ b/src/ServerList.cpp @@ -111,7 +111,7 @@ bool CServerList::LoadServerMet(const CPath& path) byte version = servermet.ReadUInt8(); if (version != 0xE0 && version != MET_HEADER) { - AddLogLineM(true, wxString::Format(_("Server.met file corrupt, found invalid versiontag: 0x%x, size %i"), version, sizeof(version))); + AddLogLineC(CFormat(_("Server.met file corrupt, found invalid versiontag: 0x%x, size %i")) % version % sizeof(version)); Notify_ServerThaw(); return false; } @@ -166,9 +166,9 @@ bool CServerList::LoadServerMet(const CPath& path) Notify_ServerThaw(); if (!merge) { - AddLogLineM(true, wxString::Format(wxPLURAL("%i server in server.met found", "%i servers in server.met found", fservercount), fservercount)); + AddLogLineC(CFormat(wxPLURAL("%i server in server.met found", "%i servers in server.met found", fservercount)) % fservercount); } else { - AddLogLineM(true, wxString::Format(wxPLURAL("%d server added", "%d servers added", iAddCount), iAddCount)); + AddLogLineC(CFormat(wxPLURAL("%d server added", "%d servers added", iAddCount)) % iAddCount); } } catch (const CInvalidPacket& err) { AddLogLineM(true, wxT("Error: the file server.met is corrupted: ") + err.what()); diff --git a/src/ServerListCtrl.cpp b/src/ServerListCtrl.cpp index f05b46d2..233f29bb 100644 --- a/src/ServerListCtrl.cpp +++ b/src/ServerListCtrl.cpp @@ -204,11 +204,10 @@ void CServerListCtrl::RefreshServer( CServer* server ) SetItem(itemnr, COLUMN_SERVER_ADDR, server->GetAddress()); if (server->GetAuxPortsList().IsEmpty()) { SetItem( itemnr, COLUMN_SERVER_PORT, - wxString::Format(wxT("%u"), server->GetPort())); + CFormat(wxT("%u")) % server->GetPort()); } else { SetItem( itemnr, COLUMN_SERVER_PORT, - wxString::Format(wxT("%u ("), - server->GetPort()) + server->GetAuxPortsList() + wxT(")") ); + CFormat(wxT("%u (%s)")) % server->GetPort() % server->GetAuxPortsList()); } SetItem( itemnr, COLUMN_SERVER_DESC, server->GetDescription() ); @@ -221,14 +220,14 @@ void CServerListCtrl::RefreshServer( CServer* server ) if ( server->GetUsers() ) { SetItem( itemnr, COLUMN_SERVER_USERS, - wxString::Format( wxT("%u"), server->GetUsers() ) ); + CFormat(wxT("%u")) % server->GetUsers()); } else { SetItem( itemnr, COLUMN_SERVER_USERS, wxEmptyString ); } if ( server->GetFiles() ) { SetItem( itemnr, COLUMN_SERVER_FILES, - wxString::Format( wxT("%u"), server->GetFiles() ) ); + CFormat(wxT("%u")) % server->GetFiles()); } else { SetItem( itemnr, COLUMN_SERVER_FILES, wxEmptyString ); } @@ -240,7 +239,7 @@ void CServerListCtrl::RefreshServer( CServer* server ) default: SetItem(itemnr, COLUMN_SERVER_PRIO, wxT("---")); // this should never happen } - SetItem( itemnr, COLUMN_SERVER_FAILS, wxString::Format( wxT("%u"),server->GetFailedCount() ) ); + SetItem( itemnr, COLUMN_SERVER_FAILS, CFormat(wxT("%u")) % server->GetFailedCount()); SetItem( itemnr, COLUMN_SERVER_STATIC, ( server->IsStaticMember() ? _("Yes") : _("No") ) ); SetItem( itemnr, COLUMN_SERVER_VERSION, server->GetVersion() ); @@ -373,7 +372,7 @@ void CServerListCtrl::ShowServerCount() wxStaticText* label = CastByName( wxT("serverListLabel"), GetParent(), wxStaticText ); if ( label ) { - label->SetLabel( wxString::Format( _("Servers (%i)"), GetItemCount() ) ); + label->SetLabel(CFormat(_("Servers (%i)")) % GetItemCount()); label->GetParent()->Layout(); } } @@ -544,7 +543,7 @@ void CServerListCtrl::OnGetED2kURL( wxCommandEvent& WXUNUSED(event) ) while ( pos != -1 ) { CServer* server = (CServer*)GetItemData(pos); - URL += wxT("ed2k://|server|") + server->GetFullIP() + wxString::Format(wxT("|%d|"), server->GetPort()) + wxT("/\n"); + URL += CFormat(wxT("ed2k://|server|%s|%d|/\n")) % server->GetFullIP() % server->GetPort(); pos = GetNextItem( pos, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); } diff --git a/src/ServerSocket.cpp b/src/ServerSocket.cpp index 84f6b8a1..c5008597 100644 --- a/src/ServerSocket.cpp +++ b/src/ServerSocket.cpp @@ -325,9 +325,7 @@ bool CServerSocket::ProcessPacket(const byte* packet, uint32 size, int8 opcode) ConnPort = data.ReadUInt32(); cur_server->SetPort(ConnPort); if (cur_server->GetAuxPortsList().IsEmpty()) { - cur_server->SetAuxPortsList(wxString::Format(wxT("%u"), rport)); -// } else { -// cur_server->SetAuxPortsList(wxString::Format(wxT("%u"), rport) + wxT(",") + cur_server->GetAuxPortsList()); + cur_server->SetAuxPortsList(CFormat(wxT("%u")) % rport); } } } else { @@ -339,9 +337,7 @@ bool CServerSocket::ProcessPacket(const byte* packet, uint32 size, int8 opcode) if (ConnPort) { pServer->SetPort(ConnPort); if (pServer->GetAuxPortsList().IsEmpty()) { - pServer->SetAuxPortsList(wxString::Format(wxT("%u"), pServer->GetConnPort())); -// } else { -// pServer->SetAuxPortsList(wxString::Format(wxT("%u"), pServer->GetConnPort()) + wxT(",") + pServer->GetAuxPortsList()); + pServer->SetAuxPortsList(CFormat(wxT("%u")) % pServer->GetConnPort()); } Notify_ServerRefresh(pServer); Notify_ServerUpdateED2KInfo(); @@ -414,7 +410,7 @@ bool CServerSocket::ProcessPacket(const byte* packet, uint32 size, int8 opcode) theApp->ShowConnectionState(); - AddLogLineM(false, wxString::Format(_("New clientid is %u"),new_id)); + AddLogLineN(CFormat(_("New clientid is %u")) % new_id); if (::IsLowID(new_id)) { AddLogLineM(true, _("WARNING: You have received Low-ID!")); AddLogLineM(false, _("\tMost likely this is because you're behind a firewall or router.")); @@ -441,7 +437,7 @@ bool CServerSocket::ProcessPacket(const byte* packet, uint32 size, int8 opcode) } case OP_FOUNDSOURCES_OBFU: case OP_FOUNDSOURCES: { - AddDebugLogLineN(logServer, wxString::Format(wxT("ServerMsg - OP_FoundSources; sources = %u"), (uint32)(byte)packet[16])); + AddDebugLogLineN(logServer, CFormat(wxT("ServerMsg - OP_FoundSources; sources = %u")) % packet[16]); theStats::AddDownOverheadServer(size); CMemFile sources(packet,size); CMD4Hash fileid = sources.ReadHash(); @@ -536,7 +532,7 @@ bool CServerSocket::ProcessPacket(const byte* packet, uint32 size, int8 opcode) } delete servers; if (addcount) { - AddLogLineM(false, wxString::Format(wxPLURAL("Received %d new server", "Received %d new servers", addcount), addcount)); + AddLogLineN(CFormat(wxPLURAL("Received %d new server", "Received %d new servers", addcount)) % addcount); } theApp->serverlist->SaveServerMet(); AddLogLineM(false, _("Saving of server-list completed.")); @@ -593,9 +589,7 @@ bool CServerSocket::ProcessPacket(const byte* packet, uint32 size, int8 opcode) break; } default: - AddDebugLogLineN( logPacketErrors, - wxString::Format( wxT("Unknown server packet with OPcode %x"), opcode ) - ); + AddDebugLogLineN(logPacketErrors, CFormat(wxT("Unknown server packet with OPcode %x")) % opcode); } return true; } catch (const CInvalidPacket& e) { @@ -657,18 +651,20 @@ void CServerSocket::ConnectToServer(CServer* server, bool bNoCrypt) void CServerSocket::OnError(wxSocketError nErrorCode) { - AddDebugLogLineN(logServer, wxT("Error in serversocket: ") + cur_server->GetListName() + wxT("(") + cur_server->GetFullIP() + wxString::Format(wxT(":%i): %u"),cur_server->GetPort(), (int)nErrorCode)); + AddDebugLogLineN(logServer, CFormat(wxT("Error in serversocket: %s(%s:%i): %u")) + % cur_server->GetListName() % cur_server->GetFullIP() % cur_server->GetPort() % (int)nErrorCode); SetConnectionState(CS_DISCONNECTED); } bool CServerSocket::PacketReceived(CPacket* packet) { - AddDebugLogLineN(logServer, wxString::Format(wxT("Server: Packet Received: Prot %x, Opcode %x, Length %u"), packet->GetProtocol(), packet->GetOpCode(), packet->GetPacketSize())); + AddDebugLogLineN(logServer, CFormat(wxT("Server: Packet Received: Prot %x, Opcode %x, Length %u")) % packet->GetProtocol() % packet->GetOpCode() % packet->GetPacketSize()); if (packet->GetProtocol() == OP_PACKEDPROT) { if (!packet->UnPackPacket(250000)){ - AddDebugLogLineN(logZLib, wxString::Format(wxT("Failed to decompress server TCP packet: protocol=0x%02x opcode=0x%02x size=%u"), packet ? packet->GetProtocol() : 0, packet ? packet->GetOpCode() : 0, packet ? packet->GetPacketSize() : 0)); + AddDebugLogLineN(logZLib, CFormat(wxT("Failed to decompress server TCP packet: protocol=0x%02x opcode=0x%02x size=%u")) + % packet->GetProtocol() % packet->GetOpCode() % packet->GetPacketSize()); theStats::AddDownOverheadServer(packet->GetPacketSize()); return true; } @@ -679,7 +675,8 @@ bool CServerSocket::PacketReceived(CPacket* packet) if (packet->GetProtocol() == OP_EDONKEYPROT) { ProcessPacket(packet->GetDataBuffer(), packet->GetPacketSize(), packet->GetOpCode()); } else { - AddDebugLogLineN(logServer, wxString::Format(wxT("Received server TCP packet with unknown protocol: protocol=0x%02x opcode=0x%02x size=%u"), packet ? packet->GetProtocol() : 0, packet ? packet->GetOpCode() : 0, packet ? packet->GetPacketSize() : 0)); + AddDebugLogLineN(logServer, CFormat(wxT("Received server TCP packet with unknown protocol: protocol=0x%02x opcode=0x%02x size=%u")) + % packet->GetProtocol() % packet->GetOpCode() % packet->GetPacketSize()); theStats::AddDownOverheadServer(packet->GetPacketSize()); } @@ -752,7 +749,8 @@ void CServerSocket::OnHostnameResolved(uint32 ip) { % useObfuscation ); - AddDebugLogLineN(logServer, wxT("Server ") + cur_server->GetAddress() + wxT("(") + Uint32toStringIP(ip) + wxT(")") + wxString::Format(wxT(" Port %i"), cur_server->GetConnPort())); + AddDebugLogLineN(logServer, CFormat(wxT("Server %s(%s) Port %i")) + % cur_server->GetAddress() % Uint32toStringIP(ip) % cur_server->GetConnPort()); Connect(addr, false); } } else { diff --git a/src/ServerUDPSocket.cpp b/src/ServerUDPSocket.cpp index a79badbe..fa43f8d6 100644 --- a/src/ServerUDPSocket.cpp +++ b/src/ServerUDPSocket.cpp @@ -94,8 +94,7 @@ void CServerUDPSocket::OnPacketReceived(uint32 serverip, uint16 serverport, byte CMemFile data(pBuffer + 2, nPayLoadLen - 2); ProcessPacket(data, opcode, serverip, serverport); } else { - AddDebugLogLineN(logServerUDP, - wxString::Format( wxT("Received invalid packet, protocol (0x%x) and opcode (0x%x)"), protocol, opcode )); + AddDebugLogLineN(logServerUDP, CFormat(wxT("Received invalid packet, protocol (0x%x) and opcode (0x%x)")) % protocol % opcode); theStats::AddDownOverheadOther(length); } @@ -174,14 +173,14 @@ void CServerUDPSocket::ProcessPacket(CMemFile& packet, uint8 opcode, uint32 ip, case OP_GLOBSERVSTATRES:{ // Reviewed with 0.47c if (!update) { - throw wxString(wxT("Unknown server on a OP_GLOBSERVSTATRES packet (") + Uint32toStringIP(ip) + wxString::Format(wxT(":%d)"), port-4)); + throw wxString(CFormat(wxT("Unknown server on a OP_GLOBSERVSTATRES packet (%s:%d)")) % Uint32toStringIP(ip) % (port-4)); } - if( size < 12) { - throw(wxString(wxString::Format(wxT("Invalid OP_GLOBSERVSTATRES packet (size=%u)"),size))); + if (size < 12) { + throw wxString(CFormat(wxT("Invalid OP_GLOBSERVSTATRES packet (size=%u)")) % size); } uint32 challenge = packet.ReadUInt32(); if (challenge != update->GetChallenge()) { - throw(wxString(wxString::Format(wxT("Invalid challenge on OP_GLOBSERVSTATRES packet (0x%x != 0x%x)"),challenge,update->GetChallenge()))); + throw wxString(CFormat(wxT("Invalid challenge on OP_GLOBSERVSTATRES packet (0x%x != 0x%x)")) % challenge % update->GetChallenge()); } update->SetChallenge(0); @@ -291,8 +290,7 @@ void CServerUDPSocket::ProcessPacket(CMemFile& packet, uint8 opcode, uint32 ip, if (tag.IsStr()) { update->SetVersion(tag.GetStr()); } else if (tag.IsInt()) { - wxString strVersion = wxString::Format(wxT("%u.%u"), tag.GetInt() >> 16, tag.GetInt() & 0xFFFF); - update->SetVersion(strVersion); + update->SetVersion(CFormat(wxT("%u.%u")) % (tag.GetInt() >> 16) % (tag.GetInt() & 0xFFFF)); } break; case ST_AUXPORTSLIST: @@ -318,8 +316,7 @@ void CServerUDPSocket::ProcessPacket(CMemFile& packet, uint8 opcode, uint32 ip, break; } default: - AddDebugLogLineC( logServerUDP, - wxString::Format( wxT("Unknown Server UDP opcode %x"), opcode ) ); + AddDebugLogLineC(logServerUDP, CFormat(wxT("Unknown Server UDP opcode %x")) % opcode); } } catch (const wxString& error) { AddDebugLogLineN(logServerUDP, wxT("Error while processing incoming UDP Packet: ") + error); diff --git a/src/ServerWnd.cpp b/src/ServerWnd.cpp index 7365d3e6..9d90263f 100644 --- a/src/ServerWnd.cpp +++ b/src/ServerWnd.cpp @@ -171,7 +171,7 @@ void CServerWnd::UpdateED2KInfo() ED2KInfoList->InsertItem(2, _("ID")); // No need to test the server connect, it's already true - ED2KInfoList->SetItem(2, 1, wxString::Format(wxT("%u"), theApp->GetED2KID())); + ED2KInfoList->SetItem(2, 1, CFormat(wxT("%u")) % theApp->GetED2KID()); ED2KInfoList->InsertItem(3, wxEmptyString); diff --git a/src/SharedFileList.cpp b/src/SharedFileList.cpp index 49b081d1..159ea578 100644 --- a/src/SharedFileList.cpp +++ b/src/SharedFileList.cpp @@ -361,13 +361,13 @@ void CSharedFileList::FindSharedFiles() filelist->ReleaseIndex(); if (addedFiles == 0) { - AddLogLineM(false, wxString::Format(wxPLURAL("Found %i known shared file", "Found %i known shared files", GetCount()), GetCount())); + AddLogLineM(false, CFormat(wxPLURAL("Found %i known shared file", "Found %i known shared files", GetCount())) % GetCount()); // Make sure the AICH-hashes are up to date. CThreadScheduler::AddTask(new CAICHSyncTask()); } else { // New files, AICH thread will be run at the end of the hashing thread. - AddLogLineM(false, wxString::Format(wxPLURAL("Found %i known shared file, %i unknown", "Found %i known shared files, %i unknown", GetCount()), GetCount(), addedFiles)); + AddLogLineM(false, CFormat(wxPLURAL("Found %i known shared file, %i unknown", "Found %i known shared files, %i unknown", GetCount())) % GetCount() % addedFiles); } } diff --git a/src/SharedFilesCtrl.cpp b/src/SharedFilesCtrl.cpp index 0f2498b3..5358507b 100644 --- a/src/SharedFilesCtrl.cpp +++ b/src/SharedFilesCtrl.cpp @@ -458,10 +458,9 @@ void CSharedFilesCtrl::UpdateItem(CKnownFile* toupdate) void CSharedFilesCtrl::ShowFilesCount() { - wxString str = wxString::Format(_("Shared Files (%i)"), GetItemCount()); wxStaticText* label = CastByName( wxT("sharedFilesLabel"), GetParent(), wxStaticText ); - label->SetLabel( str ); + label->SetLabel(CFormat(_("Shared Files (%i)")) % GetItemCount()); label->GetParent()->Layout(); } @@ -547,15 +546,15 @@ void CSharedFilesCtrl::OnDrawItem( int item, wxDC* dc, const wxRect& rect, const break; case ID_SHARED_COL_REQ: - textBuffer = wxString::Format(wxT("%u (%u)"), - file->statistic.GetRequests(), - file->statistic.GetAllTimeRequests()); + textBuffer = CFormat(wxT("%u (%u)")) + % file->statistic.GetRequests() + % file->statistic.GetAllTimeRequests(); break; case ID_SHARED_COL_AREQ: - textBuffer = wxString::Format(wxT("%u (%u)"), - file->statistic.GetAccepts(), - file->statistic.GetAllTimeAccepts()); + textBuffer = CFormat(wxT("%u (%u)")) + % file->statistic.GetAccepts() + % file->statistic.GetAllTimeAccepts(); break; case ID_SHARED_COL_TRA: @@ -564,8 +563,7 @@ void CSharedFilesCtrl::OnDrawItem( int item, wxDC* dc, const wxRect& rect, const break; case ID_SHARED_COL_RTIO: - textBuffer = wxString::Format(wxT("%.2f"), - (double)file->statistic.GetAllTimeTransferred() / file->GetFileSize() ); + textBuffer = CFormat(wxT("%.2f")) % ((double)file->statistic.GetAllTimeTransferred() / file->GetFileSize()); break; case ID_SHARED_COL_PART: @@ -580,16 +578,14 @@ void CSharedFilesCtrl::OnDrawItem( int item, wxDC* dc, const wxRect& rect, const case ID_SHARED_COL_CMPL: if ( file->m_nCompleteSourcesCountLo == 0 ) { if ( file->m_nCompleteSourcesCountHi ) { - textBuffer = wxString::Format(wxT("< %u"), file->m_nCompleteSourcesCountHi ); + textBuffer = CFormat(wxT("< %u")) % file->m_nCompleteSourcesCountHi; } else { textBuffer = wxT("0"); } } else if (file->m_nCompleteSourcesCountLo == file->m_nCompleteSourcesCountHi) { - textBuffer = wxString::Format(wxT("%u"), file->m_nCompleteSourcesCountLo); + textBuffer = CFormat(wxT("%u")) % file->m_nCompleteSourcesCountLo; } else { - textBuffer = wxString::Format(wxT("%u - %u"), - file->m_nCompleteSourcesCountLo, - file->m_nCompleteSourcesCountHi); + textBuffer = CFormat(wxT("%u - %u")) % file->m_nCompleteSourcesCountLo % file->m_nCompleteSourcesCountHi; } break; diff --git a/src/StatTree.cpp b/src/StatTree.cpp index 4d003ff7..e911ffd1 100644 --- a/src/StatTree.cpp +++ b/src/StatTree.cpp @@ -227,7 +227,7 @@ wxString CStatTreeItemSimple::GetDisplayString() const case dmBytes: return CFormat(wxGetTranslation(m_label)) % CastItoXBytes(m_intvalue); default: return CFormat(wxGetTranslation(m_label)) % m_intvalue; } - case vtFloat: return wxString::Format(wxGetTranslation(m_label), m_floatvalue); + case vtFloat: return CFormat(wxGetTranslation(m_label)) % m_floatvalue; case vtString: return CFormat(wxGetTranslation(m_label)) % m_stringvalue; default: return wxGetTranslation(m_label); } @@ -303,8 +303,7 @@ wxString CStatTreeItemCounterTmpl<_Tp>::GetDisplayString() const } else { wxString result = CFormat(wxT("%u")) % m_value; if ((m_flags & stShowPercent) && m_parent) { - result.append(wxString::Format(wxT(" (%.2f%%)"), - ((double)m_value / ((CStatTreeItemCounterTmpl<_Tp>*)m_parent)->m_value) * 100.0)); + result += CFormat(wxT(" (%.2f%%)")) % (((double)m_value / ((CStatTreeItemCounterTmpl<_Tp>*)m_parent)->m_value) * 100.0); } return label % result; } @@ -362,7 +361,7 @@ void CStatTreeItemUlDlCounter::AddECValues(CECTag *tag) const #ifndef AMULE_DAEMON wxString CStatTreeItemCounterMax::GetDisplayString() const { - return wxString::Format(wxGetTranslation(m_label), m_value); + return CFormat(wxGetTranslation(m_label)) % m_value; } #endif @@ -590,10 +589,7 @@ wxString CStatTreeItemMaxConnLimitReached::GetDisplayString() const { if (m_count) { return CFormat(wxGetTranslation(m_label)) % - (wxString::Format(wxT("%i : "), m_count) + - m_time.FormatISODate() + - wxT(" ") + - m_time.FormatISOTime()); + CFormat(wxT("%i : %s %s")) % m_count % m_time.FormatISODate() % m_time.FormatISOTime(); } else { return CFormat(wxGetTranslation(m_label)) % _("Never"); } @@ -604,10 +600,7 @@ void CStatTreeItemMaxConnLimitReached::AddECValues(CECTag *tag) const { wxString result; if (m_count) { - result = wxString::Format(wxT("%i : "), m_count) + - m_time.FormatISODate() + - wxT(" ") + - m_time.FormatISOTime(); + result = CFormat(wxT("%i : %s %s")) % m_count % m_time.FormatISODate() % m_time.FormatISOTime(); } else { result = wxTRANSLATE("Never"); } diff --git a/src/Statistics.cpp b/src/Statistics.cpp index 9244004f..ec73ed64 100644 --- a/src/Statistics.cpp +++ b/src/Statistics.cpp @@ -119,7 +119,7 @@ void CStatTreeItemRateCounter::AddECValues(CECTag* tag) const #ifndef AMULE_DAEMON wxString CStatTreeItemPeakConnections::GetDisplayString() const { - return wxString::Format(wxGetTranslation(m_label), theStats::GetPeakConnections()); + return CFormat(wxGetTranslation(m_label)) % theStats::GetPeakConnections(); } #endif diff --git a/src/StatisticsDlg.cpp b/src/StatisticsDlg.cpp index e1edabbb..c9587043 100644 --- a/src/StatisticsDlg.cpp +++ b/src/StatisticsDlg.cpp @@ -144,7 +144,7 @@ void CStatisticsDlg::ApplyStatsColor(int index) case 8: case 9: case 10: (*ppscope)->SetPlotColor(cr, iTrend); if ((ctrl = CastChild(iRes, CColorFrameCtrl)) == NULL) { - throw wxString::Format(wxT("CStatisticsDlg::ApplyStatsColor: control missing (%d)\n"),iRes); + throw wxString(CFormat(wxT("CStatisticsDlg::ApplyStatsColor: control missing (%d)\n")) % iRes); } ctrl->SetBackgroundBrushColour(cr); ctrl->SetFrameBrushColour(*wxBLACK); @@ -185,7 +185,7 @@ void CStatisticsDlg::UpdateStatGraphs(const uint32 peakconnections, const GraphU nScalePrev = nScale; wxStaticText* label = CastChild( ID_ACTIVEC, wxStaticText ); - label->SetLabel(wxString::Format(_("Active connections (1:%u)"), nScale)); + label->SetLabel(CFormat(_("Active connections (1:%u)")) % nScale); label->GetParent()->Layout(); pscopeConn->SetRange(0.0, (float)nScale*pscopeConn->GetUpperLimit(), 1); diff --git a/src/Tag.cpp b/src/Tag.cpp index fec421b4..8fa7290a 100644 --- a/src/Tag.cpp +++ b/src/Tag.cpp @@ -178,7 +178,7 @@ CTag::CTag(const CFileDataIO& data, bool bOptUTF8) } else { // Since we cannot determine the length of this tag, we // simply have to abort reading the file. - throw CInvalidPacket(wxString::Format(wxT("Unknown tag type encounted %x, cannot proceed!"),m_uType)); + throw CInvalidPacket(CFormat(wxT("Unknown tag type encounted %x, cannot proceed!")) % m_uType); } } } catch (...) { @@ -417,14 +417,14 @@ wxString CTag::GetFullInfo() const if (!m_Name.IsEmpty()) { // Special case: Kad tags, and some ED2k tags ... if (m_Name.Length() == 1) { - strTag = wxString::Format(wxT("0x%02X"), m_Name[0]); + strTag = CFormat(wxT("0x%02X")) % (unsigned)m_Name[0]; } else { strTag = wxT('\"'); strTag += m_Name; strTag += wxT('\"'); } } else { - strTag = wxString::Format(wxT("0x%02X"), m_uName); + strTag = CFormat(wxT("0x%02X")) % m_uName; } strTag += wxT("="); if (m_uType == TAGTYPE_STRING) { @@ -432,24 +432,24 @@ wxString CTag::GetFullInfo() const strTag += *m_pstrVal; strTag += wxT("\""); } else if (m_uType >= TAGTYPE_STR1 && m_uType <= TAGTYPE_STR16) { - strTag += wxString::Format(wxT("(Str%u)\""), m_uType - TAGTYPE_STR1 + 1) + strTag += CFormat(wxT("(Str%u)\"")) % (m_uType - TAGTYPE_STR1 + 1) + *m_pstrVal + wxT("\""); } else if (m_uType == TAGTYPE_UINT64) { - strTag += wxString::Format(wxT("(Int64)%") WXLONGLONGFMTSPEC wxT("u"), m_uVal); + strTag += CFormat(wxT("(Int64)%u")) % m_uVal; } else if (m_uType == TAGTYPE_UINT32) { - strTag += wxString::Format(wxT("(Int32)%u"), (unsigned)m_uVal); + strTag += CFormat(wxT("(Int32)%u")) % m_uVal; } else if (m_uType == TAGTYPE_UINT16) { - strTag += wxString::Format(wxT("(Int16)%u"), (unsigned)m_uVal); + strTag += CFormat(wxT("(Int16)%u")) % m_uVal; } else if (m_uType == TAGTYPE_UINT8) { - strTag += wxString::Format(wxT("(Int8)%u"), (unsigned)m_uVal); + strTag += CFormat(wxT("(Int8)%u")) % m_uVal; } else if (m_uType == TAGTYPE_FLOAT32) { - strTag += wxString::Format(wxT("(Float32)%f"), m_fVal); + strTag += CFormat(wxT("(Float32)%f")) % m_fVal; } else if (m_uType == TAGTYPE_BLOB) { - strTag += wxString::Format(wxT("(Blob)%u"), m_nSize); + strTag += CFormat(wxT("(Blob)%u")) % m_nSize; } else if (m_uType == TAGTYPE_BSOB) { - strTag += wxString::Format(wxT("(Bsob)%u"), m_nSize); + strTag += CFormat(wxT("(Bsob)%u")) % m_nSize; } else { - strTag += wxString::Format(wxT("Type=%u"), m_uType); + strTag += CFormat(wxT("Type=%u")) % m_uType; } return strTag; } diff --git a/src/TextClient.cpp b/src/TextClient.cpp index ee6852d2..b0eb9f75 100644 --- a/src/TextClient.cpp +++ b/src/TextClient.cpp @@ -662,14 +662,14 @@ void CamulecmdApp::Process_Answer_v2(const CECPacket *response) 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 << wxString::Format(_("IP filtering for clients is %s.\n"), - (tab->GetTagByName(EC_TAG_IPFILTER_CLIENTS) == NULL) ? _("OFF") : _("ON")); + 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 << wxString::Format(_("IP filtering for servers is %s.\n"), - (tab->GetTagByName(EC_TAG_IPFILTER_SERVERS) == NULL) ? _("OFF") : _("ON")); + 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) { @@ -750,22 +750,22 @@ void CamulecmdApp::Process_Answer_v2(const CECPacket *response) donesize = tag->SizeDone(); s << tag->FileHashString() << wxT(" ") << tag->FileName() << - wxString::Format(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::Format(wxT("+%2.2i "),(int)tag->SourceCountA4AF()) : wxString(wxT(" "))) << - ((int)tag->SourceXferCount() ? wxString::Format(wxT("(%2.2i) - "),(int)tag->SourceXferCount()) : wxString(wxT(" - "))) << + (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(" - ") << 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; @@ -811,7 +811,7 @@ void CamulecmdApp::Process_Answer_v2(const CECPacket *response) { int i = 0; m_Results_map.clear(); - s << CFormat(_("Number of search results: %i\n")) % response->GetTagCount(); + s += CFormat(_("Number of search results: %i\n")) % response->GetTagCount(); for (CECPacket::const_iterator it = response->begin(); it != response->end(); it++) { CEC_SearchFile_Tag *tag = (CEC_SearchFile_Tag *) & *it; //printf("Tag FileName: %s \n",(const char*)unicode2char(tag->FileName())); @@ -821,13 +821,18 @@ void CamulecmdApp::Process_Answer_v2(const CECPacket *response) break; } case EC_OP_SEARCH_PROGRESS: - s << _("TODO - show progress of a search"); - // gives compilation error!! - // const CECTag *tab = response->GetTagByNameSafe(EC_TAG_SEARCH_STATUS); - //s << wxString::Format(_("Search progress: %u %% \n"),(const char*)unicode2char(tab->GetStringData())); + { + 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 << wxString::Format(_("Received an unknown reply from the server, OpCode = %#x."), response->GetOpCode()); + s += CFormat(_("Received an unknown reply from the server, OpCode = %#x.")) % response->GetOpCode(); } Process_Answer(s); } diff --git a/src/ThreadTasks.cpp b/src/ThreadTasks.cpp index 27651ffa..e51dece1 100644 --- a/src/ThreadTasks.cpp +++ b/src/ThreadTasks.cpp @@ -433,7 +433,7 @@ void CCompletionTask::Entry() // Avoid saving to an already existing filename CPath newName = targetPath.JoinPaths(dstName); for (unsigned count = 0; newName.FileExists(); ++count) { - wxString postfix = wxString::Format(wxT("(%u)"), count); + wxString postfix = CFormat(wxT("(%u)")) % count; newName = targetPath.JoinPaths(dstName.AddPostfix(postfix)); } diff --git a/src/TransferWnd.cpp b/src/TransferWnd.cpp index ecce04e3..e91357da 100644 --- a/src/TransferWnd.cpp +++ b/src/TransferWnd.cpp @@ -171,7 +171,7 @@ void CTransferWnd::UpdateCategory( int index, bool titleChanged ) } } - label += wxString::Format(wxT(" (%u/%u)"), download, files ); + label += CFormat(wxT(" (%u/%u)")) % download % files; } m_dlTab->SetPageText( index, label ); @@ -303,7 +303,7 @@ void CTransferWnd::OnSetDefaultCat( wxCommandEvent& event ) void CTransferWnd::ShowQueueCount(uint32 /*number*/) { #if 0 - wxString str = wxString::Format( wxT("%u (%u %s)"), number, theStats::GetBannedCount(), _("Banned") ); + wxString str = CFormat(wxT("%u (%u %s)")) % number % theStats::GetBannedCount() % _("Banned"); wxStaticText* label = CastChild( ID_CLIENTCOUNT, wxStaticText ); label->SetLabel( str ); diff --git a/src/amule-gui.cpp b/src/amule-gui.cpp index 173800f7..5faaad86 100644 --- a/src/amule-gui.cpp +++ b/src/amule-gui.cpp @@ -186,9 +186,9 @@ int CamuleGuiBase::InitGui(bool geometry_enabled, wxString &geom_string) // Should default/last-used position be overridden? #ifdef SVNDATE #ifdef CLIENT_GUI - m_FrameTitle = wxString::Format(wxT("aMule remote control %s %s"), wxT( VERSION ), wxT( SVNDATE )); + m_FrameTitle = CFormat(wxT("aMule remote control %s %s")) % wxT( VERSION ) % wxT( SVNDATE ); #else - m_FrameTitle = wxString::Format(wxT("aMule %s %s"), wxT( VERSION ), wxT( SVNDATE )); + m_FrameTitle = CFormat(wxT("aMule %s %s")) % wxT( VERSION ) % wxT( SVNDATE ); #endif #else #ifdef CLIENT_GUI diff --git a/src/amule.cpp b/src/amule.cpp index 60a79f86..d139d00e 100644 --- a/src/amule.cpp +++ b/src/amule.cpp @@ -871,7 +871,7 @@ void CamuleApp::OnlineSig(bool zero /* reset stats (used on shutdown) */) } else { if (IsConnectedED2K()) { - temp = wxString::Format(wxT("%d"),serverconnect->GetCurrentServer()->GetPort()); + temp = CFormat(wxT("%d")) % serverconnect->GetCurrentServer()->GetPort(); // We are online emulesig_string = @@ -930,25 +930,25 @@ void CamuleApp::OnlineSig(bool zero /* reset stats (used on shutdown) */) emulesig_string += wxT("\xA"); // Datarate for downloads - temp = wxString::Format(wxT("%.1f"), theStats::GetDownloadRate() / 1024.0); + temp = CFormat(wxT("%.1f")) % (theStats::GetDownloadRate() / 1024.0); emulesig_string += temp + wxT("|"); amulesig_out.AddLine(temp); // Datarate for uploads - temp = wxString::Format(wxT("%.1f"), theStats::GetUploadRate() / 1024.0); + temp = CFormat(wxT("%.1f")) % (theStats::GetUploadRate() / 1024.0); emulesig_string += temp + wxT("|"); amulesig_out.AddLine(temp); // Number of users waiting for upload - temp = wxString::Format(wxT("%d"), theStats::GetWaitingUserCount()); + temp = CFormat(wxT("%d")) % theStats::GetWaitingUserCount(); emulesig_string += temp; amulesig_out.AddLine(temp); // Number of shared files (not on eMule) - amulesig_out.AddLine(wxString::Format(wxT("%d"), theStats::GetSharedFileCount())); + amulesig_out.AddLine(CFormat(wxT("%d")) % theStats::GetSharedFileCount()); } // eMule signature finished here. Write the line to the wxTextFile. @@ -1623,22 +1623,22 @@ void CamuleApp::CheckNewVersion(uint32 result) long newVer = make_full_ed2k_version(fields[0], fields[1], fields[2]); if (curVer < newVer) { - AddLogLineM(true, _("You are using an outdated version of aMule!")); - AddLogLineM(false, wxString::Format(_("Your aMule version is %i.%i.%i and the latest version is %li.%li.%li"), VERSION_MJR, VERSION_MIN, VERSION_UPDATE, fields[0], fields[1], fields[2])); - AddLogLineM(false, _("The latest version can always be found at http://www.amule.org")); + AddLogLineC(_("You are using an outdated version of aMule!")); + AddLogLineN(CFormat(_("Your aMule version is %i.%i.%i and the latest version is %li.%li.%li")) % VERSION_MJR % VERSION_MIN % VERSION_UPDATE % fields[0] % fields[1] % fields[2]); + AddLogLineN(_("The latest version can always be found at http://www.amule.org")); #ifdef AMULE_DAEMON - AddLogLineMS(true, CFormat(_("WARNING: Your aMuled version is outdated: %i.%i.%i < %li.%li.%li")) + AddLogLineCS(CFormat(_("WARNING: Your aMuled version is outdated: %i.%i.%i < %li.%li.%li")) % VERSION_MJR % VERSION_MIN % VERSION_UPDATE % fields[0] % fields[1] % fields[2]); #endif } else { - AddLogLineM(false, _("Your copy of aMule is up to date.")); + AddLogLineN(_("Your copy of aMule is up to date.")); } } file.Close(); wxRemoveFile(filename); } else { - AddLogLineM(true, _("Failed to download the version check file")); + AddLogLineC(_("Failed to download the version check file")); } } diff --git a/src/amuleDlg.cpp b/src/amuleDlg.cpp index 3b213be2..e10be61f 100644 --- a/src/amuleDlg.cpp +++ b/src/amuleDlg.cpp @@ -838,9 +838,9 @@ void CamuleDlg::ShowTransferRate() wxString buffer; if( thePrefs::ShowOverhead() ) { - buffer = wxString::Format(_("Up: %.1f(%.1f) | Down: %.1f(%.1f)"), kBpsUp, theStats::GetUpOverheadRate() / 1024.0, kBpsDown, theStats::GetDownOverheadRate() / 1024.0); + buffer = CFormat(_("Up: %.1f(%.1f) | Down: %.1f(%.1f)")) % kBpsUp % (theStats::GetUpOverheadRate() / 1024.0) % kBpsDown % (theStats::GetDownOverheadRate() / 1024.0); } else { - buffer = wxString::Format(_("Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown); + buffer = CFormat(_("Up: %.1f | Down: %.1f")) % kBpsUp % kBpsDown; } buffer.Truncate(50); // Max size 50 @@ -850,7 +850,7 @@ void CamuleDlg::ShowTransferRate() // Show upload/download speed in title if (thePrefs::GetShowRatesOnTitle()) { - wxString UpDownSpeed = wxString::Format(wxT("Up: %.1f | Down: %.1f"), kBpsUp, kBpsDown); + wxString UpDownSpeed = CFormat(wxT("Up: %.1f | Down: %.1f")) % kBpsUp % kBpsDown; if (thePrefs::GetShowRatesOnTitle() == 1) { SetTitle(theApp->m_FrameTitle + wxT(" -- ") + UpDownSpeed); } else { diff --git a/src/amuled.cpp b/src/amuled.cpp index 838fd46e..b1240281 100644 --- a/src/amuled.cpp +++ b/src/amuled.cpp @@ -718,7 +718,7 @@ int CamuleDaemonApp::InitGui(bool ,wxString &) // can easily manage the process // if (!m_PidFile.IsEmpty()) { - wxString temp = wxString::Format(wxT("%d\n"), pid); + wxString temp = CFormat(wxT("%d\n")) % pid; wxFFile ff(m_PidFile, wxT("w")); if (!ff.Error()) { ff.Write(temp); diff --git a/src/kademlia/kademlia/Entry.cpp b/src/kademlia/kademlia/Entry.cpp index 0200d1a3..86343207 100644 --- a/src/kademlia/kademlia/Entry.cpp +++ b/src/kademlia/kademlia/Entry.cpp @@ -339,7 +339,8 @@ void CKeyEntry::AdjustGlobalPublishTracking(uint32_t ip, bool increase, const wx } #ifdef __DEBUG__ if (!dbgReason.IsEmpty()) { - AddDebugLogLineN(logKadEntryTracking, (increase ? wxT("Adding ") : wxT("Removing ")) + KadIPToString(ip & 0xFFFFFF00) + wxT(" (") + KadIPToString(ip) + wxT(") - (") + dbgReason + wxString::Format(wxT("), new count %u"),count)); + AddDebugLogLineN(logKadEntryTracking, CFormat(wxT("%s %s (%s) - (%s), new count %u")) + % (increase ? wxT("Adding") : wxT("Removing")) % KadIPToString(ip & 0xFFFFFF00) % KadIPToString(ip) % dbgReason % count); } #endif } @@ -432,7 +433,8 @@ void CKeyEntry::MergeIPsAndFilenames(CKeyEntry* fromEntry) // since we added a new publisher, we want to (re)calculate the trust value for this entry ReCalculateTrustValue(); } - AddDebugLogLineN(logKadEntryTracking, wxString(wxT("Indexed Keyword, Refresh: ")) + (refresh ? wxT("Yes") : wxT("No")) + wxT(", Current Publisher: ") + KadIPToString(m_uIP) + wxString::Format(wxT(", Total Publishers: %u, Total different Names: %u, TrustValue: %.2f, file: "), m_publishingIPs->size(), m_filenames.size(), m_trustValue) + m_uSourceID.ToHexString()); + AddDebugLogLineN(logKadEntryTracking, CFormat(wxT("Indexed Keyword, Refresh: %s, Current Publisher: %s, Total Publishers: %u, Total different Names: %u, TrustValue: %.2f, file: %s")) + % (refresh ? wxT("Yes") : wxT("No")) % KadIPToString(m_uIP) % m_publishingIPs->size() % m_filenames.size() % m_trustValue % m_uSourceID.ToHexString()); } void CKeyEntry::ReCalculateTrustValue() @@ -558,7 +560,8 @@ void CKeyEntry::ReadPublishTrackingDataFromFile(CFileDataIO* data) ReCalculateTrustValue(); // #ifdef __DEBUG__ // if (GetTrustValue() < 1.0) { -// AddDebugLogLineN(logKadEntryTracking, wxString::Format(wxT("Loaded %u different names, %u different publishIPs (trustvalue = %.2f) for file "), nameCount, ipCount, GetTrustValue()) + m_uSourceID.ToHexString()); +// AddDebugLogLineN(logKadEntryTracking,CFormat(wxT("Loaded %u different names, %u different publishIPs (trustvalue = %.2f) for file %s")) +// % nameCount % ipCount % GetTrustValue() % m_uSourceID.ToHexString()); // } // #endif } diff --git a/src/kademlia/kademlia/Indexed.cpp b/src/kademlia/kademlia/Indexed.cpp index cf5dc589..1229c120 100644 --- a/src/kademlia/kademlia/Indexed.cpp +++ b/src/kademlia/kademlia/Indexed.cpp @@ -234,7 +234,7 @@ void CIndexed::ReadFile() m_totalIndexSource = totalSource; m_totalIndexKeyword = totalKeyword; m_totalIndexLoad = totalLoad; - AddDebugLogLineN(logKadIndex, wxString::Format(wxT("Read %u source, %u keyword, and %u load entries"),totalSource,totalKeyword,totalLoad)); + AddDebugLogLineN(logKadIndex, CFormat(wxT("Read %u source, %u keyword, and %u load entries")) % totalSource % totalKeyword % totalLoad); } } catch (const CSafeIOException& err) { AddDebugLogLineC(logKadIndex, wxT("CSafeIOException in CIndexed::readFile: ") + err.what()); @@ -350,7 +350,7 @@ CIndexed::~CIndexed() } k_file.Close(); } - AddDebugLogLineN(logKadIndex, wxString::Format(wxT("Wrote %u source, %u keyword, and %u load entries"), s_total, k_total, l_total)); + AddDebugLogLineN(logKadIndex, CFormat(wxT("Wrote %u source, %u keyword, and %u load entries")) % s_total % k_total % l_total); for (SrcHashMap::iterator itNoteHash = m_Notes_map.begin(); itNoteHash != m_Notes_map.end(); ++itNoteHash) { SrcHash* currNoteHash = itNoteHash->second; @@ -468,7 +468,7 @@ void CIndexed::Clean() m_totalIndexSource = s_Total - s_Removed; m_totalIndexKeyword = k_Total - k_Removed; - AddDebugLogLineN(logKadIndex, wxString::Format(wxT("Removed %u keyword out of %u and %u source out of %u"), k_Removed, k_Total, s_Removed, s_Total)); + AddDebugLogLineN(logKadIndex, CFormat(wxT("Removed %u keyword out of %u and %u source out of %u")) % k_Removed % k_Total % s_Removed % s_Total); m_lastClean = tNow + MIN2S(30); } @@ -800,7 +800,7 @@ void CIndexed::SendValidKeywordResult(const CUInt128& keyID, const SSearchTerm* } } while (!onlyTrusted); - AddDebugLogLineN(logKadIndex, wxString::Format(wxT("Kad keyword search result request: Sent %u trusted and %u untrusted results"), dbgResultsTrusted, dbgResultsUntrusted)); + AddDebugLogLineN(logKadIndex, CFormat(wxT("Kad keyword search result request: Sent %u trusted and %u untrusted results")) % dbgResultsTrusted % dbgResultsUntrusted); if (count > 0) { uint16_t countLeft = (uint16_t)count % 50; diff --git a/src/kademlia/kademlia/Kademlia.cpp b/src/kademlia/kademlia/Kademlia.cpp index 549e7f3a..36f0569f 100644 --- a/src/kademlia/kademlia/Kademlia.cpp +++ b/src/kademlia/kademlia/Kademlia.cpp @@ -265,7 +265,7 @@ void CKademlia::Process() if (m_consolidate <= now) { uint32_t mergedCount = instance->m_routingZone->Consolidate(); if (mergedCount) { - AddDebugLogLineN(logKadRouting, wxString::Format(wxT("Kad merged %u zones"), mergedCount)); + AddDebugLogLineN(logKadRouting, CFormat(wxT("Kad merged %u zones")) % mergedCount); } m_consolidate = MIN2S(45) + now; } @@ -283,7 +283,8 @@ void CKademlia::Process() CContact *contact = s_bootstrapList.front(); s_bootstrapList.pop_front(); m_bootstrap = now; - AddDebugLogLineN(logKadMain, wxT("Trying to bootstrap Kad from ") + KadIPToString(contact->GetIPAddress()) + wxT(", Distance: ") + contact->GetDistance().ToHexString() + wxString::Format(wxT(" Version: %u, %u contacts left"), contact->GetVersion(), s_bootstrapList.size())); + AddDebugLogLineN(logKadMain, CFormat(wxT("Trying to bootstrap Kad from %s, Distance: %s Version: %u, %u contacts left")) + % KadIPToString(contact->GetIPAddress()) % contact->GetDistance().ToHexString() % contact->GetVersion() % s_bootstrapList.size()); instance->m_udpListener->Bootstrap(contact->GetIPAddress(), contact->GetUDPPort(), contact->GetVersion(), &contact->GetClientID()); delete contact; } @@ -300,7 +301,8 @@ void CKademlia::ProcessPacket(const uint8_t *data, uint32_t lenData, uint32_t ip instance->m_udpListener->ProcessPacket(data, lenData, ip, port, validReceiverKey, senderKey); } } catch (const wxString& DEBUG_ONLY(error)) { - AddDebugLogLineN(logKadMain, wxString::Format(wxT("Exception on Kad ProcessPacket while processing packet (length = %u) from "), lenData) + KadIPPortToString(ip, port) + wxT(':')); + AddDebugLogLineN(logKadMain, CFormat(wxT("Exception on Kad ProcessPacket while processing packet (length = %u) from %s:")) + % lenData % KadIPPortToString(ip, port)); AddDebugLogLineN(logKadMain, error); throw; } catch (...) { diff --git a/src/kademlia/kademlia/Prefs.cpp b/src/kademlia/kademlia/Prefs.cpp index d9b534f1..dac2f35e 100644 --- a/src/kademlia/kademlia/Prefs.cpp +++ b/src/kademlia/kademlia/Prefs.cpp @@ -199,10 +199,10 @@ void CPrefs::SetKademliaFiles() DEBUG_ONLY( wxString method; ) if (nServerAverage > nKadAverage) { - DEBUG_ONLY( method = wxString::Format(wxT("Kad file estimate used Server avg(%u)"), nServerAverage); ) + DEBUG_ONLY( method = CFormat(wxT("Kad file estimate used Server avg(%u)")) % nServerAverage; ) nKadAverage = nServerAverage; } else { - DEBUG_ONLY( method = wxString::Format(wxT("Kad file estimate used Kad avg(%u)"), nKadAverage); ) + DEBUG_ONLY( method = CFormat(wxT("Kad file estimate used Kad avg(%u)")) % nKadAverage; ) } if( nKadAverage < 108 ) { @@ -266,7 +266,8 @@ float CPrefs::StatsGetKadV8Ratio() uint32_t nV8Contacts = 0; uint32_t nNonV8Contacts = 0; CKademlia::GetRoutingZone()->GetNumContacts(nV8Contacts, nNonV8Contacts, 8); - AddDebugLogLineN(logKadRouting, wxString::Format(wxT("Counted Kad V8 Contacts: %u out of %u in routing table. FirewalledRatios: UDP - %.02f%% | TCP - %.02f%%"), nV8Contacts, nNonV8Contacts + nV8Contacts, StatsGetFirewalledRatio(true) * 100, StatsGetFirewalledRatio(false) * 100)); + AddDebugLogLineN(logKadRouting, CFormat(wxT("Counted Kad V8 Contacts: %u out of %u in routing table. FirewalledRatios: UDP - %.02f%% | TCP - %.02f%%")) + % nV8Contacts % (nNonV8Contacts + nV8Contacts) % (StatsGetFirewalledRatio(true) * 100) % (StatsGetFirewalledRatio(false) * 100)); if (nV8Contacts > 0) { m_statsKadV8Ratio = ((float)nV8Contacts / (float)(nV8Contacts + nNonV8Contacts)); } else { @@ -285,12 +286,12 @@ void CPrefs::SetExternKadPort(uint16_t port, uint32_t fromIP) } } m_externPortIPs.push_back(fromIP); - AddDebugLogLineN(logKadPrefs, wxString::Format(wxT("Received possible external Kad port %u from "), port) + KadIPToString(fromIP)); + AddDebugLogLineN(logKadPrefs, CFormat(wxT("Received possible external Kad port %u from %s")) % port % KadIPToString(fromIP)); // if 2 out of 3 tries result in the same external port it's fine, otherwise consider it unreliable for (unsigned i = 0; i < m_externPorts.size(); i++) { if (m_externPorts[i] == port) { m_externKadPort = port; - AddDebugLogLineN(logKadPrefs, wxString::Format(wxT("Set external Kad port to %u"), port)); + AddDebugLogLineN(logKadPrefs, CFormat(wxT("Set external Kad port to %u")) % port); while (m_externPortIPs.size() < EXTERNAL_PORT_ASKIPS) { // add empty entries so we know the check has finished even if we asked less than max IPs m_externPortIPs.push_back(0); diff --git a/src/kademlia/kademlia/Search.cpp b/src/kademlia/kademlia/Search.cpp index 671d866e..19874262 100644 --- a/src/kademlia/kademlia/Search.cpp +++ b/src/kademlia/kademlia/Search.cpp @@ -266,7 +266,7 @@ void CSearch::JumpStart() if (lookupCloserNodes) { while (it != m_tried.end()) { if (m_responded.count(it->first) > 0) { - AddDebugLogLineN(logKadSearch, wxString::Format(wxT("Best %d nodes for lookup (id=%x) were unreachable or dead, reasking closest for more"), KADEMLIA_FIND_VALUE, GetSearchID())); + AddDebugLogLineN(logKadSearch, CFormat(wxT("Best %d nodes for lookup (id=%x) were unreachable or dead, reasking closest for more")) % KADEMLIA_FIND_VALUE % GetSearchID()); SendFindValue(it->second, true); return; } @@ -838,7 +838,7 @@ void CSearch::StorePacket() AddDebugLogLineN(logKadSearch, wxT("Search request type: Node")); break; default: - AddDebugLogLineN(logKadSearch, wxString::Format(wxT("Search result type: Unknown (%i)"),m_type)); + AddDebugLogLineN(logKadSearch, CFormat(wxT("Search result type: Unknown (%i)")) % m_type); break; } } @@ -911,7 +911,7 @@ void CSearch::ProcessResultFile(const CUInt128& answer, TagPtrList *info) case 4: case 5: case 6: - AddDebugLogLineN(logKadSearch, wxString::Format(wxT("Trying to add a source type %i, ip "), type) + KadIPPortToString(ip, udp)); + AddDebugLogLineN(logKadSearch, CFormat(wxT("Trying to add a source type %i, ip %s")) % type % KadIPPortToString(ip, udp)); m_answers++; theApp->downloadqueue->KademliaSearchFile(m_searchID, &answer, &buddy, type, ip, tcp, udp, buddyip, buddyport, byCryptOptions); break; @@ -1043,7 +1043,7 @@ void CSearch::ProcessResultKeyword(const CUInt128& answer, TagPtrList *info) uint32_t differentNames = (publishInfo & 0xFF000000) >> 24; uint32_t publishersKnown = (publishInfo & 0x00FF0000) >> 16; uint32_t trustValue = publishInfo & 0x0000FFFF; - AddDebugLogLineN(logKadSearch, wxString::Format(wxT("Received PublishInfo Tag: %u different names, %u publishers, %.2f trustvalue"), differentNames, publishersKnown, (double)trustValue/ 100.0)); + AddDebugLogLineN(logKadSearch, CFormat(wxT("Received PublishInfo Tag: %u different names, %u publishers, %.2f trustvalue")) % differentNames % publishersKnown % ((double)trustValue/ 100.0)); #endif } } @@ -1249,7 +1249,7 @@ void CSearch::PreparePacketForTags(CMemFile *bio, CKnownFile *file) if (pTag->IsInt() && pTag->GetInt() == 0) { continue; } - wxString szKadTagName = wxString::Format(wxT("%c"),pTag->GetNameID()); + wxString szKadTagName = CFormat(wxT("%c")) % pTag->GetNameID(); if (pTag->IsStr()) { taglist.push_back(new CTagString(szKadTagName, pTag->GetStr())); } else { diff --git a/src/kademlia/kademlia/UDPFirewallTester.cpp b/src/kademlia/kademlia/UDPFirewallTester.cpp index 90349986..d66b7880 100644 --- a/src/kademlia/kademlia/UDPFirewallTester.cpp +++ b/src/kademlia/kademlia/UDPFirewallTester.cpp @@ -100,7 +100,7 @@ void CUDPFirewallTester::SetUDPFWCheckResult(bool succeeded, bool testCancelled, // Because a proper forwarded intern port is more reliable to stay open than an extern port set by the NAT, we prefer // intern ports and change the setting. CKademlia::GetPrefs()->SetUseExternKadPort(false); - AddDebugLogLineN(logKadUdpFwTester, wxString::Format(wxT("Corrected UDP firewall result: Using open internal (%u) instead of open external port"), incomingPort)); + AddDebugLogLineN(logKadUdpFwTester, CFormat(wxT("Corrected UDP firewall result: Using open internal (%u) instead of open external port")) % incomingPort); theApp->ShowConnectionState(); return; } else if (it->answered) { diff --git a/src/kademlia/net/KademliaUDPListener.cpp b/src/kademlia/net/KademliaUDPListener.cpp index 0c9f68d2..8cf0d09c 100644 --- a/src/kademlia/net/KademliaUDPListener.cpp +++ b/src/kademlia/net/KademliaUDPListener.cpp @@ -77,14 +77,14 @@ there client on the eMule forum.. #define CHECK_PACKET_SIZE(OP, SIZE) \ if (lenPacket OP (uint32_t)(SIZE)) \ - throw wxString::Format(wxT("***NOTE: Received wrong size (%u) packet in "), lenPacket) + wxString::FromAscii(__FUNCTION__) + throw wxString(CFormat(wxT("***NOTE: Received wrong size (%u) packet in %s")) % lenPacket % wxString::FromAscii(__FUNCTION__)) #define CHECK_PACKET_MIN_SIZE(SIZE) CHECK_PACKET_SIZE(<, SIZE) #define CHECK_PACKET_EXACT_SIZE(SIZE) CHECK_PACKET_SIZE(!=, SIZE) #define CHECK_TRACKED_PACKET(OPCODE) \ if (!IsOnOutTrackList(ip, OPCODE)) \ - throw wxString::Format(wxT("***NOTE: Received unrequested response packet, size (%u) in "), lenPacket) + wxString::FromAscii(__FUNCTION__) + throw wxString(CFormat(wxT("***NOTE: Received unrequested response packet, size (%u) in %s")) % lenPacket % wxString::FromAscii(__FUNCTION__)) //////////////////////////////////////// @@ -148,7 +148,7 @@ void CKademliaUDPListener::SendMyDetails(uint8_t opcode, uint32_t ip, uint16_t p } if (kadVersion >= 6) { if (cryptTargetID == NULL || *cryptTargetID == 0) { - AddDebugLogLineN(logClientKadUDP, wxT("Sending hello response to crypt enabled Kad Node which provided an empty NodeID: ") + KadIPToString(ip) + wxString::Format(wxT(" (%u)"), kadVersion)); + AddDebugLogLineN(logClientKadUDP, CFormat(wxT("Sending hello response to crypt enabled Kad Node which provided an empty NodeID: %s (%u)")) % KadIPToString(ip) % kadVersion); SendPacket(packetdata, opcode, ip, port, targetKey, NULL); } else { SendPacket(packetdata, opcode, ip, port, targetKey, cryptTargetID); @@ -367,7 +367,7 @@ void CKademliaUDPListener::ProcessPacket(const uint8_t* data, uint32_t lenData, break; default: { - throw wxString::Format(wxT("Unknown opcode %02x on CKademliaUDPListener::ProcessPacket()"), opcode); + throw wxString(CFormat(wxT("Unknown opcode %02x on CKademliaUDPListener::ProcessPacket()")) % opcode); } } } @@ -387,7 +387,7 @@ bool CKademliaUDPListener::AddContact2(const uint8_t *data, uint32_t lenData, ui uint16_t tport = bio.ReadUInt16(); uint8_t version = bio.ReadUInt8(); if (version == 0) { - throw wxString::Format(wxT("***NOTE: Received invalid Kademlia2 version (%u) in "), version) + wxString::FromAscii(__FUNCTION__); + throw wxString(CFormat(wxT("***NOTE: Received invalid Kademlia2 version (%u) in %s")) % version % wxString::FromAscii(__FUNCTION__)); } if (outVersion != NULL) { *outVersion = version; @@ -530,7 +530,7 @@ void CKademliaUDPListener::Process2HelloRequest(const uint8_t *packetData, uint3 wxASSERT(contactVersion >= 2); #ifdef __DEBUG__ if (dbgOldUDPPort != port) { - AddDebugLogLineN(logClientKadUDP, wxT("KadContact ") + KadIPToString(ip) + wxString::Format(wxT(" uses his internal (%u) instead external (%u) UDP Port"), port, dbgOldUDPPort)); + AddDebugLogLineN(logClientKadUDP, CFormat(wxT("KadContact %s uses his internal (%u) instead external (%u) UDP Port")) % KadIPToString(ip) % port % dbgOldUDPPort); } #endif @@ -646,7 +646,7 @@ void CKademliaUDPListener::ProcessKademlia2Request(const uint8_t *packetData, ui uint8_t type = bio.ReadUInt8(); type &= 0x1F; if (type == 0) { - throw wxString::Format(wxT("***NOTE: Received wrong type (0x%02x) in "), type) + wxString::FromAscii(__FUNCTION__); + throw wxString(CFormat(wxT("***NOTE: Received wrong type (0x%02x) in %s")) % type % wxString::FromAscii(__FUNCTION__)); } // This is the target node trying to be found. @@ -679,7 +679,7 @@ void CKademliaUDPListener::ProcessKademlia2Request(const uint8_t *packetData, ui packetdata.WriteUInt8(c->GetVersion()); //<- Kad Version inserted to allow backward compatibility. } - DebugSendF(wxString::Format(wxT("Kad2Res (count=%u)"), count), ip, port); + DebugSendF(CFormat(wxT("Kad2Res (count=%u)")) % count, ip, port); SendPacket(packetdata, KADEMLIA2_RES, ip, port, senderKey, NULL); } } @@ -758,10 +758,10 @@ void CKademliaUDPListener::ProcessKademlia2Response(const uint8_t *packetData, u #ifdef __DEBUG__ if (ignoredCount > 0) { - AddDebugLogLineN(logKadRouting, wxString::Format(wxT("Ignored %u bad "), ignoredCount) + (ignoredCount > 1 ? wxT("contacts") : wxT("contact")) + wxT(" in routing answer from ") + KadIPToString(ip)); + AddDebugLogLineN(logKadRouting, CFormat(wxT("Ignored %u bad %s in routing answer from %s")) % ignoredCount % (ignoredCount > 1 ? wxT("contacts") : wxT("contact")) % KadIPToString(ip)); } if (kad1Count > 0) { - AddDebugLogLineN(logKadRouting, wxString::Format(wxT("Ignored %u kad1 "), kad1Count) + (kad1Count > 1 ? wxT("contacts") : wxT("contact")) + wxT(" in routing answer from ") + KadIPToString(ip)); + AddDebugLogLineN(logKadRouting, CFormat(wxT("Ignored %u kad1 %s in routing answer from %s")) % kad1Count % (kad1Count > 1 ? wxT("contacts") : wxT("contact")) % KadIPToString(ip)); } #endif @@ -839,7 +839,7 @@ SSearchTerm* CKademliaUDPListener::CreateSearchExpressionTree(CMemFile& bio, int } return pSearchTerm; } else { - AddDebugLogLineN(logKadSearch, wxString::Format(wxT("*** Unknown boolean search operator 0x%02x (CreateSearchExpressionTree)"), boolop)); + AddDebugLogLineN(logKadSearch, CFormat(wxT("*** Unknown boolean search operator 0x%02x (CreateSearchExpressionTree)")) % boolop); return NULL; } } else if (op == 0x01) { // String @@ -897,7 +897,7 @@ SSearchTerm* CKademliaUDPListener::CreateSearchExpressionTree(CMemFile& bio, int // read integer operator uint8_t mmop = bio.ReadUInt8(); if (mmop >= itemsof(_aOps)){ - AddDebugLogLineN(logKadSearch, wxString::Format(wxT("*** Unknown integer search op=0x%02x (CreateSearchExpressionTree)"), mmop)); + AddDebugLogLineN(logKadSearch, CFormat(wxT("*** Unknown integer search op=0x%02x (CreateSearchExpressionTree)")) % mmop); return NULL; } @@ -910,7 +910,7 @@ SSearchTerm* CKademliaUDPListener::CreateSearchExpressionTree(CMemFile& bio, int return pSearchTerm; } else { - AddDebugLogLineN(logKadSearch, wxString::Format(wxT("*** Unknown search op=0x%02x (CreateSearchExpressionTree)"), op)); + AddDebugLogLineN(logKadSearch, CFormat(wxT("*** Unknown search op=0x%02x (CreateSearchExpressionTree)")) % op); return NULL; } } @@ -1060,7 +1060,7 @@ void CKademliaUDPListener::Process2PublishKeyRequest(const uint8_t *packetData, } else { entry->m_uSize = tag->GetInt(); } - DEBUG_ONLY( strInfo += wxString::Format(wxT(" Size=%") WXLONGLONGFMTSPEC wxT("u"), entry->m_uSize); ) + DEBUG_ONLY( strInfo += CFormat(wxT(" Size=%u")) % entry->m_uSize; ) } delete tag; // tag is no longer stored, but membervar is used } else { @@ -1157,7 +1157,7 @@ void CKademliaUDPListener::Process2PublishSourceRequest(const uint8_t *packetDat } else { entry->m_uSize = tag->GetInt(); } - DEBUG_ONLY( strInfo += wxString::Format(wxT(" Size=%") WXLONGLONGFMTSPEC wxT("u"), entry->m_uSize); ) + DEBUG_ONLY( strInfo += CFormat(wxT(" Size=%u")) % entry->m_uSize; ) } delete tag; } else if (!tag->GetName().Cmp(TAG_SOURCEPORT)) { @@ -1244,7 +1244,7 @@ void CKademliaUDPListener::ProcessPublishResponse(const uint8_t *packetData, uin void CKademliaUDPListener::Process2PublishResponse(const uint8_t *packetData, uint32_t lenPacket, uint32_t ip, uint16_t port, const CKadUDPKey& senderKey) { if (!IsOnOutTrackList(ip, KADEMLIA2_PUBLISH_KEY_REQ) && !IsOnOutTrackList(ip, KADEMLIA2_PUBLISH_SOURCE_REQ) && !IsOnOutTrackList(ip, KADEMLIA2_PUBLISH_NOTES_REQ)) { - throw wxString::Format(wxT("***NOTE: Received unrequested response packet, size (%u) in "), lenPacket) + wxString::FromAscii(__FUNCTION__); + throw (CFormat(wxT("***NOTE: Received unrequested response packet, size (%u) in %s")) % lenPacket % wxString::FromAscii(__FUNCTION__)); } CMemFile bio(packetData, lenPacket); CUInt128 file = bio.ReadUInt128(); @@ -1583,13 +1583,14 @@ void CKademliaUDPListener::Process2FirewallUDP(const uint8_t *packetData, uint32 uint8_t errorCode = PeekUInt8(packetData); uint16_t incomingPort = PeekUInt16(packetData + 1); if ((incomingPort != CKademlia::GetPrefs()->GetExternalKadPort() && incomingPort != CKademlia::GetPrefs()->GetInternKadPort()) || incomingPort == 0) { - AddDebugLogLineN(logClientKadUDP, wxString::Format(wxT("Received UDP FirewallCheck on unexpected incoming port %u (") + KadIPToString(ip) + wxT(")"), incomingPort)); + AddDebugLogLineN(logClientKadUDP, CFormat(wxT("Received UDP FirewallCheck on unexpected incoming port %u from %s")) % incomingPort % KadIPToString(ip)); CUDPFirewallTester::SetUDPFWCheckResult(false, true, ip, 0); } else if (errorCode == 0) { - AddDebugLogLineN(logClientKadUDP, wxString::Format(wxT("Received UDP FirewallCheck packet from ") + KadIPToString(ip) + wxT(" with incoming port %u"), incomingPort)); + AddDebugLogLineN(logClientKadUDP, CFormat(wxT("Received UDP FirewallCheck packet from %s with incoming port %u")) % KadIPToString(ip) % incomingPort); CUDPFirewallTester::SetUDPFWCheckResult(true, false, ip, incomingPort); } else { - AddDebugLogLineN(logClientKadUDP, wxString::Format(wxT("Received UDP FirewallCheck packet from ") + KadIPToString(ip) + wxT(" with incoming port %u with remote errorcode %u - ignoring result"), incomingPort, errorCode)); + AddDebugLogLineN(logClientKadUDP, CFormat(wxT("Received UDP FirewallCheck packet from %s with incoming port %u with remote errorcode %u - ignoring result")) + % KadIPToString(ip) % incomingPort % errorCode); CUDPFirewallTester::SetUDPFWCheckResult(false, true, ip, 0); } } diff --git a/src/kademlia/net/PacketTracking.cpp b/src/kademlia/net/PacketTracking.cpp index a0108b38..6dd52cb0 100644 --- a/src/kademlia/net/PacketTracking.cpp +++ b/src/kademlia/net/PacketTracking.cpp @@ -211,14 +211,14 @@ bool CPacketTracking::InTrackListIsAllowedPacket(uint32_t ip, uint8_t opcode, bo if (it->m_count > allowedPacketsPerMinute * 5) { // this is so far above the limit that it has to be an intentional flood / misuse in any case // so we take the next higher punishment and ban the IP - AddDebugLogLineN(logKadPacketTracking, wxString::Format(wxT("Massive request flood detected for opcode 0x%X (0x%X) from IP "), opcode, dbgOrgOpcode) + KadIPToString(ip) + wxT(" - Banning IP")); + AddDebugLogLineN(logKadPacketTracking, CFormat(wxT("Massive request flood detected for opcode 0x%X (0x%X) from IP %s - Banning IP")) % opcode % dbgOrgOpcode % KadIPToString(ip)); theApp->clientlist->AddBannedClient(wxUINT32_SWAP_ALWAYS(ip)); return false; // drop packet } else if (it->m_count > allowedPacketsPerMinute) { // over the limit, drop the packet but do nothing else if (!it->m_dbgLogged) { it->m_dbgLogged = true; - AddDebugLogLineN(logKadPacketTracking, wxString::Format(wxT("Request flood detected for opcode 0x%X (0x%X) from IP "), opcode, dbgOrgOpcode) + KadIPToString(ip) + wxT(" - Dropping packets with this opcode")); + AddDebugLogLineN(logKadPacketTracking, CFormat(wxT("Request flood detected for opcode 0x%X (0x%X) from IP %s - Dropping packets with this opcode")) % opcode % dbgOrgOpcode % KadIPToString(ip)); } return false; // drop packet } else { @@ -252,7 +252,7 @@ void CPacketTracking::InTrackListCleanup() m_mapTrackPacketsIn.erase(it2); } } - AddDebugLogLineN(logKadPacketTracking, wxString::Format(wxT("Cleaned up Kad Incoming Requests Tracklist, entries before: %u, after %u"), dbgOldSize, m_mapTrackPacketsIn.size())); + AddDebugLogLineN(logKadPacketTracking, CFormat(wxT("Cleaned up Kad Incoming Requests Tracklist, entries before: %u, after %u")) % dbgOldSize % m_mapTrackPacketsIn.size()); } void CPacketTracking::AddLegacyChallenge(const CUInt128& contactID, const CUInt128& challengeID, uint32_t ip, uint8_t opcode) diff --git a/src/kademlia/routing/RoutingZone.cpp b/src/kademlia/routing/RoutingZone.cpp index 6f0bd77b..1edeb7b9 100644 --- a/src/kademlia/routing/RoutingZone.cpp +++ b/src/kademlia/routing/RoutingZone.cpp @@ -207,10 +207,10 @@ void CRoutingZone::ReadFile(const wxString& specialNodesdat) } } file.Close(); - AddLogLineM(false, wxString::Format(wxPLURAL("Read %u Kad contact", "Read %u Kad contacts", validContacts), validContacts)); + AddLogLineN(CFormat(wxPLURAL("Read %u Kad contact", "Read %u Kad contacts", validContacts)) % validContacts); #ifdef __DEBUG__ if (kad1Count > 0) { - AddDebugLogLineN(logKadRouting, wxString::Format(wxT("Ignored %u kad1 "), kad1Count) + (kad1Count > 1 ? wxT("contacts"): wxT("contact")) + wxT(" in nodes.dat file.")); + AddDebugLogLineN(logKadRouting, CFormat(wxT("Ignored %u kad1 %s in nodes.dat file.")) % kad1Count % (kad1Count > 1 ? wxT("contacts"): wxT("contact"))); } #endif if (!doHaveVerifiedContacts) { @@ -282,8 +282,8 @@ void CRoutingZone::ReadBootstrapNodesDat(CFileDataIO& file) } numContacts--; } - AddLogLineM(false, wxString::Format(wxPLURAL("Read %u Kad contact", "Read %u Kad contacts", CKademlia::s_bootstrapList.size()), CKademlia::s_bootstrapList.size())); - AddDebugLogLineN(logKadRouting, wxString::Format(wxT("Loaded Bootstrap nodes.dat, selected %u out of %u valid contacts"), CKademlia::s_bootstrapList.size(), validContacts)); + AddLogLineN(CFormat(wxPLURAL("Read %u Kad contact", "Read %u Kad contacts", CKademlia::s_bootstrapList.size())) % CKademlia::s_bootstrapList.size()); + AddDebugLogLineN(logKadRouting, CFormat(wxT("Loaded Bootstrap nodes.dat, selected %u out of %u valid contacts")) % CKademlia::s_bootstrapList.size() % validContacts); } if (CKademlia::s_bootstrapList.size() == 0) { AddLogLineM(true, _("No contacts found, please bootstrap, or download a nodes.dat file.")); @@ -304,7 +304,7 @@ void CRoutingZone::WriteFile() ContactList::size_type numContacts = contacts.size(); numContacts = std::min(numContacts, CONTACT_FILE_LIMIT); // safety precaution, should not be above if (numContacts < 25) { - AddLogLineM(false, wxString::Format(wxPLURAL("Only %d Kad contact available, nodes.dat not written", "Only %d Kad contacts available, nodes.dat not written", numContacts), numContacts)); + AddLogLineN(CFormat(wxPLURAL("Only %d Kad contact available, nodes.dat not written", "Only %d Kad contacts available, nodes.dat not written", numContacts)) % numContacts); return; } try { @@ -334,7 +334,7 @@ void CRoutingZone::WriteFile() file.WriteUInt8(c->IsIPVerified() ? 1 : 0); } } - AddLogLineM(false, wxString::Format(wxPLURAL("Wrote %d Kad contact", "Wrote %d Kad contacts", count), count)); + AddLogLineN(CFormat(wxPLURAL("Wrote %d Kad contact", "Wrote %d Kad contacts", count)) % count); } catch (const CIOFailureException& e) { AddDebugLogLineC(logKadRouting, wxT("IO failure in CRoutingZone::writeFile: ") + e.what()); } @@ -379,7 +379,7 @@ void CRoutingZone::WriteBootstrapFile() file.WriteUInt8(contact->GetVersion()); } file.Close(); - AddDebugLogLineN(logKadRouting, wxString::Format(wxT("Wrote %u contacts to bootstrap file."), mapContacts.size())); + AddDebugLogLineN(logKadRouting, CFormat(wxT("Wrote %u contacts to bootstrap file.")) % mapContacts.size()); } else { AddDebugLogLineC(logKadRouting, wxT("Unable to store Kad file: ") + m_filename); } @@ -455,9 +455,10 @@ bool CRoutingZone::Add(CContact *contact, bool& update, bool& outIpVerified) wxASSERT(!contact->IsIPVerified()); // legacy kad2 nodes should be unable to verify their IP on a HELLO outIpVerified = contactUpdate->IsIPVerified(); m_bin->SetAlive(contactUpdate); - AddDebugLogLineN(logKadRouting, wxString::Format(wxT("Updated kad contact refreshtimer only for legacy kad2 contact (") + KadIPToString(contactUpdate->GetIPAddress()) + wxT(", %u)"), contactUpdate->GetVersion())); + AddDebugLogLineN(logKadRouting, CFormat(wxT("Updated kad contact refreshtimer only for legacy kad2 contact (%s, %u)")) % KadIPToString(contactUpdate->GetIPAddress()) % contactUpdate->GetVersion()); } else { - AddDebugLogLineN(logKadRouting, wxString::Format(wxT("Rejected value update for legacy kad2 contact (") + KadIPToString(contactUpdate->GetIPAddress()) + wxT(" -> ") + KadIPToString(contact->GetIPAddress()) + wxT(", %u -> %u)"), contactUpdate->GetVersion(), contact->GetVersion())); + AddDebugLogLineN(logKadRouting, CFormat(wxT("Rejected value update for legacy kad2 contact (%s -> %s, %u -> %u)")) + % KadIPToString(contactUpdate->GetIPAddress()) % KadIPToString(contact->GetIPAddress()) % contactUpdate->GetVersion() % contact->GetVersion()); update = false; } } else { @@ -474,7 +475,8 @@ bool CRoutingZone::Add(CContact *contact, bool& update, bool& outIpVerified) if (contactUpdate->GetVersion() >= 1 && contactUpdate->GetVersion() < 6) { wxASSERT(!contactUpdate->GetReceivedHelloPacket()); - AddDebugLogLineN(logKadRouting, wxString::Format(wxT("Accepted update for legacy kad2 contact, because of first HELLO (") + KadIPToString(contactUpdate->GetIPAddress()) + wxT(" -> ") + KadIPToString(contact->GetIPAddress()) + wxT(", %u -> %u)"), contactUpdate->GetVersion(), contact->GetVersion())); + AddDebugLogLineN(logKadRouting, CFormat(wxT("Accepted update for legacy kad2 contact, because of first HELLO (%s -> %s, %u -> %u)")) + % KadIPToString(contactUpdate->GetIPAddress()) % KadIPToString(contact->GetIPAddress()) % contactUpdate->GetVersion() % contact->GetVersion()); } #endif // All other nodes (Kad1, Kad2 > 0.49a with UDPKey checked or not set, first hello updates) are allowed to do full updates diff --git a/src/kademlia/utils/UInt128.cpp b/src/kademlia/utils/UInt128.cpp index c7c3c8ca..77807257 100644 --- a/src/kademlia/utils/UInt128.cpp +++ b/src/kademlia/utils/UInt128.cpp @@ -41,6 +41,7 @@ there client on the eMule forum.. #include "UInt128.h" #include "../../ArchSpecific.h" +#include // Needed for CFormat //////////////////////////////////////// @@ -79,8 +80,9 @@ wxString CUInt128::ToHexString() const { wxString str; - for (int i = 0; i < 4; ++i) - str.Append(wxString::Format(wxT("%08X"), m_data[i])); + for (int i = 0; i < 4; ++i) { + str.Append(CFormat(wxT("%08X")) % m_data[i]); + } return str; } @@ -88,11 +90,12 @@ wxString CUInt128::ToHexString() const wxString CUInt128::ToBinaryString(bool trim) const { wxString str; + str.Alloc(128); int b; for (int i = 0; i < 128; ++i) { b = GetBitNumber(i); if ((!trim) || (b != 0)) { - str.Append(wxString::Format(wxT("%d"), b)); + str.Append(b ? wxT("1") : wxT("0")); trim = false; } } diff --git a/src/libs/common/FileFunctions.cpp b/src/libs/common/FileFunctions.cpp index 5bf59b6b..fbf19f37 100644 --- a/src/libs/common/FileFunctions.cpp +++ b/src/libs/common/FileFunctions.cpp @@ -196,7 +196,7 @@ bool UnpackGZipFile(const wxString& file) while (int bytesRead = gzread(inputFile, buffer, sizeof(buffer))) { if (bytesRead > 0) { - // AddDebugLogLineN( logFileIO, wxString::Format(wxT("Read %u bytes"), bytesRead) ); + // AddDebugLogLineN(logFileIO, CFormat(wxT("Read %u bytes")) % bytesRead); target.Write(buffer, bytesRead); } else if (bytesRead < 0) { wxString errString; @@ -229,7 +229,7 @@ bool UnpackGZipFile(const wxString& file) while (!inputStream.Eof()) { inputStream.Read(buffer, sizeof(buffer)); - // AddDebugLogLineN( logFileIO, wxString::Format(wxT("Read %u bytes"),inputStream.LastRead()) ); + // AddDebugLogLineN(logFileIO, CFormat(wxT("Read %u bytes")) % inputStream.LastRead()); if (inputStream.LastRead()) { target.Write(buffer, inputStream.LastRead()); } else { diff --git a/src/libs/common/Format.cpp b/src/libs/common/Format.cpp index 4e1c3e68..4663eb62 100644 --- a/src/libs/common/Format.cpp +++ b/src/libs/common/Format.cpp @@ -96,7 +96,7 @@ bool isTypeChar(wxChar c) case wxT('E'): // Scientific notation (mantise/exponent) using E character case wxT('g'): // Use shorter %e or %f case wxT('G'): // Use shorter %E or %f - case wxT('p'): // Not supported, still needs to be caught though + case wxT('p'): // Pointer case wxT('n'): // Not supported, still needs to be caught though return true; } @@ -384,9 +384,13 @@ CFormat& CFormat::operator%(wxChar value) CFormat& CFormat::operator%(signed long long value) { - wxString field = GetIntegerField(WXLONGLONGFMTSPEC wxT("i")); - if (!field.IsEmpty()) { - SetCurrentField(wxString::Format(field, value)); + if (GetCurrentField().EndsWith(wxT("c"))) { + SetCurrentField(wxString::Format(GetCurrentField(), (wxChar)value)); + } else { + wxString field = GetIntegerField(WXLONGLONGFMTSPEC wxT("i")); + if (!field.IsEmpty()) { + SetCurrentField(wxString::Format(field, value)); + } } return *this; @@ -395,9 +399,13 @@ CFormat& CFormat::operator%(signed long long value) CFormat& CFormat::operator%(unsigned long long value) { - wxString field = GetIntegerField(WXLONGLONGFMTSPEC wxT("u")); - if (!field.IsEmpty()) { - SetCurrentField(wxString::Format(field, value)); + if (GetCurrentField().EndsWith(wxT("c"))) { + SetCurrentField(wxString::Format(GetCurrentField(), (wxChar)value)); + } else { + wxString field = GetIntegerField(WXLONGLONGFMTSPEC wxT("u")); + if (!field.IsEmpty()) { + SetCurrentField(wxString::Format(field, value)); + } } return *this; diff --git a/src/libs/common/Format.h b/src/libs/common/Format.h index c94d3b2e..10c8f0fe 100644 --- a/src/libs/common/Format.h +++ b/src/libs/common/Format.h @@ -68,7 +68,6 @@ protected: * * CFormat lacks the following capabilities: * * The "*" width-modifier, because only one argument is fed at a time. - * * The "p" type, could be implemented using void* or templates. * * The "n" type, just unsafe, wont be implemented. * * The Long Double type, which is extremly slow and shouldn't be used. * diff --git a/src/libs/common/MD5Sum.cpp b/src/libs/common/MD5Sum.cpp index 1574897b..1e539f46 100644 --- a/src/libs/common/MD5Sum.cpp +++ b/src/libs/common/MD5Sum.cpp @@ -24,6 +24,7 @@ #include "StringFunctions.h" +#include "Format.h" // Needed for CFormat #include "MD5Sum.h" // Interface declarations. @@ -69,7 +70,7 @@ wxString MD5Sum::Calculate(const uint8* buffer, size_t len) m_sHash.Clear(); for (int i = 0; i < 16; ++i) { wxString sT; - sT = wxString::Format(wxT("%02x"), digest[i]); + sT = CFormat(wxT("%02x")) % digest[i]; m_sHash += sT; } diff --git a/src/libs/common/MuleDebug.cpp b/src/libs/common/MuleDebug.cpp index 6de21718..ac7c6abc 100644 --- a/src/libs/common/MuleDebug.cpp +++ b/src/libs/common/MuleDebug.cpp @@ -31,6 +31,7 @@ #include "MuleDebug.h" // Interface declaration #include "StringFunctions.h" // Needed for unicode2char +#include "Format.h" // Needed for CFormat #ifdef HAVE_EXECINFO # include @@ -125,7 +126,7 @@ public: void OnStackFrame(const wxStackFrame& frame) { - wxString btLine = wxString::Format(wxT("[%u] "), frame.GetLevel()); + wxString btLine = CFormat(wxT("[%u] ")) % frame.GetLevel(); wxString filename = frame.GetName(); if (!filename.IsEmpty()) { @@ -137,7 +138,7 @@ public: #endif + wxT(")"); } else { - btLine += wxString::Format(wxT("0x%lx"), frame.GetAddress()); + btLine += CFormat(wxT("%p")) % frame.GetAddress(); } if (frame.HasSourceLocation()) { @@ -147,7 +148,7 @@ public: #else frame.GetFileName().AfterLast(wxT('/')) #endif - + wxString::Format(wxT(":%u"),frame.GetLine()); + + CFormat(wxT(":%u")) % frame.GetLine(); } else { btLine += wxT(" (Unknown file/line)"); } @@ -401,7 +402,7 @@ wxString get_backtrace(unsigned n) funcname[i] = demangled; } out.Insert(wxConvCurrent->cMB2WX(s_function_name),i*2); - out.Insert(wxConvCurrent->cMB2WX(s_file_name) + wxString::Format(wxT(":%u"), s_line_number),i*2+1); + out.Insert(wxConvCurrent->cMB2WX(s_file_name) + (CFormat(wxT(":%u")) % s_line_number),i*2+1); } else { out.Insert(wxT("??"),i*2); out.Insert(wxT("??"),i*2+1); diff --git a/src/libs/ec/cpp/ECSpecialTags.cpp b/src/libs/ec/cpp/ECSpecialTags.cpp index a7766ea0..bc10f331 100644 --- a/src/libs/ec/cpp/ECSpecialTags.cpp +++ b/src/libs/ec/cpp/ECSpecialTags.cpp @@ -113,7 +113,7 @@ void FormatValue(CFormat& format, const CECTag* tag) format = format % tag->GetInt(); break; case EC_VALUE_ISTRING: - format = format % (wxString::Format(wxT("%") WXLONGLONGFMTSPEC wxT("u"), tag->GetInt()) + extra); + format = format % (CFormat(wxT("%u")) % tag->GetInt() + extra); break; case EC_VALUE_BYTES: format = format % (CastItoXBytes(tag->GetInt()) + extra); diff --git a/src/webserver/src/WebServer.cpp b/src/webserver/src/WebServer.cpp index cf822e9a..b16d65d1 100644 --- a/src/webserver/src/WebServer.cpp +++ b/src/webserver/src/WebServer.cpp @@ -1334,7 +1334,7 @@ CDynStatisticImage::CDynStatisticImage(int height, bool scale1024, CStatsData *d m_scale1024 = scale1024; // actual name doesn't matter, just make it unique - m_name = wxString::Format(wxT("dyn_%ld_stat.png"), (unsigned long int) data); + m_name = CFormat(wxT("dyn_%p_stat.png")) % data; m_num_font_w_size = 8; m_num_font_h_size = 16; @@ -1866,7 +1866,7 @@ void CScriptWebServer::ProcessURL(ThreadData Data) Print(_("Processing request [redirected]: ") + filename + wxT("\n")); session->m_vars["auto_refresh"] = (const char *)unicode2char( - wxString::Format(wxT("%d"), webInterface->m_PageRefresh)); + wxString(CFormat(wxT("%d")) % webInterface->m_PageRefresh)); session->m_vars["content_type"] = "text/html"; wxString req_file(wxFileName(m_wwwroot, filename).GetFullPath()); -- 2.11.4.GIT