@@ -15,18 +15,56 @@ class ScriptManager {
1515
1616 val scripts = mutableMapOf<String , Script >()
1717
18- private val optionFiles =
19-
2018 fun getScript (name : String ) = scripts[name]
2119
22- fun loadScript (file : File ) {
23- FastScript .instance.expansionManager.expansions.forEach {
20+ /* *
21+ * 仅接受文件后缀为yml的文件或者可用的脚本文件夹才能被处理
22+ */
23+ private fun loadScript (file : File ): ProcessResult {
24+ if (file.isDirectory) {
25+ return loadFromFolderScript(file)
26+ }
27+
28+ if (file.name.endsWith(" .yml" )) {
29+ val scriptName = file.name.substringBeforeLast(" ." )
30+
31+ val option = ScriptOptions (file)
32+
33+ }
34+
35+ FastScript .instance.expansionManager.expansions.forEach { expansion ->
2436
2537 // 載入脚本
2638 scripts[file.name.substringBeforeLast(" ." )]
2739 }
2840
2941 }
42+
43+ private fun loadFromFolderScript (folder : File ): ProcessResult {
44+ val optionFiles = arrayOf(" option.yml" , " ${folder.name} .yml" , " setting.yml" )
45+
46+ val optionFile: File = optionFiles.let {
47+ for (fileName in it) {
48+ val file = File (fileName)
49+ if (file.exists()) return @let file
50+ }
51+
52+ return ProcessResult (ProcessResultType .FAILED , " Option file not found in ${folder.name} ." )
53+ }
54+ val option = ScriptOptions (optionFile)
55+ val script = Script (ScriptDescription .fromSection(option.config), option)
56+
57+ script.scriptFiles = mutableListOf<File >().also { files ->
58+ folder.listFiles()?.forEach { file ->
59+ script.scriptProcessor.forEach {
60+ if (file.endsWith(it.value.expansion.fileSuffix)) files.add(file)
61+ }
62+ }
63+ }
64+ scripts[folder.name] = script
65+
66+ return ProcessResult (ProcessResultType .SUCCESS )
67+ }
3068 // {
3169 // scripts.add(CustomScript(file))
3270 // }
@@ -37,8 +75,8 @@ class ScriptManager {
3775 @Synchronized
3876 fun loadScripts () {
3977 scripts.clear()
40- defaultScriptPath .mkdirs()
41- defaultScriptPath .listFiles()?.forEach { loadScript(it) }
78+ folders[ 0 ] .mkdirs()
79+ folders[ 0 ] .listFiles()?.forEach { loadScript(it) }
4280
4381 settings.getStringList(settings.getLowerCaseNode(" load-script-files" )).forEach {
4482 val file = File (it)
@@ -65,29 +103,6 @@ class ScriptManager {
65103 }
66104
67105
68- fun loadFromFolderScript (folder : File ): ProcessResult {
69- val optionFile: File = arrayOf(
70- " option.yml" ,
71- " ${folder.name} .yml" ,
72- " setting.yml"
73- ).let {
74- for (fileName in it) {
75- val file = File (fileName)
76- if (file.exists()) return @let file
77- }
78-
79- return ProcessResult (ProcessResultType .FAILED , " Option file not found in ${folder.name} ." )
80- }
81- val option = ScriptOptions (optionFile)
82- val script = Script (ScriptDescription .fromSection(option.config), option)
83-
84-
85- val scriptFiles = mutableListOf<File >().also {
86-
87- }
88-
89-
90- }
91106
92107
93108}
0 commit comments