|
|
|
@ -132,7 +132,7 @@ public abstract class ClientDownload extends ServeErrors implements Runnable {
|
|
|
|
|
try {
|
|
|
|
|
sockList.get(rand.nextInt(sockList.size())).assignTask(offset);
|
|
|
|
|
offsetsPending.add(offset);
|
|
|
|
|
writeLog("Assigned task: #"+ offset, LogLevel.Info);
|
|
|
|
|
writeLog("Assigned task: #"+ offset, LogLevel.Debug);
|
|
|
|
|
} catch(InterruptedException e) {
|
|
|
|
|
writeLog(e, LogLevel.Error);
|
|
|
|
|
throw new InternalError();
|
|
|
|
@ -180,7 +180,7 @@ public abstract class ClientDownload extends ServeErrors implements Runnable {
|
|
|
|
|
}
|
|
|
|
|
ratioUpdater.put(c.getServer(), c.getReceivedBytesCount());
|
|
|
|
|
}
|
|
|
|
|
writeLog("Task check status: " + offsetsToAsk.size() + " to asks, " + offsetsPending.size() + " pending", LogLevel.Info);
|
|
|
|
|
writeLog("Task check status: " + offsetsToAsk.size() + " to asks, " + offsetsPending.size() + " pending", LogLevel.Debug);
|
|
|
|
|
if (offsetsToAsk.isEmpty() && offsetsPending.isEmpty()) {
|
|
|
|
|
stop = true;
|
|
|
|
|
}
|
|
|
|
@ -380,6 +380,7 @@ public abstract class ClientDownload extends ServeErrors implements Runnable {
|
|
|
|
|
while(!stop) {
|
|
|
|
|
assignTasks();
|
|
|
|
|
checkTasksStatus();
|
|
|
|
|
printProgression();
|
|
|
|
|
}
|
|
|
|
|
writeLog("Reassembling file parts.", LogLevel.Info);
|
|
|
|
|
reassembleFile();
|
|
|
|
@ -390,6 +391,26 @@ public abstract class ClientDownload extends ServeErrors implements Runnable {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Print progression of the download.
|
|
|
|
|
*/
|
|
|
|
|
protected void printProgression() {
|
|
|
|
|
long progression = 0;
|
|
|
|
|
for(Long dl: ratioUpdater.values()) {
|
|
|
|
|
progression += dl.longValue();
|
|
|
|
|
}
|
|
|
|
|
double percent = 100.0*progression/size;
|
|
|
|
|
String bar = "[";
|
|
|
|
|
for(int i=0;i<=100;i+=10) {
|
|
|
|
|
if (i>percent) {
|
|
|
|
|
bar += "-";
|
|
|
|
|
} else {
|
|
|
|
|
bar += "=";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bar += "]";
|
|
|
|
|
writeLog("[[" + filename + "]] " + bar + " " + String.format("%.2f", percent) + "%", LogLevel.Progression);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Initialize infos about file to download (size, hash512sum, partslist to dl).
|
|
|
|
|
* Also download first partfile (to get size).
|
|
|
|
|
* @throws InternalError
|
|
|
|
|