统一文件路径格式

main
lensfrex 3 years ago
parent b446921b42
commit fe53b334c7
Signed by: lensfrex
GPG Key ID: 947ADABD8533C476
  1. 3
      Dogename/src/main/java/me/lensferno/dogename/Main.java
  2. 5
      Dogename/src/main/java/me/lensferno/dogename/configs/ConfigLoader.java
  3. 5
      Dogename/src/main/java/me/lensferno/dogename/controllers/MainInterfaceController.java
  4. 5
      Dogename/src/main/java/me/lensferno/dogename/controllers/ProgramInfoPaneController.java
  5. 9
      Dogename/src/main/java/me/lensferno/dogename/data/Data.java
  6. 11
      Dogename/src/main/java/me/lensferno/dogename/data/History.java
  7. 9
      Dogename/src/main/java/me/lensferno/dogename/utils/FilePath.java
  8. 1
      Dogename/src/main/java/me/lensferno/dogename/voice/TokenManager.java
  9. 7
      Dogename/src/main/java/me/lensferno/dogename/voice/VoicePlayer.java

@ -9,6 +9,7 @@ import me.lensferno.dogename.configs.ConfigLoader;
import me.lensferno.dogename.controllers.MainInterfaceController; import me.lensferno.dogename.controllers.MainInterfaceController;
import me.lensferno.dogename.sayings.Gushici; import me.lensferno.dogename.sayings.Gushici;
import me.lensferno.dogename.sayings.Hitokoto; import me.lensferno.dogename.sayings.Hitokoto;
import me.lensferno.dogename.utils.FilePath;
import java.io.File; import java.io.File;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
@ -28,7 +29,7 @@ public class Main extends Application {
new File("process").mkdirs(); new File("process").mkdirs();
File tempFile = new File("process" + File.separator + pid); File tempFile = new File(FilePath.toSpecificPathForm("process/" + pid));
tempFile.createNewFile(); tempFile.createNewFile();
tempFile.deleteOnExit(); tempFile.deleteOnExit();

@ -10,6 +10,7 @@ import me.lensferno.dogename.configs.adapters.BooleanPropertyAdapter;
import me.lensferno.dogename.configs.adapters.DoublePropertyAdapter; import me.lensferno.dogename.configs.adapters.DoublePropertyAdapter;
import me.lensferno.dogename.configs.adapters.IntegerPropertyAdapter; import me.lensferno.dogename.configs.adapters.IntegerPropertyAdapter;
import me.lensferno.dogename.configs.adapters.StringPropertyAdapter; import me.lensferno.dogename.configs.adapters.StringPropertyAdapter;
import me.lensferno.dogename.utils.FilePath;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import java.io.*; import java.io.*;
@ -18,8 +19,8 @@ import java.nio.charset.StandardCharsets;
public class ConfigLoader { public class ConfigLoader {
private final String mainConfigLocation = "files" + File.separator + "Config.json"; private final String mainConfigLocation = FilePath.toSpecificPathForm("files/Config.json");
private final String voiceConfigLocation = "files" + File.separator + "VoiceConfig.json"; private final String voiceConfigLocation = FilePath.toSpecificPathForm("files/VoiceConfig.json");
//ConfigValuesBean config; //ConfigValuesBean config;
private MainConfig mainConfig; private MainConfig mainConfig;
private VoiceConfig voiceConfig; private VoiceConfig voiceConfig;

@ -22,6 +22,7 @@ import me.lensferno.dogename.data.Data;
import me.lensferno.dogename.data.History; import me.lensferno.dogename.data.History;
import me.lensferno.dogename.select.Selector; import me.lensferno.dogename.select.Selector;
import me.lensferno.dogename.utils.DialogMaker; import me.lensferno.dogename.utils.DialogMaker;
import me.lensferno.dogename.utils.FilePath;
import me.lensferno.dogename.utils.ocr.OcrTool; import me.lensferno.dogename.utils.ocr.OcrTool;
import java.io.File; import java.io.File;
@ -86,8 +87,8 @@ public final class MainInterfaceController {
} }
public void setUpConfig(ConfigLoader configLoader) { public void setUpConfig(ConfigLoader configLoader) {
mainConfig = configLoader.readConfigFromFile("files" + File.separator + "Config.json"); mainConfig = configLoader.readConfigFromFile(FilePath.toSpecificPathForm("files/Config.json"));
voiceConfig = configLoader.readVoiceConfigFromFile("files" + File.separator + "VoiceConfig.json"); voiceConfig = configLoader.readVoiceConfigFromFile(FilePath.toSpecificPathForm("files/VoiceConfig.json"));
} }
@FXML @FXML

@ -34,11 +34,6 @@ public class ProgramInfoPaneController extends VBox {
loader.setController(this); loader.setController(this);
try { try {
loader.load(); loader.load();
} catch (Exception e) {
e.printStackTrace();
}
try {
dogeView.setImage(new Image(getClass().getResourceAsStream("/images/banner.png"))); dogeView.setImage(new Image(getClass().getResourceAsStream("/images/banner.png")));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

@ -1,6 +1,7 @@
package me.lensferno.dogename.data; package me.lensferno.dogename.data;
import com.google.gson.Gson; import com.google.gson.Gson;
import me.lensferno.dogename.utils.FilePath;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -20,7 +21,7 @@ public class Data {
public Data() { public Data() {
dataFile = new File("files" + File.separator + "Namelist.data"); dataFile = new File(FilePath.toSpecificPathForm("files/Namelist.data"));
try { try {
@ -210,8 +211,8 @@ public class Data {
class IgnoreList { class IgnoreList {
private final File nameIgnoreFile = new File("files" + File.separator + "IgnoredNameList.data"); private final File nameIgnoreFile = new File(FilePath.toSpecificPathForm("files/IgnoredNameList.data"));
private final File numbIgnoreFile = new File("files" + File.separator + "IgnoredNumberList.data"); private final File numbIgnoreFile = new File(FilePath.toSpecificPathForm("files/IgnoredNumberList.data"));
private HashSet<String> ignoreNameList = new HashSet<>(); private HashSet<String> ignoreNameList = new HashSet<>();
private HashSet<String> ignoreNumberList = new HashSet<>(); private HashSet<String> ignoreNumberList = new HashSet<>();
@ -250,7 +251,7 @@ public class Data {
public void readIgnoreList() { public void readIgnoreList() {
readNameIgnoreList(); readNameIgnoreList();
readNumberIgnoreList(); readNumberIgnoreList();
System.out.println("There are " + ignoreNameList.size() + " names and " + ignoreNumberList.size() + " numbers ignored."); System.out.println(String.format("There are %d names and %d numbers ignored", ignoreNameList.size(), ignoreNumberList.size()));
} }
private void readNameIgnoreList() { private void readNameIgnoreList() {

@ -1,20 +1,22 @@
package me.lensferno.dogename.data; package me.lensferno.dogename.data;
import me.lensferno.dogename.utils.FilePath;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
public class History { public class History {
public static final String separator = File.separator;
ArrayList<String> history; ArrayList<String> history;
private String HISTORY_FILE;
private final String HISTORY_FILE = FilePath.toSpecificPathForm("files/history.data");
public void loadHistory() { public void loadHistory() {
HISTORY_FILE = "files" + separator + "history.data"; File historyFile = new File(HISTORY_FILE);
try { try {
File historyFile = new File(HISTORY_FILE);
if (!historyFile.exists()) { if (!historyFile.exists()) {
historyFile.getParentFile().mkdirs(); historyFile.getParentFile().mkdirs();
historyFile.createNewFile(); historyFile.createNewFile();
@ -52,7 +54,6 @@ public class History {
private void writeHistory() { private void writeHistory() {
HISTORY_FILE = "files" + separator + "history.data";
File historyFile = new File(HISTORY_FILE); File historyFile = new File(HISTORY_FILE);
try { try {

@ -0,0 +1,9 @@
package me.lensferno.dogename.utils;
import java.io.File;
public final class FilePath {
public static String toSpecificPathForm(String uniformFilepath) {
return uniformFilepath.replace("/", File.separator);
}
}

@ -9,7 +9,6 @@ import java.net.URL;
public class TokenManager { public class TokenManager {
public static final String separator = File.separator;
public static final int TOKEN_OK = 0; public static final int TOKEN_OK = 0;
public static final int TOKEN_BAD = 1; public static final int TOKEN_BAD = 1;
final String API_KEY = "dIHCtamVdD0ERO1yyFir2iI4"; final String API_KEY = "dIHCtamVdD0ERO1yyFir2iI4";

@ -3,6 +3,7 @@ package me.lensferno.dogename.voice;
import com.goxr3plus.streamplayer.stream.StreamPlayer; import com.goxr3plus.streamplayer.stream.StreamPlayer;
import com.goxr3plus.streamplayer.stream.StreamPlayerException; import com.goxr3plus.streamplayer.stream.StreamPlayerException;
import me.lensferno.dogename.configs.VoiceConfig; import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.utils.FilePath;
import me.lensferno.dogename.utils.IOUtil; import me.lensferno.dogename.utils.IOUtil;
import me.lensferno.dogename.utils.NetworkUtil; import me.lensferno.dogename.utils.NetworkUtil;
@ -11,10 +12,10 @@ import java.net.URLEncoder;
public class VoicePlayer { public class VoicePlayer {
public static final String separator = File.separator;
private final String VOICE_API = "https://tsn.baidu.com/text2audio"; private final String VOICE_API = "https://tsn.baidu.com/text2audio";
String cachePath = "caches" + separator + "voice" + separator;
String cachePath = FilePath.toSpecificPathForm("caches/voice/");
Token token; Token token;
StreamPlayer streamPlayer = new StreamPlayer(); StreamPlayer streamPlayer = new StreamPlayer();
private VoiceConfig voiceConfig = null; private VoiceConfig voiceConfig = null;

Loading…
Cancel
Save