@@ -7,38 +7,48 @@ import (
77 "flag"
88 "fmt"
99 "github.com/go-restruct/restruct"
10+ "path"
1011 "strings"
1112)
1213
1314func main () {
1415
1516 var pType , pSource , pInput , pOutput , pScriptFormat , pCharset , pTbl string
1617 var pImport , pExport , pSkipChar bool
18+ var pDebug int
1719 flag .StringVar (& pType , "type" , "" , `[required] Source file type.
1820 MES(msb) Script: "script"
1921 Now only MES format scripts are supported
2022 Diff Binary File: "diff"
2123 Diff input and output file
2224` )
23- flag .BoolVar (& pExport , "export" , false , "[optional] Export mode" )
25+ flag .BoolVar (& pExport , "export" , false , "[optional] Export mode. Support folder export " )
2426 flag .BoolVar (& pImport , "import" , false , "[optional] Import mode" )
27+ flag .IntVar (& pDebug , "debug" , 0 , `[optional] Debug level
28+ 0: Disable debug mode
29+ 1: Show info message
30+ 2: Show warning message (For example, the character table is missing characters)
31+ 3: Not implemented` )
2532
26- flag .StringVar (& pSource , "source" , "" , `[required] Source file ` )
33+ flag .StringVar (& pSource , "source" , "" , `[required] Source files or folder ` )
2734
2835 flag .StringVar (& pInput , "input" , "" , `[optional] Usually the import mode requires` )
29- flag .StringVar (& pOutput , "output" , "" , `[required] Output file` )
36+ flag .StringVar (& pOutput , "output" , "" , `[required] Output file or folder ` )
3037
3138 flag .StringVar (& pScriptFormat , "format" , "Npcs" , `[script.required] Format of script export and import. Case insensitive
3239 NPCSManager format: "Npcs"
3340 NPCSManager Plus format: "NpcsP"` )
3441 flag .StringVar (& pCharset , "charset" , "" , `[script.optional] Character set containing only text. Must be utf8 encoding. Choose between "charset" and "tbl"` )
3542 flag .StringVar (& pTbl , "tbl" , "" , `[script.optional] Text in TBL format. Must be utf8 encoding. Choose between "charset" and "tbl"` )
3643
37- flag .BoolVar (& pSkipChar , "skip" , true , "[script.optional] Skip duplicate code table characters ." )
44+ flag .BoolVar (& pSkipChar , "skip" , true , "[script.optional] Skip repeated characters in the character table ." )
3845
3946 flag .Parse ()
4047 restruct .EnableExprBeta ()
4148
49+ if pDebug >= 2 {
50+ utils .ShowWarning = true
51+ }
4252 switch pType {
4353 case "diff" :
4454 if len (pInput ) == 0 && len (pOutput ) == 0 {
@@ -53,7 +63,7 @@ func main() {
5363 panic ("必须指定export模式或import模式" )
5464 }
5565 if len (pSource ) == 0 {
56- panic ("必须指定source源文件 " )
66+ panic ("必须指定source源文件或文件夹 " )
5767 }
5868
5969 var _format format.Format
@@ -65,7 +75,7 @@ func main() {
6575 default :
6676 panic ("未知脚本导出格式" )
6777 }
68- scr := script .OpenScript ( pSource , _format )
78+ scr := & script.Script {}
6979
7080 if len (pCharset ) > 0 {
7181 scr .LoadCharset (pCharset , false , pSkipChar )
@@ -74,14 +84,29 @@ func main() {
7484 } else {
7585 panic ("必须指定charset文件或tbl文件" )
7686 }
77- scr . Read ()
87+
7888 if pExport {
79- if len (pOutput ) > 0 {
89+ if utils .IsDir (pSource ) && utils .IsDir (pOutput ) {
90+ files , _ := utils .GetDirFileList (pSource )
91+ for _ , file := range files {
92+ if pDebug >= 1 {
93+ fmt .Println (file )
94+ }
95+ scr .Open (file , _format )
96+ scr .Read ()
97+ // 导出
98+ scr .SaveStrings (path .Join (pOutput , path .Base (file )+ ".txt" ))
99+ }
100+ } else if utils .IsFile (pSource ) && utils .IsFile (pOutput ) {
101+ scr .Open (pSource , _format )
102+ scr .Read ()
80103 scr .SaveStrings (pOutput )
81104 } else {
82- panic ("必须指定output文件 " )
105+ panic ("source和output必须同为文件,或同为文件夹 " )
83106 }
84107 } else if pImport {
108+ scr .Open (pSource , _format )
109+ scr .Read ()
85110 if len (pInput ) > 0 {
86111 scr .LoadStrings (pInput )
87112 } else {
0 commit comments