Added error() method to DownloadListener interface.
Downloads failing due to connection errors will now send a bar notification instead of throwing an ErrorHandler dialog. Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
parent
cfd335de88
commit
f8e91cba64
|
@ -34,6 +34,8 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
|
import org.newdawn.slick.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File download.
|
* File download.
|
||||||
*/
|
*/
|
||||||
|
@ -76,6 +78,9 @@ public class Download {
|
||||||
public interface DownloadListener {
|
public interface DownloadListener {
|
||||||
/** Indication that a download has completed. */
|
/** Indication that a download has completed. */
|
||||||
public void completed();
|
public void completed();
|
||||||
|
|
||||||
|
/** Indication that an error has occurred. */
|
||||||
|
public void error();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The local path. */
|
/** The local path. */
|
||||||
|
@ -177,7 +182,9 @@ public class Download {
|
||||||
contentLength = conn.getContentLength();
|
contentLength = conn.getContentLength();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
status = Status.ERROR;
|
status = Status.ERROR;
|
||||||
ErrorHandler.error("Failed to open connection.", e, false);
|
Log.warn("Failed to open connection.", e);
|
||||||
|
if (listener != null)
|
||||||
|
listener.error();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,6 +200,7 @@ public class Download {
|
||||||
updateReadSoFar();
|
updateReadSoFar();
|
||||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||||
if (status == Status.DOWNLOADING) { // not interrupted
|
if (status == Status.DOWNLOADING) { // not interrupted
|
||||||
|
// TODO: if connection is lost before a download finishes, it's still marked as "complete"
|
||||||
status = Status.COMPLETE;
|
status = Status.COMPLETE;
|
||||||
rbc.close();
|
rbc.close();
|
||||||
fos.close();
|
fos.close();
|
||||||
|
@ -205,7 +213,9 @@ public class Download {
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
status = Status.ERROR;
|
status = Status.ERROR;
|
||||||
ErrorHandler.error("Failed to start download.", e, false);
|
Log.warn("Failed to start download.", e);
|
||||||
|
if (listener != null)
|
||||||
|
listener.error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
|
|
|
@ -225,6 +225,11 @@ public class DownloadNode {
|
||||||
public void completed() {
|
public void completed() {
|
||||||
UI.sendBarNotification(String.format("Download complete: %s", getTitle()));
|
UI.sendBarNotification(String.format("Download complete: %s", getTitle()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error() {
|
||||||
|
UI.sendBarNotification("Download failed due to a connection error.");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,6 +175,12 @@ public class Updater {
|
||||||
status = Status.UPDATE_DOWNLOADED;
|
status = Status.UPDATE_DOWNLOADED;
|
||||||
UI.sendBarNotification("Update has finished downloading.");
|
UI.sendBarNotification("Update has finished downloading.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error() {
|
||||||
|
status = Status.CONNECTION_ERROR;
|
||||||
|
UI.sendBarNotification("Update failed due to a connection error.");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,23 +103,23 @@ public class Bezier2 {
|
||||||
* Returns the total distances of this Bezier curve.
|
* Returns the total distances of this Bezier curve.
|
||||||
*/
|
*/
|
||||||
public float totalDistance() { return totalDistance; }
|
public float totalDistance() { return totalDistance; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Calculates the binomial coefficient.
|
||||||
* http://en.wikipedia.org/wiki/Binomial_coefficient#Binomial_coefficient_in_programming_languages
|
* http://en.wikipedia.org/wiki/Binomial_coefficient#Binomial_coefficient_in_programming_languages
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static long binomialCoefficient(int n, int k) {
|
public static long binomialCoefficient(int n, int k) {
|
||||||
if (k < 0 || k > n)
|
if (k < 0 || k > n)
|
||||||
return 0;
|
return 0;
|
||||||
if (k == 0 || k == n)
|
if (k == 0 || k == n)
|
||||||
return 1;
|
return 1;
|
||||||
k = Math.min(k, n - k); // # take advantage of symmetry
|
k = Math.min(k, n - k); // take advantage of symmetry
|
||||||
long c = 1;
|
long c = 1;
|
||||||
for (int i = 0; i < k; i++) {
|
for (int i = 0; i < k; i++)
|
||||||
c = c * (n - i) / (i + 1);
|
c = c * (n - i) / (i + 1);
|
||||||
}
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the Bernstein polynomial.
|
* Calculates the Bernstein polynomial.
|
||||||
* @param i the index
|
* @param i the index
|
||||||
|
@ -129,6 +129,4 @@ public class Bezier2 {
|
||||||
private static double bernstein(int i, int n, float t) {
|
private static double bernstein(int i, int n, float t) {
|
||||||
return binomialCoefficient(n, i) * Math.pow(t, i) * Math.pow(1 - t, n - i);
|
return binomialCoefficient(n, i) * Math.pow(t, i) * Math.pow(1 - t, n - i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,5 +86,4 @@ public abstract class Curve {
|
||||||
protected float lerp(float a, float b, float t) {
|
protected float lerp(float a, float b, float t) {
|
||||||
return a * (1 - t) + b * t;
|
return a * (1 - t) + b * t;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,13 +149,12 @@ public class OpenALStreamPlayer {
|
||||||
audio = new Mp3InputStream(ResourceLoader.getResourceAsStream(ref));
|
audio = new Mp3InputStream(ResourceLoader.getResourceAsStream(ref));
|
||||||
else
|
else
|
||||||
audio = new OggInputStream(ResourceLoader.getResourceAsStream(ref));
|
audio = new OggInputStream(ResourceLoader.getResourceAsStream(ref));
|
||||||
|
|
||||||
if(audio.getRate() == 0 && audio.getChannels() == 0) {
|
if (audio.getRate() == 0 && audio.getChannels() == 0) {
|
||||||
if (ref.toLowerCase().endsWith(".mp3"))
|
if (ref.toLowerCase().endsWith(".mp3"))
|
||||||
audio = new OggInputStream(ResourceLoader.getResourceAsStream(ref));
|
audio = new OggInputStream(ResourceLoader.getResourceAsStream(ref));
|
||||||
else
|
else
|
||||||
audio = new Mp3InputStream(ResourceLoader.getResourceAsStream(ref));
|
audio = new Mp3InputStream(ResourceLoader.getResourceAsStream(ref));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user