Ejemplo n.º 1
0
void TorrentPersistentData::saveTorrentPersistentData(const QTorrentHandle &h, const QString &save_path, const bool is_magnet) {
  Q_ASSERT(h.is_valid());
  qDebug("Saving persistent data for %s", qPrintable(h.hash()));
  // Save persistent data
  QHash<QString, QVariant> data = all_data.value(h.hash()).toHash();
  data["is_magnet"] = is_magnet;
  if (is_magnet) {
    data["magnet_uri"] = misc::toQString(make_magnet_uri(h));
  }
  data["seed"] = h.is_seed();
  data["priority"] = h.queue_position();
  if (save_path.isEmpty()) {
    qDebug("TorrentPersistantData: save path is %s", qPrintable(h.save_path()));
    data["save_path"] = h.save_path();
  } else {
    qDebug("TorrentPersistantData: overriding save path is %s", qPrintable(save_path));
    data["save_path"] = save_path; // Override torrent save path (e.g. because it is a temp dir)
  }
  // Label
  data["label"] = TorrentTempData::getLabel(h.hash());
  // Save data
  all_data[h.hash()] = data;
  markDirty();
  qDebug("TorrentPersistentData: Saving save_path %s, hash: %s", qPrintable(h.save_path()), qPrintable(h.hash()));
  // Set Added date
  setAddedDate(h.hash(), QDateTime::currentDateTime());
  // Finally, remove temp data
  TorrentTempData::deleteTempData(h.hash());
}
Ejemplo n.º 2
0
int dump_torrent::printInfo(int argc, char* argv[])
{
    fileList.clear();
	if (argc < 2 || argc > 4)
	{
		fputs("usage: dump_torrent torrent-file [total-items-limit] [recursion-limit]\n", stderr);
		return 1;
	}

	int item_limit = 1000000;
	int depth_limit = 1000;

    std::vector<char> buf;
    error_code ec;
    int ret = dump_torrent::load_file(argv[0], buf, ec, 40 * 1000000);
	if (ret == -1)
	{
		fprintf(stderr, "file too big, aborting\n");
		return 1;
	}

	if (ret != 0)
	{
		fprintf(stderr, "failed to load file: %s\n", ec.message().c_str());
		return 1;
	}
    bdecode_node e;
	int pos = -1;
	printf("decoding. recursion limit: %d total item count limit: %d\n"
		, depth_limit, item_limit);
    ret = bdecode(&buf[0], &buf[0] + buf.size(), e, ec, &pos
		, depth_limit, item_limit);

	printf("\n\n----- raw info -----\n\n%s\n", print_entry(e).c_str());

	if (ret != 0)
    {
		fprintf(stderr, "failed to decode: '%s' at character: %d\n", ec.message().c_str(), pos);
		return 1;
	}

    torrent_info t(e, ec);
	if (ec)
	{
		fprintf(stderr, "%s\n", ec.message().c_str());
		return 1;
	}
	e.clear();
	std::vector<char>().swap(buf);

	// print info about torrent
	printf("\n\n----- torrent file info -----\n\n"
		"nodes:\n");

	typedef std::vector<std::pair<std::string, int> > node_vec;
	node_vec const& nodes = t.nodes();
	for (node_vec::const_iterator i = nodes.begin(), end(nodes.end());
		i != end; ++i)
	{
		printf("%s: %d\n", i->first.c_str(), i->second);
	}
    puts("trackers:\n");
    for (std::vector<announce_entry>::const_iterator i = t.trackers().begin();
		i != t.trackers().end(); ++i)
	{
		printf("%2d: %s\n", i->tier, i->url.c_str());
	}

	char ih[41];
	to_hex((char const*)&t.info_hash()[0], 20, ih);
	printf("number of pieces: %d\n"
		"piece length: %d\n"
		"info hash: %s\n"
		"comment: %s\n"
		"created by: %s\n"
		"magnet link: %s\n"
		"name: %s\n"
		"number of files: %d\n"
        "files:\n"
		, t.num_pieces()
		, t.piece_length()
		, ih
		, t.comment().c_str()
		, t.creator().c_str()
		, make_magnet_uri(t).c_str()
		, t.name().c_str()
        , t.num_files());

    emit setNumOfPieces(t.num_pieces());
    emit setPiecesLength(t.piece_length());
    emit setInfoHash(ih);
    emit setComment(t.comment().c_str());
    emit setCreatedBy(t.creator().c_str());
    emit setMagnetLink(make_magnet_uri(t).c_str());
    emit setName(t.name().c_str());
    emit setNumOfFiles(t.num_files());

    fileList.begin();
	file_storage const& st = t.files();
	for (int i = 0; i < st.num_files(); ++i)
	{
		int first = st.map_file(i, 0, 0).piece;
		int last = st.map_file(i, (std::max)(boost::int64_t(st.file_size(i))-1, boost::int64_t(0)), 0).piece;
		int flags = st.file_flags(i);
        printf(" %8" PRIx64 " %11" PRId64 " %c%c%c%c [ %5d, %5d ] %7u %s %s %s     %s\n"
			, st.file_offset(i)
			, st.file_size(i)
			, ((flags & file_storage::flag_pad_file)?'p':'-')
			, ((flags & file_storage::flag_executable)?'x':'-')
            , ((flags & file_storage::flag_hidden)?'h':'-')
			, ((flags & file_storage::flag_symlink)?'l':'-')
			, first, last
            , boost::uint32_t(st.mtime(i))
			, st.hash(i) != sha1_hash(0) ? to_hex(st.hash(i).to_string()).c_str() : ""
			, st.file_path(i).c_str()
			, (flags & file_storage::flag_symlink) ? "-> " : ""
			, (flags & file_storage::flag_symlink) ? st.symlink(i).c_str() : "");

       fileName[i] = st.file_path(i).c_str();

       fileList.append(QString(st.file_path(i).c_str()));
    }

    emit setFilesList(fileList);


    for(int i = 0; i < 4;i++){
        printf("\n%s\n", fileName[i]);
    }
    return 0;
}