From f7e49edeea70b48e660ec331a29900c65e3a9a98 Mon Sep 17 00:00:00 2001 From: upstream svn Date: Sat, 21 Nov 2009 16:12:56 +0000 Subject: [PATCH] Upstream tarball 9877 --- .svn-revision | 2 +- docs/Changelog | 1 + src/amule.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/amule.h | 1 + 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/.svn-revision b/.svn-revision index 96aaf52d..5e06abb3 100644 --- a/.svn-revision +++ b/.svn-revision @@ -1 +1 @@ -9875 +9877 diff --git a/docs/Changelog b/docs/Changelog index a5dfe9fd..b4f6cd59 100644 --- a/docs/Changelog +++ b/docs/Changelog @@ -106,6 +106,7 @@ Version 2.3.0 - The river knows. * Configure option --enable-fileview * Bypass amulegui connection dialog with switch -s / --skip * Fixed Core Timer + * Allow passing of ED2K links by command line to amule and amuled, making ed2k program obsolete Vollstrecker: * Unify copyright lines diff --git a/src/amule.cpp b/src/amule.cpp index cf731417..70d8e601 100644 --- a/src/amule.cpp +++ b/src/amule.cpp @@ -57,6 +57,7 @@ #include "ClientCreditsList.h" // Needed for CClientCreditsList #include "ClientList.h" // Needed for CClientList #include "ClientUDPSocket.h" // Needed for CClientUDPSocket & CMuleUDPSocket +#include "ED2KLink.h" // Needed for command line passing of links #include "ExternalConn.h" // Needed for ExternalConn & MuleConnection #include // Needed for CDirIterator #include "FriendList.h" // Needed for CFriendList @@ -471,6 +472,9 @@ bool CamuleApp::OnInit() // Change webserver path, not available on Windows cmdline.AddOption(wxT("w"), wxT("use-amuleweb"), wxT("Specify location of amuleweb binary.")); #endif + // Allow passing of links to the app + cmdline.AddOption(wxT("c"), wxT("category"), wxT("Set category for passed ED2K links."), wxCMD_LINE_VAL_NUMBER); + cmdline.AddParam(wxT("ED2K link"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE); // Show help on --help or invalid commands if ( cmdline.Parse() ) { @@ -553,6 +557,32 @@ bool CamuleApp::OnInit() wxRenameFile(ConfigDir + wxT("amule.conf"), ConfigDir + wxT("amule.conf.backup")); AddLogLineMS(false, wxT("Your settings have been reset to default values.\nThe old config file has been saved as amule.conf.backup\n")); } + + size_t linksPassed = cmdline.GetParamCount(); // number of links from the command line + int linksActuallyPassed = 0; // number of links that pass the syntax check + if (linksPassed) { + long cat = 0; + if (!cmdline.Found(wxT("c"), &cat)) { + cat = 0; + } + + wxTextFile ed2kFile(ConfigDir + wxT("ED2KLinks")); + if (!ed2kFile.Exists()) { + ed2kFile.Create(); + } + if (ed2kFile.Open()) { + for (size_t i = 0; i < linksPassed; i++) { + wxString link; + if (CheckPassedLink(cmdline.GetParam(i), link, cat)) { + ed2kFile.AddLine(link); + linksActuallyPassed++; + } + } + ed2kFile.Write(); + } else { + AddLogLineCS(wxT("Failed to open 'ED2KFile', cannot add links.")); + } + } #if defined(__WXMAC__) && defined(AMULE_DAEMON) //#warning TODO: fix wxSingleInstanceChecker for amuled on Mac (wx link problems) @@ -566,6 +596,11 @@ bool CamuleApp::OnInit() && m_singleInstance->IsAnotherRunning()) { AddLogLineMS(true, wxT("There is an instance of aMule already running")); AddLogLineNS(CFormat(wxT("(lock file: %s%s)")) % ConfigDir % wxT("muleLock")); + if (linksPassed) { + AddLogLineNS(CFormat(wxT("passed %d %s to it, finished")) % linksActuallyPassed + % (linksPassed == 1 ? wxT("link") : wxT("links"))); + return false; + } // This is very tricky. The most secure way to communicate is via ED2K links file wxTextFile ed2kFile(ConfigDir + wxT("ED2KLinks")); @@ -886,6 +921,31 @@ bool CamuleApp::OnInit() return true; } +bool CamuleApp::CheckPassedLink(const wxString &in, wxString &out, int cat) +{ + wxString link(in); + + if (link.compare(0, 7, wxT("magnet:")) == 0) { + link = CMagnetED2KConverter(link); + if (link.empty()) { + AddLogLineCS(CFormat(wxT("Cannot convert magnet link to eD2k: %s")) % in); + return false; + } + } + + try { + CScopedPtr uri(CED2KLink::CreateLinkFromUrl(link)); + out = uri.get()->GetLink(); + if (cat && uri.get()->GetKind() == CED2KLink::kFile) { + out += CFormat(wxT(":%d")) % cat; + } + return true; + } catch ( const wxString& err ) { + AddLogLineCS(CFormat(wxT("Invalid eD2k link \"%s\" - ERROR: %s")) % link % err); + } + return false; +} + bool CamuleApp::ReinitializeNetwork(wxString* msg) { bool ok = true; diff --git a/src/amule.h b/src/amule.h index 18c8cd93..7720ce3b 100644 --- a/src/amule.h +++ b/src/amule.h @@ -112,6 +112,7 @@ private: APP_STATE_SHUTTINGDOWN, APP_STATE_STARTING }; + bool CheckPassedLink(const wxString &in, wxString &out, int cat); public: CamuleApp(); -- 2.11.4.GIT