summaryrefslogtreecommitdiff
path: root/src/main/java/com/mesasoft/cn/config/SettingConfig.java
blob: a78197af3b9b442c48bbf49151fae7d122eed900 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
    }
}