Changeset 304
- Timestamp:
- 09/22/07 19:31:07 (13 years ago)
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/halTorrent.cpp
r303 r304 6 6 7 7 8 #define HALITE_VERSION 0,2,9, 2939 #define HALITE_VERSION_STRING "v 0.2.9 dev 293"8 #define HALITE_VERSION 0,2,9,304 9 #define HALITE_VERSION_STRING "v 0.2.9 dev 304" 10 10 11 11 #define LBT_EVENT_TORRENT_FINISHED 80001 … … 539 539 { 540 540 541 fs::wofstream ofs(workingDirectory/L"Torrents.xml"); 542 boost::archive::xml_woarchive oxa(ofs); 543 544 oxa << make_nvp("theTorrents", theTorrents); 541 // fs::wofstream ofs(workingDirectory/L"Torrents.xml"); 542 // boost::archive::xml_woarchive oxa(ofs); 543 544 // oxa << make_nvp("theTorrents", theTorrents); 545 546 theTorrents.save(); 547 bittorrentIni.save_data(); 545 548 546 549 if (dht_on_) … … 584 587 TorrentInternal::the_session_ = &theSession; 585 588 586 theSession.set_severity_level(lbt::alert::debug); 587 589 theSession.set_severity_level(lbt::alert::debug); 588 590 theSession.add_extension(&lbt::create_metadata_plugin); 589 591 theSession.add_extension(&lbt::create_ut_pex_plugin); 590 592 theSession.set_max_half_open_connections(10); 591 593 592 /*593 bool tryOld = false;594 594 bittorrentIni.load_data(); 595 theTorrents.load(); 596 595 597 try 596 { 597 598 fs::wifstream ifs(workingDirectory/L"BitTorrent.xml"); 599 if (ifs) 600 { 601 boost::archive::xml_wiarchive ia(ifs); 602 ia >> make_nvp("theTorrents", theTorrents); 603 } 604 605 } 606 catch (const boost::archive::archive_exception& e) 607 { 608 tryOld = true; 598 { 599 if (fs::exists(workingDirectory/L"Torrents.xml")) 600 { 601 { 602 fs::wifstream ifs(workingDirectory/L"Torrents.xml"); 603 604 event().post(shared_ptr<EventDetail>(new EventMsg(L"Loading old Torrents.xml"))); 605 606 TorrentMap torrents; 607 boost::archive::xml_wiarchive ia(ifs); 608 ia >> make_nvp("torrents", torrents); 609 610 theTorrents = torrents; 611 } 612 613 event().post(shared_ptr<EventDetail>(new EventMsg( 614 wformat(L"Total %1%.") % theTorrents.size()))); 615 616 fs::rename(workingDirectory/L"Torrents.xml", workingDirectory/L"Torrents.xml.safe.to.delete"); 617 } 609 618 } 610 619 catch(const std::exception& e) 611 620 { 612 621 event().post(shared_ptr<EventDetail>( 613 new EventStdException(Event::fatal, e, L"Loading Torrents.xml"))); 614 } 615 616 if (tryOld) 617 { 618 try 619 { 620 621 fs::wifstream ifs(workingDirectory/L"Torrents.xml"); 622 if (ifs) 623 { 624 TorrentMap torrents; 625 boost::archive::xml_wiarchive ia(ifs); 626 ia >> make_nvp("torrents", torrents); 622 new EventStdException(Event::fatal, e, L"Loading Old Torrents.xml"))); 623 } 627 624 628 theTorrents = torrents;629 }630 631 }632 catch(const std::exception& e)633 {634 event().post(shared_ptr<EventDetail>(635 new EventStdException(Event::fatal, e, L"Loading Old Torrents.xml")));636 }637 }638 639 */640 625 if (exists(workingDirectory/L"DHTState.bin")) 641 626 { … … 1268 1253 mutex_t::scoped_lock l(torrentDetails_.mutex_); 1269 1254 1270 torrentDetails_.clearAll(l); 1271 1272 // torrentDetails_.torrents_.reserve(pimpl->torrents.size()); 1255 torrentDetails_.clearAll(l); 1256 torrentDetails_.torrents_.reserve(pimpl->theTorrents.size()); 1273 1257 1274 1258 for (TorrentManager::torrentByName::iterator i=pimpl->theTorrents.begin(), e=pimpl->theTorrents.end(); i != e; ++i) … … 1300 1284 for (TorrentManager::torrentByName::iterator i=pimpl->theTorrents.begin(), e=pimpl->theTorrents.end(); i != e;) 1301 1285 { 1302 wpath file = wpath(pimpl->workingDirectory)/L"torrents"/wpath((*i).torrent.filename());; 1303 1304 // vvv Handle old naming style! 1305 if ((*i).torrent.originalFilename() != L"") 1306 file = wpath(pimpl->workingDirectory)/L"torrents"/wpath((*i).torrent.originalFilename()); 1307 // ^^^ Handle old naming style! 1308 1286 wpath file = wpath(pimpl->workingDirectory)/L"torrents"/(*i).torrent.filename(); 1287 1309 1288 if (exists(file)) 1310 1289 { -
src/halTorrentInternal.hpp
r303 r304 40 40 #include <boost/multi_index/tag.hpp> 41 41 42 #include "HaliteIni.hpp" 43 42 44 namespace hal 43 45 { … … 45 47 } 46 48 47 BOOST_CLASS_VERSION(hal::TorrentInternal, 10)49 BOOST_CLASS_VERSION(hal::TorrentInternal, 7) 48 50 49 51 namespace hal … … 192 194 private: 193 195 TransferTracker<boost::posix_time::time_duration> total_; 194 mutable boost::posix_time::ptime start_; 195 196 mutable boost::posix_time::ptime start_; 196 197 }; 197 198 … … 210 211 211 212 TorrentInternal() : 212 TORRENT_INTERNALS_DEFAULTS, 213 TORRENT_INTERNALS_DEFAULTS, 214 compactStorage_(true), 213 215 in_session_(false) 214 216 {} … … 411 413 ar & make_nvp("transferLimit", transferLimit_); 412 414 ar & make_nvp("connections", connections_); 413 ar & make_nvp("uploads", uploads_); 414 if (version > 8) { 415 ar & make_nvp("uploads", uploads_); 416 417 if (version > 6) { 415 418 ar & make_nvp("filename", filename_); 416 419 } 417 else { 418 ar & make_nvp("filename", originalFilename_); 419 } 420 else 421 { 422 wstring originalFilename; 423 ar & make_nvp("filename", originalFilename); 424 425 updatePreVersion7Files(originalFilename); 426 } 427 420 428 ar & make_nvp("saveDirectory", save_directory_); 421 429 … … 455 463 } 456 464 if (version > 6) { 457 ar & make_nvp("name", name_); 458 } 459 else { 460 name_ = filename_; 461 } 462 if (version > 7) { 463 ar & make_nvp("compactStorage", compactStorage_); 464 } 465 if (version > 9) { 466 ar & make_nvp("finishTime", finishTime_); 467 } 465 ar & make_nvp("name", name_); 466 ar & make_nvp("compactStorage", compactStorage_); 467 ar & make_nvp("finishTime", finishTime_); 468 } 468 469 } 470 471 void updatePreVersion7Files(wstring originalFilename) 472 { 473 try 474 { 475 476 wpath oldFile = app().working_directory()/L"torrents"/originalFilename; 477 478 if (exists(oldFile)) 479 extractNames(haldecode(oldFile)); 480 481 wpath oldResumeFile = app().working_directory()/L"resume"/originalFilename; 482 483 if (filename_ != originalFilename) 484 { 485 fs::rename(oldFile, app().working_directory()/L"torrents"/filename_); 486 487 if (fs::exists(oldResumeFile)) 488 fs::rename(oldResumeFile, app().working_directory()/L"resume"/filename_); 489 } 490 491 } 492 catch(std::exception &e) 493 { 494 hal::event().post(boost::shared_ptr<hal::EventDetail>( 495 new hal::EventStdException(Event::critical, e, L"updatePreVersion7Files"))); 496 } 497 } 469 498 470 499 void setEntryData(libtorrent::entry metadata, libtorrent::entry resumedata) … … 523 552 void prepare(wpath filename, wpath saveDirectory, wpath workingDirectory) 524 553 { 525 metadata_ = haldecode(filename);526 lbt::torrent_info info_(metadata_);527 528 name_ = hal::from_utf8_safe(info_.name());529 530 filename_ = name_;531 532 if (!boost::find_last(filename_, L".torrent"))533 filename_ += L".torrent";534 535 554 const wpath resumeFile = workingDirectory/L"resume"/filename_; 536 537 // vvv Handle old naming style! 538 const wpath oldResumeFile = workingDirectory/L"resume"/filename.leaf(); 539 540 if (resumeFile != oldResumeFile && !exists(resumeFile) && exists(oldResumeFile)) 541 fs::rename(oldResumeFile, resumeFile); 542 // ^^^ Handle old naming style! 543 555 const wpath torrentFile = workingDirectory/L"torrents"/filename_; 556 557 event().post(shared_ptr<EventDetail>(new EventMsg( 558 wformat(L"File: %1%, %2%.") % resumeFile % torrentFile))); 559 544 560 if (exists(resumeFile)) 545 { 546 try 547 { 548 resumedata_ = haldecode(resumeFile); 549 } 550 catch(std::exception &e) 551 { 552 hal::event().post(boost::shared_ptr<hal::EventDetail>( 553 new hal::EventStdException(Event::critical, e, L"prepTorrent, Resume"))); 554 555 remove(resumeFile); 556 } 557 } 561 resumedata_ = haldecode(resumeFile); 562 if (exists(filename)) 563 metadata_ = haldecode(filename); 558 564 559 565 if (!exists(workingDirectory/L"torrents")) 560 566 create_directory(workingDirectory/L"torrents"); 561 567 562 if (!exists( workingDirectory/L"torrents"/filename_))563 copy_file(filename.string(), workingDirectory/L"torrents"/filename_);568 if (!exists(torrentFile)) 569 copy_file(filename.string(), torrentFile); 564 570 565 571 if (!exists(saveDirectory)) 566 create_directory(saveDirectory); 572 create_directory(saveDirectory); 573 574 extractNames(metadata_); 575 } 576 577 void extractNames(lbt::entry& metadata) 578 { 579 lbt::torrent_info info(metadata); 580 name_ = hal::from_utf8_safe(info.name()); 581 582 filename_ = name_; 583 if (!boost::find_last(filename_, L".torrent")) 584 filename_ += L".torrent"; 585 586 event().post(shared_ptr<EventDetail>(new EventMsg( 587 wformat(L"Loaded names: %1%, %2%") % name_ % filename_))); 567 588 } 568 589 … … 704 725 typedef std::pair<std::string, TorrentInternal> TorrentPair; 705 726 706 class TorrentManager : public ini_adapter 727 class TorrentManager : 728 public CHaliteIni<TorrentManager> 707 729 { 730 typedef TorrentManager thisClass; 731 typedef CHaliteIni<thisClass> iniClass; 732 708 733 struct TorrentHolder 709 734 { … … 755 780 756 781 TorrentManager(ini_file& ini) : 757 ini _adapter("manager", ini)782 iniClass("bittorrent", "TorrentManager", ini) 758 783 {} 759 784 … … 763 788 764 789 for (TorrentMap::const_iterator i=map.begin(), e=map.end(); i != e; ++i) 765 { 790 { 791 event().post(shared_ptr<EventDetail>(new EventMsg( 792 wformat(L"Converting %1%.") % (*i).second.name()))); 793 766 794 torrents_.insert(TorrentHolder((*i).second)); 767 795 } 796 797 return *this; 768 798 } 769 799 … … 814 844 { 815 845 return torrents_.get<byName>().erase(where); 846 } 847 848 size_t size() 849 { 850 return torrents_.size(); 816 851 } 817 852
Note: See TracChangeset
for help on using the changeset viewer.