Skip to content

Commit

Permalink
shared: detect root from NWN_ROOT and update with new torrent IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
niv committed Nov 22, 2017
1 parent b52ca68 commit 8bf9e8c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/lib/shared.nim
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ proc DOC*(body: string): Table[string, docopt_internal.Value] =
proc findNwnRoot*(): string =
if Args["--root"]:
result = $Args["--root"]
elif getEnv("NWN_ROOT") != "":
result = getEnv("NWN_ROOT")
else:
when defined(macosx):
let settingsFile = r"~/Library/Application Support/Beamdog Client/settings.json".expandTilde
Expand All @@ -104,9 +106,21 @@ proc findNwnRoot*(): string =
let j = data.parseJson
doAssert(j.hasKey("folders"))
doAssert(j["folders"].kind == JArray)
var fo = j["folders"].mapIt(it.str / "00785")
fo.keepItIf(dirExists(it))
if fo.len > 0: result = fo[0]

# Which NWN release do we want? So many questions. We pick the first one available, in order:
# 00840: Digital Deluxe Beta (Head Start)
# 00829: Normal Beta (Head Start)
# TODO:
# 00839: Digital Deluxe
# 00832: Nightly
const releases = ["00840", "00829"]
for torrentId in releases:
var fo = j["folders"].mapIt(it.str / torrentId)

fo.keepItIf(dirExists(it))
if fo.len > 0:
result = fo[0]
break

if result == "" or not dirExists(result): raise newException(ValueError,
"Could not locate NWN; try --root")
Expand Down

0 comments on commit 8bf9e8c

Please sign in to comment.