From b4ee9a7a6cfe2e623cf2eb751912e9a9e535c78a Mon Sep 17 00:00:00 2001 From: Ringo Sham Date: Mon, 27 Apr 2020 15:23:02 +0100 Subject: [PATCH] Improved timeout system. Untested --- .../threads/imports/download/Downloader.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/com/ringosham/threads/imports/download/Downloader.java b/src/com/ringosham/threads/imports/download/Downloader.java index a81afff..50f081b 100644 --- a/src/com/ringosham/threads/imports/download/Downloader.java +++ b/src/com/ringosham/threads/imports/download/Downloader.java @@ -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; @@ -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; @@ -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--; + } + } +} \ No newline at end of file