feat: 固定使用user.home/.jnotepad作为输出目录
This commit is contained in:
parent
017156b0eb
commit
8c533b7a6f
@ -10,6 +10,7 @@ import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -28,15 +29,18 @@ public abstract class LoadJnotepadConfig {
|
|||||||
Logger logger = LogUtil.getLogger(this.getClass());
|
Logger logger = LogUtil.getLogger(this.getClass());
|
||||||
|
|
||||||
public final void load() {
|
public final void load() {
|
||||||
|
String path = getConfigPath();
|
||||||
|
if (!Files.exists(Paths.get(path))) {
|
||||||
|
// 不存在则创建
|
||||||
|
createConfig();
|
||||||
|
}
|
||||||
// 判断是否存在这个配置文件
|
// 判断是否存在这个配置文件
|
||||||
try (InputStream inputStream = new FileInputStream(CONFIG_NAME)) {
|
try (InputStream inputStream = new FileInputStream(getConfigPath())) {
|
||||||
logger.info("正在加载配置文件...");
|
logger.info("正在加载配置文件...");
|
||||||
// 存在则加载
|
// 存在则加载
|
||||||
loadConfig(inputStream);
|
loadConfig(inputStream);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.info("未检测到配置文件!");
|
logger.info("未检测到配置文件!");
|
||||||
// 不存在则创建
|
|
||||||
createConfig();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +57,7 @@ public abstract class LoadJnotepadConfig {
|
|||||||
// 动态添加快捷键
|
// 动态添加快捷键
|
||||||
menuItem.setAccelerator(KeyCombination.keyCombination(shortKeyValue));
|
menuItem.setAccelerator(KeyCombination.keyCombination(shortKeyValue));
|
||||||
}
|
}
|
||||||
String jsonConfigPath= Paths.get(new Config().getAppConfigDir(), CONFIG_NAME).toString();
|
String jsonConfigPath = getConfigPath();
|
||||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(jsonConfigPath))) {
|
try (BufferedWriter writer = new BufferedWriter(new FileWriter(jsonConfigPath))) {
|
||||||
writer.write(JNOTEPAD_CONFIG);
|
writer.write(JNOTEPAD_CONFIG);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -61,6 +65,10 @@ public abstract class LoadJnotepadConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getConfigPath() {
|
||||||
|
return Paths.get(new Config().getAppConfigDir(), CONFIG_NAME).toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取快捷键集合
|
* 获取快捷键集合
|
||||||
*
|
*
|
||||||
|
|||||||
@ -5,6 +5,8 @@ import org.slf4j.Logger;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@ -26,8 +28,9 @@ public class Config {
|
|||||||
|
|
||||||
public Config() {
|
public Config() {
|
||||||
appConfigDir = System.getProperty("user.home") + File.separator + ".jnotepad";
|
appConfigDir = System.getProperty("user.home") + File.separator + ".jnotepad";
|
||||||
boolean isConfigDirReady = Paths.get(appConfigDir).toFile().mkdirs();
|
Path path = Paths.get(appConfigDir);
|
||||||
if (!isConfigDirReady) {
|
boolean isConfigDirReady = path.toFile().mkdirs();
|
||||||
|
if (!isConfigDirReady && !Files.exists(path)) {
|
||||||
appConfigDir = "/tmp";
|
appConfigDir = "/tmp";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -42,13 +45,19 @@ public class Config {
|
|||||||
|
|
||||||
//设置语言包
|
//设置语言包
|
||||||
languagePackName = EN_LANGUAGE_PACK_NAME;
|
languagePackName = EN_LANGUAGE_PACK_NAME;
|
||||||
try (InputStream inputStream = new FileInputStream(languagePackName)) {
|
String languageFilePath = Paths.get(appConfigDir, languagePackName).toString();
|
||||||
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); // 使用 UTF-8 编码
|
|
||||||
properties.load(reader);
|
if (!Files.exists(Paths.get(languageFilePath))) {
|
||||||
} catch (IOException e) {
|
|
||||||
// 如果读取出错,则调用初始化方法
|
// 如果读取出错,则调用初始化方法
|
||||||
initializePropertiesFile();
|
initializePropertiesFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try (InputStream inputStream = new FileInputStream(languageFilePath)) {
|
||||||
|
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); // 使用 UTF-8 编码
|
||||||
|
properties.load(reader);
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
|
||||||
|
}
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,13 +3,13 @@
|
|||||||
<!-- scanPeriod属性设置监测配置文件修改的时间间隔,默认单位为毫秒,在scan为true时才生效 -->
|
<!-- scanPeriod属性设置监测配置文件修改的时间间隔,默认单位为毫秒,在scan为true时才生效 -->
|
||||||
<!-- debug属性如果为true时,会打印出logback内部的日志信息 -->
|
<!-- debug属性如果为true时,会打印出logback内部的日志信息 -->
|
||||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||||
<!-- 定义参数常量 -->JJ
|
<!-- 定义参数常量 -->
|
||||||
<!-- 日志级别:TRACE<DEBUG<INFO<WARN<ERROR,其中常用的是DEBUG、INFO和ERROR -->
|
<!-- 日志级别:TRACE<DEBUG<INFO<WARN<ERROR,其中常用的是DEBUG、INFO和ERROR -->
|
||||||
<property name="log.level" value="debug"/>
|
<property name="log.level" value="debug"/>
|
||||||
<!-- 文件保留时间 -->
|
<!-- 文件保留时间 -->
|
||||||
<property name="log.maxHistory" value="30"/>
|
<property name="log.maxHistory" value="30"/>
|
||||||
<!-- 日志存储路径 -->
|
<!-- 日志存储路径 -->
|
||||||
<property name="log.filePath" value="logs"/>
|
<property name="log.filePath" value="${user.home}/.jnotepad/logs"/>
|
||||||
<!--打包时,请使用下方的路径-->
|
<!--打包时,请使用下方的路径-->
|
||||||
<!--<property name="log.filePath" value="../logs"/>-->
|
<!--<property name="log.filePath" value="../logs"/>-->
|
||||||
<!-- 日志的显式格式 -->
|
<!-- 日志的显式格式 -->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user