diff --git a/pom.xml b/pom.xml index ff2d73c..54e5266 100644 --- a/pom.xml +++ b/pom.xml @@ -1,8 +1,9 @@ - + 4.0.0 pw.yumc MiaoScript - 0.9.1 + 0.9.3 502647092 @@ -53,6 +54,7 @@ DEV + §620-09-21 §afeat: 完善 upgrade 逻辑; §620-08-27 §afeat: 新增ProtocolLib依赖; §620-07-28 §afeat: 新增框架升级功能; §620-06-23 §afeat: 支持自定义参数; diff --git a/src/main/java/pw/yumc/MiaoScript/Base.java b/src/main/java/pw/yumc/MiaoScript/Base.java index cff4006..b17019d 100644 --- a/src/main/java/pw/yumc/MiaoScript/Base.java +++ b/src/main/java/pw/yumc/MiaoScript/Base.java @@ -2,9 +2,9 @@ package pw.yumc.MiaoScript; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.util.stream.Collectors; /** * Created with IntelliJ IDEA @@ -32,27 +32,51 @@ public class Base { } public String read(String path) throws IOException { - return new String(Files.readAllBytes(new File(path).toPath()), "UTF-8"); + return new String(Files.readAllBytes(new File(path).toPath()), StandardCharsets.UTF_8); } public void save(String path, String content) throws IOException { File file = new File(path); file.getParentFile().mkdirs(); - Files.write(file.toPath(), content.getBytes("UTF-8")); + Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8)); } - public void delete(String path) throws IOException { - delete(new File(path).toPath()); + public boolean move(String source, String target) { + File file = new File(source); + return file.renameTo(new File(target)); + } + + public boolean delete(String path) throws IOException { + return delete(new File(path)); } public void delete(Path path) throws IOException { - File file = path.toFile(); - if (!file.exists()) { return; } - if (file.isDirectory()) { - for (Path f : Files.list(file.toPath()).collect(Collectors.toList())) { - delete(f); + delete(path.toFile()); + } + + public boolean delete(File file) throws IOException { + if (!file.exists()) { + return false; + } + if (file.isFile()) { + return file.delete(); + } + File[] files = file.listFiles(); + if (files != null) { + for (File f : files) { + if (f.isFile()) { + if (!f.delete()) { + f.deleteOnExit(); + } + } else { + this.delete(f.getAbsolutePath()); + } } } - Files.delete(path); + boolean result = file.delete(); + if (!result) { + file.deleteOnExit(); + } + return result; } } diff --git a/src/main/resources/bios.js b/src/main/resources/bios.js index 76bce52..c63db67 100644 --- a/src/main/resources/bios.js +++ b/src/main/resources/bios.js @@ -5,6 +5,18 @@ var global = this; */ (function () { var loader; + global.engineDisable = function () { + global.engineDisableImpl && global.engineDisableImpl() + if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "old_node_modules"))) { + logger.info('Found old_node_modules folder delete...'); + base.delete(java.nio.file.Paths.get(root, "old_node_modules")) + } + if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "upgrade"))) { + logger.info('Found upgrade file delete node_modules...'); + base.delete(java.nio.file.Paths.get(root, "node_modules")) + base.delete(java.nio.file.Paths.get(root, "upgrade")) + } + }; global.boot = function (root, logger) { global.scope = java.lang.System.getenv("MS_NODE_CORE_SCOPE") || "@ccms"; global.log = logger; @@ -24,16 +36,22 @@ var global = this; } if (java.nio.file.Files.exists(java.nio.file.Paths.get(root, "upgrade"))) { logger.info('Found upgrade file starting upgrade...'); - base.delete(java.nio.file.Paths.get(root, "node_modules")) + base.move(java.nio.file.Paths.get(root, "node_modules"), java.nio.file.Paths.get(root, "old_node_modules")) base.delete(java.nio.file.Paths.get(root, "upgrade")) } + new java.lang.Thread(function () { + try { + base.delete(java.nio.file.Paths.get(root, "old_node_modules")) + } catch (ex) { + } + }, "MiaoScript node_modules clean thread").start() // Check Class Loader, Sometimes Server will can't found plugin.yml file loader = checkClassLoader(); // Async Loading MiaoScript Engine new java.lang.Thread(function () { java.lang.Thread.currentThread().contextClassLoader = loader; load(java.lang.System.getenv("MS_NODE_CORE_PLOYFILL") || 'classpath:core/ployfill.js')(root, logger); - global.engineDisable = require(java.lang.System.getenv("MS_NODE_CORE_MODULE") || global.scope + '/core').default || function () { + global.engineDisableImpl = require(java.lang.System.getenv("MS_NODE_CORE_MODULE") || global.scope + '/core').default || function () { logger.info('Error: abnormal Initialization MiaoScript Engine. Skip disable step...') }; }, "MiaoScript thread").start()