mirror of
https://github.com/Geniusay/ChopperBot.git
synced 2026-05-23 12:49:42 +08:00
修复BUG #00005
This commit is contained in:
@@ -14,7 +14,7 @@ import java.util.List;
|
||||
public class FileCacheManagerInstance {
|
||||
|
||||
//获取全局的一个fileCaches
|
||||
private static List<FileCache> fileCaches = GlobalFileCache.fileCaches;
|
||||
private static List<FileCache> fileCaches = List.of(GlobalFileCache.ModuleSrcConfigFile);
|
||||
private static volatile FileCacheManager Instance;
|
||||
|
||||
public static FileCacheManager getInstance(){
|
||||
|
||||
@@ -16,16 +16,10 @@ import java.util.List;
|
||||
*/
|
||||
public class GlobalFileCache {
|
||||
|
||||
public static FileCache ModuleSrcConfigFile;
|
||||
|
||||
static {
|
||||
try {
|
||||
ModuleSrcConfigFile = new FileCache(new ModuleSrcConfigFile());
|
||||
} catch (FileCacheException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
public GlobalFileCache() {
|
||||
}
|
||||
|
||||
public static List<FileCache> fileCaches
|
||||
= List.of(ModuleSrcConfigFile);
|
||||
public static FileCache ModuleSrcConfigFile;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ public class FileModuleInitMachine extends ModuleInitMachine{
|
||||
|
||||
public FileModuleInitMachine() {
|
||||
super(List.of(
|
||||
new ModuleSrcConfigFileInitMachine(),
|
||||
new FileCacheManagerInitMachine()
|
||||
), ConstPool.FILE, ChopperLogFactory.getLogger(LoggerType.File));
|
||||
}
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
package org.example.init;
|
||||
|
||||
import org.example.constpool.PluginName;
|
||||
import org.example.log.ChopperLogFactory;
|
||||
import org.example.log.LoggerType;
|
||||
import org.example.pojo.configfile.ModuleSrcConfigFile;
|
||||
import org.example.util.FileUtil;
|
||||
import org.example.util.JsonFileUtil;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Genius
|
||||
* @date 2023/04/20 18:34
|
||||
**/
|
||||
|
||||
public class ModuleSrcConfigFileInitMachine extends CommonInitMachine {
|
||||
|
||||
ModuleSrcConfigFile moduleSrcConfigFile;
|
||||
|
||||
public ModuleSrcConfigFileInitMachine() {
|
||||
super( ChopperLogFactory.getLogger(LoggerType.File),
|
||||
PluginName.MODULE_CONFIG_PLUGIN);
|
||||
moduleSrcConfigFile = new ModuleSrcConfigFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean init() {
|
||||
Path dir = Paths.get(moduleSrcConfigFile.getFilePath());
|
||||
if (!createConfigDirectory(dir)) {
|
||||
return fail("创建Config目录失败");
|
||||
}
|
||||
if (!createConfigFile(dir)) {
|
||||
return fail("创建Config文件失败");
|
||||
}
|
||||
if (!createModuleDirectory()) {
|
||||
return fail("创建模块文件夹失败");
|
||||
}
|
||||
return success();
|
||||
}
|
||||
|
||||
private boolean createConfigDirectory(Path dir) {
|
||||
try {
|
||||
if (!Files.exists(dir)) {
|
||||
Files.createDirectory(dir);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean createConfigFile(Path dir) {
|
||||
Path path = Paths.get(dir.toString(), moduleSrcConfigFile.getFileName());
|
||||
try {
|
||||
if (!Files.exists(path)) {
|
||||
JsonFileUtil.writeJsonFile(path.toString(),moduleSrcConfigFile.packageConfig());
|
||||
}
|
||||
}catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean createModuleDirectory() {
|
||||
|
||||
Map<String, ModuleSrcConfigFile.SRC> moduleSrcConfigFileMap
|
||||
= (Map<String, ModuleSrcConfigFile.SRC>) moduleSrcConfigFile.packageConfig().get("data");
|
||||
|
||||
for (Map.Entry<String, ModuleSrcConfigFile.SRC> stringModuleConfigSrcEntry : moduleSrcConfigFileMap.entrySet()) {
|
||||
|
||||
ModuleSrcConfigFile.SRC src = stringModuleConfigSrcEntry.getValue();
|
||||
try {
|
||||
if (!FileUtil.isFileExist(src.getSrc())) {
|
||||
Files.createDirectory(Path.of(src.getSrc()));
|
||||
}
|
||||
}catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import org.example.bean.ConfigFile;
|
||||
import org.example.bean.FileType;
|
||||
import org.example.constpool.ConstPool;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -12,44 +13,29 @@ import java.util.Map;
|
||||
**/
|
||||
|
||||
|
||||
public class ModuleSrcConfigFile extends ConfigFile<Map<String, ModuleSrcConfigFile.SRC>> {
|
||||
|
||||
private static Map<String, SRC> config;
|
||||
|
||||
public static class SRC{
|
||||
private String src;
|
||||
public SRC(String src) {
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
public String getSrc() {
|
||||
return src;
|
||||
}
|
||||
|
||||
public void setSrc(String src){this.src =src;}
|
||||
}
|
||||
|
||||
static{
|
||||
config = Map.of(
|
||||
ConstPool.ACCOUNT, new SRC("./config/"+ConstPool.ACCOUNT),
|
||||
ConstPool.SECTION, new SRC("./config/"+ConstPool.SECTION),
|
||||
ConstPool.BARRAGE, new SRC("./config/"+ConstPool.BARRAGE),
|
||||
ConstPool.CREEPER, new SRC("./config/"+ConstPool.CREEPER),
|
||||
ConstPool.SECTION_WORK, new SRC("./config/"+ConstPool.SECTION_WORK),
|
||||
ConstPool.HOT, new SRC("./config/"+ConstPool.HOT),
|
||||
ConstPool.PUBLISH, new SRC("./config/"+ConstPool.PUBLISH)
|
||||
);
|
||||
}
|
||||
public class ModuleSrcConfigFile extends ConfigFile<Map<String, Object>> {
|
||||
|
||||
private static final String filePath = "./config/";
|
||||
|
||||
private static final String fileName = "chopperBotConfig.json";
|
||||
public ModuleSrcConfigFile() {
|
||||
super("./config/"
|
||||
, "moduleConfig.json"
|
||||
, config, FileType.CHOPPER_BOT);
|
||||
super( filePath, fileName,
|
||||
Map.of("src",Map.of( ConstPool.ACCOUNT, "./config/"+ConstPool.ACCOUNT,
|
||||
ConstPool.SECTION, "./config/"+ConstPool.SECTION,
|
||||
ConstPool.BARRAGE, "./config/"+ConstPool.BARRAGE,
|
||||
ConstPool.CREEPER, "./config/"+ConstPool.CREEPER,
|
||||
ConstPool.SECTION_WORK, "./config/"+ConstPool.SECTION_WORK,
|
||||
ConstPool.HOT, "./config/"+ConstPool.HOT,
|
||||
ConstPool.PUBLISH, "./config/"+ConstPool.PUBLISH)),
|
||||
FileType.CHOPPER_BOT);
|
||||
}
|
||||
|
||||
public Map<String,Object> packageConfig() {
|
||||
return super.packageConfig();
|
||||
}
|
||||
|
||||
public static final String getFullPath(){
|
||||
return Paths.get(filePath,fileName).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user