-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathnwn_nwsync_print.nim
59 lines (45 loc) · 1.48 KB
/
nwn_nwsync_print.nim
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
import shared
let ARGS = DOC """
This utility prints a manifest in human-readable form.
Usage:
$0 [options] <manifest>
$USAGE
Options:
--verify Verify presence and checksum of files in manifest.
$OPT
"""
import std/[logging, streams, strutils, options, os]
import neverwinter/[nwsync]
import neverwinter/nwsync/private/libupdate
addHandler newFileLogger(stderr, fmtStr = verboseFmtStr)
setLogFilter(if ARGS["--verbose"]: lvlDebug elif ARGS["--quiet"]: lvlWarn else: lvlInfo)
let doVerify = ARGS["--verify"]
doAssert(fileExists($ARGS["<manifest>"]))
let mf = readManifest(newFileStream($ARGS["<manifest>"], fmRead))
echo "--"
echo "Version: ", mf.version
echo "Hash algorithm: ", mf.algorithm
echo "Hash tree depth: ", mf.hashTreeDepth
echo "Entries: ", mf.entries.len
echo "Size: ", formatSize(totalSize(mf))
echo "--"
echo ""
for entry in mf.entries:
let resolved = entry.resref.resolve()
let rystr = if resolved.isSome:
resolved.unsafeGet().resExt
else:
$entry.resref.resType.int
echo entry.sha1,
" ",
align($entry.size, 15),
" ",
align(rystr, 7),
" ",
escape(entry.resref.resref, "", "")
if doVerify:
let pa = pathForEntry(mf, $ARGS["<manifest>"] / ".." / "..", entry.sha1, false)
let fs = openFileStream(pa, fmRead)
defer: fs.close()
if entry.sha1 != toLowerAscii $secureHash(decompress(fs, makeMagic("NSYC"))):
raise newException(ValueError, "File checksum mismatch: " & pa)