feat: 使用用户目录下.jnotepad作为默认配置目录
This commit is contained in:
parent
f950b42450
commit
017156b0eb
@ -3,12 +3,14 @@ package org.jcnc.jnotepad.app.config;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.scene.input.KeyCombination;
|
||||
import org.jcnc.jnotepad.app.entity.ShortcutKey;
|
||||
import org.jcnc.jnotepad.init.Config;
|
||||
import org.jcnc.jnotepad.tool.LogUtil;
|
||||
import org.jcnc.jnotepad.tool.PopUpUtil;
|
||||
import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -51,7 +53,8 @@ public abstract class LoadJnotepadConfig {
|
||||
// 动态添加快捷键
|
||||
menuItem.setAccelerator(KeyCombination.keyCombination(shortKeyValue));
|
||||
}
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(CONFIG_NAME))) {
|
||||
String jsonConfigPath= Paths.get(new Config().getAppConfigDir(), CONFIG_NAME).toString();
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(jsonConfigPath))) {
|
||||
writer.write(JNOTEPAD_CONFIG);
|
||||
} catch (IOException e) {
|
||||
PopUpUtil.errorAlert("错误", "读写错误", "配置文件读写错误!");
|
||||
|
||||
@ -5,6 +5,7 @@ import org.slf4j.Logger;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.jcnc.jnotepad.constants.AppConstants.CH_LANGUAGE_PACK_NAME;
|
||||
@ -20,8 +21,17 @@ public class Config {
|
||||
|
||||
private String languagePackName;
|
||||
|
||||
private String appConfigDir;
|
||||
Logger logger = LogUtil.getLogger(this.getClass());
|
||||
|
||||
public Config() {
|
||||
appConfigDir = System.getProperty("user.home") + File.separator + ".jnotepad";
|
||||
boolean isConfigDirReady = Paths.get(appConfigDir).toFile().mkdirs();
|
||||
if (!isConfigDirReady) {
|
||||
appConfigDir = "/tmp";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从文件中读取属性配置。
|
||||
*
|
||||
@ -51,7 +61,8 @@ public class Config {
|
||||
|
||||
Properties enLanguagePack = getEnglishLanguagePack();
|
||||
|
||||
try (OutputStream outputStream = new FileOutputStream(CH_LANGUAGE_PACK_NAME)) {
|
||||
String chineseFilePath = Paths.get(appConfigDir, CH_LANGUAGE_PACK_NAME).toString();
|
||||
try (OutputStream outputStream = new FileOutputStream(chineseFilePath)) {
|
||||
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8); // 使用 UTF-8 编码
|
||||
chLanguagePack.store(writer, JNOTEPAD_CH_LANGUAGE_PACK_NAME);
|
||||
|
||||
@ -59,7 +70,8 @@ public class Config {
|
||||
logger.info("未检测到中文语言包!");
|
||||
}
|
||||
|
||||
try (OutputStream outputStream = new FileOutputStream(EN_LANGUAGE_PACK_NAME)) {
|
||||
String enFilePath = Paths.get(appConfigDir, EN_LANGUAGE_PACK_NAME).toString();
|
||||
try (OutputStream outputStream = new FileOutputStream(enFilePath)) {
|
||||
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8); // 使用 UTF-8 编码
|
||||
enLanguagePack.store(writer, JNOTEPAD_EN_LANGUAGE_PACK_NAME);
|
||||
|
||||
@ -114,4 +126,7 @@ public class Config {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public String getAppConfigDir() {
|
||||
return appConfigDir;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user