From d47427a2d51fcc7f8e1f8926a706e04ff01603ed Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 20 Aug 2016 08:31:29 +0200 Subject: Present torrent files as a tree A torrent info dictionary has two modes: single and multi files. When in multi-mode, the name-entry is the directory containing the files. Represent it as a tree. During testing I discovered a fatal bug in the torrent parser: If we encounter an invalid string, we have to move mPos forward, else we will loop indefinitely until we're OOM. I also added some icons for folders, files and trackers. --- torrentparser.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'torrentparser.cpp') diff --git a/torrentparser.cpp b/torrentparser.cpp index fc59233..8e09681 100644 --- a/torrentparser.cpp +++ b/torrentparser.cpp @@ -2,7 +2,7 @@ #include "torrentparser.h" -TorrentParser::TorrentParser(const QString file, QObject *parent) : QObject(parent), mFile(file), mPos(0), mOk(true) {} +TorrentParser::TorrentParser(const QString file, QObject *parent) : QObject(parent), mFile(file), mPos(0) {} const QList TorrentParser::parse(){ QFile f(mFile); @@ -41,12 +41,11 @@ const QVariant TorrentParser::parseObject(){ const QByteArray TorrentParser::parseString(){ int lenlen = mData.indexOf(':', mPos) - mPos; if(lenlen <= 0){ - mOk = false; + ++mPos; return QByteArray(); } int len = mData.mid(mPos, lenlen).toInt(); if(mPos + len > mData.size()){ - mOk = false; return QByteArray(); } mPos = mPos + lenlen + 1; @@ -82,8 +81,6 @@ const QList TorrentParser::parseList(){ return retval; } - - const QHash TorrentParser::parseDict(){ QHash retval; if(mData.at(mPos) != 'd'){ -- cgit v1.2.3-70-g09d2