-Chunkdownloader mono resume download fix
This commit is contained in:
tonikelope 2018-11-04 21:05:52 +01:00
parent 862d69b3ea
commit 80ad172bd5
7 changed files with 32 additions and 30 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.tonikelope</groupId> <groupId>com.tonikelope</groupId>
<artifactId>MegaBasterd</artifactId> <artifactId>MegaBasterd</artifactId>
<version>5.63</version> <version>5.64</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<dependencies> <dependencies>
<dependency> <dependency>

View File

@ -290,10 +290,10 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Worker [{1}] has RECOVERED PREVIOUS chunk [{2}]!", new Object[]{Thread.currentThread().getName(), _id, chunk_id}); Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Worker [{1}] has RECOVERED PREVIOUS chunk [{2}]!", new Object[]{Thread.currentThread().getName(), _id, chunk_id});
reads = -1;
finish_chunk_time = -1; finish_chunk_time = -1;
chunk_reads = chunk_size;
_download.getPartialProgress().add(chunk_size); _download.getPartialProgress().add(chunk_size);
_download.getProgress_meter().secureNotify(); _download.getProgress_meter().secureNotify();
@ -301,7 +301,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
} }
} }
if (chunk_reads == chunk_size || reads == -1) { if (chunk_reads == chunk_size) {
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Worker [{1}] has DOWNLOADED chunk [{2}]!", new Object[]{Thread.currentThread().getName(), _id, chunk_id}); Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Worker [{1}] has DOWNLOADED chunk [{2}]!", new Object[]{Thread.currentThread().getName(), _id, chunk_id});
@ -322,7 +322,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
_download.getChunkmanager().secureNotify(); _download.getChunkmanager().secureNotify();
if (current_smart_proxy != null && finish_chunk_time > 0) { if (current_smart_proxy != null && finish_chunk_time != -1) {
//Proxy speed benchmark //Proxy speed benchmark
long chunk_speed = Math.round(chunk_size / ((double) (finish_chunk_time - init_chunk_time - paused) / 1000)); long chunk_speed = Math.round(chunk_size / ((double) (finish_chunk_time - init_chunk_time - paused) / 1000));

View File

@ -161,7 +161,7 @@ public class ChunkDownloaderMono extends ChunkDownloader {
} }
if (chunk_reads == chunk_size || reads == -1) { if (chunk_reads == chunk_size) {
bytes_downloaded += chunk_reads; bytes_downloaded += chunk_reads;
@ -176,12 +176,10 @@ public class ChunkDownloaderMono extends ChunkDownloader {
} }
} catch (IOException ex) { } catch (IOException | InterruptedException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
} finally { } finally {
if (chunk_error) { if (chunk_error) {

View File

@ -78,15 +78,13 @@ public final class ChunkManager implements Runnable, SecureSingleThreadNotifiabl
_rejectedChunkIds = new ConcurrentLinkedQueue<>(); _rejectedChunkIds = new ConcurrentLinkedQueue<>();
if (_download.getProgress() == 0) { if (_download.getProgress() == 0) {
_download.setLast_chunk_id_dispatched(0);
_last_chunk_id_written = 0; _last_chunk_id_written = 0;
_bytes_written = 0; _bytes_written = 0;
} else {
_last_chunk_id_written = calculateLastWrittenChunk(_download.getProgress());
_download.setLast_chunk_id_dispatched(_last_chunk_id_written); } else {
_last_chunk_id_written = _download.getLast_chunk_id_dispatched();
_bytes_written = _download.getProgress(); _bytes_written = _download.getProgress();
} }
@ -159,7 +157,7 @@ public final class ChunkManager implements Runnable, SecureSingleThreadNotifiabl
_bytes_written += chunk_file.length(); _bytes_written += chunk_file.length();
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Chunkmanager has written to disk chunk [{1}] {2} {3}...", new Object[]{Thread.currentThread().getName(), _last_chunk_id_written + 1, _bytes_written, calculateLastWrittenChunk(_bytes_written)}); Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Chunkmanager has written to disk chunk [{1}] {2} {3}...", new Object[]{Thread.currentThread().getName(), _last_chunk_id_written + 1, _bytes_written, _download.calculateLastWrittenChunk(_bytes_written)});
_last_chunk_id_written++; _last_chunk_id_written++;
@ -191,19 +189,4 @@ public final class ChunkManager implements Runnable, SecureSingleThreadNotifiabl
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Chunkmanager: bye bye{1}", new Object[]{Thread.currentThread().getName(), _download.getFile().getName()}); Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Chunkmanager: bye bye{1}", new Object[]{Thread.currentThread().getName(), _download.getFile().getName()});
} }
private long calculateLastWrittenChunk(long temp_file_size) {
if (temp_file_size > 3584 * 1024) {
return 7 + (long) Math.floor((float) (temp_file_size - 3584 * 1024) / (1024 * 1024 * (_download.isUse_slots() ? Download.CHUNK_SIZE_MULTI : 1)));
} else {
long i = 0, tot = 0;
while (tot < temp_file_size) {
i++;
tot += i * 128 * 1024;
}
return i;
}
}
} }

View File

@ -176,6 +176,25 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
} }
public long getLast_chunk_id_dispatched() {
return _last_chunk_id_dispatched;
}
public long calculateLastWrittenChunk(long temp_file_size) {
if (temp_file_size > 3584 * 1024) {
return 7 + (long) Math.floor((float) (temp_file_size - 3584 * 1024) / (1024 * 1024 * (this.isUse_slots() ? Download.CHUNK_SIZE_MULTI : 1)));
} else {
long i = 0, tot = 0;
while (tot < temp_file_size) {
i++;
tot += i * 128 * 1024;
}
return i;
}
}
public void enableProxyTurboMode() { public void enableProxyTurboMode() {
synchronized (_turbo_proxy_lock) { synchronized (_turbo_proxy_lock) {
@ -531,6 +550,8 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
_progress = _file.length(); _progress = _file.length();
_last_chunk_id_dispatched = calculateLastWrittenChunk(_progress);
getView().updateProgressBar(_progress, _progress_bar_rate); getView().updateProgressBar(_progress, _progress_bar_rate);
} else { } else {

View File

@ -47,7 +47,7 @@ import javax.swing.UIManager;
*/ */
public final class MainPanel { public final class MainPanel {
public static final String VERSION = "5.63"; public static final String VERSION = "5.64";
public static final int THROTTLE_SLICE_SIZE = 16 * 1024; public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024; public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
public static final int STREAMER_PORT = 1337; public static final int STREAMER_PORT = 1337;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 190 KiB

After

Width:  |  Height:  |  Size: 191 KiB