From 13243568277c6e872b1537e359e7d92bd0444561 Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 21 Dec 2019 11:50:01 +0100 Subject: [PATCH] Moved local files to .envoy directory in user home Fixes #57 --- .gitignore | 5 +---- src/main/java/envoy/client/Config.java | 2 +- src/main/java/envoy/client/Settings.java | 2 +- src/main/java/envoy/client/ui/Startup.java | 12 +++++------- src/main/java/envoy/client/util/EnvoyLog.java | 2 +- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index d77958c..a6f89c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1 @@ -/target/ -/localDB/ -/log/ -/themes.ser \ No newline at end of file +/target/ \ No newline at end of file diff --git a/src/main/java/envoy/client/Config.java b/src/main/java/envoy/client/Config.java index b1388ae..b479de8 100644 --- a/src/main/java/envoy/client/Config.java +++ b/src/main/java/envoy/client/Config.java @@ -32,7 +32,7 @@ public class Config { items.put("port", new ConfigItem<>("port", "p", (input) -> Integer.parseInt(input), null)); items.put("localDB", new ConfigItem<>("localDB", "db", (input) -> new File(input), new File("localDB"))); items.put("syncTimeout", new ConfigItem<>("syncTimeout", "st", (input) -> Integer.parseInt(input), 1000)); - items.put("homeDirectory", new ConfigItem<>("homeDirectory", "h", (input) -> new File(input), new File(System.getProperty("user.home")))); + items.put("homeDirectory", new ConfigItem<>("homeDirectory", "h", (input) -> new File(input), new File(System.getProperty("user.home"), ".envoy"))); items.put("fileLevelBarrier", new ConfigItem<>("fileLevelBarrier", "fb", (input) -> Level.parse(input), Level.CONFIG)); items.put("consoleLevelBarrier", new ConfigItem<>("consoleLevelBarrier", "cb", (input) -> Level.parse(input), Level.FINEST)); } diff --git a/src/main/java/envoy/client/Settings.java b/src/main/java/envoy/client/Settings.java index d7e01de..6502049 100644 --- a/src/main/java/envoy/client/Settings.java +++ b/src/main/java/envoy/client/Settings.java @@ -37,7 +37,7 @@ public class Settings { /** * User-defined themes are stored inside this file. */ - private File themeFile = new File("themes.ser"); + private File themeFile = new File(Config.getInstance().getHomeDirectory(), "themes.ser"); /** * Singleton instance of this class. diff --git a/src/main/java/envoy/client/ui/Startup.java b/src/main/java/envoy/client/ui/Startup.java index f1d75bb..11db9f6 100644 --- a/src/main/java/envoy/client/ui/Startup.java +++ b/src/main/java/envoy/client/ui/Startup.java @@ -1,6 +1,7 @@ package envoy.client.ui; import java.awt.EventQueue; +import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; @@ -8,10 +9,7 @@ import java.util.logging.Logger; import javax.swing.JFrame; import javax.swing.JOptionPane; -import envoy.client.Client; -import envoy.client.Config; -import envoy.client.LocalDB; -import envoy.client.Settings; +import envoy.client.*; import envoy.client.util.EnvoyLog; import envoy.exception.EnvoyException; import envoy.schema.User; @@ -62,8 +60,8 @@ public class Startup { e.printStackTrace(); } - EnvoyLog.setFileLevelBarrier(Config.getInstance().getFileLevelBarrier()); - EnvoyLog.setConsoleLevelBarrier(Config.getInstance().getConsoleLevelBarrier()); + EnvoyLog.setFileLevelBarrier(config.getFileLevelBarrier()); + EnvoyLog.setConsoleLevelBarrier(config.getConsoleLevelBarrier()); // Ask the user for their user name String userName = JOptionPane.showInputDialog("Please enter your username"); @@ -75,7 +73,7 @@ public class Startup { // Initialize the local database LocalDB localDB; try { - localDB = new LocalDB(config.getLocalDB()); + localDB = new LocalDB(new File(config.getHomeDirectory(), config.getLocalDB().getPath())); } catch (IOException e3) { logger.log(Level.SEVERE, "Could not initialize local database", e3); JOptionPane.showMessageDialog(null, "Could not initialize local database!\n" + e3.toString()); diff --git a/src/main/java/envoy/client/util/EnvoyLog.java b/src/main/java/envoy/client/util/EnvoyLog.java index f844aae..1e93b4c 100644 --- a/src/main/java/envoy/client/util/EnvoyLog.java +++ b/src/main/java/envoy/client/util/EnvoyLog.java @@ -31,7 +31,7 @@ public class EnvoyLog { // Get a logger with the specified name Logger logger = Logger.getLogger(name); - final String logPath = "log/envoy_user.log"; + final String logPath = new File(Config.getInstance().getHomeDirectory(), "log/envoy_user.log").getAbsolutePath(); new File(logPath).getParentFile().mkdirs(); SimpleFormatter formatter = new SimpleFormatter();