示例#1
0
MainWindow::~MainWindow() {
    endwin();
    if ((main == NULL) || (!main->torrent->is_valid() || (main->torrent->status().progress < 0.5))) {
        informationFlushed = true;
        qDebug() << "Sending information about (upload/download) sizes to tracker";
        delete session;
        return;
    }
    qDebug() << "saving information about torrent";
    std::deque<alert *> trash;
    session->pop_alerts(&trash);
    main->torrent->save_resume_data(torrent_handle::save_info_dict);
    const alert *a = session->wait_for_alert(libtorrent::seconds(3));
    if (a == NULL) {
        qDebug() << "Can not save resume data";
        exit(1);
    }

    std::auto_ptr<alert> holder = session->pop_alert();
    if (libtorrent::alert_cast<libtorrent::save_resume_data_failed_alert>(a)) {
        qDebug() << "Failed alert";
        exit(1);
    }

    const libtorrent::save_resume_data_alert *rd = libtorrent::alert_cast<libtorrent::save_resume_data_alert>(a);
    if (rd == 0) {
        qDebug() << "Very big fail";
        exit(1);
    }

    QSettings s(settingsPath + QString::fromStdString(main->torrent->name()) + ".qlivebittorrent", QSettings::IniFormat);
    s.setValue("path", QVariant(resumeSavePath));
    s.setValue("data", saveResumeData(rd));
    s.sync();

    informationFlushed = true;
    qDebug() << "Sending information about (upload/download) sizes to tracker";
    delete session;
}
SeedManager::~SeedManager() {
    endwin();
    qDebug() << "saving information about torrents";
    std::vector<torrent_handle> v = session->get_torrents();
    for (int i = 0; i < v.size(); i++) {
        std::deque<alert *> trash;
        session->pop_alerts(&trash);
        v[i].save_resume_data(torrent_handle::save_info_dict);
        const alert *a = session->wait_for_alert(libtorrent::seconds(3));
        if (a == NULL) {
            qDebug() << "Can not save resume data";
            break;
        }

        std::auto_ptr<alert> holder = session->pop_alert();
        if (libtorrent::alert_cast<libtorrent::save_resume_data_failed_alert>(a)) {
            qDebug() << "Failed alert";
            break;
        }

        const libtorrent::save_resume_data_alert *rd = libtorrent::alert_cast<libtorrent::save_resume_data_alert>(a);
        if (rd == 0) {
            qDebug() << "Very big fail";
            break;
        }

        QSettings s(settingsPath + QString::fromStdString(v[i].name()) + ".qlivebittorrent", QSettings::IniFormat);
        s.setValue("data", QVariant(saveResumeData(rd)));
        s.sync();
    }

    informationFlushed = true;
    qDebug() << "sending information about (upload/download) sizes to trackers";
    session->pause();
    delete session;
}