]> git.pld-linux.org Git - packages/qbittorrent.git/blob - qbittorrent-libtorrent14.patch
- removed TODO
[packages/qbittorrent.git] / qbittorrent-libtorrent14.patch
1 Index: src/qtorrenthandle.h
2 ===================================================================
3 --- src/qtorrenthandle.h        (revision 2069)
4 +++ src/qtorrenthandle.h        (revision 2070)
5 @@ -54,7 +54,7 @@
6      QString hash() const;
7      QString name() const;
8      float progress() const;
9 -    const std::vector<bool>* pieces() const;
10 +    bitfield pieces() const;
11      void get_download_queue(std::vector<partial_piece_info>& queue) const;
12      QString current_tracker() const;
13      bool is_valid() const;
14 @@ -76,7 +76,7 @@
15      int upload_limit() const;
16      int num_files() const;
17      bool has_metadata() const;
18 -    entry write_resume_data() const;
19 +    void save_resume_data() const;
20      QString file_at(unsigned int index) const;
21      size_type filesize_at(unsigned int index) const;
22      std::vector<announce_entry> const& trackers() const;
23 @@ -84,7 +84,7 @@
24      QString creator() const;
25      QString comment() const;
26      size_type total_failed_bytes() const;
27 -    void file_progress(std::vector<float>& fp);
28 +    void file_progress(std::vector<size_type>& fp);
29      size_type total_payload_download();
30      size_type total_payload_upload();
31      QStringList files_path() const;
32 @@ -107,7 +107,7 @@
33      void set_ratio(float ratio) const;
34      void replace_trackers(std::vector<announce_entry> const&) const;
35      void force_reannounce();
36 -    void set_sequenced_download_threshold(int val);
37 +    void set_sequential_download(bool);
38      void set_tracker_login(QString username, QString password);
39  
40      //
41 Index: src/arborescence.h
42 ===================================================================
43 --- src/arborescence.h  (revision 2069)
44 +++ src/arborescence.h  (revision 2070)
45 @@ -172,27 +172,27 @@
46      torrent_file *root;
47  
48    public:
49 -    arborescence(torrent_info t) {
50 -      torrent_info::file_iterator fi = t.begin_files();
51 -      if(t.num_files() > 1) {
52 -        root = new torrent_file(0, misc::toQString(t.name()), true);
53 +    arborescence(boost::intrusive_ptr<torrent_info> t) {
54 +      torrent_info::file_iterator fi = t->begin_files();
55 +      if(t->num_files() > 1) {
56 +        root = new torrent_file(0, misc::toQString(t->name()), true);
57        } else {
58          // XXX: Will crash if there is no file in torrent
59 -        root = new torrent_file(0, misc::toQString(t.name()), false, fi->size, 0);
60 +        root = new torrent_file(0, misc::toQString(t->name()), false, fi->size, 0);
61          return;
62        }
63        int i = 0;
64 -      while(fi != t.end_files()) {
65 +      while(fi != t->end_files()) {
66          QString path = QDir::cleanPath(misc::toQString(fi->path.string()));
67          addFile(path, fi->size, i);
68          fi++;
69          ++i;
70        }
71 -      qDebug("real size: %ld, tree size: %ld", (long)t.total_size(), (long)root->getSize());
72 -      Q_ASSERT(root->getSize() == t.total_size());
73 +      qDebug("real size: %ld, tree size: %ld", (long)t->total_size(), (long)root->getSize());
74 +      Q_ASSERT(root->getSize() == t->total_size());
75      }
76  
77 -    arborescence(torrent_info t, std::vector<float> fp, int *prioritiesTab) {
78 +    arborescence(torrent_info const& t, std::vector<size_type> fp, int *prioritiesTab) {
79        torrent_info::file_iterator fi = t.begin_files();
80        if(t.num_files() > 1) {
81          qDebug("More than one file in the torrent, setting a folder as root");
82 @@ -200,13 +200,13 @@
83        } else {
84          // XXX: Will crash if there is no file in torrent
85          qDebug("one file in the torrent, setting it as root with index 0");
86 -        root = new torrent_file(0, misc::toQString(t.name()), false, fi->size, 0, fp[0], prioritiesTab[0]);
87 +        root = new torrent_file(0, misc::toQString(t.name()), false, fi->size, 0, fp[0]/t.file_at(0).size, prioritiesTab[0]);
88          return;
89        }
90        int i = 0;
91        while(fi != t.end_files()) {
92          QString path = QDir::cleanPath(misc::toQString(fi->path.string()));
93 -        addFile(path, fi->size, i, fp[i], prioritiesTab[i]);
94 +        addFile(path, fi->size, i, fp[i]/t.file_at(i).size, prioritiesTab[i]);
95          fi++;
96          ++i;
97        }
98 Index: src/properties_imp.cpp
99 ===================================================================
100 --- src/properties_imp.cpp      (revision 2069)
101 +++ src/properties_imp.cpp      (revision 2070)
102 @@ -102,7 +102,7 @@
103      }
104    }
105    shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1)));
106 -  std::vector<float> fp;
107 +  std::vector<size_type> fp;
108    h.file_progress(fp);
109    int *prioritiesTab = loadPiecesPriorities();
110    // List files in torrent
111 @@ -669,11 +669,11 @@
112        QFile incremental_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".incremental"));
113        incremental_file.open(QIODevice::WriteOnly | QIODevice::Text);
114        incremental_file.close();
115 -      h.set_sequenced_download_threshold(1);
116 +      h.set_sequential_download(true);
117      }
118    }else{
119      QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".incremental");
120 -    h.set_sequenced_download_threshold(100); // Disabled
121 +    h.set_sequential_download(false);
122    }
123  }
124  
125 Index: src/eventmanager.cpp
126 ===================================================================
127 --- src/eventmanager.cpp        (revision 2069)
128 +++ src/eventmanager.cpp        (revision 2070)
129 @@ -66,12 +66,6 @@
130                         case torrent_status::queued_for_checking:
131                                 event["state"] = QVariant("checking");
132                                 break;
133 -                       case torrent_status::connecting_to_tracker:
134 -                               if(h.download_payload_rate() > 0)
135 -                                       event["state"] = QVariant("downloading");
136 -                               else
137 -                                       event["state"] = QVariant("connecting");
138 -                               break;
139                         case torrent_status::downloading:
140                         case torrent_status::downloading_metadata:
141                                 if(h.download_payload_rate() > 0)
142 @@ -113,12 +107,6 @@
143                         case torrent_status::queued_for_checking:
144                                 event["state"] = QVariant("checking");
145                                 break;
146 -                       case torrent_status::connecting_to_tracker:
147 -                               if(h.download_payload_rate() > 0)
148 -                                       event["state"] = QVariant("downloading");
149 -                               else
150 -                                       event["state"] = QVariant("connecting");
151 -                               break;
152                         case torrent_status::downloading:
153                         case torrent_status::downloading_metadata:
154                                 if(h.download_payload_rate() > 0)
155 Index: src/previewSelect.h
156 ===================================================================
157 --- src/previewSelect.h (revision 2069)
158 +++ src/previewSelect.h (revision 2070)
159 @@ -90,7 +90,7 @@
160        previewList->setItemDelegate(listDelegate);
161        previewList->header()->resizeSection(0, 200);
162        // Fill list in
163 -      std::vector<float> fp;
164 +      std::vector<size_type> fp;
165        h.file_progress(fp);
166        unsigned int nbFiles = h.num_files();
167        for(unsigned int i=0; i<nbFiles; ++i){
168 @@ -101,7 +101,7 @@
169            previewListModel->insertRow(row);
170            previewListModel->setData(previewListModel->index(row, NAME), QVariant(fileName));
171            previewListModel->setData(previewListModel->index(row, SIZE), QVariant((qlonglong)h.filesize_at(i)));
172 -          previewListModel->setData(previewListModel->index(row, PROGRESS), QVariant((double)fp[i]));
173 +          previewListModel->setData(previewListModel->index(row, PROGRESS), QVariant((double)fp[i]/h.filesize_at(i)));
174            indexes << i;
175          }
176        }
177 Index: src/Icons/skin/connecting.png
178 ===================================================================
179 Cannot display: file marked as a binary type.
180 svn:mime-type = application/octet-stream
181 Index: src/webui/scripts/client.js
182 ===================================================================
183 --- src/webui/scripts/client.js (revision 2069)
184 +++ src/webui/scripts/client.js (revision 2070)
185 @@ -44,8 +44,6 @@
186            return '<img src="images/time.png"/>';
187        case 'downloading':
188            return '<img src="images/skin/downloading.png"/>';
189 -      case 'connecting':
190 -          return '<img src="images/skin/connecting.png"/>';
191        case 'stalled':
192            return '<img src="images/skin/stalled.png"/>';
193        case 'queued':
194 Index: src/bittorrent.cpp
195 ===================================================================
196 --- src/bittorrent.cpp  (revision 2069)
197 +++ src/bittorrent.cpp  (revision 2070)
198 @@ -28,7 +28,6 @@
199  #include "bittorrent.h"
200  #include "misc.h"
201  #include "downloadThread.h"
202 -#include "deleteThread.h"
203  #include "filterParserThread.h"
204  
205  #include <libtorrent/extensions/metadata_transfer.hpp>
206 @@ -55,7 +54,7 @@
207      s = new session(fingerprint("qB", VERSION_MAJOR, VERSION_MINOR, VERSION_BUGFIX, 0));
208    }
209    // Set severity level of libtorrent session
210 -  s->set_severity_level(alert::info);
211 +  s->set_alert_mask(alert::error_notification|alert::peer_notification|alert::port_mapping_notification|alert::storage_notification|alert::tracker_notification|alert::status_notification|alert::ip_block_notification);
212    // Enabling metadata plugin
213    s->add_extension(&create_metadata_plugin);
214    timerAlerts = new QTimer();
215 @@ -68,8 +67,6 @@
216    downloader = new downloadThread(this);
217    connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString)));
218    connect(downloader, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
219 -  // File deleter (thread)
220 -  deleter = new deleteThread(this);
221    BigRatioTimer = 0;
222    filterParser = 0;
223    downloadQueue = 0;
224 @@ -94,7 +91,6 @@
225    // Disable directory scanning
226    disableDirectoryScanning();
227    // Delete our objects
228 -  delete deleter;
229    delete fastResumeSaver;
230    delete timerAlerts;
231    if(BigRatioTimer)
232 @@ -123,16 +119,6 @@
233    if(change) {
234      qDebug("PreAllocateAll changed, reloading all torrents!");
235      preAllocateAll = b;
236 -    // Reload All unfinished torrents
237 -    QString hash;
238 -    foreach(hash, unfinishedTorrents) {
239 -      QTorrentHandle h = getTorrentHandle(hash);
240 -      if(!h.is_valid()) {
241 -        qDebug("/!\\ Error: Invalid handle");
242 -        continue;
243 -      }
244 -      reloadTorrent(h, b);
245 -    }
246    }
247  }
248  
249 @@ -543,8 +529,7 @@
250    QTorrentHandle h = getTorrentHandle(hash);
251    if(!h.is_valid()) return -1;
252    switch(h.state()) {
253 -    case torrent_status::downloading:
254 -    case torrent_status::connecting_to_tracker: {
255 +    case torrent_status::downloading: {
256        if(!TorrentsStartTime.contains(hash)) return -1;
257        int timeElapsed = TorrentsStartTime.value(hash).secsTo(QDateTime::currentDateTime());
258        double avg_speed;
259 @@ -614,12 +599,11 @@
260    }
261    QString savePath = h.save_path();
262    QString fileName = h.name();
263 -  arborescence *files_arb = 0;
264 -  if(permanent){
265 -    files_arb = new arborescence(h.get_torrent_info());
266 -  }
267    // Remove it from session
268 -  s->remove_torrent(h.get_torrent_handle());
269 +  if(permanent)
270 +      s->remove_torrent(h.get_torrent_handle(), session::delete_files);
271 +  else
272 +    s->remove_torrent(h.get_torrent_handle());
273    // Remove it from torrent backup directory
274    QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
275    QStringList filters;
276 @@ -666,12 +650,6 @@
277      QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio");
278    if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued"))
279      QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".queued");
280 -  if(permanent && files_arb != 0) {
281 -    // Remove from Hard drive
282 -    qDebug("Removing this on hard drive: %s", qPrintable(savePath+QDir::separator()+fileName));
283 -    // Deleting in a thread to avoid GUI freeze
284 -    deleter->deleteTorrent(savePath, files_arb);
285 -  }
286    if(permanent)
287      addConsoleMessage(tr("'%1' was removed permanently.", "'xxx.avi' was removed permanently.").arg(fileName));
288    else
289 @@ -894,7 +872,6 @@
290  // Add a torrent to the bittorrent session
291  void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bool resumed) {
292    QTorrentHandle h;
293 -  entry resume_data;
294    bool fastResume=false;
295    QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
296    QString file, dest_file, scan_dir;
297 @@ -914,203 +891,164 @@
298    }
299    Q_ASSERT(!file.startsWith("http://", Qt::CaseInsensitive) && !file.startsWith("https://", Qt::CaseInsensitive) && !file.startsWith("ftp://", Qt::CaseInsensitive));
300    qDebug("Adding %s to download list", file.toUtf8().data());
301 -  std::ifstream in(file.toUtf8().data(), std::ios_base::binary);
302 -  in.unsetf(std::ios_base::skipws);
303 -  try{
304 -    // Decode torrent file
305 -    entry e = bdecode(std::istream_iterator<char>(in), std::istream_iterator<char>());
306 -    // Getting torrent file informations
307 -    boost::intrusive_ptr<torrent_info> t(new torrent_info(e));
308 -    qDebug(" -> Hash: %s", misc::toString(t->info_hash()).c_str());
309 -    qDebug(" -> Name: %s", t->name().c_str());
310 -    QString hash = misc::toQString(t->info_hash());
311 -    if(file.startsWith(torrentBackup.path())) {
312 +  boost::intrusive_ptr<torrent_info> t;
313 +  try {
314 +      // Getting torrent file informations
315 +      t = new torrent_info(file.toUtf8().data());
316 +  } catch(std::exception&) {
317 +      if(!from_url.isNull()) {
318 +          addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(from_url), QString::fromUtf8("red"));
319 +          //emit invalidTorrent(from_url);
320 +          QFile::remove(file);
321 +      }else{
322 +          addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(file), QString::fromUtf8("red"));
323 +          //emit invalidTorrent(file);
324 +      }
325 +      addConsoleMessage(tr("This file is either corrupted or this isn't a torrent."),QString::fromUtf8("red"));
326 +      if(fromScanDir) {
327 +          // Remove .corrupt file in case it already exists
328 +          QFile::remove(file+".corrupt");
329 +          //Rename file extension so that it won't display error message more than once
330 +          QFile::rename(file,file+".corrupt");
331 +      }
332 +  }
333 +  qDebug(" -> Hash: %s", misc::toString(t->info_hash()).c_str());
334 +  qDebug(" -> Name: %s", t->name().c_str());
335 +  QString hash = misc::toQString(t->info_hash());
336 +  if(file.startsWith(torrentBackup.path())) {
337        QFileInfo fi(file);
338        QString old_hash = fi.baseName();
339        if(old_hash != hash){
340 -        qDebug("* ERROR: Strange, hash changed from %s to %s", old_hash.toUtf8().data(), hash.toUtf8().data());
341 +          qDebug("* ERROR: Strange, hash changed from %s to %s", old_hash.toUtf8().data(), hash.toUtf8().data());
342        }
343 -    }
344 -    if(s->find_torrent(t->info_hash()).is_valid()) {
345 +  }
346 +  // Check if torrent is already in download list
347 +  if(s->find_torrent(t->info_hash()).is_valid()) {
348        qDebug("/!\\ Torrent is already in download list");
349        // Update info Bar
350        if(!fromScanDir) {
351 -        if(!from_url.isNull()) {
352 -          // If download from url, remove temp file
353 -          QFile::remove(file);
354 -           addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(from_url));
355 -          //emit duplicateTorrent(from_url);
356 -        }else{
357 -          addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(file));
358 -          //emit duplicateTorrent(file);
359 -        }
360 +          if(!from_url.isNull()) {
361 +              // If download from url, remove temp file
362 +              QFile::remove(file);
363 +              addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(from_url));
364 +              //emit duplicateTorrent(from_url);
365 +          }else{
366 +              addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(file));
367 +              //emit duplicateTorrent(file);
368 +          }
369        }else{
370 -        // Delete torrent from scan dir
371 -        QFile::remove(file);
372 +          // Delete torrent from scan dir
373 +          QFile::remove(file);
374        }
375        return;
376 -    }
377 -    //Getting fast resume data if existing
378 -    if(torrentBackup.exists(hash+".fastresume")) {
379 -      try{
380 -        std::stringstream strStream;
381 -        strStream << hash.toStdString() << ".fastresume";
382 -        boost::filesystem::ifstream resume_file(fs::path(torrentBackup.path().toUtf8().data()) / strStream.str(), std::ios_base::binary);
383 -        resume_file.unsetf(std::ios_base::skipws);
384 -        resume_data = bdecode(std::istream_iterator<char>(resume_file), std::istream_iterator<char>());
385 -        fastResume=true;
386 -      }catch (invalid_encoding&) {}
387 -      catch (fs::filesystem_error&) {}
388 -    }
389 -    QString savePath = getSavePath(hash);
390 -    // Save save_path to hard drive
391 -    QFile savepath_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".savepath"));
392 -    if(!savepath_file.exists()) {
393 +  }
394 +  add_torrent_params p;
395 +  //Getting fast resume data if existing
396 +  std::vector<char> buf;
397 +  if (load_file((torrentBackup.path()+hash+QString(".fastresume")).toUtf8().data(), buf) == 0) {
398 +      fastResume = true;
399 +      p.resume_data = &buf;
400 +  }
401 +  QString savePath = getSavePath(hash);
402 +  // Save save_path to hard drive
403 +  QFile savepath_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".savepath"));
404 +  if(!savepath_file.exists()) {
405        savepath_file.open(QIODevice::WriteOnly | QIODevice::Text);
406        savepath_file.write(savePath.toUtf8());
407        savepath_file.close();
408 -    }
409 -    // Adding files to bittorrent session
410 -    if(preAllocateAll) {
411 -      h = s->add_torrent(t, fs::path(savePath.toUtf8().data()), resume_data, storage_mode_allocate, true);
412 -      qDebug(" -> Full allocation mode");
413 -    }else{
414 -      h = s->add_torrent(t, fs::path(savePath.toUtf8().data()), resume_data, storage_mode_sparse, true);
415 -      qDebug(" -> Sparse allocation mode");
416 -    }
417 -    if(!h.is_valid()) {
418 +  }
419 +  p.save_path = savePath.toUtf8().data();
420 +  p.ti = t;
421 +  // Preallocate all?
422 +  if(preAllocateAll)
423 +    p.storage_mode = storage_mode_allocate;
424 +  else
425 +    p.storage_mode = storage_mode_sparse;
426 +  // Start in pause
427 +  p.paused = true;
428 +  p.duplicate_is_error = false; // Already checked
429 +  p.auto_managed = true;
430 +  // Adding torrent to bittorrent session
431 +  h =  s->add_torrent(p);
432 +  // Check if it worked
433 +  if(!h.is_valid()) {
434        // No need to keep on, it failed.
435        qDebug("/!\\ Error: Invalid handle");
436        // If download from url, remove temp file
437        if(!from_url.isNull()) QFile::remove(file);
438        return;
439 -    }
440 -    // Connections limit per torrent
441 -    h.set_max_connections(maxConnecsPerTorrent);
442 -    // Uploads limit per torrent
443 -    h.set_max_uploads(maxUploadsPerTorrent);
444 -    // Load filtered files
445 -    loadFilesPriorities(h);
446 -    // Load custom url seeds
447 -    loadWebSeeds(hash);
448 -    // Load speed limit from hard drive
449 -    loadTorrentSpeedLimits(hash);
450 -    // Load ratio data
451 -    loadDownloadUploadForTorrent(hash);
452 -    // Load trackers
453 -    bool loaded_trackers = loadTrackerFile(hash);
454 -    // Doing this to order trackers well
455 -    if(!loaded_trackers) {
456 +  }
457 +  // Connections limit per torrent
458 +  h.set_max_connections(maxConnecsPerTorrent);
459 +  // Uploads limit per torrent
460 +  h.set_max_uploads(maxUploadsPerTorrent);
461 +  // Load filtered files
462 +  loadFilesPriorities(h);
463 +  // Load custom url seeds
464 +  loadWebSeeds(hash);
465 +  // Load speed limit from hard drive
466 +  loadTorrentSpeedLimits(hash);
467 +  // Load ratio data
468 +  loadDownloadUploadForTorrent(hash);
469 +  // Load trackers
470 +  bool loaded_trackers = loadTrackerFile(hash);
471 +  // Doing this to order trackers well
472 +  if(!loaded_trackers) {
473        saveTrackerFile(hash);
474        loadTrackerFile(hash);
475 -    }
476 -    QString newFile = torrentBackup.path() + QDir::separator() + hash + ".torrent";
477 -    if(file != newFile) {
478 +  }
479 +  QString newFile = torrentBackup.path() + QDir::separator() + hash + ".torrent";
480 +  if(file != newFile) {
481        // Delete file from torrentBackup directory in case it exists because
482        // QFile::copy() do not overwrite
483        QFile::remove(newFile);
484        // Copy it to torrentBackup directory
485        QFile::copy(file, newFile);
486 -    }
487 -    // Incremental download
488 -    if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".incremental")) {
489 +  }
490 +  // Incremental download
491 +  if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".incremental")) {
492        qDebug("Incremental download enabled for %s", t->name().c_str());
493 -      h.set_sequenced_download_threshold(1);
494 -    }
495 -    if((resumed || !addInPause) && !QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused")) {
496 +      h.set_sequential_download(true);
497 +  }
498 +  if((resumed || !addInPause) && !QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused")) {
499        // Start torrent because it was added in paused state
500        h.resume();
501 -    }
502 -    if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".finished")) {
503 +  }
504 +  if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".finished")) {
505        finishedTorrents << hash;
506        if(!resumed && queueingEnabled) {
507 -        uploadQueue->append(hash);
508 -        saveTorrentPriority(hash, uploadQueue->size()-1);
509 -        updateUploadQueue();
510 +          uploadQueue->append(hash);
511 +          saveTorrentPriority(hash, uploadQueue->size()-1);
512 +          updateUploadQueue();
513        }
514 -    }else{
515 +  }else{
516        unfinishedTorrents << hash;
517        if(!resumed && queueingEnabled) {
518 -        downloadQueue->append(hash);
519 -        saveTorrentPriority(hash, downloadQueue->size()-1);
520 -        updateDownloadQueue();
521 +          downloadQueue->append(hash);
522 +          saveTorrentPriority(hash, downloadQueue->size()-1);
523 +          updateDownloadQueue();
524        }
525 -    }
526 -    // If download from url, remove temp file
527 -    if(!from_url.isNull()) QFile::remove(file);
528 -    // Delete from scan dir to avoid trying to download it again
529 -    if(fromScanDir) {
530 +  }
531 +  // If download from url, remove temp file
532 +  if(!from_url.isNull()) QFile::remove(file);
533 +  // Delete from scan dir to avoid trying to download it again
534 +  if(fromScanDir) {
535        QFile::remove(file);
536 -    }
537 -    // Send torrent addition signal
538 -    if(!from_url.isNull()) {
539 +  }
540 +  // Send torrent addition signal
541 +  if(!from_url.isNull()) {
542        emit addedTorrent(h);
543        if(fastResume)
544 -        addConsoleMessage(tr("'%1' resumed. (fast resume)", "'/home/y/xxx.torrent' was resumed. (fast resume)").arg(from_url));
545 +          addConsoleMessage(tr("'%1' resumed. (fast resume)", "'/home/y/xxx.torrent' was resumed. (fast resume)").arg(from_url));
546        else
547 -        addConsoleMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(from_url));
548 -    }else{
549 +          addConsoleMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(from_url));
550 +  }else{
551        emit addedTorrent(h);
552        if(fastResume)
553 -        addConsoleMessage(tr("'%1' resumed. (fast resume)", "'/home/y/xxx.torrent' was resumed. (fast resume)").arg(file));
554 +          addConsoleMessage(tr("'%1' resumed. (fast resume)", "'/home/y/xxx.torrent' was resumed. (fast resume)").arg(file));
555        else
556 -        addConsoleMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(file));
557 -    }
558 -  }catch (invalid_encoding& e) { // Raised by bdecode()
559 -    std::cerr << "Could not decode file, reason: " << e.what() << '\n';
560 -    // Display warning to tell user we can't decode the torrent file
561 -    if(!from_url.isNull()) {
562 -      addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(from_url), QString::fromUtf8("red"));
563 -      //emit invalidTorrent(from_url);
564 -      QFile::remove(file);
565 -    }else{
566 -      addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(file), QString::fromUtf8("red"));
567 -      //emit invalidTorrent(file);
568 -    }
569 -    addConsoleMessage(tr("This file is either corrupted or this isn't a torrent."),QString::fromUtf8("red"));
570 -    if(fromScanDir) {
571 -      // Remove .corrupt file in case it already exists
572 -      QFile::remove(file+".corrupt");
573 -      //Rename file extension so that it won't display error message more than once
574 -      QFile::rename(file,file+".corrupt");
575 -    }
576 +          addConsoleMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(file));
577    }
578 -  catch (invalid_torrent_file&) { // Raised by torrent_info constructor
579 -    // Display warning to tell user we can't decode the torrent file
580 -    if(!from_url.isNull()) {
581 -      addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(from_url), QString::fromUtf8("red"));
582 -      //emit invalidTorrent(from_url);
583 -      qDebug("File path is: %s", file.toUtf8().data());
584 -      QFile::remove(file);
585 -    }else{
586 -      addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(file), QString::fromUtf8("red"));
587 -      //emit invalidTorrent(file);
588 -    }
589 -    if(fromScanDir) {
590 -      // Remove .corrupt file in case it already exists
591 -      QFile::remove(file+".corrupt");
592 -      //Rename file extension so that it won't display error message more than once
593 -      QFile::rename(file,file+".corrupt");
594 -    }
595 -  }
596 -  catch (std::exception& e) {
597 -    std::cerr << "Could not decode file, reason: " << e.what() << '\n';
598 -    // Display warning to tell user we can't decode the torrent file
599 -    if(!from_url.isNull()) {
600 -      addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(from_url), QString::fromUtf8("red"));
601 -      //emit invalidTorrent(from_url);
602 -      QFile::remove(file);
603 -    }else{
604 -      addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(file), QString::fromUtf8("red"));
605 -      //emit invalidTorrent(file);
606 -    }
607 -    if(fromScanDir) {
608 -      // Remove .corrupt file in case it already exists
609 -      QFile::remove(file+".corrupt");
610 -      //Rename file extension so that it won't display error message more than once
611 -      QFile::rename(file,file+".corrupt");
612 -    }
613 -  }
614  }
615  
616  // Check in .priorities file if the user filtered files
617 @@ -1502,11 +1440,7 @@
618        // Remove old .fastresume data in case it exists
619        QFile::remove(torrentBackup.path()+QDir::separator()+hash + ".fastresume");
620        // Write fast resume data
621 -      entry resumeData = h.write_resume_data();
622 -      file = hash + ".fastresume";
623 -      boost::filesystem::ofstream out(fs::path(torrentBackup.path().toUtf8().data()) / file.toUtf8().data(), std::ios_base::binary);
624 -      out.unsetf(std::ios_base::skipws);
625 -      bencode(std::ostream_iterator<char>(out), resumeData);
626 +      h.save_resume_data();
627      }
628      // Save ratio data
629      saveDownloadUploadForTorrent(hash);
630 @@ -1762,9 +1696,21 @@
631          emit finishedTorrent(h);
632        }
633      }
634 +    else if (save_resume_data_alert* p = dynamic_cast<save_resume_data_alert*>(a.get())) {
635 +        QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
636 +        QTorrentHandle h(p->handle);
637 +        QString file = torrentBackup.path()+QDir::separator()+h.hash()+".torrent";
638 +        TORRENT_ASSERT(p->resume_data);
639 +        if (p->resume_data)
640 +        {
641 +            boost::filesystem::ofstream out(fs::path(torrentBackup.path().toUtf8().data()) / file.toUtf8().data(), std::ios_base::binary);
642 +            out.unsetf(std::ios_base::skipws);
643 +            bencode(std::ostream_iterator<char>(out), *p->resume_data);
644 +        }
645 +    }
646      else if (file_error_alert* p = dynamic_cast<file_error_alert*>(a.get())) {
647        QTorrentHandle h(p->handle);
648 -      qDebug("File Error: %s", p->msg().c_str());
649 +      qDebug("File Error: %s", p->message().c_str());
650        if(h.is_valid())
651          emit fullDiskError(h);
652      }
653 @@ -1773,7 +1719,7 @@
654        addConsoleMessage(tr("Couldn't listen on any of the given ports."), QString::fromUtf8("red"));
655        //emit portListeningFailure();
656      }
657 -    else if (tracker_alert* p = dynamic_cast<tracker_alert*>(a.get())) {
658 +    else if (tracker_error_alert* p = dynamic_cast<tracker_error_alert*>(a.get())) {
659        // Level: fatal
660        QTorrentHandle h(p->handle);
661        if(h.is_valid()){
662 @@ -1783,7 +1729,7 @@
663            qDebug("Received a tracker error for %s", p->url.c_str());
664            QHash<QString, QString> errors = trackersErrors.value(hash, QHash<QString, QString>());
665            // p->url requires at least libtorrent v0.13.1
666 -          errors[misc::toQString(p->url)] = QString::fromUtf8(a->msg().c_str());
667 +          errors[misc::toQString(p->url)] = QString::fromUtf8(a->message().c_str());
668            trackersErrors[hash] = errors;
669          } else {
670            emit trackerAuthenticationRequired(h);
671 @@ -1802,12 +1748,12 @@
672        }
673      }
674      else if (portmap_error_alert* p = dynamic_cast<portmap_error_alert*>(a.get())) {
675 -      addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping failure, message: %1").arg(QString(p->msg().c_str())), QColor("red"));
676 +      addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping failure, message: %1").arg(QString(p->message().c_str())), QColor("red"));
677        //emit UPnPError(QString(p->msg().c_str()));
678      }
679      else if (portmap_alert* p = dynamic_cast<portmap_alert*>(a.get())) {
680 -      qDebug("UPnP Success, msg: %s", p->msg().c_str());
681 -      addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping successful, message: %1").arg(QString(p->msg().c_str())), QColor("blue"));
682 +      qDebug("UPnP Success, msg: %s", p->message().c_str());
683 +      addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping successful, message: %1").arg(QString(p->message().c_str())), QColor("blue"));
684        //emit UPnPSuccess(QString(p->msg().c_str()));
685      }
686      else if (peer_blocked_alert* p = dynamic_cast<peer_blocked_alert*>(a.get())) {
687 @@ -1821,13 +1767,13 @@
688      else if (fastresume_rejected_alert* p = dynamic_cast<fastresume_rejected_alert*>(a.get())) {
689        QTorrentHandle h(p->handle);
690        if(h.is_valid()){
691 -        qDebug("/!\\ Fast resume failed for %s, reason: %s", h.name().toUtf8().data(), p->msg().c_str());
692 +        qDebug("/!\\ Fast resume failed for %s, reason: %s", h.name().toUtf8().data(), p->message().c_str());
693          addConsoleMessage(tr("Fast resume data was rejected for torrent %1, checking again...").arg(h.name()), QString::fromUtf8("red"));
694          //emit fastResumeDataRejected(h.name());
695        }
696      }
697      else if (url_seed_alert* p = dynamic_cast<url_seed_alert*>(a.get())) {
698 -      addConsoleMessage(tr("Url seed lookup failed for url: %1, message: %2").arg(QString::fromUtf8(p->url.c_str())).arg(QString::fromUtf8(p->msg().c_str())), QString::fromUtf8("red"));
699 +      addConsoleMessage(tr("Url seed lookup failed for url: %1, message: %2").arg(QString::fromUtf8(p->url.c_str())).arg(QString::fromUtf8(p->message().c_str())), QString::fromUtf8("red"));
700        //emit urlSeedProblem(QString::fromUtf8(p->url.c_str()), QString::fromUtf8(p->msg().c_str()));
701      }
702      else if (torrent_checked_alert* p = dynamic_cast<torrent_checked_alert*>(a.get())) {
703 @@ -1853,72 +1799,6 @@
704    return trackersErrors.value(hash, QHash<QString, QString>());
705  }
706  
707 -// Reload a torrent with full allocation mode
708 -void bittorrent::reloadTorrent(const QTorrentHandle &h, bool full_alloc) {
709 -  qDebug("** Reloading a torrent");
710 -  if(!h.is_valid()) {
711 -    qDebug("/!\\ Error: Invalid handle");
712 -    return;
713 -  }
714 -  QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
715 -  fs::path saveDir = h.save_path_boost();
716 -  QString fileName = h.name();
717 -  QString hash = h.hash();
718 -  boost::intrusive_ptr<torrent_info> t(new torrent_info(h.get_torrent_info()));
719 -  qDebug("Reloading torrent: %s", fileName.toUtf8().data());
720 -  entry resumeData;
721 -    // Checking if torrentBackup Dir exists
722 -  // create it if it is not
723 -  if(! torrentBackup.exists()) {
724 -    torrentBackup.mkpath(torrentBackup.path());
725 -  }
726 -  // Extracting resume data
727 -  if (h.has_metadata()) {
728 -    // get fast resume data
729 -    resumeData = h.write_resume_data();
730 -  }
731 -  // Remove torrent
732 -  s->remove_torrent(h.get_torrent_handle());
733 -  // Add torrent again to session
734 -  unsigned int timeout = 0;
735 -  while(h.is_valid() && timeout < 6) {
736 -    qDebug("Waiting for the torrent to be removed...");
737 -    SleeperThread::msleep(1000);
738 -    ++timeout;
739 -  }
740 -  QTorrentHandle new_h;
741 -  if(full_alloc) {
742 -    new_h = s->add_torrent(t, saveDir, resumeData, storage_mode_allocate);
743 -    qDebug("Using full allocation mode");
744 -  } else {
745 -    new_h = s->add_torrent(t, saveDir, resumeData, storage_mode_sparse);
746 -    qDebug("Using sparse mode");
747 -  }
748 -  // Connections limit per torrent
749 -  new_h.set_max_connections(maxConnecsPerTorrent);
750 -  // Uploads limit per torrent
751 -  new_h.set_max_uploads(maxUploadsPerTorrent);
752 -  // Load filtered Files
753 -  loadFilesPriorities(new_h);
754 -  // Load speed limit from hard drive
755 -  loadTorrentSpeedLimits(hash);
756 -  // Load custom url seeds
757 -  loadWebSeeds(hash);
758 -  // Load ratio data
759 -  loadDownloadUploadForTorrent(hash);
760 -  // Pause torrent if it was paused last time
761 -  if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".paused")) {
762 -    new_h.pause();
763 -  }
764 -  // Incremental download
765 -  if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".incremental")) {
766 -    qDebug("Incremental download enabled for %s", fileName.toUtf8().data());
767 -    new_h.set_sequenced_download_threshold(1);
768 -  }
769 -}
770 -
771 -
772 -
773  int bittorrent::getListenPort() const{
774    return s->listen_port();
775  }
776 Index: src/torrentAddition.h
777 ===================================================================
778 --- src/torrentAddition.h       (revision 2069)
779 +++ src/torrentAddition.h       (revision 2070)
780 @@ -95,26 +95,32 @@
781      }
782  
783      void showLoad(QString filePath, bool fromScanDir=false, QString from_url=QString::null){
784 -      this->filePath = filePath;
785 -      this->fromScanDir = fromScanDir;
786 -      this->from_url = from_url;
787 -      std::ifstream in(filePath.toUtf8().data(), std::ios_base::binary);
788 -      in.unsetf(std::ios_base::skipws);
789 -      try{
790 -        // Decode torrent file
791 -        entry e = bdecode(std::istream_iterator<char>(in), std::istream_iterator<char>());
792 +        this->filePath = filePath;
793 +        this->fromScanDir = fromScanDir;
794 +        this->from_url = from_url;
795          // Getting torrent file informations
796 -        torrent_info t(e);
797 -        nbFiles = t.num_files();
798 +        boost::intrusive_ptr<torrent_info> t;
799 +        try {
800 +            t = new torrent_info(filePath.toUtf8().data());
801 +        } catch(std::exception&) {
802 +            if(!from_url.isNull()){
803 +                BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red"));
804 +                QFile::remove(filePath);
805 +            }else{
806 +                BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red"));
807 +            }
808 +            close();
809 +        }
810 +        nbFiles = t->num_files();
811          // Setting file name
812 -        fileName = misc::toQString(t.name());
813 -        hash = misc::toQString(t.info_hash());
814 +        fileName = misc::toQString(t->name());
815 +        hash = misc::toQString(t->info_hash());
816          // Use left() to remove .old extension
817          QString newFileName;
818          if(fileName.endsWith(QString::fromUtf8(".old"))){
819 -          newFileName = fileName.left(fileName.size()-4);
820 +            newFileName = fileName.left(fileName.size()-4);
821          }else{
822 -          newFileName = fileName;
823 +            newFileName = fileName;
824          }
825          fileNameLbl->setText(QString::fromUtf8("<center><b>")+newFileName+QString::fromUtf8("</b></center>"));
826          // List files in torrent
827 @@ -123,62 +129,7 @@
828          delete arb;
829          connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
830          torrentContentList->expandAll();
831 -      }
832 -      catch (invalid_torrent_file&){ // Raised by torrent_info constructor
833 -        // Display warning to tell user we can't decode the torrent file
834 -        if(!from_url.isNull()){
835 -          BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red"));
836 -          QFile::remove(filePath);
837 -        }else{
838 -          BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red"));
839 -        }
840 -        BTSession->addConsoleMessage(tr("This file is either corrupted or this isn't a torrent."), QString::fromUtf8("red"));
841 -        if(fromScanDir){
842 -          // Remove .corrupt file in case it already exists
843 -          QFile::remove(filePath+QString::fromUtf8(".corrupt"));
844 -          //Rename file extension so that it won't display error message more than once
845 -          QFile::rename(filePath,filePath+QString::fromUtf8(".corrupt"));
846 -        }
847 -        close();
848 -      }
849 -      catch(invalid_encoding& e){
850 -        std::cerr << "Could not decode file, reason: " << e.what() << '\n';
851 -        // Display warning to tell user we can't decode the torrent file
852 -        if(!from_url.isNull()){
853 -          BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red"));
854 -          QFile::remove(filePath);
855 -        }else{
856 -          BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red"));
857 -        }
858 -        qDebug("path is %s", filePath.toUtf8().data());
859 -        BTSession->addConsoleMessage(tr("This file is either corrupted or this isn't a torrent."), QString::fromUtf8("red"));
860 -        if(fromScanDir){
861 -          // Remove .corrupt file in case it already exists
862 -          QFile::remove(filePath+QString::fromUtf8(".corrupt"));
863 -          //Rename file extension so that it won't display error message more than once
864 -          QFile::rename(filePath,filePath+QString::fromUtf8(".corrupt"));
865 -        }
866 -        close();
867 -      }
868 -      catch(std::exception& e){
869 -        std::cerr << "Could not decode file, reason: " << e.what() << '\n';
870 -        if(!from_url.isNull()){
871 -          BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red"));
872 -          QFile::remove(filePath);
873 -        }else{
874 -          BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red"));
875 -        }
876 -        qDebug("path is %s", filePath.toUtf8().data());
877 -        BTSession->addConsoleMessage(tr("This file is either corrupted or this isn't a torrent."), QString::fromUtf8("red"));
878 -        if(fromScanDir){
879 -          // Remove .corrupt file in case it already exists
880 -          QFile::remove(filePath+QString::fromUtf8(".corrupt"));
881 -          //Rename file extension so that it won't display error message more than once
882 -          QFile::rename(filePath,filePath+QString::fromUtf8(".corrupt"));
883 -        }
884 -        close();
885 -      }
886 -      show();
887 +        show();
888      }
889  
890      void addFilesToTree(torrent_file *root, QStandardItem *parent) {
891 Index: src/realprogressbarthread.cpp
892 ===================================================================
893 --- src/realprogressbarthread.cpp       (revision 2069)
894 +++ src/realprogressbarthread.cpp       (revision 2070)
895 @@ -65,9 +65,9 @@
896                 size_type total_size = thandle.total_size();
897                 size_type piece_length = thandle.piece_length();
898                 int num_pieces = thandle.num_pieces();
899 -               const std::vector<bool>* pieces = thandle.pieces();
900 +                bitfield pieces = thandle.pieces();
901                 //pieces not returned
902 -               if (pieces == 0)
903 +                if (pieces.empty())
904                 {
905                         qDebug("pieces vector not returned");
906                         return;
907 @@ -97,7 +97,7 @@
908                         }
909                         qreal start = i * fraction;
910                         qreal end = start + fraction;
911 -                       if((*pieces)[i])
912 +                        if(pieces[i])
913                                 mark(start, end);
914                 }
915                 if (success)
916 Index: src/createtorrent_imp.cpp
917 ===================================================================
918 --- src/createtorrent_imp.cpp   (revision 2069)
919 +++ src/createtorrent_imp.cpp   (revision 2070)
920 @@ -26,6 +26,7 @@
921  #include <boost/filesystem/operations.hpp>
922  #include <boost/filesystem/path.hpp>
923  #include <boost/filesystem/fstream.hpp>
924 +#include <boost/bind.hpp>
925  
926  #include <libtorrent/entry.hpp>
927  #include <libtorrent/bencode.hpp>
928 @@ -34,6 +35,7 @@
929  #include <libtorrent/storage.hpp>
930  #include <libtorrent/hasher.hpp>
931  #include <libtorrent/file_pool.hpp>
932 +#include <libtorrent/create_torrent.hpp>
933  
934  #include "createtorrent_imp.h"
935  #include "misc.h"
936 @@ -41,13 +43,23 @@
937  using namespace libtorrent;
938  using namespace boost::filesystem;
939  
940 +// do not include files and folders whose
941 +// name starts with a .
942 +bool file_filter(boost::filesystem::path const& filename)
943 +{
944 +        if (filename.leaf()[0] == '.') return false;
945 +        std::cerr << filename << std::endl;
946 +        return true;
947 +}
948 +
949  createtorrent::createtorrent(QWidget *parent): QDialog(parent){
950    setupUi(this);
951    setAttribute(Qt::WA_DeleteOnClose);
952 -  creatorThread = new torrentCreatorThread();
953 -  connect(creatorThread, SIGNAL(creationSuccess(QString, const char*, QString)), this, SLOT(handleCreationSuccess(QString, const char*, QString)));
954 +  creatorThread = new torrentCreatorThread(this);
955 +  connect(creatorThread, SIGNAL(creationSuccess(QString, const char*)), this, SLOT(handleCreationSuccess(QString, const char*)));
956    connect(creatorThread, SIGNAL(creationFailure(QString)), this, SLOT(handleCreationFailure(QString)));
957    connect(creatorThread, SIGNAL(updateProgress(int)), this, SLOT(updateProgressBar(int)));
958 +  path::default_name_check(no_check);
959    show();
960  }
961  
962 @@ -126,31 +138,6 @@
963    }
964  }
965  
966 -// Subfunction to add files to a torrent_info structure
967 -// Written by Arvid Norberg (libtorrent Author)
968 -void add_files(torrent_info& t, path const& p, path const& l){
969 -  using boost::filesystem::path;
970 -  using boost::filesystem::directory_iterator;
971 -#if BOOST_VERSION < 103600
972 -  std::string const& leaf = l.leaf();
973 -#else
974 -  std::string const& leaf = l.filename();
975 -#endif
976 -  if (leaf == ".." || leaf == ".") return;
977 -  path f(p / l);
978 -  if (is_directory(f)) {
979 -    for (directory_iterator i(f), end; i != end; ++i)
980 -#if BOOST_VERSION < 103600
981 -      add_files(t, p, l / i->leaf());
982 -#else
983 -      add_files(t, p, l / i->filename());
984 -#endif
985 -  } else {
986 -    qDebug("Adding %s", l.string().c_str());
987 -    t.add_file(l, file_size(f));
988 -  }
989 -}
990 -
991  QStringList createtorrent::allItems(QListWidget *list){
992    QStringList res;
993    unsigned int nbItems = list->count();
994 @@ -191,17 +178,25 @@
995    hide();
996  }
997  
998 -void createtorrent::handleCreationSuccess(QString path, const char* branch_path, QString hash) {
999 -  if(checkStartSeeding->isChecked()) {
1000 -    // Create save path file
1001 -    QFile savepath_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".savepath"));
1002 -    savepath_file.open(QIODevice::WriteOnly | QIODevice::Text);
1003 -    savepath_file.write(branch_path);
1004 -    savepath_file.close();
1005 -    emit torrent_to_seed(path);
1006 -  }
1007 -  QMessageBox::information(0, tr("Torrent creation"), tr("Torrent was created successfully:")+" "+path);
1008 -  hide();
1009 +void createtorrent::handleCreationSuccess(QString path, const char* branch_path) {
1010 +    if(checkStartSeeding->isChecked()) {
1011 +        // Create save path file
1012 +        boost::intrusive_ptr<torrent_info> t;
1013 +        try {
1014 +            t = new torrent_info(path.toUtf8().data());
1015 +        } catch(std::exception&) {
1016 +            QMessageBox::critical(0, tr("Torrent creation"), tr("Created torrent file is invalid. It won't be added to download list."));
1017 +            return;
1018 +        }
1019 +        QString hash = misc::toQString(t->info_hash());
1020 +        QFile savepath_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".savepath"));
1021 +        savepath_file.open(QIODevice::WriteOnly | QIODevice::Text);
1022 +        savepath_file.write(branch_path);
1023 +        savepath_file.close();
1024 +        emit torrent_to_seed(path);
1025 +    }
1026 +    QMessageBox::information(0, tr("Torrent creation"), tr("Torrent was created successfully:")+" "+path);
1027 +    hide();
1028  }
1029  
1030  void createtorrent::updateProgressBar(int progress) {
1031 @@ -224,58 +219,47 @@
1032    start();
1033  }
1034  
1035 +void sendProgressUpdateSignal(int i, int num, QDialog *parent){
1036 +    ((createtorrent*)parent)->updateProgressBar((int)(i*100./(float)num));
1037 +}
1038 +
1039  void torrentCreatorThread::run() {
1040    emit updateProgress(0);
1041    char const* creator_str = "qBittorrent "VERSION;
1042    try {
1043 -    boost::intrusive_ptr<torrent_info> t(new torrent_info);
1044 -    ofstream out(complete(path((const char*)save_path.toUtf8())), std::ios_base::binary);
1045 -    // Adding files to the torrent
1046 +    file_storage fs;
1047 +    file_pool fp;
1048      path full_path = complete(path(input_path.toUtf8().data()));
1049 -#if BOOST_VERSION < 103600
1050 -    add_files(*t, full_path.branch_path(), full_path.leaf());
1051 -#else
1052 -    add_files(*t, full_path.branch_path(), full_path.filename());
1053 -#endif
1054 +    // Adding files to the torrent
1055 +    add_files(fs, full_path, file_filter);
1056      if(abort) return;
1057 -    // Set piece size
1058 -    t->set_piece_size(piece_size);
1059 +    create_torrent t(fs, piece_size);
1060 +
1061      // Add url seeds
1062      QString seed;
1063      foreach(seed, url_seeds){
1064 -      t->add_url_seed(seed.toUtf8().data());
1065 +      t.add_url_seed(seed.toUtf8().data());
1066      }
1067      for(int i=0; i<trackers.size(); ++i){
1068 -      t->add_tracker(trackers.at(i).toUtf8().data());
1069 +      t.add_tracker(trackers.at(i).toUtf8().data());
1070      }
1071      if(abort) return;
1072      // calculate the hash for all pieces
1073 -    file_pool fp;
1074 -    boost::scoped_ptr<storage_interface> st(default_storage_constructor(t, full_path.branch_path(), fp));
1075 -    int num = t->num_pieces();
1076 -    std::vector<char> buf(piece_size);
1077 -    for (int i = 0; i < num; ++i) {
1078 -      st->read(&buf[0], i, 0, t->piece_size(i));
1079 -      hasher h(&buf[0], t->piece_size(i));
1080 -      t->set_hash(i, h.final());
1081 -      emit updateProgress((int)(i*100./(float)num));
1082 -      if(abort) return;
1083 -    }
1084 +    set_piece_hashes(t, full_path.branch_path(), boost::bind(&sendProgressUpdateSignal, _1, t.num_pieces(), parent));
1085      // Set qBittorrent as creator and add user comment to
1086      // torrent_info structure
1087 -    t->set_creator(creator_str);
1088 -    t->set_comment((const char*)comment.toUtf8());
1089 +    t.set_creator(creator_str);
1090 +    t.set_comment((const char*)comment.toUtf8());
1091      // Is private ?
1092      if(is_private){
1093 -      t->set_priv(true);
1094 +      t.set_priv(true);
1095      }
1096      if(abort) return;
1097      // create the torrent and print it to out
1098 -    entry e = t->create_torrent();
1099 -    libtorrent::bencode(std::ostream_iterator<char>(out), e);
1100 -    out.flush();
1101 +    ofstream out(complete(path((const char*)save_path.toUtf8())), std::ios_base::binary);
1102 +    bencode(std::ostream_iterator<char>(out), t.generate());
1103      emit updateProgress(100);
1104 -    emit creationSuccess(save_path, full_path.branch_path().string().c_str(), misc::toQString(t->info_hash()));
1105 +    emit creationSuccess(save_path, full_path.branch_path().string().c_str());
1106    }
1107    catch (std::exception& e){
1108      emit creationFailure(QString::fromUtf8(e.what()));
1109 Index: src/bittorrent.h
1110 ===================================================================
1111 --- src/bittorrent.h    (revision 2069)
1112 +++ src/bittorrent.h    (revision 2070)
1113 @@ -180,7 +180,6 @@
1114      void enableNATPMP(bool b);
1115      void enableLSD(bool b);
1116      bool enableDHT(bool b);
1117 -    void reloadTorrent(const QTorrentHandle &h, bool full_alloc);
1118      void setTimerScanInterval(int secs);
1119      void setMaxActiveDownloads(int val);
1120      void setMaxActiveTorrents(int val);
1121 Index: src/src.pro
1122 ===================================================================
1123 --- src/src.pro (revision 2069)
1124 +++ src/src.pro (revision 2070)
1125 @@ -146,7 +146,7 @@
1126             PropListDelegate.h previewSelect.h \
1127             PreviewListDelegate.h trackerLogin.h \
1128             downloadThread.h downloadFromURLImp.h \
1129 -           torrentAddition.h deleteThread.h \
1130 +           torrentAddition.h \
1131             bittorrent.h searchEngine.h \
1132             rss.h rss_imp.h FinishedTorrents.h \
1133             allocationDlg.h FinishedListDelegate.h \
1134 Index: src/downloadingTorrents.cpp
1135 ===================================================================
1136 --- src/downloadingTorrents.cpp (revision 2069)
1137 +++ src/downloadingTorrents.cpp (revision 2070)
1138 @@ -529,31 +529,6 @@
1139              DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)h.progress()));
1140            }
1141            break;
1142 -        case torrent_status::connecting_to_tracker:
1143 -          if(h.download_payload_rate() > 0) {
1144 -            // Display "Downloading" status when connecting if download speed > 0
1145 -            if(!downloadList->isColumnHidden(ETA)) {
1146 -              DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)BTSession->getETA(hash)));
1147 -            }
1148 -            DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/downloading.png"))), Qt::DecorationRole);
1149 -            setRowColor(row, QString::fromUtf8("green"));
1150 -          }else{
1151 -            if(!downloadList->isColumnHidden(ETA)) {
1152 -              DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1));
1153 -            }
1154 -            DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/connecting.png"))), Qt::DecorationRole);
1155 -            setRowColor(row, QString::fromUtf8("grey"));
1156 -          }
1157 -          if(!downloadList->isColumnHidden(PROGRESS)) {
1158 -            DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)h.progress()));
1159 -          }
1160 -          if(!downloadList->isColumnHidden(DLSPEED)) {
1161 -            DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)h.download_payload_rate()));
1162 -          }
1163 -          if(!downloadList->isColumnHidden(UPSPEED)) {
1164 -            DLListModel->setData(DLListModel->index(row, UPSPEED), QVariant((double)h.upload_payload_rate()));
1165 -          }
1166 -          break;
1167          case torrent_status::downloading:
1168          case torrent_status::downloading_metadata:
1169            if(h.download_payload_rate() > 0) {
1170 Index: src/qtorrenthandle.cpp
1171 ===================================================================
1172 --- src/qtorrenthandle.cpp      (revision 2069)
1173 +++ src/qtorrenthandle.cpp      (revision 2070)
1174 @@ -64,7 +64,7 @@
1175    return progress;
1176  }
1177  
1178 -const std::vector<bool>* QTorrentHandle::pieces() const {
1179 +bitfield QTorrentHandle::pieces() const {
1180         Q_ASSERT(h.is_valid());
1181         return h.status().pieces;
1182  }
1183 @@ -185,9 +185,9 @@
1184    return h.has_metadata();
1185  }
1186  
1187 -entry QTorrentHandle::write_resume_data() const {
1188 +void QTorrentHandle::save_resume_data() const {
1189    Q_ASSERT(h.is_valid());
1190 -  return h.write_resume_data();
1191 +  return h.save_resume_data();
1192  }
1193  
1194  QString QTorrentHandle::file_at(unsigned int index) const {
1195 @@ -227,7 +227,7 @@
1196    return h.status().total_failed_bytes;
1197  }
1198  
1199 -void QTorrentHandle::file_progress(std::vector<float>& fp) {
1200 +void QTorrentHandle::file_progress(std::vector<size_type>& fp) {
1201    Q_ASSERT(h.is_valid());
1202    return h.file_progress(fp);
1203  }
1204 @@ -330,9 +330,9 @@
1205    h.force_reannounce();
1206  }
1207  
1208 -void QTorrentHandle::set_sequenced_download_threshold(int val) {
1209 +void QTorrentHandle::set_sequential_download(bool b) {
1210    Q_ASSERT(h.is_valid());
1211 -  h.set_sequenced_download_threshold(val);
1212 +  h.set_sequential_download(b);
1213  }
1214  
1215  void QTorrentHandle::set_tracker_login(QString username, QString password) {
1216 Index: src/createtorrent_imp.h
1217 ===================================================================
1218 --- src/createtorrent_imp.h     (revision 2069)
1219 +++ src/createtorrent_imp.h     (revision 2070)
1220 @@ -37,9 +37,12 @@
1221    bool is_private;
1222    int piece_size;
1223    bool abort;
1224 +  QDialog *parent;
1225    
1226    public:
1227 -    torrentCreatorThread() {}
1228 +    torrentCreatorThread(QDialog *_parent) {
1229 +        parent = _parent;
1230 +    }
1231      ~torrentCreatorThread() {
1232        abort = true;
1233        wait();
1234 @@ -51,7 +54,7 @@
1235      
1236    signals:
1237      void creationFailure(QString msg);
1238 -    void creationSuccess(QString path, const char* branch_path, QString hash);
1239 +    void creationSuccess(QString path, const char* branch_path);
1240      void updateProgress(int progress);
1241  };
1242  
1243 @@ -70,6 +73,9 @@
1244    signals:
1245      void torrent_to_seed(QString path);
1246  
1247 +  public slots:
1248 +    void updateProgressBar(int progress);
1249 +
1250    protected slots:
1251      void on_createButton_clicked();
1252      void on_addFile_button_clicked();
1253 @@ -79,8 +85,7 @@
1254      void on_addURLSeed_button_clicked();
1255      void on_removeURLSeed_button_clicked();
1256      void handleCreationFailure(QString msg);
1257 -    void handleCreationSuccess(QString path, const char* branch_path, QString hash);
1258 -    void updateProgressBar(int progress);
1259 +    void handleCreationSuccess(QString path, const char* branch_path);
1260  };
1261  
1262  #endif
1263 Index: src/icons.qrc
1264 ===================================================================
1265 --- src/icons.qrc       (revision 2069)
1266 +++ src/icons.qrc       (revision 2070)
1267 @@ -76,7 +76,6 @@
1268    <file>Icons/flags/united_kingdom.png</file>
1269    <file>Icons/skin/add.png</file>
1270    <file>Icons/skin/connected.png</file>
1271 -  <file>Icons/skin/connecting.png</file>
1272    <file>Icons/skin/decrease.png</file>
1273    <file>Icons/skin/delete.png</file>
1274    <file>Icons/skin/delete_all.png</file>
This page took 0.495236 seconds and 3 git commands to generate.