@@ -21,38 +21,45 @@ class ScriptManager {
2121 * 仅接受文件后缀为yml的文件或者可用的脚本文件夹才能被处理
2222 */
2323 private fun loadScript (file : File ): ProcessResult {
24+ if (file.name.contains(" " )) return ProcessResult (ProcessResultType .FAILED , " File name cannot contain spaces!" )
2425 if (file.isDirectory) {
2526 return loadFromFolderScript(file)
2627 }
2728
28- if (file.name.endsWith(" .yml" )) {
29- val scriptName = file.name.substringBeforeLast(" ." )
29+ val scriptName= if (file.name.endsWith(" .yml" ))
30+ file.name.substringBeforeLast(" ." )
31+ else
32+ return ProcessResult (ProcessResultType .OTHER , " The file does not belong to the script, skip reading!" )
3033
31- val option = ScriptOptions (file)
34+ val options = ScriptOptions (file)
35+ val script = Script (ScriptDescription .fromSection(options.config), options)
3236
37+ script.scriptFiles = mutableListOf<File >().also { files ->
38+ FastScript .instance.expansionManager.expansions.forEach { expansion ->
39+ val candidateFile = File (file.parentFile, " $scriptName .${expansion.fileSuffix} " )
40+ if (candidateFile.exists()) {
41+ files.add(candidateFile)
42+ }
43+ }
3344 }
3445
35- FastScript .instance.expansionManager.expansions.forEach { expansion ->
36-
37- // 載入脚本
38- scripts[file.name.substringBeforeLast(" ." )]
39- }
40-
46+ scripts[file.name.substringBeforeLast(" ." )] = script
47+ return ProcessResult (ProcessResultType .SUCCESS )
4148 }
4249
4350 private fun loadFromFolderScript (folder : File ): ProcessResult {
44- val optionFiles = arrayOf(" option.yml" , " ${folder.name} .yml" , " setting.yml" )
51+ val optionsFiles = arrayOf(" option.yml" , " ${folder.name} .yml" , " setting.yml" )
4552
46- val optionFile : File = optionFiles .let {
53+ val optionsFile : File = optionsFiles .let {
4754 for (fileName in it) {
4855 val file = File (fileName)
4956 if (file.exists()) return @let file
5057 }
5158
5259 return ProcessResult (ProcessResultType .FAILED , " Option file not found in ${folder.name} ." )
5360 }
54- val option = ScriptOptions (optionFile )
55- val script = Script (ScriptDescription .fromSection(option .config), option )
61+ val options = ScriptOptions (optionsFile )
62+ val script = Script (ScriptDescription .fromSection(options .config), options )
5663
5764 script.scriptFiles = mutableListOf<File >().also { files ->
5865 folder.listFiles()?.forEach { file ->
@@ -81,7 +88,7 @@ class ScriptManager {
8188 settings.getStringList(settings.getLowerCaseNode(" load-script-files" )).forEach {
8289 val file = File (it)
8390
84- if (file.exists()) selectScriptFiles( file) .forEach { loadScript(it) }
91+ if (file.isDirectory && file. exists()) file.listFiles()? .forEach { loadScript(it) }
8592
8693 }
8794 }
@@ -91,16 +98,6 @@ class ScriptManager {
9198 (section.isString(section.getLowerCaseNode(" version" )) || section.isInt(section.getLowerCaseNode(" version" ))) &&
9299 section.isString(section.getLowerCaseNode(" main" ))
93100
94- fun selectScriptFiles (file : File ): MutableList <File > = mutableListOf<File >().let { files ->
95- if (file.isDirectory) {
96- file.listFiles()?.forEach {
97- files.addAll(selectScriptFiles(it))
98- }
99- } else if (file.name.endsWith(" .yml" , true )) {
100- files.add(file)
101- }
102- files
103- }
104101
105102
106103
0 commit comments