diff --git a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogDownloadManager.java b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogDownloadManager.java index 31b4abcd4..78f2b73bf 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogDownloadManager.java +++ b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogDownloadManager.java @@ -546,25 +546,39 @@ public final class GogDownloadManager { final AtomicBoolean okRef = new AtomicBoolean(false); final AtomicBoolean linkExpiryRef = new AtomicBoolean(false); final AtomicReference errRef = new AtomicReference<>(""); + // The bar between file completions: what earlier runs counted, plus the files this run + // skipped as already verified (the engine credits those no bytes), plus the engine's own + // byte count, which includes the files still in flight. Never shown going back. + final long runStart = totalBytes.get(); + final AtomicLong verifiedInRun = new AtomicLong(0); + final AtomicLong shownBytes = new AtomicLong(runStart); GogNative.Listener listener = new GogNative.Listener() { @Override public void onProgress(long bytesDone, long bytesTotal, int filesDone, int filesTotal, String file, long fileBytes, boolean verified) { donePaths.add(file); int done = doneCount.incrementAndGet(); int pct = 15 + (int) ((done / (float) total) * 80); long tb = totalBytes.addAndGet(fileBytes); - if (verified) { cb.onProgress(verifiedMsg, pct); cb.onBytes(tb, planned, speedBps.get()); return; } - sampleSpeed(tb, lastSpeedMs, lastSpeedB, speedBps); + if (verified) verifiedInRun.addAndGet(fileBytes); + long shown = shownBytes.accumulateAndGet(tb, Math::max); + if (verified) { cb.onProgress(verifiedMsg, pct); cb.onBytes(shown, planned, speedBps.get()); return; } + sampleSpeed(shown, lastSpeedMs, lastSpeedB, speedBps); cb.onProgress("Downloading: " + baseName(file) + speedSuffix(speedBps.get()), pct); - cb.onBytes(tb, planned, speedBps.get()); + cb.onBytes(shown, planned, speedBps.get()); + } + @Override public void onBytes(long bytesDone, long bytesTotal) { + long shown = shownBytes.accumulateAndGet(Math.min(planned, runStart + verifiedInRun.get() + bytesDone), Math::max); + sampleSpeed(shown, lastSpeedMs, lastSpeedB, speedBps); + cb.onBytes(shown, planned, speedBps.get()); } @Override public void onLog(String line) { cb.onLog(line); } @Override public void onComplete(boolean success, boolean wasCancelled, boolean linkExpiry, String error, long bytesWritten, int filesDone) { okRef.set(success); linkExpiryRef.set(linkExpiry); errRef.set(error == null ? "" : error); latch.countDown(); } }; - // The engine takes one base today; it gets the first of the set (JNI.md). - if (run == 1) cb.onLog("gog: " + base.split("\n").length + " CDN host(s) offered"); - long handle = GogNative.start(kind, manifests, firstCdn(base), installPath.getAbsolutePath(), donePaths.toArray(new String[0]), "", + // Every CDN of the set: the engine spreads its window across the hosts (JNI.md). + String[] bases = (base == null || base.isEmpty()) ? new String[0] : base.split("\n"); + if (run == 1) cb.onLog("gog: " + bases.length + " CDN host(s) offered"); + long handle = GogNative.start(kind, manifests, bases, installPath.getAbsolutePath(), donePaths.toArray(new String[0]), "", workers, process, sortLargestFirst, label + " run=" + run, listener); if (handle == 0L) { cb.onLog("gog: native start failed"); anyFailed.set(true); return; } boolean interrupted = false; diff --git a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogNative.kt b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogNative.kt index 173ad8059..0922eda9a 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/gog/GogNative.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/gog/GogNative.kt @@ -28,6 +28,12 @@ object GogNative { */ fun onProgress(bytesDone: Long, bytesTotal: Long, filesDone: Int, filesTotal: Int, file: String, fileBytes: Long, verified: Boolean) + /** + * Byte progress between file completions, every 250 ms while fetching (and once at the end): + * assembled bytes plus what the files in flight have so far. Drives the bar and the speed. + */ + fun onBytes(bytesDone: Long, bytesTotal: Long) + /** Engine diagnostics (already in logcat under `GogNative`). */ fun onLog(line: String) @@ -60,12 +66,12 @@ object GogNative { */ @JvmStatic fun start( - kind: Int, depotManifests: Array, cdnBase: String, installDir: String, skipPaths: Array, + kind: Int, depotManifests: Array, cdnBases: Array, installDir: String, skipPaths: Array, caBundlePath: String, maxWorkers: Int, processWorkers: Int, sortLargestFirst: Boolean, label: String, listener: Listener, ): Long { if (!isAvailable()) return 0L return try { - nativeStart(kind, depotManifests, cdnBase, installDir, skipPaths, caBundlePath, maxWorkers, processWorkers, sortLargestFirst, label, listener) + nativeStart(kind, depotManifests, cdnBases, installDir, skipPaths, caBundlePath, maxWorkers, processWorkers, sortLargestFirst, label, listener) } catch (t: Throwable) { Log.e(TAG, "nativeStart threw: ${t.javaClass.simpleName}: ${t.message}") 0L @@ -91,7 +97,7 @@ object GogNative { @JvmStatic private external fun nativeStart( - kind: Int, depotManifests: Array, cdnBase: String, installDir: String, skipPaths: Array, + kind: Int, depotManifests: Array, cdnBases: Array, installDir: String, skipPaths: Array, caBundlePath: String, maxWorkers: Int, processWorkers: Int, sortLargestFirst: Boolean, label: String, listener: Listener, ): Long diff --git a/docs/progress-log.md b/docs/progress-log.md index 3d5cbbe9d..4f7f14ffc 100644 --- a/docs/progress-log.md +++ b/docs/progress-log.md @@ -146,9 +146,10 @@ without it and Setup says "Stores engine not built"). Akamai URL. The engine's own logcat lines (tag `EpicNative` etc.) are written on the native side. - **GOG downloads use every CDN host:** the secure link lists several hosts; only the first was taken (`used=1/1 servers`). All are parsed now and kept as one set, refreshed together on - expiry; the Java pool takes them in turn, and the native engine gets the first until its contract - takes a list. The progress bars glide to each new value over 250 ms. The engine's periodic byte - progress (asked of the Rust side) is wired when JNI.md has it. + expiry; the Java pool takes them in turn. The progress bars glide to each new value over 250 ms. With the engine's `0849a7c` the + native start takes the whole set (`cdnBases`; the engine spreads its window across the hosts) and + its `onBytes` - every 250 ms, including files still in flight - drives the bar and the speed, so a + large file no longer moves the bar in one jump. - **GOG and Epic cloud saves** (ported from Bannerlator's managers, device-proven there in August): down before every launch where the cloud copy is newer (the compat tool waits up to 15 s), up after the game exits (the compat tool waits for Proton for such a game, then asks without