2 // This file is part of the aMule Project.
4 // Copyright (c) 2005-2008 aMule Team ( admin@amule.org / http://www.amule.org )
6 // Any parts of this program derived from the xMule, lMule or eMule project,
7 // or contributed by third-party developers are copyrighted by their
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define AMULE_REMOTE_GUI_CPP
30 #include <wx/cmdline.h> // Needed for wxCmdLineParser
31 #include <wx/config.h> // Do_not_auto_remove (win32)
32 #include <wx/fileconf.h> // Needed for wxFileConfig
35 #include <common/Format.h>
36 #include <common/StringFunctions.h>
37 #include <common/MD5Sum.h>
40 #include <include/common/EventIDs.h>
43 #include "amule.h" // Interface declarations.
44 #include "amuleDlg.h" // Needed for CamuleDlg
45 #include "ClientCredits.h"
46 #include "ClientListCtrl.h"
47 #include "DataToText.h" // Needed for GetSoftName()
48 #include "DownloadListCtrl.h" // Needed for CDownloadListCtrl
49 #include "GuiEvents.h"
50 #ifdef ENABLE_IP2COUNTRY
51 #include "IP2Country.h" // Needed for IP2Country
53 #include "InternalEvents.h" // Needed for wxEVT_CORE_FINISHED_HTTP_DOWNLOAD
55 #include "muuli_wdr.h" // Needed for IDs
56 #include "PartFile.h" // Needed for CPartFile
57 #include "SearchDlg.h" // Needed for CSearchDlg
58 #include "Server.h" // Needed for GetListName
59 #include "ServerWnd.h" // Needed for CServerWnd
60 #include "SharedFilesCtrl.h" // Needed for CSharedFilesCtrl
61 #include "SharedFilesWnd.h" // Needed for CSharedFilesWnd
62 #include "TransferWnd.h" // Needed for CTransferWnd
63 #include "updownclient.h"
64 #include "ServerListCtrl.h" // Needed for CServerListCtrl
65 #include "MagnetURI.h" // Needed for CMagnetURI
66 #include "ScopedPtr.h"
69 CEConnectDlg::CEConnectDlg()
71 wxDialog(theApp
->amuledlg
, -1, _("Connect to remote amule"), wxDefaultPosition
)
73 CoreConnect(this, true);
75 wxString pref_host
, pref_port
;
76 wxConfig::Get()->Read(wxT("/EC/Host"), &pref_host
, wxT("localhost"));
77 wxConfig::Get()->Read(wxT("/EC/Port"), &pref_port
, wxT("4712"));
78 wxConfig::Get()->Read(wxT("/EC/Password"), &pwd_hash
);
80 CastChild(ID_REMOTE_HOST
, wxTextCtrl
)->SetValue(pref_host
);
81 CastChild(ID_REMOTE_PORT
, wxTextCtrl
)->SetValue(pref_port
);
82 CastChild(ID_EC_PASSWD
, wxTextCtrl
)->SetValue(pwd_hash
);
88 wxString
CEConnectDlg::PassHash()
94 BEGIN_EVENT_TABLE(CEConnectDlg
, wxDialog
)
95 EVT_BUTTON(wxID_OK
, CEConnectDlg::OnOK
)
99 void CEConnectDlg::OnOK(wxCommandEvent
& evt
)
101 wxString s_port
= CastChild(ID_REMOTE_PORT
, wxTextCtrl
)->GetValue();
102 port
= StrToLong(s_port
);
104 host
= CastChild(ID_REMOTE_HOST
, wxTextCtrl
)->GetValue();
105 passwd
= CastChild(ID_EC_PASSWD
, wxTextCtrl
)->GetValue();
107 if (passwd
!= pwd_hash
) {
108 pwd_hash
= MD5Sum(passwd
).GetHash();
110 m_save_user_pass
= CastChild(ID_EC_SAVE
, wxCheckBox
)->IsChecked();
115 DEFINE_LOCAL_EVENT_TYPE(wxEVT_EC_INIT_DONE
)
118 BEGIN_EVENT_TABLE(CamuleRemoteGuiApp
, wxApp
)
120 EVT_TIMER(ID_CORE_TIMER_EVENT
, CamuleRemoteGuiApp::OnPollTimer
)
122 EVT_CUSTOM(wxEVT_EC_CONNECTION
, -1, CamuleRemoteGuiApp::OnECConnection
)
123 EVT_CUSTOM(wxEVT_EC_INIT_DONE
, -1, CamuleRemoteGuiApp::OnECInitDone
)
125 EVT_MULE_NOTIFY(CamuleRemoteGuiApp::OnNotifyEvent
)
127 #ifdef ENABLE_IP2COUNTRY
128 // HTTPDownload finished
129 EVT_MULE_INTERNAL(wxEVT_CORE_FINISHED_HTTP_DOWNLOAD
, -1, CamuleRemoteGuiApp::OnFinishedHTTPDownload
)
134 IMPLEMENT_APP(CamuleRemoteGuiApp
)
137 int CamuleRemoteGuiApp::OnExit()
141 return wxApp::OnExit();
145 void CamuleRemoteGuiApp::OnPollTimer(wxTimerEvent
&)
147 static int request_step
= 0;
149 if (m_connect
->RequestFifoFull()) {
153 switch (request_step
) {
155 serverconnect
->ReQuery();
156 serverlist
->UpdateUserFileStatus(serverconnect
->GetCurrentServer());
160 CECPacket
stats_req(EC_OP_STAT_REQ
);
161 m_connect
->SendRequest(&m_stats_updater
, &stats_req
);
162 amuledlg
->ShowTransferRate();
167 if (amuledlg
->m_sharedfileswnd
->IsShown()) {
168 sharedfiles
->DoRequery(EC_OP_GET_SHARED_FILES
, EC_TAG_KNOWNFILE
);
169 } else if (amuledlg
->m_serverwnd
->IsShown()) {
170 //serverlist->FullReload(EC_OP_GET_SERVER_LIST);
171 } else if (amuledlg
->m_transferwnd
->IsShown()) {
172 static bool firstcall
= true;
173 downloadqueue
->DoRequery(
174 theApp
->m_FileDetailDialogActive
|| firstcall
?
175 EC_OP_GET_DLOAD_QUEUE_DETAIL
: EC_OP_GET_DLOAD_QUEUE
,
178 switch(amuledlg
->m_transferwnd
->clientlistctrl
->GetListView()) {
180 uploadqueue
->ReQueryUp();
183 uploadqueue
->ReQueryWait();
190 amuledlg
->m_transferwnd
->ShowQueueCount(theStats::GetWaitingUserCount());
191 } else if (amuledlg
->m_searchwnd
->IsShown()) {
192 if (searchlist
->m_curr_search
!= -1) {
193 searchlist
->DoRequery(EC_OP_SEARCH_RESULTS
, EC_TAG_SEARCHFILE
);
200 AddLogLineCS(wxT("WTF?")); // should not happen. :-)
206 void CamuleRemoteGuiApp::OnFinishedHTTPDownload(CMuleInternalEvent
& event
)
208 #ifdef ENABLE_IP2COUNTRY
209 if (event
.GetInt() == HTTP_GeoIP
) {
210 amuledlg
->IP2CountryDownloadFinished(event
.GetExtraLong());
211 // If we updated, the dialog is already up. Redraw it to show the flags.
218 void CamuleRemoteGuiApp::ShutDown(wxCloseEvent
&WXUNUSED(evt
))
220 // Stop the Core Timer
224 // Destroy the EC socket
225 m_connect
->Destroy();
230 amuledlg
->DlgShutDown();
237 bool CamuleRemoteGuiApp::OnInit()
241 if ( !wxApp::OnInit() ) {
246 theApp
= &wxGetApp();
248 // Handle uncaught exceptions
249 InstallMuleExceptionHandler();
251 // Create the polling timer
252 poll_timer
= new wxTimer(this,ID_CORE_TIMER_EVENT
);
254 AddLogLineCS(_("Fatal Error: Failed to create Poll Timer"));
258 m_connect
= new CRemoteConnect(this);
259 SetAppName(wxT("aMule"));
262 // This creates the CFG file we shall use
263 ConfigDir
= GetConfigDir();
264 if (!wxDirExists(ConfigDir
)) {
268 wxConfig::Set(new wxFileConfig(wxEmptyString
, wxEmptyString
,
269 ConfigDir
+ wxT("remote.conf")));
271 glob_prefs
= new CPreferencesRem(m_connect
);
273 InitCustomLanguages();
274 InitLocale(m_locale
, StrLang2wx(thePrefs::GetLanguageID()));
276 bool result
= ShowConnectionDialog();
278 AddLogLineNS(_("Going to event loop..."));
284 bool CamuleRemoteGuiApp::CryptoAvailable() const
286 return thePrefs::IsSecureIdentEnabled(); // good enough
290 bool CamuleRemoteGuiApp::ShowConnectionDialog() {
292 dialog
= new CEConnectDlg
;
294 if (dialog
->ShowModal() != wxID_OK
) {
299 AddLogLineNS(_("Connecting..."));
300 if (!m_connect
->ConnectToCore(dialog
->Host(), dialog
->Port(),
301 dialog
->Login(), dialog
->PassHash(),
302 wxT("amule-remote"), wxT("0x0001"))) {
303 wxMessageBox(_("Connection failed "),_("ERROR"),wxOK
);
312 void CamuleRemoteGuiApp::OnECConnection(wxEvent
& event
) {
313 wxECSocketEvent
& evt
= *((wxECSocketEvent
*)&event
);
314 AddLogLineNS(_("Remote GUI EC event handler"));
315 wxString reply
= evt
.GetServerReply();
316 AddLogLineM(true, reply
);
317 if (evt
.GetResult() == true) {
318 // Connected - go to next init step
319 glob_prefs
->LoadRemote();
321 AddLogLineNS(_("Going down"));
322 if (dialog
) { // connect failed
324 (CFormat(_("Connection Failed. Unable to connect to %s:%d\n")) % dialog
->Host() % dialog
->Port()) + reply
,
326 } else { // server disconnected (probably terminated) later
327 wxMessageBox(_("Connection closed - aMule has terminated probably."), _("ERROR"), wxOK
);
334 void CamuleRemoteGuiApp::OnECInitDone(wxEvent
& )
340 void CamuleRemoteGuiApp::OnNotifyEvent(CMuleGUIEvent
& evt
)
346 void CamuleRemoteGuiApp::Startup() {
348 if (dialog
->SaveUserPass()) {
349 wxConfig::Get()->Write(wxT("/EC/Host"), dialog
->Host());
350 wxConfig::Get()->Write(wxT("/EC/Port"), dialog
->Port());
351 wxConfig::Get()->Write(wxT("/EC/Password"), dialog
->PassHash());
359 serverconnect
= new CServerConnectRem(m_connect
);
360 m_statistics
= new CStatistics(*m_connect
);
362 clientlist
= new CClientListRem(m_connect
);
363 searchlist
= new CSearchListRem(m_connect
);
364 serverlist
= new CServerListRem(m_connect
);
366 sharedfiles
= new CSharedFilesRem(m_connect
);
367 knownfiles
= new CKnownFilesRem(sharedfiles
);
369 // bugfix - do this before creating the uploadqueue
370 downloadqueue
= new CDownQueueRem(m_connect
);
371 uploadqueue
= new CUpQueueRem(m_connect
);
372 ipfilter
= new CIPFilterRem(m_connect
);
374 // Parse cmdline arguments.
375 wxCmdLineParser
cmdline(wxApp::argc
, wxApp::argv
);
376 cmdline
.AddSwitch(wxT("v"), wxT("version"),
377 wxT("Displays the current version number."));
378 cmdline
.AddSwitch(wxT("h"), wxT("help"),
379 wxT("Displays this information."));
380 cmdline
.AddOption(wxT("geometry"), wxEmptyString
, wxT("Sets the geometry of the app.\n\t\t\t<str> uses the same format as standard X11 apps:\n\t\t\t[=][<width>{xX}<height>][{+-}<xoffset>{+-}<yoffset>]"));
383 bool geometry_enabled
= false;
384 wxString geom_string
;
385 if (cmdline
.Found(wxT("geometry"), &geom_string
)) {
386 geometry_enabled
= true;
389 // Create main dialog
390 InitGui(0, geom_string
);
392 // Forward wxLog events to CLogger
393 wxLog::SetActiveTarget(new CLoggerTarget
);
394 serverlist
->FullReload(EC_OP_GET_SERVER_LIST
);
395 sharedfiles
->DoRequery(EC_OP_GET_SHARED_FILES
, EC_TAG_KNOWNFILE
);
397 // Start the Poll Timer
398 poll_timer
->Start(1000);
399 amuledlg
->StartGuiTimer();
401 // Now activate GeoIP, so that the download dialog doesn't get destroyed immediately
402 #ifdef ENABLE_IP2COUNTRY
403 if (thePrefs::IsGeoIPEnabled()) {
404 amuledlg
->m_IP2Country
->Enable();
410 void CamuleRemoteGuiApp::ShowAlert(wxString msg
, wxString title
, int flags
)
412 CamuleGuiBase::ShowAlert(msg
, title
, flags
);
416 void CamuleRemoteGuiApp::AddRemoteLogLine(const wxString
& line
)
418 amuledlg
->AddLogLine(line
);
421 int CamuleRemoteGuiApp::InitGui(bool geometry_enabled
, wxString
&geom_string
)
423 CamuleGuiBase::InitGui(geometry_enabled
, geom_string
);
424 SetTopWindow(amuledlg
);
425 AddLogLineN(_("Ready")); // The first log line after the window is up triggers output of all the ones before
430 bool CamuleRemoteGuiApp::CopyTextToClipboard(wxString strText
)
432 return CamuleGuiBase::CopyTextToClipboard(strText
);
436 uint32
CamuleRemoteGuiApp::GetPublicIP()
442 wxString
CamuleRemoteGuiApp::GetLog(bool)
444 return wxEmptyString
;
448 wxString
CamuleRemoteGuiApp::GetServerLog(bool)
450 return wxEmptyString
;
454 wxString
CamuleRemoteGuiApp::CreateMagnetLink(const CAbstractFile
* f
)
456 // TODO: Remove duplicate code (also in amule.cpp) ...
459 uri
.AddField(wxT("dn"), f
->GetFileName().Cleanup(false).GetPrintable());
460 uri
.AddField(wxT("xt"), wxString(wxT("urn:ed2k:")) + f
->GetFileHash().Encode().Lower());
461 uri
.AddField(wxT("xt"), wxString(wxT("urn:ed2khash:")) + f
->GetFileHash().Encode().Lower());
462 uri
.AddField(wxT("xl"), wxString::Format(wxT("%") wxLongLongFmtSpec
wxT("u"), f
->GetFileSize()));
464 return uri
.GetLink();
467 wxString
CamuleRemoteGuiApp::CreateED2kLink(const CAbstractFile
* f
, bool add_source
, bool use_hostname
, bool addcryptoptions
)
469 // TODO: Avoid duplicate code (also in amule.cpp) ...
470 wxASSERT(!(!add_source
&& (use_hostname
|| addcryptoptions
)));
471 // Construct URL like this: ed2k://|file|<filename>|<size>|<hash>|/
472 wxString strURL
= CFormat(wxT("ed2k://|file|%s|%i|%s|/"))
473 % f
->GetFileName().Cleanup(false)
474 % f
->GetFileSize() % f
->GetFileHash().Encode();
476 if (add_source
&& IsConnected() && !IsFirewalled()) {
477 // Create the first part of the URL
478 strURL
<< wxT("|sources,");
481 strURL
<< thePrefs::GetYourHostname();
483 uint32 clientID
= GetID();
484 strURL
<< (uint8
) clientID
<< wxT(".") <<
485 (uint8
)(clientID
>> 8) << wxT(".") <<
486 (uint8
)(clientID
>> 16) << wxT(".") <<
487 (uint8
)(clientID
>> 24);
490 strURL
<< wxT(":") <<
493 if (addcryptoptions
) {
494 const uint8 uSupportsCryptLayer
= thePrefs::IsClientCryptLayerSupported() ? 1 : 0;
495 const uint8 uRequestsCryptLayer
= thePrefs::IsClientCryptLayerRequested() ? 1 : 0;
496 const uint8 uRequiresCryptLayer
= thePrefs::IsClientCryptLayerRequired() ? 1 : 0;
497 const uint8 byCryptOptions
= (uRequiresCryptLayer
<< 2) | (uRequestsCryptLayer
<< 1) | (uSupportsCryptLayer
<< 0) | (uSupportsCryptLayer
? 0x80 : 0x00);
499 strURL
<< wxT(":") << byCryptOptions
;
501 if (byCryptOptions
& 0x80) {
502 strURL
<< wxT(":") << thePrefs::GetUserHash().Encode();
507 } else if (add_source
) {
508 AddLogLineM(true, _("WARNING: You can't add yourself as a source for an eD2k link while having a lowid."));
511 // Result is "ed2k://|file|<filename>|<size>|<hash>|/|sources,[(<ip>|<hostname>):<port>[:cryptoptions[:hash]]]|/"
516 wxString
CamuleRemoteGuiApp::CreateED2kAICHLink(const CKnownFile
* f
)
518 // TODO: Avoid duplicate code (also in amule.cpp) ...
519 // Create the first part of the URL
520 wxString strURL
= CreateED2kLink(f
);
521 // Append the AICH info
522 if (f
->HasProperAICHHashSet()) {
523 strURL
.RemoveLast(); // remove trailing '/'
524 strURL
<< wxT("h=") << f
->GetAICHMasterHash() << wxT("|/");
527 // Result is "ed2k://|file|<filename>|<size>|<hash>|h=<AICH master hash>|/"
532 bool CamuleRemoteGuiApp::AddServer(CServer
*, bool)
534 // #warning TODO: Add remote command
539 bool CamuleRemoteGuiApp::IsFirewalled() const
541 if (IsConnectedED2K() && !serverconnect
->IsLowID()) {
545 return IsFirewalledKad();
549 bool CamuleRemoteGuiApp::IsConnectedED2K() const {
550 return serverconnect
&& serverconnect
->IsConnected();
554 void CamuleRemoteGuiApp::StartKad() {
555 m_connect
->StartKad();
559 void CamuleRemoteGuiApp::StopKad() {
560 m_connect
->StopKad();
564 void CamuleRemoteGuiApp::BootstrapKad(uint32 ip
, uint16 port
)
566 CECPacket
req(EC_OP_KAD_BOOTSTRAP_FROM_IP
);
567 req
.AddTag(CECTag(EC_TAG_BOOTSTRAP_IP
, ip
));
568 req
.AddTag(CECTag(EC_TAG_BOOTSTRAP_PORT
, port
));
570 m_connect
->SendPacket(&req
);
574 void CamuleRemoteGuiApp::UpdateNotesDat(const wxString
& url
)
576 CECPacket
req(EC_OP_KAD_UPDATE_FROM_URL
);
577 req
.AddTag(CECTag(EC_TAG_KADEMLIA_UPDATE_URL
, url
));
579 m_connect
->SendPacket(&req
);
583 void CamuleRemoteGuiApp::DisconnectED2K() {
584 if (IsConnectedED2K()) {
585 m_connect
->DisconnectED2K();
590 uint32
CamuleRemoteGuiApp::GetED2KID() const
592 return serverconnect
? serverconnect
->GetClientID() : 0;
596 uint32
CamuleRemoteGuiApp::GetID() const
602 void CamuleRemoteGuiApp::ShowUserCount() {
605 static const wxString s_singlenetstatusformat
= _("Users: %s | Files: %s");
606 static const wxString s_bothnetstatusformat
= _("Users: E: %s K: %s | Files: E: %s K: %s");
608 if (thePrefs::GetNetworkED2K() && thePrefs::GetNetworkKademlia()) {
609 buffer
= CFormat(s_bothnetstatusformat
) % CastItoIShort(theStats::GetED2KUsers()) % CastItoIShort(theStats::GetKadUsers()) % CastItoIShort(theStats::GetED2KFiles()) % CastItoIShort(theStats::GetKadFiles());
610 } else if (thePrefs::GetNetworkED2K()) {
611 buffer
= CFormat(s_singlenetstatusformat
) % CastItoIShort(theStats::GetED2KUsers()) % CastItoIShort(theStats::GetED2KFiles());
612 } else if (thePrefs::GetNetworkKademlia()) {
613 buffer
= CFormat(s_singlenetstatusformat
) % CastItoIShort(theStats::GetKadUsers()) % CastItoIShort(theStats::GetKadFiles());
615 buffer
= _("No networks selected");
618 Notify_ShowUserCount(buffer
);
623 * Preferences: holds both local and remote settings.
625 * First, everything is loaded from local config file. Later, settings
626 * that are relevant on remote side only are loaded thru EC
628 CPreferencesRem::CPreferencesRem(CRemoteConnect
*conn
)
632 CPreferences::BuildItemList(theApp
->ConfigDir
);
633 CPreferences::LoadAllItems(wxConfigBase::Get());
636 // Settings queried from remote side
638 m_exchange_send_selected_prefs
=
640 EC_PREFS_CONNECTIONS
|
641 EC_PREFS_MESSAGEFILTER
|
647 EC_PREFS_CORETWEAKS
|
648 EC_PREFS_REMOTECONTROLS
|
650 m_exchange_recv_selected_prefs
=
651 m_exchange_send_selected_prefs
|
656 void CPreferencesRem::HandlePacket(const CECPacket
*packet
)
658 ((CEC_Prefs_Packet
*)packet
)->Apply();
660 if ( packet
->GetTagByName(EC_TAG_PREFS_CATEGORIES
) != 0 ) {
661 for (size_t i
= 0; i
< packet
->GetTagByName(EC_TAG_PREFS_CATEGORIES
)->GetTagCount(); i
++) {
662 const CECTag
*cat_tag
= packet
->GetTagByName(EC_TAG_PREFS_CATEGORIES
)->GetTagByIndex(i
);
663 Category_Struct
*cat
= new Category_Struct
;
664 cat
->title
= cat_tag
->GetTagByName(EC_TAG_CATEGORY_TITLE
)->GetStringData();
665 cat
->path
= CPath(cat_tag
->GetTagByName(EC_TAG_CATEGORY_PATH
)->GetStringData());
666 cat
->comment
= cat_tag
->GetTagByName(EC_TAG_CATEGORY_COMMENT
)->GetStringData();
667 cat
->color
= cat_tag
->GetTagByName(EC_TAG_CATEGORY_COLOR
)->GetInt();
668 cat
->prio
= cat_tag
->GetTagByName(EC_TAG_CATEGORY_PRIO
)->GetInt();
669 theApp
->glob_prefs
->AddCat(cat
);
672 Category_Struct
*cat
= new Category_Struct
;
673 cat
->title
= _("All");
675 cat
->prio
= PR_NORMAL
;
676 theApp
->glob_prefs
->AddCat(cat
);
678 wxECInitDoneEvent event
;
679 theApp
->AddPendingEvent(event
);
684 bool CPreferencesRem::LoadRemote()
687 // override local settings with remote
688 CECPacket
req(EC_OP_GET_PREFERENCES
, EC_DETAIL_UPDATE
);
690 // bring categories too
691 req
.AddTag(CECTag(EC_TAG_SELECT_PREFS
, m_exchange_recv_selected_prefs
));
693 m_conn
->SendRequest(this, &req
);
699 void CPreferencesRem::SendToRemote()
701 CEC_Prefs_Packet
pref_packet(m_exchange_send_selected_prefs
, EC_DETAIL_UPDATE
, EC_DETAIL_FULL
);
702 m_conn
->SendPacket(&pref_packet
);
706 Category_Struct
*CPreferencesRem::CreateCategory(
707 const wxString
& name
,
709 const wxString
& comment
,
713 CECPacket
req(EC_OP_CREATE_CATEGORY
);
714 CEC_Category_Tag
tag(0xffffffff, name
, path
.GetRaw(), comment
, color
, prio
);
716 m_conn
->SendPacket(&req
);
718 Category_Struct
*category
= new Category_Struct();
719 category
->path
= path
;
720 category
->title
= name
;
721 category
->comment
= comment
;
722 category
->color
= color
;
723 category
->prio
= prio
;
731 void CPreferencesRem::UpdateCategory(
733 const wxString
& name
,
735 const wxString
& comment
,
739 CECPacket
req(EC_OP_UPDATE_CATEGORY
);
740 CEC_Category_Tag
tag(cat
, name
, path
.GetRaw(), comment
, color
, prio
);
742 m_conn
->SendPacket(&req
);
744 Category_Struct
*category
= m_CatList
[cat
];
745 category
->path
= path
;
746 category
->title
= name
;
747 category
->comment
= comment
;
748 category
->color
= color
;
749 category
->prio
= prio
;
753 void CPreferencesRem::RemoveCat(uint8 cat
)
755 CECPacket
req(EC_OP_DELETE_CATEGORY
);
756 CEC_Category_Tag
tag(cat
, EC_DETAIL_CMD
);
758 m_conn
->SendPacket(&req
);
759 CPreferences::RemoveCat(cat
);
764 // Container implementation
766 CServerConnectRem::CServerConnectRem(CRemoteConnect
*conn
)
773 void CServerConnectRem::ConnectToAnyServer()
775 CECPacket
req(EC_OP_SERVER_CONNECT
);
776 m_Conn
->SendPacket(&req
);
780 void CServerConnectRem::StopConnectionTry()
782 // lfroen: isn't Disconnect the same ?
786 void CServerConnectRem::Disconnect()
788 CECPacket
req(EC_OP_SERVER_DISCONNECT
);
789 m_Conn
->SendPacket(&req
);
793 void CServerConnectRem::ConnectToServer(CServer
*server
)
795 m_Conn
->ConnectED2K(server
->GetIP(), server
->GetPort());
799 bool CServerConnectRem::ReQuery()
801 CECPacket
stat_req(EC_OP_GET_CONNSTATE
);
802 m_Conn
->SendRequest(this, &stat_req
);
808 void CServerConnectRem::HandlePacket(const CECPacket
*packet
)
810 CEC_ConnState_Tag
*tag
=
811 (CEC_ConnState_Tag
*)packet
->GetTagByName(EC_TAG_CONNSTATE
);
816 theApp
->m_ConnState
= 0;
818 m_ID
= tag
->GetEd2kId();
819 theApp
->m_clientID
= tag
->GetClientId();
821 if (tag
->IsConnectedED2K()) {
822 CECTag
*srvtag
= tag
->GetTagByName(EC_TAG_SERVER
);
826 server
= theApp
->serverlist
->GetByID(srvtag
->GetIPv4Data().IP());
827 if (m_CurrServer
&& (server
!= m_CurrServer
)) {
828 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->
829 HighlightServer(m_CurrServer
, false);
831 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->
832 HighlightServer(server
, true);
833 m_CurrServer
= server
;
834 theApp
->m_ConnState
|= CONNECTED_ED2K
;
836 if ( m_CurrServer
) {
837 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->
838 HighlightServer(m_CurrServer
, false);
843 if (tag
->IsConnectedKademlia()) {
844 if (tag
->IsKadFirewalled()) {
845 theApp
->m_ConnState
|= CONNECTED_KAD_FIREWALLED
;
847 theApp
->m_ConnState
|= CONNECTED_KAD_OK
;
850 if (tag
->IsKadRunning()) {
851 theApp
->m_ConnState
|= CONNECTED_KAD_NOT
;
855 theApp
->amuledlg
->ShowConnectionState();
860 * Server list: host list of ed2k servers.
862 CServerListRem::CServerListRem(CRemoteConnect
*conn
)
864 CRemoteContainer
<CServer
, uint32
, CEC_Server_Tag
>(conn
)
869 void CServerListRem::HandlePacket(const CECPacket
*packet
)
871 CRemoteContainer
<CServer
, uint32
, CEC_Server_Tag
>::HandlePacket(packet
);
876 void CServerListRem::UpdateServerMetFromURL(wxString url
)
878 CECPacket
req(EC_OP_SERVER_UPDATE_FROM_URL
);
879 req
.AddTag(CECTag(EC_TAG_SERVERS_UPDATE_URL
, url
));
881 m_conn
->SendPacket(&req
);
885 void CServerListRem::SaveServerMet()
887 // lfroen: stub, nothing to do
891 void CServerListRem::FilterServers()
898 void CServerListRem::RemoveServer(CServer
* server
)
900 m_conn
->RemoveServer(server
->GetIP(),server
->GetPort());
904 void CServerListRem::UpdateUserFileStatus(CServer
*server
)
907 m_TotalUser
= server
->GetUsers();
908 m_TotalFile
= server
->GetFiles();
911 CFormat(_("Total Users: %s | Total Files: %s")) % CastItoIShort(m_TotalUser
) % CastItoIShort(m_TotalFile
);
913 Notify_ShowUserCount(buffer
);
918 CServer
*CServerListRem::GetServerByAddress(const wxString
& WXUNUSED(address
), uint16
WXUNUSED(port
)) const
920 // It's ok to return 0 for context where this code is used in remote gui
924 CServer
*CServerListRem::GetServerByIPTCP(uint32
WXUNUSED(nIP
), uint16
WXUNUSED(nPort
)) const
926 // It's ok to return 0 for context where this code is used in remote gui
930 CServer
*CServerListRem::CreateItem(CEC_Server_Tag
*tag
)
932 return new CServer(tag
);
936 void CServerListRem::DeleteItem(CServer
*in_srv
)
938 CScopedPtr
<CServer
> srv(in_srv
);
939 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->RemoveServer(srv
.get());
943 uint32
CServerListRem::GetItemID(CServer
*server
)
945 return server
->GetIP();
949 void CServerListRem::ProcessItemUpdate(CEC_Server_Tag
*, CServer
*)
951 // server list is always realoaded from scratch
956 void CServerListRem::ReloadControl()
958 for(uint32 i
= 0;i
< GetCount(); i
++) {
959 CServer
*srv
= GetByIndex(i
);
960 theApp
->amuledlg
->m_serverwnd
->serverlistctrl
->RefreshServer(srv
);
965 CIPFilterRem::CIPFilterRem(CRemoteConnect
* conn
)
971 void CIPFilterRem::Reload()
973 CECPacket
req(EC_OP_IPFILTER_RELOAD
);
974 m_conn
->SendPacket(&req
);
978 void CIPFilterRem::Update(wxString
WXUNUSED(url
))
980 // FIXME: add command
988 CSharedFilesRem::CSharedFilesRem(CRemoteConnect
*conn
) : CRemoteContainer
<CKnownFile
, CMD4Hash
, CEC_SharedFile_Tag
>(conn
, true)
990 m_rename_file
= NULL
;
994 void CSharedFilesRem::Reload(bool, bool)
996 CECPacket
req(EC_OP_SHAREDFILES_RELOAD
);
998 m_conn
->SendPacket(&req
);
1002 void CSharedFilesRem::AddFilesFromDirectory(const CPath
& path
)
1004 CECPacket
req(EC_OP_SHAREDFILES_ADD_DIRECTORY
);
1006 req
.AddTag(CECTag(EC_TAG_PREFS_DIRECTORIES
, path
.GetRaw()));
1008 m_conn
->SendPacket(&req
);
1012 bool CSharedFilesRem::RenameFile(CKnownFile
* file
, const CPath
& newName
)
1014 // We use the printable name, as the filename originated from user input,
1015 // and the filesystem name might not be valid on the remote host.
1016 const wxString strNewName
= newName
.GetPrintable();
1018 CECPacket
request(EC_OP_RENAME_FILE
);
1019 request
.AddTag(CECTag(EC_TAG_KNOWNFILE
, file
->GetFileHash()));
1020 request
.AddTag(CECTag(EC_TAG_PARTFILE_NAME
, strNewName
));
1022 m_conn
->SendRequest(this, &request
);
1023 m_rename_file
= file
;
1024 m_new_name
= strNewName
;
1030 void CSharedFilesRem::HandlePacket(const CECPacket
*packet
)
1032 if (m_rename_file
&& (packet
->GetOpCode() == EC_OP_NOOP
)) {
1033 m_rename_file
->SetFileName(CPath(m_new_name
));
1034 m_rename_file
= NULL
;
1035 } else if (packet
->GetOpCode() != EC_OP_FAILED
) {
1036 CRemoteContainer
<CKnownFile
, CMD4Hash
, CEC_SharedFile_Tag
>::HandlePacket(packet
);
1041 CKnownFile
*CSharedFilesRem::CreateItem(CEC_SharedFile_Tag
*tag
)
1043 CKnownFile
*file
= new CKnownFile(tag
);
1045 m_enc_map
[file
->GetFileHash()] = RLE_Data(file
->GetPartCount(), true);
1047 ProcessItemUpdate(tag
, file
);
1049 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->ShowFile(file
);
1055 void CSharedFilesRem::DeleteItem(CKnownFile
*in_file
)
1057 CScopedPtr
<CKnownFile
> file(in_file
);
1059 m_enc_map
.erase(file
->GetFileHash());
1061 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->RemoveFile(file
.get());
1065 CMD4Hash
CSharedFilesRem::GetItemID(CKnownFile
*file
)
1067 return file
->GetFileHash();
1071 void CSharedFilesRem::ProcessItemUpdate(CEC_SharedFile_Tag
*tag
, CKnownFile
*file
)
1073 CECTag
*parttag
= tag
->GetTagByName(EC_TAG_PARTFILE_PART_STATUS
);
1074 const unsigned char *data
=
1075 m_enc_map
[file
->GetFileHash()].Decode(
1076 (unsigned char *)parttag
->GetTagData(),
1077 parttag
->GetTagDataLen());
1078 for(int i
= 0; i
< file
->GetPartCount(); ++i
) {
1079 file
->m_AvailPartFrequency
[i
] = data
[i
];
1082 tag
->SetRequests(file
->statistic
.requested
);
1083 tag
->SetAllRequests(file
->statistic
.alltimerequested
);
1084 tag
->SetAccepts(file
->statistic
.accepted
);
1085 tag
->SetAllAccepts(file
->statistic
.alltimeaccepted
);
1086 tag
->SetXferred(file
->statistic
.transferred
);
1087 tag
->SetAllXferred(file
->statistic
.alltimetransferred
);
1088 tag
->SetPrio(file
->m_iUpPriority
);
1090 file
->statistic
.requested
= tag
->GetRequests();
1091 file
->statistic
.alltimerequested
= tag
->GetAllRequests();
1092 file
->statistic
.accepted
= tag
->GetAccepts();
1093 file
->statistic
.alltimeaccepted
= tag
->GetAllAccepts();
1094 file
->statistic
.transferred
= tag
->GetXferred();
1095 file
->statistic
.alltimetransferred
= tag
->GetAllXferred();
1096 file
->m_iUpPriority
= tag
->Prio();
1098 if (file
->m_iUpPriority
>= 10) {
1099 file
->m_iUpPriority
-= 10;
1100 file
->m_bAutoUpPriority
= true;
1102 file
->m_bAutoUpPriority
= false;
1105 theApp
->knownfiles
->requested
+= file
->statistic
.requested
;
1106 theApp
->knownfiles
->transferred
+= file
->statistic
.transferred
;
1107 theApp
->knownfiles
->accepted
+= file
->statistic
.transferred
;
1109 theApp
->amuledlg
->m_sharedfileswnd
->sharedfilesctrl
->UpdateItem(file
);
1112 bool CSharedFilesRem::Phase1Done(const CECPacket
*)
1114 theApp
->knownfiles
->requested
= 0;
1115 theApp
->knownfiles
->transferred
= 0;
1116 theApp
->knownfiles
->accepted
= 0;
1121 void CSharedFilesRem::SetFilePrio(CKnownFile
*file
, uint8 prio
)
1123 CECPacket
req(EC_OP_SHARED_SET_PRIO
);
1125 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1126 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
, prio
));
1128 req
.AddTag(hashtag
);
1130 m_conn
->SendPacket(&req
);
1134 * List of uploading and waiting clients.
1136 CUpDownClientListRem::CUpDownClientListRem(CRemoteConnect
*conn
, int viewtype
)
1138 CRemoteContainer
<CUpDownClient
, uint32
, CEC_UpDownClient_Tag
>(conn
)
1140 m_viewtype
= viewtype
;
1144 CUpDownClient::CUpDownClient(CEC_UpDownClient_Tag
*tag
)
1146 m_bRemoteQueueFull
= false;
1147 m_nUserIDHybrid
= tag
->ID();
1148 m_Username
= tag
->ClientName();
1149 m_score
= tag
->Score();
1150 m_clientSoft
= tag
->ClientSoftware();
1151 m_clientVersionString
= GetSoftName(m_clientSoft
);
1152 m_clientSoftString
= m_clientVersionString
;
1153 m_identState
= tag
->GetCurrentIdentState();
1154 m_hasbeenobfuscatinglately
= tag
->HasObfuscatedConnection();
1156 // The functions to retrieve m_clientVerString information are
1157 // currently in BaseClient.cpp, which is not linked in remote-gui app.
1158 // So, in the meantime, we use a tag sent from core.
1159 m_clientVerString
= tag
->SoftVerStr();
1160 m_strModVersion
= wxEmptyString
;
1161 wxString clientModString
;
1162 if (!clientModString
.IsEmpty()) {
1163 m_clientVerString
+= wxT(" - ") + clientModString
;
1165 m_fullClientVerString
= m_clientSoftString
+ wxT(" ") + m_clientVerString
;
1168 m_UserHash
= tag
->UserID();
1171 m_nConnectIP
= m_dwUserIP
= tag
->UserIP();
1172 m_nUserPort
= tag
->UserPort();
1173 m_FullUserIP
= m_nConnectIP
;
1176 m_dwServerIP
= tag
->ServerIP();
1177 m_nServerPort
= tag
->ServerPort();
1178 m_ServerName
= tag
->ServerName();
1180 m_waitingPosition
= tag
->WaitingPosition();
1183 if (tag
->HaveFile()) {
1184 CMD4Hash filehash
= tag
->FileID();
1185 m_uploadingfile
= theApp
->sharedfiles
->GetByID(filehash
);
1186 if (!m_uploadingfile
) {
1187 m_uploadingfile
= theApp
->downloadqueue
->GetByID(filehash
);
1190 m_uploadingfile
= NULL
;
1193 m_nCurSessionUp
= 0;
1195 credits
= new CClientCredits(new CreditStruct());
1198 uint16
CUpQueueRem::GetWaitingPosition(const CUpDownClient
*client
) const
1200 return client
->GetWaitingPosition();
1203 /* Warning: do common base */
1206 bool CUpDownClient::IsIdentified() const
1208 return m_identState
== IS_IDENTIFIED
;
1212 bool CUpDownClient::IsBadGuy() const
1214 return m_identState
== IS_IDBADGUY
;
1218 bool CUpDownClient::SUIFailed() const
1220 return m_identState
== IS_IDFAILED
;
1224 bool CUpDownClient::SUINeeded() const
1226 return m_identState
== IS_IDNEEDED
;
1230 bool CUpDownClient::SUINotSupported() const
1232 return m_identState
== IS_NOTAVAILABLE
;
1236 uint64
CUpDownClient::GetDownloadedTotal() const
1238 return credits
->GetDownloadedTotal();
1242 uint64
CUpDownClient::GetUploadedTotal() const
1244 return credits
->GetUploadedTotal();
1248 double CUpDownClient::GetScoreRatio() const
1250 return credits
->GetScoreRatio(GetIP(), theApp
->CryptoAvailable());
1256 CUpDownClient::~CUpDownClient()
1262 CUpDownClient
*CUpDownClientListRem::CreateItem(CEC_UpDownClient_Tag
*tag
)
1264 CUpDownClient
*client
= new CUpDownClient(tag
);
1265 ProcessItemUpdate(tag
, client
);
1267 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->InsertClient(client
, (ViewType
)m_viewtype
);
1273 void CUpDownClientListRem::DeleteItem(CUpDownClient
*client
)
1275 theApp
->amuledlg
->m_transferwnd
->clientlistctrl
->
1276 RemoveClient(client
, (ViewType
)m_viewtype
);
1281 uint32
CUpDownClientListRem::GetItemID(CUpDownClient
*client
)
1283 return client
->GetUserIDHybrid();
1287 void CUpDownClientListRem::ProcessItemUpdate(
1288 CEC_UpDownClient_Tag
*tag
,
1289 CUpDownClient
*client
)
1291 uint16 state
= tag
->ClientState();
1293 client
->m_nDownloadState
= state
& 0xff;
1294 client
->m_nUploadState
= (state
>> 8) & 0xff;
1296 client
->m_nUpDatarate
= tag
->SpeedUp();
1297 if ( client
->m_nDownloadState
== DS_DOWNLOADING
) {
1298 client
->kBpsDown
= tag
->SpeedDown() / 1024.0;
1300 client
->kBpsDown
= 0;
1303 client
->m_WaitTime
= tag
->WaitTime();
1304 client
->m_UpStartTimeDelay
= tag
->XferTime();
1305 client
->m_dwLastUpRequest
= tag
->LastReqTime();
1306 client
->m_WaitStartTime
= tag
->QueueTime();
1308 CreditStruct
*credit_struct
=
1309 (CreditStruct
*)client
->credits
->GetDataStruct();
1310 credit_struct
->uploaded
= tag
->XferUp();
1311 client
->m_nTransferredUp
= tag
->XferUpSession();
1313 credit_struct
->downloaded
= tag
->XferDown();
1314 client
->m_nTransferredDown
= tag
->XferDownSession();
1316 client
->m_score
= tag
->Score();
1317 client
->m_rating
= tag
->Rating();
1321 CUpQueueRem::CUpQueueRem(CRemoteConnect
*conn
)
1323 m_up_list(conn
, vtUploading
), m_wait_list(conn
, vtQueued
)
1329 * Download queue container: hold PartFiles with progress status
1334 CDownQueueRem::CDownQueueRem(CRemoteConnect
*conn
)
1336 CRemoteContainer
<CPartFile
, CMD4Hash
, CEC_PartFile_Tag
>(conn
, true)
1341 bool CDownQueueRem::AddLink(const wxString
&link
, int)
1343 CECPacket
req(EC_OP_ADD_LINK
);
1344 req
.AddTag(CECTag(EC_TAG_STRING
, link
));
1346 m_conn
->SendPacket(&req
);
1351 void CDownQueueRem::StopUDPRequests()
1353 // have no idea what is it about
1357 void CDownQueueRem::ResetCatParts(int)
1359 // called when category being deleted. Command will be performed on remote side
1363 bool CDownQueueRem::IsPartFile(const CKnownFile
*) const
1365 // hope i understand it right
1370 void CDownQueueRem::OnConnectionState(bool)
1375 CPartFile
*CDownQueueRem::CreateItem(CEC_PartFile_Tag
*tag
)
1377 CPartFile
*file
= new CPartFile(tag
);
1378 m_enc_map
[file
->GetFileHash()] = PartFileEncoderData(file
->GetPartCount(), 10);
1379 ProcessItemUpdate(tag
, file
);
1381 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->AddFile(file
);
1386 void CDownQueueRem::DeleteItem(CPartFile
*in_file
)
1388 CScopedPtr
<CPartFile
> file(in_file
);
1390 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->RemoveFile(file
.get());
1392 m_enc_map
.erase(file
->GetFileHash());
1396 CMD4Hash
CDownQueueRem::GetItemID(CPartFile
*file
)
1398 return file
->GetFileHash();
1402 void CDownQueueRem::ProcessItemUpdate(CEC_PartFile_Tag
*tag
, CPartFile
*file
)
1408 uint32 tmpval
= (uint32
)(file
->kBpsDown
* 1024);
1409 tag
->SetSpeed(tmpval
);
1410 file
->kBpsDown
= tmpval
/ 1024.0;
1412 tag
->SetSizeXfer(file
->transferred
);
1413 tag
->SetSizeDone(file
->completedsize
);
1414 tag
->SetSourceXferCount(file
->transferingsrc
);
1415 tag
->SetSourceNotCurrCount(file
->m_notCurrentSources
);
1416 tag
->SetSourceCount(file
->m_source_count
);
1417 tag
->SetSourceCountA4AF(file
->m_a4af_source_count
);
1418 tag
->SetFileStatus(file
->status
);
1420 tag
->SetLastSeenComplete(file
->lastseencomplete
);
1422 tag
->SetFileCat(file
->m_category
);
1424 tag
->SetPrio(file
->m_iDownPriority
);
1426 file
->kBpsDown
= tag
->Speed() / 1024.0;
1428 if ( file
->kBpsDown
> 0 ) {
1429 file
->transferred
= tag
->SizeXfer();
1430 file
->SetCompletedSize(tag
->SizeDone());
1433 file
->transferingsrc
= tag
->SourceXferCount();
1434 file
->m_notCurrentSources
= tag
->SourceNotCurrCount();
1435 file
->m_source_count
= tag
->SourceCount();
1436 file
->m_a4af_source_count
= tag
->SourceCountA4AF();
1437 file
->status
= tag
->FileStatus();
1438 file
->m_stopped
= tag
->Stopped();
1440 file
->lastseencomplete
= tag
->LastSeenComplete();
1441 file
->m_lastDateChanged
= tag
->LastDateChanged();
1443 file
->m_category
= tag
->FileCat();
1445 file
->m_iDownPriority
= tag
->Prio();
1446 if ( file
->m_iDownPriority
>= 10 ) {
1447 file
->m_iDownPriority
-= 10;
1448 file
->m_bAutoDownPriority
= true;
1450 file
->m_bAutoDownPriority
= false;
1453 file
->percentcompleted
= (100.0*file
->GetCompletedSize()) / file
->GetFileSize();
1454 if ( file
->m_iDownPriority
>= 10 ) {
1455 file
->m_iDownPriority
-= 10;
1456 file
->m_bAutoUpPriority
= true;
1458 file
->m_bAutoUpPriority
= false;
1462 // Copy part/gap status
1464 CECTag
*gaptag
= tag
->GetTagByName(EC_TAG_PARTFILE_GAP_STATUS
);
1465 CECTag
*parttag
= tag
->GetTagByName(EC_TAG_PARTFILE_PART_STATUS
);
1466 CECTag
*reqtag
= tag
->GetTagByName(EC_TAG_PARTFILE_REQ_STATUS
);
1467 if (gaptag
&& parttag
&& reqtag
) {
1468 wxASSERT(m_enc_map
.count(file
->GetFileHash()));
1470 PartFileEncoderData
&encoder
= m_enc_map
[file
->GetFileHash()];
1472 (unsigned char *)gaptag
->GetTagData(), gaptag
->GetTagDataLen(),
1473 (unsigned char *)parttag
->GetTagData(), parttag
->GetTagDataLen());
1475 const uint64
*reqparts
= (const uint64
*)reqtag
->GetTagData();
1476 unsigned reqcount
= reqtag
->GetTagDataLen() / (2 * sizeof(uint64
));
1478 unsigned gap_size
= encoder
.m_gap_status
.Size() / (2 * sizeof(uint64
));
1480 file
->m_gaplist
.Init(file
->GetFileSize(), false);
1483 const uint64
*gap_info
= (const uint64
*)encoder
.m_gap_status
.Buffer();
1484 for (unsigned j
= 0; j
< gap_size
;j
++) {
1485 file
->m_gaplist
.AddGap(ENDIAN_NTOHLL(gap_info
[2*j
]), ENDIAN_NTOHLL(gap_info
[2*j
+1]));
1488 // adjust size of requested block list
1489 while ( file
->m_requestedblocks_list
.size() > reqcount
) {
1490 delete file
->m_requestedblocks_list
.front();
1491 file
->m_requestedblocks_list
.pop_front();
1493 while ( file
->m_requestedblocks_list
.size() != reqcount
) {
1494 file
->m_requestedblocks_list
.push_front(new Requested_Block_Struct
);
1497 std::list
<Requested_Block_Struct
*>::iterator it2
= file
->m_requestedblocks_list
.begin();
1498 for (unsigned i
= 0; i
< reqcount
; ++i
) {
1499 Requested_Block_Struct
* block
= *it2
++;
1500 block
->StartOffset
= ENDIAN_NTOHLL(reqparts
[2*i
]);
1501 block
->EndOffset
= ENDIAN_NTOHLL(reqparts
[2*i
+1]);
1503 // copy parts frequency
1504 const unsigned char *part_info
= encoder
.m_part_status
.Buffer();
1505 for(int i
= 0; i
< file
->GetPartCount(); ++i
) {
1506 file
->m_SrcpartFrequency
[i
] = part_info
[i
];
1509 AddLogLineNS(CFormat(wxT("ERROR: %X %X %X")) % (size_t)gaptag
% (size_t)parttag
% (size_t)reqtag
);
1513 CECTag
*srcnametag
= tag
->GetTagByName(EC_TAG_PARTFILE_SOURCE_NAMES
);
1515 file
->ClearSourcenameItemList();
1516 int max
= srcnametag
->GetTagCount();
1517 for (int i
= 0; i
< max
- 1; ) {
1518 wxString name
= srcnametag
->GetTagByIndex(i
++)->GetStringData();
1519 long count
= srcnametag
->GetTagByIndex(i
++)->GetInt();
1520 file
->AddSourcenameItemList(name
, count
);
1525 CECTag
*commenttag
= tag
->GetTagByName(EC_TAG_PARTFILE_COMMENTS
);
1527 file
->ClearFileRatingList();
1528 int max
= commenttag
->GetTagCount();
1529 for (int i
= 0; i
< max
- 3; ) {
1530 wxString u
= commenttag
->GetTagByIndex(i
++)->GetStringData();
1531 wxString f
= commenttag
->GetTagByIndex(i
++)->GetStringData();
1532 int r
= commenttag
->GetTagByIndex(i
++)->GetInt();
1533 wxString c
= commenttag
->GetTagByIndex(i
++)->GetStringData();
1534 file
->AddFileRatingList(u
, f
, r
, c
);
1536 file
->UpdateFileRatingCommentAvail();
1539 theApp
->amuledlg
->m_transferwnd
->downloadlistctrl
->UpdateItem(file
);
1543 bool CDownQueueRem::Phase1Done(const CECPacket
*)
1549 void CDownQueueRem::SendFileCommand(CPartFile
*file
, ec_tagname_t cmd
)
1552 req
.AddTag(CECTag(EC_TAG_PARTFILE
, file
->GetFileHash()));
1554 m_conn
->SendPacket(&req
);
1558 void CDownQueueRem::Prio(CPartFile
*file
, uint8 prio
)
1560 CECPacket
req(EC_OP_PARTFILE_PRIO_SET
);
1562 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1563 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
, prio
));
1564 req
.AddTag(hashtag
);
1566 m_conn
->SendPacket(&req
);
1570 void CDownQueueRem::AutoPrio(CPartFile
*file
, bool flag
)
1572 CECPacket
req(EC_OP_PARTFILE_PRIO_SET
);
1574 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1576 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_PRIO
,
1577 (uint8
)(flag
? PR_AUTO
: file
->GetDownPriority())));
1578 req
.AddTag(hashtag
);
1580 m_conn
->SendPacket(&req
);
1584 void CDownQueueRem::Category(CPartFile
*file
, uint8 cat
)
1586 CECPacket
req(EC_OP_PARTFILE_SET_CAT
);
1587 file
->m_category
= cat
;
1589 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1590 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_CAT
, cat
));
1591 req
.AddTag(hashtag
);
1593 m_conn
->SendPacket(&req
);
1597 void CDownQueueRem::AddSearchToDownload(CSearchFile
* file
, uint8 category
)
1599 CECPacket
req(EC_OP_DOWNLOAD_SEARCH_RESULT
);
1600 CECTag
hashtag(EC_TAG_PARTFILE
, file
->GetFileHash());
1601 hashtag
.AddTag(CECTag(EC_TAG_PARTFILE_CAT
, category
));
1602 req
.AddTag(hashtag
);
1604 m_conn
->SendPacket(&req
);
1608 CClientListRem::CClientListRem(CRemoteConnect
*conn
)
1614 void CClientListRem::FilterQueues()
1621 CSearchListRem::CSearchListRem(CRemoteConnect
*conn
) : CRemoteContainer
<CSearchFile
, CMD4Hash
, CEC_SearchFile_Tag
>(conn
)
1627 wxString
CSearchListRem::StartNewSearch(
1628 uint32
* nSearchID
, SearchType search_type
,
1629 const CSearchList::CSearchParams
& params
)
1631 CECPacket
search_req(EC_OP_SEARCH_START
);
1632 EC_SEARCH_TYPE ec_search_type
= EC_SEARCH_LOCAL
;
1633 switch(search_type
) {
1634 case LocalSearch
: ec_search_type
= EC_SEARCH_LOCAL
; break;
1635 case GlobalSearch
: ec_search_type
= EC_SEARCH_GLOBAL
; break;
1636 case KadSearch
: ec_search_type
= EC_SEARCH_KAD
; break;
1639 CEC_Search_Tag(params
.searchString
, ec_search_type
,
1640 params
.typeText
, params
.extension
, params
.availability
,
1641 params
.minSize
, params
.maxSize
));
1643 m_conn
->SendPacket(&search_req
);
1644 m_curr_search
= *(nSearchID
); // No kad remote search yet.
1648 return wxEmptyString
; // EC reply will have the error mesg is needed.
1652 void CSearchListRem::StopGlobalSearch()
1654 if (m_curr_search
!= -1) {
1655 CECPacket
search_req(EC_OP_SEARCH_STOP
);
1656 m_conn
->SendPacket(&search_req
);
1661 void CSearchListRem::HandlePacket(const CECPacket
*packet
)
1663 if ( packet
->GetOpCode() == EC_OP_SEARCH_PROGRESS
) {
1664 CoreNotify_Search_Update_Progress(packet
->GetTagByIndex(0)->GetInt());
1666 CRemoteContainer
<CSearchFile
, CMD4Hash
, CEC_SearchFile_Tag
>::HandlePacket(packet
);
1671 CSearchFile::CSearchFile(CEC_SearchFile_Tag
*tag
)
1674 m_showChildren(false),
1676 m_completeSourceCount(0),
1681 SetFileName(CPath(tag
->FileName()));
1682 m_abyFileHash
= tag
->ID();
1683 SetFileSize(tag
->SizeFull());
1685 m_searchID
= theApp
->searchlist
->m_curr_search
;
1690 // dtor is virtual - must be implemented
1691 CSearchFile::~CSearchFile()
1696 CSearchFile
*CSearchListRem::CreateItem(CEC_SearchFile_Tag
*tag
)
1698 CSearchFile
*file
= new CSearchFile(tag
);
1699 ProcessItemUpdate(tag
, file
);
1701 theApp
->amuledlg
->m_searchwnd
->AddResult(file
);
1707 void CSearchListRem::DeleteItem(CSearchFile
*file
)
1713 CMD4Hash
CSearchListRem::GetItemID(CSearchFile
*file
)
1715 return file
->GetFileHash();
1719 void CSearchListRem::ProcessItemUpdate(CEC_SearchFile_Tag
*tag
, CSearchFile
*file
)
1721 file
->m_sourceCount
= tag
->SourceCount();
1722 file
->m_completeSourceCount
= tag
->CompleteSourceCount();
1726 bool CSearchListRem::Phase1Done(const CECPacket
*WXUNUSED(reply
))
1728 CECPacket
progress_req(EC_OP_SEARCH_PROGRESS
);
1729 m_conn
->SendRequest(this, &progress_req
);
1735 void CSearchListRem::RemoveResults(long nSearchID
)
1737 ResultMap::iterator it
= m_results
.find(nSearchID
);
1738 if (it
!= m_results
.end()) {
1739 CSearchResultList
& list
= it
->second
;
1740 for (unsigned int i
= 0; i
< list
.size(); ++i
) {
1743 m_results
.erase(it
);
1748 const CSearchResultList
& CSearchListRem::GetSearchResults(long nSearchID
)
1750 ResultMap::const_iterator it
= m_results
.find(nSearchID
);
1751 if (it
!= m_results
.end()) {
1755 // TODO: Should we assert in this case?
1756 static CSearchResultList list
;
1761 void CStatsUpdaterRem::HandlePacket(const CECPacket
*packet
)
1763 theStats::UpdateStats(packet
);
1764 theApp
->ShowUserCount(); // maybe there should be a check if a usercount changed ?
1768 bool CUpDownClient::IsBanned() const
1776 // Those functions have different implementation in remote gui
1778 void CUpDownClient::Ban()
1785 void CUpDownClient::UnBan()
1792 void CUpDownClient::RequestSharedFileList()
1799 void CKnownFile::SetFileComment(const wxString
&)
1802 wxMessageBox(_("Comments and ratings are not supported on remote gui yet"), _("Information"), wxOK
| wxICON_INFORMATION
);
1806 void CKnownFile::SetFileRating(unsigned char)
1812 // I don't think it will be implemented - too match data transfer. But who knows ?
1813 wxString
CUpDownClient::ShowDownloadingParts() const
1815 return wxEmptyString
;
1819 bool CUpDownClient::SwapToAnotherFile(
1820 bool WXUNUSED(bIgnoreNoNeeded
),
1821 bool WXUNUSED(ignoreSuspensions
),
1822 bool WXUNUSED(bRemoveCompletely
),
1823 CPartFile
* WXUNUSED(toFile
))
1832 // Those functions are virtual. So even they don't get called they must
1833 // be defined so linker will be happy
1835 CPacket
* CKnownFile::CreateSrcInfoPacket(const CUpDownClient
*, uint8
/*byRequestedVersion*/, uint16
/*nRequestedOptions*/)
1842 bool CKnownFile::LoadFromFile(const class CFileDataIO
*)
1849 void CKnownFile::UpdatePartsInfo()
1855 CPacket
* CPartFile::CreateSrcInfoPacket(CUpDownClient
const *, uint8
/*byRequestedVersion*/, uint16
/*nRequestedOptions*/)
1862 void CPartFile::UpdatePartsInfo()
1868 void CPartFile::UpdateFileRatingCommentAvail()
1870 bool prevComment
= m_hasComment
;
1871 int prevRating
= m_iUserRating
;
1873 m_hasComment
= false;
1875 int ratingCount
= 0;
1877 FileRatingList::iterator it
= m_FileRatingList
.begin();
1878 for (; it
!= m_FileRatingList
.end(); ++it
) {
1879 SFileRating
& cur_rat
= *it
;
1881 if (!cur_rat
.Comment
.IsEmpty()) {
1882 m_hasComment
= true;
1885 uint8 rating
= cur_rat
.Rating
;
1887 wxASSERT(rating
<= 5);
1890 m_iUserRating
+= rating
;
1895 m_iUserRating
/= ratingCount
;
1896 wxASSERT(m_iUserRating
> 0 && m_iUserRating
<= 5);
1899 if ((prevComment
!= m_hasComment
) || (prevRating
!= m_iUserRating
)) {
1900 UpdateDisplayedInfo();
1904 bool CPartFile::SavePartFile(bool)
1912 // since gui is not linked with amule.cpp - define events here
1914 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_FINISHED_HTTP_DOWNLOAD
)
1915 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_SOURCE_DNS_DONE
)
1916 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_UDP_DNS_DONE
)
1917 DEFINE_LOCAL_EVENT_TYPE(wxEVT_CORE_SERVER_DNS_DONE
)
1918 // File_checked_for_headers