-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
132 lines (116 loc) · 3.58 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
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
package main
import (
"flag"
"fmt"
"path/filepath"
"strings"
"MagesTools/script"
"MagesTools/script/format"
"MagesTools/script/utils"
"github.com/go-restruct/restruct"
)
func main() {
fmt.Print(`MagesTools
Version: 0.2.3_2024.06.05
Author: WéΤοr ([email protected])
Github: https://github.com/wetor/MagesTools
License: GPL-3.0
`)
var pType, pSource, pInput, pOutput, pScriptFormat, pCharset, pTbl string
var pImport, pExport, pSkipChar bool
var pDebug int
flag.StringVar(&pType, "type", "", `[required] Source file type.
Mages Script: "script"
Supported MES(msb), SC3(scx)
Diff Binary File: "diff"
Diff input and output file
`)
flag.BoolVar(&pExport, "export", false, "[optional] Export mode. Support folder export")
flag.BoolVar(&pImport, "import", false, "[optional] Import mode")
flag.IntVar(&pDebug, "debug", 0, `[optional] Debug level
0: Disable debug mode
1: Show info message
2: Show warning message (For example, the character table is missing characters)
3: Not implemented`)
flag.StringVar(&pSource, "source", "", `[required] Source files or folder`)
flag.StringVar(&pInput, "input", "", `[optional] Usually the import mode requires`)
flag.StringVar(&pOutput, "output", "", `[required] Output file or folder`)
flag.StringVar(&pScriptFormat, "format", "Npcs", `[script.required] Format of script export and import. Case insensitive
NPCSManager format: "Npcs"
NPCSManager Plus format: "NpcsP"`)
flag.StringVar(&pCharset, "charset", "", `[script.optional] Character set containing only text. Must be utf8 encoding. Choose between "charset" and "tbl"`)
flag.StringVar(&pTbl, "tbl", "", `[script.optional] Text in TBL format. Must be utf8 encoding. Choose between "charset" and "tbl"`)
flag.BoolVar(&pSkipChar, "skip", true, "[script.optional] Skip repeated characters in the character table.")
flag.Parse()
restruct.EnableExprBeta()
if pDebug >= 2 {
utils.ShowWarning = true
}
switch pType {
case "diff":
if len(pInput) == 0 && len(pOutput) == 0 {
panic("Diff需要input和output")
}
res := utils.FileSameCheck(pInput, pOutput)
if res {
fmt.Println("两文件完全相同")
}
case "script":
if !pExport && !pImport {
panic("必须指定export模式或import模式")
}
if len(pSource) == 0 {
panic("必须指定source源文件或文件夹")
}
var _format format.Format
switch strings.ToUpper(pScriptFormat) {
case "NPCS":
_format = &format.Npcs{}
case "NPCSP":
_format = &format.NpcsP{}
default:
panic("未知脚本导出格式")
}
scr := &script.Script{}
if len(pCharset) > 0 {
scr.LoadCharset(pCharset, false, pSkipChar)
} else if len(pTbl) > 0 {
scr.LoadCharset(pTbl, true, pSkipChar)
} else {
panic("必须指定charset文件或tbl文件")
}
if pExport {
if utils.IsDir(pSource) && utils.IsDir(pOutput) {
files, _ := utils.GetDirFileList(pSource)
for _, file := range files {
if pDebug >= 1 {
fmt.Println(file)
}
scr.Open(file, _format)
scr.Read()
// 导出
scr.SaveStrings(filepath.Join(pOutput, filepath.Base(file)+".txt"))
}
} else if utils.IsFile(pSource) && utils.IsFile(pOutput) {
scr.Open(pSource, _format)
scr.Read()
scr.SaveStrings(pOutput)
} else {
panic("source和output必须同为文件,或同为文件夹")
}
} else if pImport {
scr.Open(pSource, _format)
scr.Read()
if len(pInput) > 0 {
scr.LoadStrings(pInput)
} else {
panic("必须指定input文件")
}
if len(pOutput) > 0 {
scr.Write(pOutput)
} else {
panic("必须指定output文件")
}
}
}
}