void CamuleDlg::Add_Skin_Icon( const wxString &iconName, const wxBitmap &stdIcon, bool useSkins) { wxImage new_image; if (useSkins) { wxFFileInputStream in(m_skinFileName.GetFullPath()); wxZipInputStream zip(in); ZipCatalog::iterator it = cat.find(wxZipEntry::GetInternalName(iconName + wxT(".png"))); if ( it != cat.end() ) { zip.OpenEntry(*it->second); if ( !new_image.LoadFile(zip,wxBITMAP_TYPE_PNG) ) { AddLogLineN(wxT("Warning: Error loading icon for ") + iconName); useSkins = false; } }else { AddLogLineN(wxT("Warning: Can't load icon for ") + iconName); useSkins = false; } } wxBitmap bmp(useSkins ? new_image : stdIcon); if (iconName.StartsWith(wxT("Client_"))) { m_imagelist.Add(bmp); } else if (iconName.StartsWith(wxT("Toolbar_"))) { m_tblist.Add(bmp); } }
void CIP2Country::Update() { AddLogLineN(CFormat(_("Download new GeoIP.dat from %s")) % thePrefs::GetGeoIPUpdateUrl()); CHTTPDownloadThread *downloader = new CHTTPDownloadThread(thePrefs::GetGeoIPUpdateUrl(), m_DataBasePath + wxT(".download"), m_DataBasePath, HTTP_GeoIP, true, true); downloader->Create(); downloader->Run(); }
void CFriendList::LoadList() { CPath metfile = CPath(theApp->ConfigDir + wxT("emfriends.met")); if (!metfile.FileExists()) { return; } CFile file; try { if ( file.Open(metfile) ) { if ( file.ReadUInt8() /*header*/ == MET_HEADER ) { uint32 nRecordsNumber = file.ReadUInt32(); for (uint32 i = 0; i < nRecordsNumber; i++) { CFriend* Record = new CFriend(); Record->LoadFromFile(&file); m_FriendList.push_back(Record); Notify_ChatUpdateFriend(Record); } } } else { AddLogLineN(_("Failed to open friend list file 'emfriends.met' for reading!")); } } catch (const CInvalidPacket& e) { AddDebugLogLineC(logGeneral, wxT("Invalid entry in friend list, file may be corrupt: ") + e.what()); } catch (const CSafeIOException& e) { AddDebugLogLineC(logGeneral, wxT("IO error while reading 'emfriends.met': ") + e.what()); } }
void CamuleDlg::LaunchUrl( const wxString& url ) { wxString cmd; cmd = thePrefs::GetBrowser(); wxString tmp = url; // Pipes cause problems, so escape them tmp.Replace( wxT("|"), wxT("%7C") ); if ( !cmd.IsEmpty() ) { if (!cmd.Replace(wxT("%s"), tmp)) { // No %s found, just append the url cmd += wxT(" ") + tmp; } CTerminationProcess *p = new CTerminationProcess(cmd); if (wxExecute(cmd, wxEXEC_ASYNC, p)) { AddLogLineN(_("Launch Command: ") + cmd); return; } else { delete p; } } else { wxLaunchDefaultBrowser(tmp); return; } // Unable to execute browser. But this error message doesn't make sense, // cosidering that you _can't_ set the browser executable path... =/ wxLogError(wxT("Unable to launch browser. Please set correct browser executable path in Preferences.")); }
wxThread::ExitCode CAsyncDNS::Entry() { uint32 result = StringHosttoUint32(m_ipName); uint32 event_id = 0; void* event_data = NULL; switch (m_type) { case DNS_UDP: event_id = wxEVT_CORE_UDP_DNS_DONE; event_data = m_socket; break; case DNS_SOURCE: event_id = wxEVT_CORE_SOURCE_DNS_DONE; event_data = NULL; break; case DNS_SERVER_CONNECT: event_id = wxEVT_CORE_SERVER_DNS_DONE; event_data = m_socket; break; default: AddLogLineN(wxT("WRONG TYPE ID ON ASYNC DNS SOLVING!!!")); } if (event_id) { CMuleInternalEvent evt(event_id); evt.SetExtraLong(result); evt.SetClientData(event_data); wxPostEvent(m_handler,evt); } return NULL; }
void CIP2Country::DownloadFinished(uint32 result) { if (result == HTTP_Success) { Disable(); // download succeeded. Switch over to new database. wxString newDat = m_DataBasePath + wxT(".download"); // Try to unpack the file, might be an archive wxWCharBuffer dataBaseName = m_DataBaseName.wc_str(); const wxChar* geoip_files[] = { dataBaseName, NULL }; if (UnpackArchive(CPath(newDat), geoip_files).second == EFT_Error) { AddLogLineC(_("Download of GeoIP.dat file failed, aborting update.")); return; } if (wxFileExists(m_DataBasePath)) { if (!wxRemoveFile(m_DataBasePath)) { AddLogLineC(CFormat(_("Failed to remove %s file, aborting update.")) % m_DataBaseName); return; } } if (!wxRenameFile(newDat, m_DataBasePath)) { AddLogLineC(CFormat(_("Failed to rename %s file, aborting update.")) % m_DataBaseName); return; } Enable(); if (m_geoip) { AddLogLineN(CFormat(_("Successfully updated %s")) % m_DataBaseName); } else { AddLogLineC(_("Error updating GeoIP.dat")); } } else if (result == HTTP_Skipped) { AddLogLineN(CFormat(_("Skipped download of %s, because requested file is not newer.")) % m_DataBaseName); } else { AddLogLineC(CFormat(_("Failed to download %s from %s")) % m_DataBaseName % thePrefs::GetGeoIPUpdateUrl()); // if it failed and there is no database, turn it off if (!wxFileExists(m_DataBasePath)) { thePrefs::SetGeoIPEnabled(false); } } }
void CServerList::DownloadFinished(uint32 result) { if(result == HTTP_Success) { const CPath tempFilename = CPath(theApp->ConfigDir + wxT("server.met.download")); // curl succeeded. proceed with server.met loading LoadServerMet(tempFilename); SaveServerMet(); // So, file is loaded and merged, and also saved CPath::RemoveFile(tempFilename); AddLogLineN(CFormat(_("Finished downloading the server list from %s")) % m_URLUpdate); } else if (result == HTTP_Skipped) { AddLogLineN(CFormat(_("Skipped download of %s, because requested file is not newer.")) % wxT("server.met")); } else { AddLogLineC(CFormat(_("Failed to download %s from %s")) % wxT("server.met") % m_URLUpdate); } }
CamuleDlg::~CamuleDlg() { theApp->amuledlg = NULL; #ifdef ENABLE_IP2COUNTRY delete m_IP2Country; #endif AddLogLineN(_("aMule dialog destroyed")); }
// Check all clients that uploaded corrupted data, // and ban them if they didn't upload enough good data too. void CCorruptionBlackBox::EvaluateData() { CCBBClientMap::iterator it = m_badClients.begin(); for (; it != m_badClients.end(); ++it) { uint32 ip = it->first; uint64 bad = it->second.m_downloaded; if (!bad) { wxFAIL; // this should not happen continue; } uint64 good = 0; CCBBClientMap::iterator it2 = m_goodClients.find(ip); if (it2 != m_goodClients.end()) { good = it2->second.m_downloaded; } int nCorruptPercentage = bad * 100 / (bad + good); if (nCorruptPercentage > CBB_BANTHRESHOLD) { CUpDownClient* pEvilClient = theApp->clientlist->FindClientByIP(ip); wxString clientName; if (pEvilClient != NULL) { clientName = pEvilClient->GetClientShortInfo(); AddDebugLogLineN(logPartFile, CFormat(wxT("CorruptionBlackBox(%s): Banning: Found client which sent %d of %d corrupted data, %s")) % m_partNumber % bad % (good + bad) % pEvilClient->GetClientFullInfo()); theApp->clientlist->AddTrackClient(pEvilClient); pEvilClient->Ban(); // Identified as sender of corrupt data // Stop download right away pEvilClient->SetDownloadState(DS_BANNED); if (pEvilClient->Disconnected(wxT("Upload of corrupted data"))) { pEvilClient->Safe_Delete(); } } else { clientName = Uint32toStringIP(ip); theApp->clientlist->AddBannedClient(ip); } AddLogLineN(CFormat(_("Banned client %s for sending %s corrupt data of %s total for the file '%s'")) % clientName % CastItoXBytes(bad) % CastItoXBytes(good + bad) % m_fileName); } else { CUpDownClient* pSuspectClient = theApp->clientlist->FindClientByIP(ip); if (pSuspectClient != NULL) { AddDebugLogLineN(logPartFile, CFormat(wxT("CorruptionBlackBox(%s): Reporting: Found client which probably sent %d of %d corrupted data, but it is within the acceptable limit, %s")) % m_partNumber % bad % (good + bad) % pSuspectClient->GetClientFullInfo()); theApp->clientlist->AddTrackClient(pSuspectClient); } else { AddDebugLogLineN(logPartFile, CFormat(wxT("CorruptionBlackBox(%s): Reporting: Found client which probably sent %d of %d corrupted data, but it is within the acceptable limit, %s")) % m_partNumber % bad % (good + bad) % Uint32toStringIP(ip)); } } } }
void CMuleUDPSocket::CreateSocket() { wxCHECK_RET(!m_socket, wxT("Socket already opened.")); m_socket = new CEncryptedDatagramSocket(m_addr, wxSOCKET_NOWAIT, m_proxy); m_socket->SetClientData(this); m_socket->SetEventHandler(*theApp, m_id); m_socket->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_OUTPUT_FLAG | wxSOCKET_LOST_FLAG); m_socket->Notify(true); if (!m_socket->IsOk()) { AddDebugLogLineC(logMuleUDP, wxT("Failed to create valid ") + m_name); DestroySocket(); } else { AddLogLineN(wxString(wxT("Created ")) << m_name << wxT(" at port ") << m_addr.Service()); } }
void CFriendList::SaveList() { CFile file; if (file.Create(theApp->ConfigDir + wxT("emfriends.met"), true)) { try { file.WriteUInt8(MET_HEADER); file.WriteUInt32(m_FriendList.size()); for (FriendList::iterator it = m_FriendList.begin(); it != m_FriendList.end(); ++it) { (*it)->WriteToFile(&file); } } catch (const CIOFailureException& e) { AddDebugLogLineC(logGeneral, wxT("IO failure while saving 'emfriends.met': ") + e.what()); } } else { AddLogLineN(_("Failed to open friend list file 'emfriends.met' for writing!")); } }
void CLoggerTarget::DoLogText(const wxString &msg) { // prevent infinite recursion static bool recursion = false; if (recursion) { return; } recursion = true; // This is much simpler than manually handling all wx log-types. if (msg.StartsWith(_("ERROR: ")) || msg.StartsWith(_("WARNING: "))) { AddLogLineC(msg); } else { AddLogLineN(msg); } recursion = false; }
void CServerList::SaveStaticServers() { CTextFile file; if (!file.Open(m_staticServersConfig, CTextFile::write)) { AddLogLineN(CFormat( _("Failed to open '%s'") ) % m_staticServersConfig ); return; } for (CInternalList::const_iterator it = m_servers.begin(); it != m_servers.end(); ++it) { const CServer* server = *it; if (server->IsStaticMember()) { file.WriteLine(CFormat(wxT("%s:%u,%u,%s")) % server->GetAddress() % server->GetPort() % server->GetPreferences() % server->GetListName()); } } file.Close(); }
bool CMuleUDPSocket::SendTo(uint8_t *buffer, uint32_t length, uint32_t ip, uint16_t port) { // Just pretend that we sent the packet in order to avoid infinite loops. if (!(m_socket && m_socket->Ok())) { return true; } amuleIPV4Address addr; addr.Hostname(ip); addr.Service(port); // We better clear this flag here, status might have been changed // between the U.B.T. addition and the real sending happening later m_busy = false; bool sent = false; m_socket->SendTo(addr, buffer, length); if (m_socket->Error()) { wxSocketError error = m_socket->LastError(); if (error == wxSOCKET_WOULDBLOCK) { // Socket is busy and can't send this data right now, // so we just return not sent and set the wouldblock // flag so it gets resent when socket is ready. m_busy = true; } else { // An error which we can't handle happended, so we drop // the packet rather than risk entering an infinite loop. AddLogLineN((wxT("WARNING! ") + m_name + wxT(": Packet to ")) << Uint32_16toStringIP_Port(ip, port) << wxT(" discarded due to error (") << error << wxT(") while sending.")); sent = true; } } else { AddDebugLogLineN(logMuleUDP, (m_name + wxT(": Packet sent (")) << Uint32_16toStringIP_Port(ip, port) << wxT("): ") << length << wxT("b")); sent = true; } return sent; }
void CLoggerTarget::DoLogString(const wxChar* msg, time_t) { // prevent infinite recursion static bool recursion = false; if (recursion) { return; } recursion = true; wxCHECK_RET(msg, wxT("Log message is NULL in DoLogString!")); wxString str(msg); // This is much simpler than manually handling all wx log-types. if (str.StartsWith(_("ERROR: ")) || str.StartsWith(_("WARNING: "))) { AddLogLineC(str); } else { AddLogLineN(str); } recursion = false; }
bool CServerList::SaveServerMet() { CPath curservermet = CPath(theApp->ConfigDir + wxT("server.met")); CFile servermet(curservermet, CFile::write_safe); if (!servermet.IsOpened()) { AddLogLineN(_("Failed to save server.met!")); return false; } try { servermet.WriteUInt8(0xE0); servermet.WriteUInt32( m_servers.size() ); for ( CInternalList::const_iterator it = m_servers.begin(); it != m_servers.end(); ++it) { const CServer* const server = *it; uint16 tagcount = 12; if (!server->GetListName().IsEmpty()) { ++tagcount; } if (!server->GetDynIP().IsEmpty()) { ++tagcount; } if (!server->GetDescription().IsEmpty()) { ++tagcount; } if (server->GetConnPort() != server->GetPort()) { ++tagcount; } // For unicoded name, description, and dynip if ( !server->GetListName().IsEmpty() ) { ++tagcount; } if ( !server->GetDynIP().IsEmpty() ) { ++tagcount; } if ( !server->GetDescription().IsEmpty() ) { ++tagcount; } if (!server->GetVersion().IsEmpty()) { ++tagcount; } if (server->GetServerKeyUDP(true)) { ++tagcount; } if (server->GetServerKeyUDPIP()) { ++tagcount; } if (server->GetObfuscationPortTCP()) { ++tagcount; } if (server->GetObfuscationPortUDP()) { ++tagcount; } servermet.WriteUInt32(server->GetIP()); servermet.WriteUInt16(server->GetPort()); servermet.WriteUInt32(tagcount); if ( !server->GetListName().IsEmpty() ) { // This is BOM to keep eMule compatibility CTagString( ST_SERVERNAME, server->GetListName()).WriteTagToFile( &servermet, utf8strOptBOM); CTagString( ST_SERVERNAME, server->GetListName()).WriteTagToFile( &servermet ); } if ( !server->GetDynIP().IsEmpty() ) { // This is BOM to keep eMule compatibility CTagString( ST_DYNIP, server->GetDynIP()).WriteTagToFile( &servermet, utf8strOptBOM ); CTagString( ST_DYNIP, server->GetDynIP()).WriteTagToFile( &servermet ); } if ( !server->GetDescription().IsEmpty() ) { // This is BOM to keep eMule compatibility CTagString( ST_DESCRIPTION, server->GetDescription()).WriteTagToFile( &servermet, utf8strOptBOM ); CTagString( ST_DESCRIPTION, server->GetDescription()).WriteTagToFile( &servermet ); } if ( server->GetConnPort() != server->GetPort() ) { CTagString( ST_AUXPORTSLIST, server->GetAuxPortsList() ).WriteTagToFile( &servermet ); } CTagInt32( ST_FAIL, server->GetFailedCount() ).WriteTagToFile( &servermet ); CTagInt32( ST_PREFERENCE, server->GetPreferences() ).WriteTagToFile( &servermet ); CTagInt32( wxT("users"), server->GetUsers() ).WriteTagToFile( &servermet ); CTagInt32( wxT("files"), server->GetFiles() ).WriteTagToFile( &servermet ); CTagInt32( ST_PING, server->GetPing() ).WriteTagToFile( &servermet ); CTagInt32( ST_LASTPING, server->GetLastPingedTime()).WriteTagToFile( &servermet ); CTagInt32( ST_MAXUSERS, server->GetMaxUsers() ).WriteTagToFile( &servermet ); CTagInt32( ST_SOFTFILES, server->GetSoftFiles() ).WriteTagToFile( &servermet ); CTagInt32( ST_HARDFILES, server->GetHardFiles() ).WriteTagToFile( &servermet ); if (!server->GetVersion().IsEmpty()){ CTagString( ST_VERSION, server->GetVersion() ).WriteTagToFile( &servermet, utf8strOptBOM ); CTagString( ST_VERSION, server->GetVersion() ).WriteTagToFile( &servermet ); } CTagInt32( ST_UDPFLAGS, server->GetUDPFlags() ).WriteTagToFile( &servermet ); CTagInt32( ST_LOWIDUSERS, server->GetLowIDUsers() ).WriteTagToFile( &servermet ); if (server->GetServerKeyUDP(true)) { CTagInt32(ST_UDPKEY, server->GetServerKeyUDP(true)).WriteTagToFile( &servermet ); } if (server->GetServerKeyUDPIP()) { CTagInt32(ST_UDPKEYIP, server->GetServerKeyUDPIP()).WriteTagToFile( &servermet ); } if (server->GetObfuscationPortTCP()) { CTagInt16(ST_TCPPORTOBFUSCATION, server->GetObfuscationPortTCP()).WriteTagToFile( &servermet ); } if (server->GetObfuscationPortUDP()) { CTagInt16(ST_UDPPORTOBFUSCATION, server->GetObfuscationPortUDP()).WriteTagToFile( &servermet ); } } // Now server.met.new is ready to be closed and renamed to server.met. // But first rename existing server.met to server.met.bak (replacing old .bak file). const CPath oldservermet = CPath(theApp->ConfigDir + wxT("server.met.bak")); if (curservermet.FileExists()) { CPath::RenameFile(curservermet, oldservermet, true); } servermet.Close(); } catch (const CIOFailureException& e) { AddLogLineC(wxT("IO failure while writing 'server.met': ") + e.what()); return false; } return true; }
void CTerminationProcess::OnTerminate(int pid, int status) { AddLogLineN(CFormat(_("Command '%s' with pid '%d' has finished with status code '%d'.")) % m_cmd % pid % status); delete this; }
CamuleDlg::CamuleDlg( wxWindow* pParent, const wxString &title, wxPoint where, wxSize dlg_size) : wxFrame( pParent, -1, title, where, dlg_size, wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxDIALOG_NO_PARENT| wxRESIZE_BORDER|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxCLOSE_BOX, wxT("aMule")), m_activewnd(NULL), m_transferwnd(NULL), m_serverwnd(NULL), m_sharedfileswnd(NULL), m_searchwnd(NULL), m_chatwnd(NULL), m_statisticswnd(NULL), m_kademliawnd(NULL), m_prefsDialog(NULL), m_srv_split_pos(0), m_imagelist(16,16), m_tblist(32,32), m_prefsVisible(false), m_wndToolbar(NULL), m_wndTaskbarNotifier(NULL), m_nActiveDialog(DT_NETWORKS_WND), m_is_safe_state(false), m_BlinkMessages(false), m_CurrentBlinkBitmap(24), m_last_iconizing(0), m_skinFileName(), m_clientSkinNames(CLIENT_SKIN_SIZE) { // Initialize skin names m_clientSkinNames[Client_Green_Smiley] = wxT("Transfer"); m_clientSkinNames[Client_Red_Smiley] = wxT("Connecting"); m_clientSkinNames[Client_Yellow_Smiley] = wxT("OnQueue"); m_clientSkinNames[Client_Grey_Smiley] = wxT("A4AFNoNeededPartsQueueFull"); m_clientSkinNames[Client_White_Smiley] = wxT("StatusUnknown"); m_clientSkinNames[Client_ExtendedProtocol_Smiley] = wxT("ExtendedProtocol"); m_clientSkinNames[Client_SecIdent_Smiley] = wxT("SecIdent"); m_clientSkinNames[Client_BadGuy_Smiley] = wxT("BadGuy"); m_clientSkinNames[Client_CreditsGrey_Smiley] = wxT("CreditsGrey"); m_clientSkinNames[Client_CreditsYellow_Smiley] = wxT("CreditsYellow"); m_clientSkinNames[Client_Upload_Smiley] = wxT("Upload"); m_clientSkinNames[Client_Friend_Smiley] = wxT("Friend"); m_clientSkinNames[Client_eMule_Smiley] = wxT("eMule"); m_clientSkinNames[Client_mlDonkey_Smiley] = wxT("mlDonkey"); m_clientSkinNames[Client_eDonkeyHybrid_Smiley] = wxT("eDonkeyHybrid"); m_clientSkinNames[Client_aMule_Smiley] = wxT("aMule"); m_clientSkinNames[Client_lphant_Smiley] = wxT("lphant"); m_clientSkinNames[Client_Shareaza_Smiley] = wxT("Shareaza"); m_clientSkinNames[Client_xMule_Smiley] = wxT("xMule"); m_clientSkinNames[Client_Unknown] = wxT("Unknown"); m_clientSkinNames[Client_InvalidRating_Smiley] = wxT("InvalidRatingOnFile"); m_clientSkinNames[Client_PoorRating_Smiley] = wxT("PoorRatingOnFile"); m_clientSkinNames[Client_GoodRating_Smiley] = wxT("GoodRatingOnFile"); m_clientSkinNames[Client_FairRating_Smiley] = wxT("FairRatingOnFile"); m_clientSkinNames[Client_ExcellentRating_Smiley] = wxT("ExcellentRatingOnFile"); m_clientSkinNames[Client_CommentOnly_Smiley] = wxT("CommentOnly"); m_clientSkinNames[Client_Encryption_Smiley] = wxT("Encrypted"); // wxWidgets send idle events to ALL WINDOWS by default... *SIGH* wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED); wxUpdateUIEvent::SetMode(wxUPDATE_UI_PROCESS_SPECIFIED); wxInitAllImageHandlers(); Apply_Clients_Skin(); #ifdef __WINDOWS__ wxSystemOptions::SetOption(wxT("msw.remap"), 0); #endif #if !(wxCHECK_VERSION(2, 9, 0) && defined(__WXMAC__)) // this crashes on Mac with wx 2.9 SetIcon(wxICON(aMule)); #endif srand(time(NULL)); // Create new sizer and stuff a wxPanel in there. wxFlexGridSizer *s_main = new wxFlexGridSizer(1); s_main->AddGrowableCol(0); s_main->AddGrowableRow(0); wxPanel* p_cnt = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize); s_main->Add(p_cnt, 0, wxGROW|wxEXPAND, 0); muleDlg(p_cnt, false, true); SetSizer(s_main, true); m_serverwnd = new CServerWnd(p_cnt, m_srv_split_pos); AddLogLineN(wxEmptyString); AddLogLineN(wxT(" - ") + CFormat(_("This is aMule %s based on eMule.")) % GetMuleVersion()); AddLogLineN(wxT(" ") + CFormat(_("Running on %s")) % wxGetOsDescription()); AddLogLineN(wxT(" - ") + wxString(_("Visit http://www.amule.org to check if a new version is available."))); AddLogLineN(wxEmptyString); #ifdef ENABLE_IP2COUNTRY m_GeoIPavailable = true; m_IP2Country = new CIP2Country(thePrefs::GetConfigDir()); #else m_GeoIPavailable = false; #endif m_searchwnd = new CSearchDlg(p_cnt); m_transferwnd = new CTransferWnd(p_cnt); m_sharedfileswnd = new CSharedFilesWnd(p_cnt); m_statisticswnd = new CStatisticsDlg(p_cnt, theApp->m_statistics); m_chatwnd = new CChatWnd(p_cnt); m_kademliawnd = CastChild(wxT("kadWnd"), CKadDlg); m_serverwnd->Show(false); m_searchwnd->Show(false); m_transferwnd->Show(false); m_sharedfileswnd->Show(false); m_statisticswnd->Show(false); m_chatwnd->Show(false); // Create the GUI timer gui_timer=new wxTimer(this,ID_GUI_TIMER_EVENT); if (!gui_timer) { AddLogLineN(_("FATAL ERROR: Failed to create Timer")); exit(1); } // Set transfers as active window Create_Toolbar(thePrefs::VerticalToolbar()); SetActiveDialog(DT_TRANSFER_WND, m_transferwnd); m_wndToolbar->ToggleTool(ID_BUTTONDOWNLOADS, true ); bool override_where = (where != wxDefaultPosition); bool override_size = ( (dlg_size.x != DEFAULT_SIZE_X) || (dlg_size.y != DEFAULT_SIZE_Y) ); if (!LoadGUIPrefs(override_where, override_size)) { // Prefs not loaded for some reason, exit AddLogLineC(wxT("Error! Unable to load Preferences") ); return; } // Prepare the dialog, sets the splitter-position (AFTER window size is set) m_transferwnd->Prepare(); m_is_safe_state = true; // Init statistics stuff, better do it asap m_statisticswnd->Init(); m_kademliawnd->Init(); m_searchwnd->UpdateCatChoice(); if (thePrefs::UseTrayIcon()) { CreateSystray(); } Show(true); // Must we start minimized? if (thePrefs::GetStartMinimized()) { DoIconize(true); } // Set shortcut keys wxAcceleratorEntry entries[] = { wxAcceleratorEntry(wxACCEL_CTRL, wxT('Q'), wxID_EXIT) }; SetAcceleratorTable(wxAcceleratorTable(itemsof(entries), entries)); ShowED2KLinksHandler( thePrefs::GetFED2KLH() ); wxNotebook* logs_notebook = CastChild( ID_SRVLOG_NOTEBOOK, wxNotebook); wxNotebook* networks_notebook = CastChild( ID_NETNOTEBOOK, wxNotebook); wxASSERT(logs_notebook->GetPageCount() == 4); wxASSERT(networks_notebook->GetPageCount() == 2); for (uint32 i = 0; i < logs_notebook->GetPageCount(); ++i) { m_logpages[i].page = logs_notebook->GetPage(i); m_logpages[i].name = logs_notebook->GetPageText(i); } for (uint32 i = 0; i < networks_notebook->GetPageCount(); ++i) { m_networkpages[i].page = networks_notebook->GetPage(i); m_networkpages[i].name = networks_notebook->GetPageText(i); } DoNetworkRearrange(); }
bool CServerList::LoadServerMet(const CPath& path) { AddLogLineN(CFormat(_("Loading server.met file: %s")) % path); bool merge = !m_servers.empty(); if (!path.FileExists()) { AddLogLineN(_("Server.met file not found!")); return false; } // Try to unpack the file, might be an archive const wxChar* mets[] = { wxT("server.met"), NULL }; // Try to unpack the file, might be an archive if (UnpackArchive(path, mets).second != EFT_Met) { AddLogLineC(CFormat(_("Failed to load server.met file '%s', unknown format encountered.")) % path); return false; } CFile servermet(path, CFile::read); if ( !servermet.IsOpened() ){ AddLogLineN(_("Failed to open server.met!") ); return false; } try { Notify_ServerFreeze(); byte version = servermet.ReadUInt8(); if (version != 0xE0 && version != MET_HEADER) { AddLogLineC(CFormat(_("Server.met file corrupt, found invalid versiontag: 0x%x, size %i")) % version % sizeof(version)); Notify_ServerThaw(); return false; } uint32 fservercount = servermet.ReadUInt32(); ServerMet_Struct sbuffer; uint32 iAddCount = 0; for ( uint32 j = 0; j < fservercount; ++j ) { sbuffer.ip = servermet.ReadUInt32(); sbuffer.port = servermet.ReadUInt16(); sbuffer.tagcount = servermet.ReadUInt32(); CServer* newserver = new CServer(&sbuffer); // Load tags for ( uint32 i = 0; i < sbuffer.tagcount; ++i ) { newserver->AddTagFromFile(&servermet); } // Server priorities are not in sorted order // High = 1, Low = 2, Normal = 0, so we have to check // in a less logical fashion. int priority = newserver->GetPreferences(); if (priority < SRV_PR_MIN || priority > SRV_PR_MAX) { newserver->SetPreference(SRV_PR_NORMAL); } // set listname for server if ( newserver->GetListName().IsEmpty() ) { newserver->SetListName(wxT("Server ") +newserver->GetAddress()); } if ( !theApp->AddServer(newserver) ) { CServer* update = GetServerByAddress(newserver->GetAddress(), newserver->GetPort()); if(update) { update->SetListName( newserver->GetListName()); if(!newserver->GetDescription().IsEmpty()) { update->SetDescription( newserver->GetDescription()); } Notify_ServerRefresh(update); } delete newserver; } else { ++iAddCount; } } Notify_ServerThaw(); if (!merge) { AddLogLineC(CFormat(wxPLURAL("%i server in server.met found", "%i servers in server.met found", fservercount)) % fservercount); } else { AddLogLineC(CFormat(wxPLURAL("%d server added", "%d servers added", iAddCount)) % iAddCount); } } catch (const CInvalidPacket& err) { AddLogLineC(_("Error: the file 'server.met' is corrupted: ") + err.what()); Notify_ServerThaw(); return false; } catch (const CSafeIOException& err) { AddLogLineC(_("IO error while reading 'server.met': ") + err.what()); Notify_ServerThaw(); return false; } return true; }
CTag *CFileDataIO::ReadTag(bool bOptACP) const { CTag *retVal = NULL; wxString name; byte type = 0; try { type = ReadUInt8(); name = ReadString(false); switch (type) { // NOTE: This tag data type is accepted and stored only to give us the possibility to upgrade // the net in some months. // // And still.. it doesnt't work this way without breaking backward compatibility. To properly // do this without messing up the network the following would have to be done: // - those tag types have to be ignored by any client, otherwise those tags would also be sent (and // that's really the problem) // // - ignoring means, each client has to read and right throw away those tags, so those tags get // get never stored in any tag list which might be sent by that client to some other client. // // - all calling functions have to be changed to deal with the 'nr. of tags' attribute (which was // already parsed) correctly.. just ignoring those tags here is not enough, any taglists have to // be built with the knowledge that the 'nr. of tags' attribute may get decreased during the tag // reading.. // // If those new tags would just be stored and sent to remote clients, any malicious or just bugged // client could let send a lot of nodes "corrupted" packets... // case TAGTYPE_HASH16: { retVal = new CTagHash(name, ReadHash()); break; } case TAGTYPE_STRING: retVal = new CTagString(name, ReadString(bOptACP)); break; case TAGTYPE_UINT64: retVal = new CTagInt64(name, ReadUInt64()); break; case TAGTYPE_UINT32: retVal = new CTagInt32(name, ReadUInt32()); break; case TAGTYPE_UINT16: retVal = new CTagInt16(name, ReadUInt16()); break; case TAGTYPE_UINT8: retVal = new CTagInt8(name, ReadUInt8()); break; case TAGTYPE_FLOAT32: retVal = new CTagFloat(name, ReadFloat()); break; // NOTE: This tag data type is accepted and stored only to give us the possibility to upgrade // the net in some months. // // And still.. it doesnt't work this way without breaking backward compatibility case TAGTYPE_BSOB: { uint8 size = 0; CScopedArray<unsigned char> value(ReadBsob(&size)); retVal = new CTagBsob(name, value.get(), size); break; } default: throw wxString(CFormat(wxT("Invalid Kad tag type; type=0x%02x name=%s\n")) % type % name); } } catch(const CMuleException& e) { AddLogLineN(e.what()); delete retVal; throw; } catch(const wxString& e) { AddLogLineN(e); throw; } return retVal; }
void CDownloadQueue::LoadMetFiles(const CPath& path) { AddLogLineNS(CFormat(_("Loading temp files from %s.")) % path.GetPrintable()); std::vector<CPath> files; // Locate part-files to be loaded CDirIterator TempDir(path); CPath fileName = TempDir.GetFirstFile(CDirIterator::File, wxT("*.part.met")); while (fileName.IsOk()) { files.push_back(path.JoinPaths(fileName)); fileName = TempDir.GetNextFile(); } // Loading in order makes it easier to figure which // file is broken in case of crashes, or the like. std::sort(files.begin(), files.end()); // Load part-files for ( size_t i = 0; i < files.size(); i++ ) { AddLogLineNS(CFormat(_("Loading PartFile %u of %u")) % (i + 1) % files.size()); fileName = files[i].GetFullName(); CPartFile *toadd = new CPartFile(); bool result = toadd->LoadPartFile(path, fileName) != 0; if (!result) { // Try from backup result = toadd->LoadPartFile(path, fileName, true) != 0; } if (result && !IsFileExisting(toadd->GetFileHash())) { { wxMutexLocker lock(m_mutex); m_filelist.push_back(toadd); } NotifyObservers(EventType(EventType::INSERTED, toadd)); Notify_DownloadCtrlAddFile(toadd); } else { wxString msg; if (result) { msg << CFormat(wxT("WARNING: Duplicate partfile with hash '%s' found, skipping: %s")) % toadd->GetFileHash().Encode() % fileName; } else { // If result is false, then reading of both the primary and the backup .met failed AddLogLineN(_("ERROR: Failed to load backup file. Search http://forum.amule.org for .part.met recovery solutions.")); msg << CFormat(wxT("ERROR: Failed to load PartFile '%s'")) % fileName; } AddLogLineCS(msg); // Delete the partfile object in the end. delete toadd; } } AddLogLineNS(_("All PartFiles Loaded.")); if ( GetFileCount() == 0 ) { AddLogLineN(_("No part files found")); } else { AddLogLineN(CFormat(wxPLURAL("Found %u part file", "Found %u part files", GetFileCount())) % GetFileCount()); DoSortByPriority(); CheckDiskspace( path ); Notify_ShowUpdateCatTabTitles(); } }