diff --git a/src/itdelatrisu/opsu/downloads/Download.java b/src/itdelatrisu/opsu/downloads/Download.java index a3f62390..09ebe292 100644 --- a/src/itdelatrisu/opsu/downloads/Download.java +++ b/src/itdelatrisu/opsu/downloads/Download.java @@ -245,9 +245,18 @@ public class Download { fos = fileOutputStream; status = Status.DOWNLOADING; updateReadSoFar(); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + long bytesRead = fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); if (status == Status.DOWNLOADING) { // not interrupted - // TODO: if connection is lost before a download finishes, it's still marked as "complete" + // check if the entire file was received + if (bytesRead < contentLength) { + status = Status.ERROR; + Log.warn(String.format("Download '%s' failed: %d bytes expected, %d bytes received.", url.toString(), contentLength, bytesRead)); + if (listener != null) + listener.error(); + return; + } + + // mark download as complete status = Status.COMPLETE; rbc.close(); fos.close(); @@ -320,7 +329,7 @@ public class Download { public long readSoFar() { switch (status) { case COMPLETE: - return contentLength; + return (rbc != null) ? rbc.getReadSoFar() : contentLength; case DOWNLOADING: if (rbc != null) return rbc.getReadSoFar(); diff --git a/src/itdelatrisu/opsu/downloads/servers/MengSkyServer.java b/src/itdelatrisu/opsu/downloads/servers/MengSkyServer.java index 829a9094..ce4647be 100644 --- a/src/itdelatrisu/opsu/downloads/servers/MengSkyServer.java +++ b/src/itdelatrisu/opsu/downloads/servers/MengSkyServer.java @@ -174,9 +174,7 @@ public class MengSkyServer extends DownloadServer { continue; } - DownloadNode node = new DownloadNode(id, date, title, titleUnicode, artist, artistUnicode, creator); - System.out.println(node); - nodeList.add(node); + nodeList.add(new DownloadNode(id, date, title, titleUnicode, artist, artistUnicode, creator)); } nodes = nodeList.toArray(new DownloadNode[nodeList.size()]);