Skip to content

Commit

Permalink
Improved timeout system. Untested
Browse files Browse the repository at this point in the history
  • Loading branch information
ringosham committed Apr 27, 2020
1 parent 7652d5c commit b4ee9a7
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/com/ringosham/threads/imports/download/Downloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,7 @@ private boolean downloadBeatmap(File osz, URL url, BeatmapXML beatmap) {
while ((line = reader.readLine()) != null)
errorString.append(line);
if (errorString.toString().contains("slow down")) {
int timeout = 30;
while (timeout >= 0) {
int finalTimeout = timeout;
Platform.runLater(() -> {
mainScreen.statusText.setText(Localizer.getLocalizedText("status.download.timeout")
.replace("%TIMEOUT%", String.valueOf(finalTimeout)));
mainScreen.subProgress.setProgress(-1);
});
Thread.sleep(1000);
timeout--;
}
timeout();
in.close();
out.close();
return false;
Expand All @@ -172,7 +162,10 @@ private boolean downloadBeatmap(File osz, URL url, BeatmapXML beatmap) {
timeoutCurrent = System.currentTimeMillis();
//If osu! has stop sending any data for 5 seconds
if (timeoutCurrent - timeoutStart >= 5000) {
//TODO Display timeout. Retry
timeout();
in.close();
out.close();
return false;
}
} else {
timeoutStart = -1;
Expand All @@ -193,8 +186,24 @@ private boolean downloadBeatmap(File osz, URL url, BeatmapXML beatmap) {
mainScreen.consoleArea.appendText(error + "\n");
mainScreen.consoleArea.appendText(e.getClass().getName() + " : " + e.getMessage() + "\n");
e.printStackTrace();
} catch (InterruptedException ignored) {
}
return true;
}
}

private void timeout() {
int timeout = 30;
while (timeout >= 0) {
int finalTimeout = timeout;
Platform.runLater(() -> {
mainScreen.statusText.setText(Localizer.getLocalizedText("status.download.timeout")
.replace("%TIMEOUT%", String.valueOf(finalTimeout)));
mainScreen.subProgress.setProgress(-1);
});
try {
Thread.sleep(30000);
} catch (InterruptedException ignored) {
}
timeout--;
}
}
}

0 comments on commit b4ee9a7

Please sign in to comment.