/* */ #include "TorrentRequestInfo.h" #include "DownloadEngineFactory.h" #include "prefs.h" #include "Util.h" extern RequestInfo* requestInfo; extern void setSignalHander(int signal, void (*handler)(int), int flags); void torrentHandler(int signal) { ((TorrentDownloadEngine*)requestInfo->getDownloadEngine())-> torrentMan->setHalt(true); } RequestInfo* TorrentRequestInfo::execute() { if(op->get(PREF_SHOW_FILES) == V_TRUE) { showFileEntry(); return 0; } e = DownloadEngineFactory::newTorrentConsoleEngine(op, torrentFile, targetFiles); setSignalHander(SIGINT, torrentHandler, SA_RESETHAND); setSignalHander(SIGTERM, torrentHandler, SA_RESETHAND); try { e->run(); if(e->torrentMan->downloadComplete()) { printDownloadCompeleteMessage(); } } catch(Exception* e) { logger->error("Exception caught", e); delete e; fail = true; } setSignalHander(SIGINT, SIG_DFL, 0); setSignalHander(SIGTERM, SIG_DFL, 0); delete e; return 0; } // TODO should be const TorrentMan* torrentMan void TorrentRequestInfo::showFileEntry() { TorrentMan torrentMan; torrentMan.option = op; FileEntries fileEntries = torrentMan.readFileEntryFromMetaInfoFile(torrentFile); cout << _("Files:") << endl; cout << "idx|path/length" << endl; cout << "===+===========================================================================" << endl; int count = 1; for(FileEntries::const_iterator itr = fileEntries.begin(); itr != fileEntries.end(); count++, itr++) { printf("%3d|%s\n |%s Bytes\n", count, itr->path.c_str(), Util::llitos(itr->length, true).c_str()); cout << "---+---------------------------------------------------------------------------" << endl; } }