Skip to content

Commit

Permalink
fix addons not being found & show warning if cache is empty (fixes #77)
Browse files Browse the repository at this point in the history
  • Loading branch information
froehlichA committed Jul 4, 2022
1 parent 81e4e18 commit 11fe34c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/api/cfcache.nim
Expand Up @@ -103,6 +103,13 @@ proc purge*(): void =
except IOError:
discard

proc isEmpty*(): bool =
## returns true if no addons & files are in cache.
for _ in walkDir(getCacheDir("pax")):
return false
return true


template withCachedAddon*(c: untyped, projectId: int, body: untyped) =
## do something with a cached addon.
let addon = getAddon(projectId)
Expand Down
4 changes: 2 additions & 2 deletions src/api/cfclient.nim
Expand Up @@ -113,7 +113,7 @@ proc fetchAddonFiles*(projectId: int): Future[seq[CfAddonFile]] {.async.} =
return data

proc fetchAddonFilesChunks(fileIds: seq[int], fallback = true): Future[seq[CfAddonFile]] {.async.} =
## get all addons with their given `projectId`.
## get all addons with their given `fileIds`.
if fileIds.len == 0:
return @[]
try:
Expand All @@ -123,7 +123,7 @@ proc fetchAddonFilesChunks(fileIds: seq[int], fallback = true): Future[seq[CfAdd
except CfApiError as e:
# fallback to looking up the ids individually
if fallback:
return all(fileIds.map((x) => fetchAddonFilesChunks(@[x], fallback = false))).await.flatten()
return all(fileIds.map((x) => fetchAddonFilesChunks(@[x], fallback = true))).await.flatten()
raise newException(CfApiError, e.msg)

proc fetchAddonFiles*(fileIds: seq[int], chunk = true): Future[seq[CfAddonFile]] {.async.} =
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/list.nim
@@ -1,6 +1,6 @@
import std/[algorithm, asyncdispatch, sequtils, strutils, os, sugar]
import common
import ../api/[cfclient, cfcore]
import ../api/[cfcache, cfclient, cfcore]
import ../modpack/[manifest, modinfo]
import ../term/log

Expand All @@ -12,6 +12,8 @@ proc paxList*(status: bool, info: bool): void =
let manifest = readManifestFromDisk()

let fileCount = manifest.files.len
if fileCount > 100 and isEmpty():
echoWarn "The cache is being built - this will take a while.."
let mcMods: Future[seq[CfAddon]] = manifest.files.map((x) => x.projectId).fetchAddons
let mcModFiles: Future[seq[CfAddonFile]] = manifest.files.map((x) => x.fileId).fetchAddonFiles

Expand Down

0 comments on commit 11fe34c

Please sign in to comment.