-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate.go
More file actions
207 lines (181 loc) · 5.43 KB
/
generate.go
File metadata and controls
207 lines (181 loc) · 5.43 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package main
import (
"bufio"
_ "embed"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
)
//go:embed embed/peachrec.cfg
var peachRecCfg string
//go:embed embed/hudanimations_manifest.txt
var hudAnimationsManifest string
func generateManifest(manifest string, peachRecManifest []string) {
// Update existing manifest to include PeachREC
file, err := os.Create(manifest)
if err != nil {
fmt.Println("Error generating hudanimations_manifest.txt:", err)
pressToExit()
}
defer file.Close()
// Write peachRecManifest over hudanimations_manifest.txt
for _, line := range peachRecManifest {
_, err = file.WriteString(line + "\n")
if err != nil {
fmt.Println("Error writing hudanimations_manifest.txt:", err)
pressToExit()
}
}
fmt.Println("Added PeachREC to hudanimation_manifest.txt")
}
func generateDefaultManifest(workingDir string) {
// Check that _PeachREC directory exists
filePath := filepath.Join(workingDir, modName)
_, err := os.Stat(filePath)
if errors.Is(err, os.ErrNotExist) { // If _PeachREC does not exist, create one
err = os.Mkdir(filePath, os.ModePerm)
if err != nil {
fmt.Println("Error creating", modName, "directory:", err)
pressToExit()
}
}
// Check that _PeachREC/scripts directory exists
filePath = filepath.Join(filePath, "scripts")
_, er := os.Stat(filePath)
if errors.Is(er, os.ErrNotExist) { // If scripts does not exist, create one
err = os.Mkdir(filePath, os.ModePerm)
if err != nil {
fmt.Println("Error creating", modName+"/scripts directory:", err)
pressToExit()
}
}
// Generate hudanimations_manifest using default code
fileName := filepath.Join(filePath, "hudanimations_manifest.txt")
file, err := os.Create(fileName)
if err != nil {
fmt.Println("Error generating hudanimations_manifest.txt with default code:", err)
pressToExit()
}
defer file.Close()
// Write hudanimations_manifest.txt default code
_, err = file.WriteString(hudAnimationsManifest)
if err != nil {
fmt.Println("Error writing hudanimations_manifest.txt with default code:", err)
pressToExit()
}
fmt.Println("Created", modName+"/scripts/hudanimations_manifest.txt")
}
func generateAnimations(workingDir string, peachRecAnimations []string) {
// Generate hudanimations_peachrec.txt
filePath := filepath.Join(workingDir, modName)
_, err := os.Stat(filePath)
if errors.Is(err, os.ErrNotExist) { // If _PeachREC does not exist, create one
err = os.Mkdir(filePath, os.ModePerm)
if err != nil {
fmt.Println("Error creating", modName, "directory:", err)
pressToExit()
}
}
file, err := os.Create(filepath.Join(filePath, "hudanimations_peachrec.txt"))
if err != nil {
fmt.Println("Error generating hudanimations_peachrec.txt:", err)
pressToExit()
}
defer file.Close()
// Write peachRecAnimations to hudanimations_peachrec.txt
for _, line := range peachRecAnimations {
_, err = file.WriteString(line + "\n")
if err != nil {
fmt.Println("Error writing hudanimations_peachrec.txt:", err)
pressToExit()
}
}
fmt.Println("Created", modName+"/hudanimations_peachrec.txt")
}
func generateConfig(workingDir string) {
// Check that _PeachREC directory exists
filePath := filepath.Join(workingDir, modName)
_, err := os.Stat(filePath)
if errors.Is(err, os.ErrNotExist) { // If _PeachREC does not exist, create one
err = os.Mkdir(filePath, os.ModePerm)
if err != nil {
fmt.Println("Error creating", modName, "directory:", err)
pressToExit()
}
}
// Check that _PeachREC/cfg directory exists
filePath = filepath.Join(filePath, "cfg")
_, er := os.Stat(filePath)
if errors.Is(er, os.ErrNotExist) { // If cfg does not exist, create one
err = os.Mkdir(filePath, os.ModePerm)
if err != nil {
fmt.Println("Error creating", modName+"/cfg directory:", err)
pressToExit()
}
}
// Generate cfg/peachrec.cfg
fileName := filepath.Join(filePath, "peachrec.cfg")
file, err := os.Create(fileName)
if err != nil {
fmt.Println("Error generating peachrec.cfg:", err)
pressToExit()
}
defer file.Close()
// Write peachrec.cfg
_, err = file.WriteString(peachRecCfg)
if err != nil {
fmt.Println("Error writing peachrec.cfg:", err)
pressToExit()
}
fmt.Println("Created", modName+"/cfg/peachrec.cfg")
}
func generateAutoexec(file string) {
// Check that tf/cfg/autoexec exists
input, err := os.Open(file)
if errors.Is(err, os.ErrNotExist) {
// Check that tf/cfg exists
_, err = os.Stat(filepath.Dir(file))
if errors.Is(err, os.ErrNotExist) { // If cfg does not exist, create it
err = os.Mkdir(filepath.Dir(file), os.ModePerm)
if err != nil {
fmt.Println("Error creating autoexec directory:", err)
pressToExit()
}
}
} else if err != nil {
fmt.Printf("Error opening %v to add PeachREC to autoexec: %v\n", file, err)
pressToExit()
}
// Copy contents
var contents []string
scnr := bufio.NewScanner(input)
for scnr.Scan() {
line := scnr.Text()
if !strings.Contains(line, "exec peachrec") {
contents = append(contents, line)
}
}
// Rewrite contents to file
output, err := os.Create(file)
if err != nil {
fmt.Println("Error generating autoexec:", err)
pressToExit()
}
defer output.Close()
for _, line := range contents {
_, err = output.WriteString(line + "\n")
if err != nil {
fmt.Println("Error writing autoexec:", err)
pressToExit()
}
}
// Insert PeachREC exec
_, err = output.WriteString("exec peachrec")
if err != nil {
fmt.Println("Error writing PeachREC to autoexec:", err)
pressToExit()
}
fmt.Println("Added PeachREC to autoexec.cfg")
}