From f49f52494a57aecb76f779b6f98a28b29f8e9284 Mon Sep 17 00:00:00 2001 From: _0Steven <42909981+00-Steven@users.noreply.github.com> Date: Sat, 2 Nov 2024 14:20:29 +0100 Subject: [PATCH] Fix NT Software Hub displaying >100% completion or NaN/Infinite% completion. (#87619) ## About The Pull Request During all that fiddling with NTNRC I noticed that sometimes the download percentage would shoot above 100%. Looking into it, it seems that that's just because it isn't actually capped at the downloaded file size. So we cap it to the file size after adding our next download chunk, but parallel to before don't complete it immediately so that we stay on 100% for another cycle before finishing. For style reasons. Then I noticed files with a size of 0 would sometimes display NaN% or Infinite%, presumably because both of the progress percentage calculations in the ui would be dividing by zero. So to avoid this, we just skip the downloading cycle entirely for 0 size programs, and go to download completion immediately on clicking. This fixes our issues. ## Why It's Good For The Game Fixes some jank. ## Changelog :cl: fix: NT Software Hub no longer displays >100% completion on downloads sometimes. fix: NT Software Hub no longer displays NaN% or Infinite% completion on files with a size of 0 sometimes. /:cl: --------- Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com> Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com> --- .../file_system/programs/ntdownloader.dm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/code/modules/modular_computers/file_system/programs/ntdownloader.dm b/code/modules/modular_computers/file_system/programs/ntdownloader.dm index 3fbc7843f18..a26d9bd3d51 100644 --- a/code/modules/modular_computers/file_system/programs/ntdownloader.dm +++ b/code/modules/modular_computers/file_system/programs/ntdownloader.dm @@ -65,6 +65,10 @@ downloaded_file = PRG.clone() + // If the filesize is 0 (or somehow lower), we instantly download to avoid invalid number issues with stepwise download. + if(downloaded_file.size <= 0) + complete_file_download() + /datum/computer_file/program/ntnetdownload/proc/abort_file_download() if(!downloaded_file) return @@ -89,8 +93,9 @@ return if(download_completion >= downloaded_file.size) complete_file_download() + return // Download speed according to connectivity state. NTNet server is assumed to be on unlimited speed so we're limited by our local connectivity - var/download_netspeed + var/download_netspeed = 0 // Speed defines are found in misc.dm switch(ntnet_status) if(NTNET_LOW_SIGNAL) @@ -99,10 +104,13 @@ download_netspeed = NTNETSPEED_HIGHSIGNAL if(NTNET_ETHERNET_SIGNAL) download_netspeed = NTNETSPEED_ETHERNET - if(download_netspeed) - if(HAS_TRAIT(computer, TRAIT_MODPC_HALVED_DOWNLOAD_SPEED)) - download_netspeed *= 0.5 - download_completion += download_netspeed + if(download_netspeed <= 0) + return + if(HAS_TRAIT(computer, TRAIT_MODPC_HALVED_DOWNLOAD_SPEED)) + download_netspeed *= 0.5 + // We don't complete it here so we stay on 100% for a cycle + // We do cap out our completion to avoid UI issues + download_completion = min(download_completion + download_netspeed, downloaded_file.size) /datum/computer_file/program/ntnetdownload/ui_act(action, params, datum/tgui/ui, datum/ui_state/state) . = ..()