-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtorrentdecoder.cpp
104 lines (92 loc) · 3.41 KB
/
torrentdecoder.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "torrentdecoder.h"
#include "ui_torrentdecoder.h"
#include "metainfo.h"
TorrentDecoder::TorrentDecoder(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::TorrentDecoder),torrentFile(NULL), fileOpened(false),dataRead(false)
{
ui->setupUi(this);
}
TorrentDecoder::~TorrentDecoder()
{
delete ui;
}
void TorrentDecoder::on_decodeFileButton_clicked()
{
if(!fileOpened)
{
return;
}
if(dataRead)
{
return;
}
QByteArray arr = torrentFile->readAll();
MetaInfo mi;
mi.parse(arr);
ui->textEdit->append(QString::fromStdString("MAIN TRACKER URL"));
ui->textEdit->append(QString::fromStdString(mi.getMainTrackerUrl().toStdString()));
ui->textEdit->append(QString::fromStdString("CREATION DATE: ")+mi.getCreationDate().toString());
ui->textEdit->append(QString::fromStdString("CREATED BY: ")+mi.getCreatedBy());
ui->textEdit->append(QString::fromStdString("COMMENT : ")+mi.getComment());
ui->textEdit->append(QString::fromStdString("\nPIECE LENGTH : "));
ui->textEdit->append(QString::number(mi.getPieceLength())+QString::fromStdString(" B / ")+
(QString::number(mi.getPieceLength()/1024)+QString::fromStdString(" kB")));
ui->textEdit->append(QString::fromStdString("\nNUMBER OF PIECES: ")+QString::number(mi.getNumberOfPieces()));
ui->textEdit->append(QString::fromStdString("*********************"));
if(!mi.isMultiFile())
{
ui->textEdit->append(QString::fromStdString("\n THIS TORRENT IS A SINGLE FILE"));
ui->textEdit->append(QString::fromStdString("*********************"));
ui->textEdit->append(QString::fromStdString("FILE NAME: ")+mi.getName()+
QString::fromStdString(" ' LENGTH: ")+QString::number(mi.getTotalLength()));
}
else
{
ui->textEdit->append(QString::fromStdString("\n THIS TORRENT IS A MULTI FILE"));
ui->textEdit->append(QString::fromStdString("*********************"));
ui->textEdit->append(QString::fromStdString("ROOT DIRECTORY NAME: ' ")+mi.getName()+QString::fromStdString(" '"));
ui->textEdit->append(QString::fromStdString("*********************"));
ui->textEdit->append(QString::fromStdString("FILES: "));
foreach (QString path , mi.getMultiFilePaths())
{
ui->textEdit->append(QString::fromStdString("PATH: ' ")+path+QString::fromStdString(" ' LENGTH: ")+
QString::number(mi.getFileLengthByPath(path)));
ui->textEdit->append(QString::fromStdString("**********************"));
}
}
dataRead=true;
}
void TorrentDecoder::on_resetButton_clicked()
{
ui->textEdit->clear();
if(torrentFile!=NULL)
{
fileOpened=false;
torrentFile->close();
delete torrentFile;
}
}
void TorrentDecoder::on_quitButton_clicked()
{
qApp->quit();
}
void TorrentDecoder::on_actionOpen_triggered()
{
if(fileOpened)
{
return;
}
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),QString(), tr("Torrent Files (*.torrent);;Text Files (*.txt);;C++ Files (*.cpp *.h)"));
if(!fileName.isEmpty())
{
torrentFile = new QFile(fileName);
if(!torrentFile->open(QIODevice::ReadOnly))
{
QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
return;
}
fileOpened=true;
dataRead=false;
}
}