-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnwn_ccc.nim
More file actions
89 lines (75 loc) · 3.69 KB
/
Copy pathnwn_ccc.nim
File metadata and controls
89 lines (75 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import docopt;
let ARGS = docopt """
NWCCC - Neverwinter Custom Content Compiler
Usage:
nwn_ccc [options] <nwcfile>...
nwn_ccc [options] -f <nwcfile-list>
nwn_ccc [options] -r <directory>
nwn_ccc [options] -u | --update-cache
nwn_ccc -h | --help
Options:
-a, --append=<tophak> Run in append mode, modifying 2DAs in <tophak>; can either be a hak file or a directory
-d, --destination=<dest> Download all asset files to <dest>; can either be a hak file or a directory [default: ./]
-t, --tlk=<tlkfile> Add TLK entries to <tlkfile> when running in append mode
-r, --recursive=<dir> Recursively process all NWC files in <dir>
-n, --nwc=<nwchak> Store a copy of processed NWC files in <nwchak>; can either be a hak file or a directory
-c, --credits=<file> Write credit fragments to <file> [default: credits.txt]
-f, --filelist=<filelist> Process all NWC files in <filelist>
-u, --update-cache Update local manifest cache
-l, --local-cache=<dir> Also search <dir> for local files before downloading
--parallel=<N> Parallel downloads [default: 20]
-v, --verbose Verbose prints as files are being processed
-q, --quiet Suppresses all non-error prints
-h, --help Print this help message and exit
--noenv Ignore environment variables for config options (except NWN_HOME)
--nwccc-home=<homedir> Override NWCCC home directory (default $NWCCC_HOME, then $NWN_HOME/nwccc)
--userdirectory=<userdir> Override NWN user directory (default $NWN_HOME, then autodetect)
--resolve=<policy> Conflict resolve policy [default: fail]
Valid policies:
ask: Prompt user for answer every time
new: Overwrite older files with newer
old: Keep older files, discard newer
big: Overwrite smaller files with larger
small: Overwrite larger files with smaller
fail: Report error and abort
"""
import std/[os, logging, strutils, asyncdispatch]
import libnwccc
var cfg: NwcccConfig
cfg.parallelDownloads = ($ARGS["--parallel"]).parseInt
cfg.loglevel = if ARGS["--verbose"]: lvlDebug elif ARGS["--quiet"]: lvlError else: lvlNotice
cfg.nwmaster = "http://api.nwn.beamdog.net/v1/servers"
cfg.userAgent = "nwccc"
# Register directories which will be scanned for files to copy locally
cfg.localDirs.add($ARGS["--destination"])
if ARGS["--local-cache"]:
cfg.localDirs.add($ARGS["--local-cache"])
if ARGS["--userdirectory"]:
cfg.nwnHome = $ARGS["--userdirectory"];
if ARGS["--nwccc-home"]:
cfg.nwcccHome = $ARGS["--nwccc-home"];
elif existsEnv("NWCCC_HOME") and not ARGS["--noenv"]:
cfg.nwcccHome = getEnv("NWCCC_HOME")
nwcccInit(cfg)
if ARGS["--update-cache"]:
waitFor nwcccUpdateCache()
# TODOs
if ARGS["--append"]: warn "append mode not yet implemented"
if ARGS["--tlk"]: warn "writing to TLK not yet implemented"
if ARGS["--resolve"]: warn "auto resolve not yet implemented"
proc processNwc(nwcfile: string) =
waitFor nwcccProcessNwcFile(nwcfile, $ARGS["--destination"])
if ARGS["--nwc"]:
nwcccWriteFile(nwcfile.extractFilename(), readFile(nwcfile), $ARGS["--nwc"])
if ARGS["--filelist"]:
for nwcfile in lines($ARGS["--filelist"]):
processNwc(nwcfile)
elif ARGS["--recursive"]:
for nwcfile in walkDirRec($ARGS["--recursive"]):
if nwcfile.toLowerAscii.endsWith(".nwc"):
processNwc(nwcfile)
else:
for nwcfile in ARGS["<nwcfile>"]:
processNwc(nwcfile)
if ARGS["--credits"]:
nwcccWriteCredits($ARGS["--credits"])