forked from Edru2/DeMuddler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (48 loc) · 1.23 KB
/
main.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
package main
import (
"archive/zip"
"flag"
"fmt"
"os"
"path/filepath"
"strings"
)
func containsIllegalCharacters(filename string) bool {
illegalCharacters := []rune{'<', '>', ':', '"', '/', '\\', '|', '?', '*'}
result := strings.ContainsAny(filename, string(illegalCharacters))
if result {
fmt.Printf("warn: file %s contains illegal characters, consider changing its name.\n", filename)
}
return result
}
func main() {
filePath := flag.String("f", "", "Path to the file")
flag.Parse()
if *filePath == "" {
fmt.Println("You must specify a file path using the -f flag.")
os.Exit(1)
}
r, err := zip.OpenReader(*filePath)
if err != nil {
panic(err)
}
defer r.Close()
workDir, err := os.Getwd()
if err != nil {
panic(err)
}
fileNameWithExtension := filepath.Base(*filePath)
fileName := strings.TrimSuffix(fileNameWithExtension, filepath.Ext(fileNameWithExtension))
baseDir := filepath.Join(workDir, fileName, "src")
for _, f := range r.File {
if strings.HasSuffix(strings.ToLower(f.Name), ".xml") {
handleXML(f, baseDir)
continue
}
if strings.EqualFold(f.Name, "config.lua") {
handleConfig(f, filepath.Join(workDir, fileName))
continue
}
handleResources(f, filepath.Join(baseDir, "resources"))
}
}