Beispiel #1
0
int main(int argc, char *argv[])
{
    signal(SIGTERM, sigtermListened);
    signal(SIGINT, sigtermListened);
    signal(SIGQUIT, sigtermListened);

    std::string torrent, bt;
    std::string downloadPath;
    std::string mountPath;
    std::string rate;

    if ((argc == 2) && (argv[1][0] != '-')) {
        bt = argv[1];
        argv[1] = "-g";
    }

    po::options_description desc("General options");
    desc.add_options()
            ("torrent,t", po::value<std::string>(&torrent), "Input torrent file")
            ("downloadpath,d", po::value<std::string>(&downloadPath), "Download path")
            ("mount,m", po::value<std::string>(&mountPath), "Path to mount files")
            ("limit-rate,r", po::value<std::string>(&rate), "Limit rate")
            ("seeding-manager,s", "To start a seeding manager")
            ("gui,g", "Start a little gui")
            ("help,h", "Show help");

    po::variables_map vm;
    po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run();
    po::store(parsed, vm);
    po::notify(vm);

    if (vm.count("help"))
        showHelp();

    if (torrent == "")
        torrent = bt;

    bool magnet = isMagnet(QString::fromStdString(torrent));

    if (vm.count("seeding-manager")) {
        QCoreApplication a(argc, argv);
        SeedManager manager(QString::fromStdString(rate), &a);
        c = &manager;
        return a.exec();
    } else if (vm.count("gui") || (!QFile::exists(QString::fromStdString(torrent)) && !magnet)) {
        if ((vm.count("gui") == 0) && (!QFile::exists(QString::fromStdString(torrent))) && !isMagnet(QString::fromStdString(torrent)))
            printf("You must specify a valid torrent file (or --gui)\n");

        QApplication a(argc, argv);
        MainWindow w(QString::fromStdString(torrent), QString::fromStdString(downloadPath), QString::fromStdString(mountPath), QString::fromStdString(rate), true);
        c = &w;
        return a.exec();
    } else {
        QCoreApplication a(argc, argv);
        MainWindow w(QString::fromStdString(torrent), QString::fromStdString(downloadPath), QString::fromStdString(mountPath), QString::fromStdString(rate), false, &a);
        c = &w;
        return a.exec();
    }
}
Beispiel #2
0
void MainWindow::addTorrent() {
    QString torrent = QFileDialog::getOpenFileName(fake, QString(), QString(),
                                                   QString("*.torrent"));
    if (QFile(torrent).exists() || isMagnet(torrent))
        findPaths(torrent);
    else
        die("User don't choose torrent file");
}
Beispiel #3
0
void MainWindow::realAddTorrent(QString torrentFile, QString torrentPath, QString mountPath) {
    if (!QFile::exists(torrentFile) && !isMagnet(torrentFile))
        die("torrent file not found");

    standartText = ("Torrent file: " + torrentFile + "\nDownload path: " + torrentPath + "\nMount path: " + mountPath + "\n").toLocal8Bit();
    standartTextLen = standartText.size();
    updateStandartText();

    if (torrentPath[torrentPath.length() - 1] != QChar('/'))
        torrentPath += "/";
    if (mountPath[mountPath.length() - 1] != QChar('/'))
        mountPath += "/";

    resumeSavePath = torrentPath;

    add_torrent_params p;
    p.storage_mode = libtorrent::storage_mode_allocate;

    if (isMagnet(torrentFile)) {
        int i;
        for (i = 1; torrentFile[i] != '='; i++);
        for (i = i + 1; torrentFile[i] != '='; i++);

        QString url;
        for (i = i + 1; torrentFile[i] != '&'; i++)
            url += torrentFile[i];

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
        QString name = QUrl(url).toString().replace("+", " ");
#else
        QString name = QUrl(url).toString(QUrl::PreferLocalFile).replace("+", " ");
#endif
        p.save_path = (torrentPath + name + "/").toStdString();

        const torrent_handle h = libtorrent::add_magnet_uri(*session, torrentFile.toStdString(), p);
        main = new Torrent(torrentPath + QString::fromStdString(h.name()), mountPath + QString::fromStdString(h.name()), h, this);
    } else {
        torrent_info *inf = new libtorrent::torrent_info(torrentFile.toStdString());
        p.ti = inf;
        p.save_path = (torrentPath + QString::fromStdString(inf->name()) + "/").toStdString();
        main = new Torrent(torrentPath + QString::fromStdString(inf->name()), mountPath + QString::fromStdString(inf->name()), session->add_torrent(p), this);
    }

    setupTimers();
}
Beispiel #4
0
MainWindow::MainWindow(QString torrent, QString downloadPath, QString mountPath, QString rate, bool gui, QObject *parent): QObject(parent) {
    initSession(rate);
    initscr();
    nodelay(stdscr, true);
    noecho();
    main = NULL;
    if (!gui)
        realAddTorrent(torrent, downloadPath, mountPath);
    else {
        fake = new QMainWindow;
        if (QFile(torrent).exists() || isMagnet(torrent))
            findPaths(torrent);
        else
            addTorrent();
    }
}