mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-11 04:32:30 +00:00
bd7849199c
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@252 e378c898-3ddf-0310-93e7-cc216c733640
98 lines
1.9 KiB
C++
98 lines
1.9 KiB
C++
#include <string>
|
|
#include <stdexcept>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <torrent/torrent.h>
|
|
#include <sigc++/bind.h>
|
|
|
|
#include "display/canvas.h"
|
|
#include "display/window_statusbar.h"
|
|
|
|
#include "core/poll.h"
|
|
#include "core/curl_stack.h"
|
|
#include "core/download_list.h"
|
|
|
|
#include "ui/control.h"
|
|
#include "ui/download_list.h"
|
|
|
|
#include "signal_handler.h"
|
|
|
|
bool start_shutdown = false;
|
|
bool is_shutting_down = false;
|
|
|
|
core::Poll poll;
|
|
core::DownloadList downloads;
|
|
|
|
void
|
|
set_shutdown() {
|
|
start_shutdown = true;
|
|
}
|
|
|
|
void
|
|
do_shutdown() {
|
|
if (is_shutting_down)
|
|
// Be quick about it...
|
|
return;
|
|
|
|
is_shutting_down = true;
|
|
|
|
torrent::listen_close();
|
|
|
|
std::for_each(downloads.begin(), downloads.end(), std::mem_fun_ref(&core::Download::stop));
|
|
}
|
|
|
|
int
|
|
main(int argc, char** argv) {
|
|
try {
|
|
|
|
display::Canvas::init();
|
|
core::CurlStack::init();
|
|
|
|
ui::Control uiControl;
|
|
ui::DownloadList uiDownloadList(&downloads, &uiControl);
|
|
|
|
uiControl.get_display().push_front(new display::WindowStatusbar);
|
|
|
|
uiDownloadList.activate();
|
|
|
|
poll.slot_read_stdin(sigc::mem_fun(uiControl.get_input(), &input::Manager::pressed));
|
|
poll.register_http();
|
|
|
|
torrent::initialize();
|
|
torrent::listen_open(6880, 6999);
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
std::fstream f(argv[i], std::ios::in);
|
|
|
|
core::DownloadList::iterator itr = downloads.create(f);
|
|
|
|
itr->open();
|
|
itr->hash_check();
|
|
}
|
|
|
|
SignalHandler::set_handler(SIGINT, sigc::ptr_fun(&set_shutdown));
|
|
|
|
while (!is_shutting_down || !torrent::get(torrent::SHUTDOWN_DONE)) {
|
|
if (start_shutdown && !is_shutting_down)
|
|
do_shutdown();
|
|
|
|
uiControl.get_display().adjust_layout();
|
|
uiControl.get_display().do_update();
|
|
|
|
poll.poll();
|
|
}
|
|
|
|
display::Canvas::cleanup();
|
|
|
|
} catch (std::exception& e) {
|
|
display::Canvas::cleanup();
|
|
|
|
std::cout << "Caught exception: \"" << e.what() << '"' << std::endl;
|
|
}
|
|
|
|
torrent::cleanup();
|
|
core::CurlStack::cleanup();
|
|
|
|
return 0;
|
|
}
|