This repository has been archived by the owner on May 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathextract.go
99 lines (84 loc) · 1.83 KB
/
extract.go
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
90
91
92
93
94
95
96
97
98
99
package main
import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"regexp"
"strings"
"github.com/Nightgunner5/vpk"
"github.com/davecgh/go-spew/spew"
)
var versionFlag = flag.Bool("v", false, "get version from ~/Steam")
func main() {
flag.Parse()
if *versionFlag {
getVersion()
return
}
if len(os.Args) < 3 {
fmt.Println("Usage:", os.Args[0], "filename.vpk", "target_directory")
return
}
MAIN_FILE := os.Args[1]
TARGET := os.Args[2]
ignoreExt := map[string]bool{}
ignorePath := []string{}
if len(os.Args) > 3 {
for _, arg := range os.Args[3:] {
if strings.HasPrefix(arg, ".") {
ignoreExt[arg] = true
} else {
ignorePath = append(ignorePath, arg)
}
}
}
f, err := os.Open(MAIN_FILE)
eh(err)
defer f.Close()
vpkFile, err := vpk.ReadVPKFile(f)
eh(err)
for _, filename := range vpkFile.ListFiles() {
if ignoreExt[path.Ext(filename)] {
continue
}
ignore := false
for _, path := range ignorePath {
if strings.HasPrefix(filename, path) {
ignore = true
break
}
}
if ignore {
continue
}
dir := path.Dir(TARGET + "/" + filename)
eh(os.MkdirAll(dir, 0777))
data, err := vpkFile.GetReader(vpkFile.GetFileInfo(filename), MAIN_FILE)
fd, err := os.Create(path.Join(dir, path.Base(filename)))
eh(err)
io.Copy(fd, data)
eh(fd.Close())
eh(data.Close())
}
}
func eh(err error) {
if err != nil {
panic(err)
}
}
var infMatch = regexp.MustCompile(`(?m)^([^=]+)=(\S+)\s*`)
func getVersion() {
home := os.Getenv("HOME")
inf, err := ioutil.ReadFile(home + "/Steam/steamapps/common/dota 2 beta/dota/steam.inf")
if err != nil {
panic(err)
}
steamInf := map[string]string{}
for _, match := range infMatch.FindAllStringSubmatch(string(inf), -1) {
steamInf[match[1]] = match[2]
}
spew.Printf("Client %s Patch %s\n", steamInf["ClientVersion"], steamInf["PatchVersion"])
}