|
|
@ -44,9 +44,17 @@ using namespace boost::filesystem; |
|
|
|
createtorrent::createtorrent(QWidget *parent): QDialog(parent){ |
|
|
|
createtorrent::createtorrent(QWidget *parent): QDialog(parent){ |
|
|
|
setupUi(this); |
|
|
|
setupUi(this); |
|
|
|
setAttribute(Qt::WA_DeleteOnClose); |
|
|
|
setAttribute(Qt::WA_DeleteOnClose); |
|
|
|
|
|
|
|
creatorThread = new torrentCreatorThread(); |
|
|
|
|
|
|
|
connect(creatorThread, SIGNAL(creationSuccess(QString)), this, SLOT(handleCreationSucess(QString))); |
|
|
|
|
|
|
|
connect(creatorThread, SIGNAL(creationFailure(QString)), this, SLOT(handleCreationFailure(QString))); |
|
|
|
|
|
|
|
connect(creatorThread, SIGNAL(updateProgress(int)), this, SLOT(updateProgressBar(int))); |
|
|
|
show(); |
|
|
|
show(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
createtorrent::~createtorrent() { |
|
|
|
|
|
|
|
delete creatorThread; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void createtorrent::on_addFolder_button_clicked(){ |
|
|
|
void createtorrent::on_addFolder_button_clicked(){ |
|
|
|
QString dir = QFileDialog::getExistingDirectory(this, tr("Select a folder to add to the torrent"), QDir::homePath(), QFileDialog::ShowDirsOnly); |
|
|
|
QString dir = QFileDialog::getExistingDirectory(this, tr("Select a folder to add to the torrent"), QDir::homePath(), QFileDialog::ShowDirsOnly); |
|
|
|
if(!dir.isEmpty()) |
|
|
|
if(!dir.isEmpty()) |
|
|
@ -162,26 +170,70 @@ void createtorrent::on_createButton_clicked(){ |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
QStringList url_seeds = allItems(URLSeeds_list); |
|
|
|
|
|
|
|
QString comment = txt_comment->toPlainText(); |
|
|
|
|
|
|
|
creatorThread->create(input, destination, trackers, url_seeds, comment, check_private->isChecked(), getPieceSize()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void createtorrent::handleCreationFailure(QString msg) { |
|
|
|
|
|
|
|
QMessageBox::information(0, tr("Torrent creation"), tr("Torrent creation was unsuccessful, reason: %1").arg(msg)); |
|
|
|
|
|
|
|
hide(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void createtorrent::handleCreationSuccess(QString path, const char* branch_path, QString hash) { |
|
|
|
|
|
|
|
if(checkStartSeeding->isChecked()) { |
|
|
|
|
|
|
|
// Create save path file
|
|
|
|
|
|
|
|
QFile savepath_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".savepath")); |
|
|
|
|
|
|
|
savepath_file.open(QIODevice::WriteOnly | QIODevice::Text); |
|
|
|
|
|
|
|
savepath_file.write(branch_path); |
|
|
|
|
|
|
|
savepath_file.close(); |
|
|
|
|
|
|
|
emit torrent_to_seed(path); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
QMessageBox::information(0, tr("Torrent creation"), tr("Torrent was created successfully:")+" "+path); |
|
|
|
|
|
|
|
hide(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void createtorrent::updateProgressBar(int progress) { |
|
|
|
|
|
|
|
progressBar->setValue(progress); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Torrent Creator Thread
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void torrentCreatorThread::create(QString _input_path, QString _save_path, QStringList _trackers, QStringList _url_seeds, QString _comment, bool _is_private, int _piece_size) { |
|
|
|
|
|
|
|
input_path = _input_path; |
|
|
|
|
|
|
|
save_path = _save_path; |
|
|
|
|
|
|
|
trackers = _trackers; |
|
|
|
|
|
|
|
url_seeds = _url_seeds; |
|
|
|
|
|
|
|
comment = _comment; |
|
|
|
|
|
|
|
is_private = _is_private; |
|
|
|
|
|
|
|
piece_size = _piece_size; |
|
|
|
|
|
|
|
abort = false; |
|
|
|
|
|
|
|
start(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void torrentCreatorThread::run() { |
|
|
|
|
|
|
|
emit updateProgress(0); |
|
|
|
char const* creator_str = "qBittorrent "VERSION; |
|
|
|
char const* creator_str = "qBittorrent "VERSION; |
|
|
|
try { |
|
|
|
try { |
|
|
|
boost::intrusive_ptr<torrent_info> t(new torrent_info); |
|
|
|
boost::intrusive_ptr<torrent_info> t(new torrent_info); |
|
|
|
ofstream out(complete(path((const char*)destination.toUtf8())), std::ios_base::binary); |
|
|
|
ofstream out(complete(path((const char*)save_path.toUtf8())), std::ios_base::binary); |
|
|
|
// Adding files to the torrent
|
|
|
|
// Adding files to the torrent
|
|
|
|
path full_path = complete(path(input.toUtf8().data())); |
|
|
|
path full_path = complete(path(input_path.toUtf8().data())); |
|
|
|
add_files(*t, full_path.branch_path(), full_path.leaf()); |
|
|
|
add_files(*t, full_path.branch_path(), full_path.leaf()); |
|
|
|
|
|
|
|
if(abort) return; |
|
|
|
// Set piece size
|
|
|
|
// Set piece size
|
|
|
|
int piece_size = getPieceSize(); |
|
|
|
|
|
|
|
t->set_piece_size(piece_size); |
|
|
|
t->set_piece_size(piece_size); |
|
|
|
// Add url seeds
|
|
|
|
// Add url seeds
|
|
|
|
QStringList urlSeeds = allItems(URLSeeds_list); |
|
|
|
|
|
|
|
QString seed; |
|
|
|
QString seed; |
|
|
|
foreach(seed, urlSeeds){ |
|
|
|
foreach(seed, url_seeds){ |
|
|
|
t->add_url_seed(seed.toUtf8().data()); |
|
|
|
t->add_url_seed(seed.toUtf8().data()); |
|
|
|
} |
|
|
|
} |
|
|
|
for(int i=0; i<trackers.size(); ++i){ |
|
|
|
for(int i=0; i<trackers.size(); ++i){ |
|
|
|
t->add_tracker(trackers.at(i).toUtf8().data()); |
|
|
|
t->add_tracker(trackers.at(i).toUtf8().data()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(abort) return; |
|
|
|
// calculate the hash for all pieces
|
|
|
|
// calculate the hash for all pieces
|
|
|
|
file_pool fp; |
|
|
|
file_pool fp; |
|
|
|
boost::scoped_ptr<storage_interface> st(default_storage_constructor(t, full_path.branch_path(), fp)); |
|
|
|
boost::scoped_ptr<storage_interface> st(default_storage_constructor(t, full_path.branch_path(), fp)); |
|
|
@ -191,34 +243,26 @@ void createtorrent::on_createButton_clicked(){ |
|
|
|
st->read(&buf[0], i, 0, t->piece_size(i)); |
|
|
|
st->read(&buf[0], i, 0, t->piece_size(i)); |
|
|
|
hasher h(&buf[0], t->piece_size(i)); |
|
|
|
hasher h(&buf[0], t->piece_size(i)); |
|
|
|
t->set_hash(i, h.final()); |
|
|
|
t->set_hash(i, h.final()); |
|
|
|
|
|
|
|
emit updateProgress((int)(i*100./(float)num)); |
|
|
|
|
|
|
|
if(abort) return; |
|
|
|
} |
|
|
|
} |
|
|
|
// Set qBittorrent as creator and add user comment to
|
|
|
|
// Set qBittorrent as creator and add user comment to
|
|
|
|
// torrent_info structure
|
|
|
|
// torrent_info structure
|
|
|
|
t->set_creator(creator_str); |
|
|
|
t->set_creator(creator_str); |
|
|
|
t->set_comment((const char*)txt_comment->toPlainText().toUtf8()); |
|
|
|
t->set_comment((const char*)comment.toUtf8()); |
|
|
|
// Is private ?
|
|
|
|
// Is private ?
|
|
|
|
if(check_private->isChecked()){ |
|
|
|
if(is_private){ |
|
|
|
t->set_priv(true); |
|
|
|
t->set_priv(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(abort) return; |
|
|
|
// create the torrent and print it to out
|
|
|
|
// create the torrent and print it to out
|
|
|
|
entry e = t->create_torrent(); |
|
|
|
entry e = t->create_torrent(); |
|
|
|
libtorrent::bencode(std::ostream_iterator<char>(out), e); |
|
|
|
libtorrent::bencode(std::ostream_iterator<char>(out), e); |
|
|
|
out.flush(); |
|
|
|
out.flush(); |
|
|
|
if(checkStartSeeding->isChecked()) { |
|
|
|
emit updateProgress(100); |
|
|
|
// Create save path file
|
|
|
|
emit creationSuccess(save_path, full_path.branch_path().string().c_str(), misc::toQString(t->info_hash())); |
|
|
|
QFile savepath_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+misc::toQString(t->info_hash())+QString::fromUtf8(".savepath")); |
|
|
|
|
|
|
|
savepath_file.open(QIODevice::WriteOnly | QIODevice::Text); |
|
|
|
|
|
|
|
savepath_file.write(full_path.branch_path().string().c_str()); |
|
|
|
|
|
|
|
savepath_file.close(); |
|
|
|
|
|
|
|
emit torrent_to_seed(destination); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
catch (std::exception& e){ |
|
|
|
catch (std::exception& e){ |
|
|
|
std::cerr << e.what() << "\n"; |
|
|
|
emit creationFailure(QString::fromUtf8(e.what())); |
|
|
|
QMessageBox::information(0, tr("Torrent creation"), tr("Torrent creation was unsuccessful, reason: %1").arg(QString::fromUtf8(e.what()))); |
|
|
|
|
|
|
|
hide(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
hide(); |
|
|
|
|
|
|
|
QMessageBox::information(0, tr("Torrent creation"), tr("Torrent was created successfully:")+" "+destination); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|