diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/mirrors/DownloadMirror.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/mirrors/DownloadMirror.java index 6e8beea693..f24159a328 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/mirrors/DownloadMirror.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/mirrors/DownloadMirror.java @@ -43,7 +43,7 @@ public static void downloadFileMirrored(int downloadClass, String urlInput, File return; }catch (FileNotFoundException e) { Log.w("DownloadMirror", "Cannot find the file on the mirror", e); - Log.i("DownloadMirror", "Failling back to default source"); + Log.i("DownloadMirror", "Falling back to default source"); } DownloadUtils.downloadFileMonitored(urlInput, outputFile, buffer, monitor); } @@ -63,24 +63,24 @@ public static void downloadFileMirrored(int downloadClass, String urlInput, File return; }catch (FileNotFoundException e) { Log.w("DownloadMirror", "Cannot find the file on the mirror", e); - Log.i("DownloadMirror", "Failling back to default source"); + Log.i("DownloadMirror", "Falling back to default source"); } DownloadUtils.downloadFile(urlInput, outputFile); } /** - * Getht he content length of a file on the current mirror. If the file is missing on the mirror, + * Get the content length of a file on the current mirror. If the file is missing on the mirror, * or the mirror does not give out the length, request the length from the original source * @param downloadClass Class of the download. Can either be DOWNLOAD_CLASS_LIBRARIES, * DOWNLOAD_CLASS_METADATA or DOWNLOAD_CLASS_ASSETS * @param urlInput The original (Mojang) URL for the download - * @return the length of the file denoted by the URL + * @return the length of the file denoted by the URL in bytes, or -1 if not available */ public static long getContentLengthMirrored(int downloadClass, String urlInput) throws IOException { long length = DownloadUtils.getContentLength(getMirrorMapping(downloadClass, urlInput)); if(length < 1) { Log.w("DownloadMirror", "Unable to get content length from mirror"); - Log.i("DownloadMirror", "Failling back to default source"); + Log.i("DownloadMirror", "Falling back to default source"); return DownloadUtils.getContentLength(urlInput); }else { return length; diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/MinecraftDownloader.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/MinecraftDownloader.java index 525f5d378e..95074cc804 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/MinecraftDownloader.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/MinecraftDownloader.java @@ -92,7 +92,7 @@ private void downloadGame(Activity activity, JMinecraftVersionList.Version verIn mProcessedSizeCounter = new AtomicLong(0); mInternetUsageCounter = new AtomicLong(0); mDownloaderThreadException = new AtomicReference<>(null); - mUseFileCounter = true; + mUseFileCounter = false; if(!downloadAndProcessMetadata(activity, verInfo, versionName)) { throw new RuntimeException(activity.getString(R.string.exception_failed_to_unpack_jre17)); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/SpeedCalculator.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/SpeedCalculator.java index e1f084a33a..136b0c1789 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/SpeedCalculator.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/tasks/SpeedCalculator.java @@ -11,7 +11,7 @@ public class SpeedCalculator { private double mSum; public SpeedCalculator() { - this(4); + this(64); } public SpeedCalculator(int averageDepth) { @@ -27,13 +27,18 @@ private double addToAverage(double speed) { return (mSum + (dLength / 2d)) / dLength; } - public double feed(long newBytes) { + /** + * Update the current amount of bytes downloaded. + * @param bytes the new amount of bytes downloaded + * @return the current download speed in bytes per second + */ + public double feed(long bytes) { long millis = System.currentTimeMillis(); - long deltaBytes = newBytes - mLastBytes; + long deltaBytes = bytes - mLastBytes; long deltaMillis = millis - mLastMillis; - mLastBytes = deltaBytes; + mLastBytes = bytes; mLastMillis = millis; - double speed = (double)deltaBytes / (double)deltaMillis; + double speed = (double)deltaBytes / ((double)deltaMillis / 1000d); return addToAverage(speed); } }