diff options
| author | zhanghongqing <[email protected]> | 2022-08-09 16:54:16 +0800 |
|---|---|---|
| committer | zhanghongqing <[email protected]> | 2022-08-09 16:54:16 +0800 |
| commit | b3fa11d4b1b5a68d7b04fde5eb6cfbda557927eb (patch) | |
| tree | a49d344e49fc427fbf4cf00aa4963c4d04cd98a4 /src/main/java/com/mesasoft/cn/config/SettingConfig.java | |
| parent | d8a2be0d094ac9ba2d47c81ebf03b3fe6e34a078 (diff) | |
Diffstat (limited to 'src/main/java/com/mesasoft/cn/config/SettingConfig.java')
| -rw-r--r-- | src/main/java/com/mesasoft/cn/config/SettingConfig.java | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/main/java/com/mesasoft/cn/config/SettingConfig.java b/src/main/java/com/mesasoft/cn/config/SettingConfig.java new file mode 100644 index 0000000..a78197a --- /dev/null +++ b/src/main/java/com/mesasoft/cn/config/SettingConfig.java @@ -0,0 +1,100 @@ +package com.mesasoft.cn.config; + +import com.mesasoft.cn.SketchApplication; +import com.mesasoft.cn.modules.constant.ConfigConsts; +import com.mesasoft.cn.util.CommonUtils; +import com.zhazhapan.modules.constant.ValueConsts; +import com.zhazhapan.util.Checker; +import com.zhazhapan.util.FileExecutor; +import com.zhazhapan.util.Formatter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; + +/** + * @author pantao + * @since 2018/1/26 + */ +public class SettingConfig { + + private static final String WINDOWS = "windows"; + + private static final String MAC = "mac"; + + private static final String LINUX = "linux"; + + private static Logger logger = LoggerFactory.getLogger(SettingConfig.class); + + private static OsName currentOS; + + static { + if (Checker.isWindows()) { + currentOS = OsName.WINDOWS; + } else if (Checker.isMacOS()) { + currentOS = OsName.MAC; + } else { + currentOS = OsName.LINUX; + } + } + + public static int[] getAuth(String jsonPath) { + int[] auth = new int[5]; + for (int i = 0; i < ConfigConsts.AUTH_OF_SETTINGS.length; i++) { + String key = jsonPath + ValueConsts.DOT_SIGN + ConfigConsts.AUTH_OF_SETTINGS[i]; + auth[i] = SketchApplication.settings.getBooleanUseEval(key) ? 1 : 0; + } + return auth; + } + + public static String getUploadStoragePath() { + String parent = getStoragePath(ConfigConsts.UPLOAD_PATH_OF_SETTING); + String formatWay = SketchApplication.settings.getStringUseEval(ConfigConsts.UPLOAD_FORM_OF_SETTING); + String childPath = ValueConsts.SEPARATOR + Formatter.datetimeToCustomString(new Date(), formatWay); + String path = parent + childPath; + if (!FileExecutor.createFolder(path)) { + path = ConfigConsts.DEFAULT_UPLOAD_PATH + childPath; + FileExecutor.createFolder(path); + } + logger.info("upload path: " + path); + return path; + } + + public static String getAvatarStoragePath() { + String path = getStoragePath(ConfigConsts.UPLOAD_PATH_OF_SETTING) + ValueConsts.SEPARATOR + "avatar"; + FileExecutor.createFolder(path); + return path; + } + + public static String getStoragePath(String path) { + path += ValueConsts.DOT_SIGN; + if (currentOS == OsName.WINDOWS) { + path += WINDOWS; + } else if (currentOS == OsName.MAC) { + path += MAC; + } else { + path += LINUX; + } + return CommonUtils.checkPath(SketchApplication.settings.getStringUseEval(path)); + } + + /** + * 当前系统名称 + */ + public enum OsName { + /** + * windows系统 + */ + WINDOWS, + + /** + * MacOS系统 + */ + MAC, + + /** + * Linux系统 + */ + LINUX + } +} |
