-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreator.go
More file actions
91 lines (72 loc) · 1.76 KB
/
creator.go
File metadata and controls
91 lines (72 loc) · 1.76 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
90
91
package main
import (
"bufio"
"flag"
"fmt"
"os"
"strconv"
)
// Creates a workshop.lua file with commands to download the workshop collection
func main() {
apiKey := ""
collectionId := 0
out := ""
flag.StringVar(&apiKey, "api-key", "", "Your steam api key")
flag.IntVar(&collectionId, "collection", 0, "The workshop collection id")
flag.StringVar(&out, "output", "", "Where the file should be stored")
flag.Parse()
if apiKey == "" {
fmt.Println("Invalid api key")
return
}
if collectionId <= 0 {
fmt.Println("Invalid collection id")
return
}
if out == "" {
fmt.Println("Invalid output file")
return
}
files, err := download(apiKey, collectionId)
if err != nil {
panic(err)
}
file, err := openLua(out)
if err != nil {
panic(err)
}
defer func() {
_ = file.Close()
}()
writer := bufio.NewWriter(file)
writeLua(writer, collectionId, files)
_ = writer.Flush()
}
func download(apiKey string, collectionId int) ([]WorkshopFile, error) {
fileIds, err := requestCollection(apiKey, collectionId)
if err != nil {
return nil, err
}
files, err := requestFileDetails(apiKey, fileIds)
if err != nil {
return nil, err
}
return files, nil
}
func writeLua(s *bufio.Writer, collectionId int, files []WorkshopFile) {
_, _ = s.WriteString(
"-- Created with workshop-lua (https://github.com/LukWebsForge/LuaWorkshopGen)\n" +
"-- List based on collection https://steamcommunity.com/sharedfiles/filedetails/?id=" + strconv.Itoa(collectionId) +
"\n" +
"\n")
for _, file := range files {
_, _ = s.WriteString("resource.AddWorkshop(\"" + strconv.Itoa(file.Id) + "\") -- " + file.Name + "\n")
}
}
func openLua(filename string) (*os.File, error) {
file, err := os.Create(filename)
if err != nil {
return nil, err
}
return file, nil
}