Procházet zdrojové kódy

2007-07-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Create directory structure specified in metalink file.
	* src/RequestGroup.h, src/RequestGroup.cc
	(initAndOpenFile): Create a directory to store files if it does 
not
	exist.
	(getDir): New function.

	Added ETA and download speed for an individual file to readout.
	* src/ConsoleDownloadEngine.cc (sendStatistics)
	* src/RequestGroup.h
	(calculateDownloadSpeed): New function.
Tatsuhiro Tsujikawa před 18 roky
rodič
revize
a19cf91f9b
4 změnil soubory, kde provedl 35 přidání a 4 odebrání
  1. 5 0
      ChangeLog
  2. 24 3
      src/ConsoleDownloadEngine.cc
  3. 1 1
      src/DownloadCommand.cc
  4. 5 0
      src/RequestGroup.h

+ 5 - 0
ChangeLog

@@ -6,6 +6,11 @@
 	exist.
 	(getDir): New function.
 
+	Added ETA and download speed for an individual file to readout.
+	* src/ConsoleDownloadEngine.cc (sendStatistics)
+	* src/RequestGroup.h
+	(calculateDownloadSpeed): New function.
+	
 2007-06-30  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Made -S option work with metalink file and provided selective download

+ 24 - 3
src/ConsoleDownloadEngine.cc

@@ -61,6 +61,12 @@ void ConsoleDownloadEngine::sendStatistics(long long int currentSize, long long
   cout << "\r";
   if(_requestGroupMan->countRequestGroup() > 0) {
     RequestGroupHandle firstRequestGroup = _requestGroupMan->getRequestGroup(0);
+    int32_t dlSpeed = firstRequestGroup->calculateDownloadSpeed();
+    int32_t eta = 0;
+    if(firstRequestGroup->getTotalLength() > 0 && dlSpeed > 0) {
+      eta = (firstRequestGroup->getTotalLength()-firstRequestGroup->getDownloadLength())/dlSpeed;
+    }
+
     cout << "["
 	 << "#" << firstRequestGroup->getGID() << " "
 	 << Util::abbrevSize(firstRequestGroup->getDownloadLength())
@@ -76,6 +82,15 @@ void ConsoleDownloadEngine::sendStatistics(long long int currentSize, long long
     cout << "("
 	 << firstRequestGroup->numConnection
 	 << "cn)";
+    cout << "("
+	 << fixed << setprecision(2)
+	 << dlSpeed/1024.0 << "KiB/s"
+	 << ")";
+    if(eta > 0) {
+      cout << " "
+	   << "ETA:"
+	   << Util::secfmt(eta);
+    }
     if(_requestGroupMan->countRequestGroup() > 1) {
       cout << "("
 	   << _requestGroupMan->countRequestGroup()-1
@@ -83,12 +98,17 @@ void ConsoleDownloadEngine::sendStatistics(long long int currentSize, long long
     }
     cout << "]";
   }
-  cout << "[" << fixed << setprecision(2) << speed/1024.0 << "KiB/s" << "]";
+
+  if(_requestGroupMan->countRequestGroup() > 1) {
+    cout << " "
+	 << "[" << fixed << setprecision(2) << speed/1024.0 << "KiB/s" << "]";
+  }
 
   {
     FileAllocationEntryHandle entry = _fileAllocationMan->getCurrentFileAllocationEntry();
     if(!entry.isNull()) {
-      cout << "[FileAlloc:"
+      cout << " "
+	   << "[FileAlloc:"
 	   << "#" << entry->getRequestGroup()->getGID() << " "
 	   << Util::abbrevSize(entry->getCurrentLength())
 	   << "B"
@@ -109,7 +129,8 @@ void ConsoleDownloadEngine::sendStatistics(long long int currentSize, long long
   {
     CheckIntegrityEntryHandle entry = _checkIntegrityMan->getFirstCheckIntegrityEntry();
     if(!entry.isNull()) {
-      cout << "[Checksum:"
+      cout << " "
+	   << "[Checksum:"
 	   << "#" << entry->getRequestGroup()->getGID() << " "
 	   << Util::abbrevSize(entry->getCurrentLength())
 	   << "B"

+ 1 - 1
src/DownloadCommand.cc

@@ -53,7 +53,7 @@ DownloadCommand::DownloadCommand(int cuid,
   transferDecoder(0)
 {
   peerStat = _requestGroup->getSegmentMan()->getPeerStat(cuid);
-  if(!peerStat.get()) {
+  if(peerStat.isNull()) {
     peerStat = new PeerStat(cuid);
     _requestGroup->getSegmentMan()->registerPeerStat(peerStat);
   }

+ 5 - 0
src/RequestGroup.h

@@ -296,6 +296,11 @@ public:
   {
     _topDir = topDir;
   }
+
+  int32_t calculateDownloadSpeed() const
+  {
+    return _segmentMan->calculateDownloadSpeed();
+  }
 };
 
 typedef SharedHandle<RequestGroup> RequestGroupHandle;