Default config paths added
This commit is contained in:
parent
da69d690af
commit
dd81f7acf6
@ -224,12 +224,12 @@ public class App {
|
||||
}
|
||||
|
||||
private static void loadHistory() {
|
||||
File historyFile = new File("history.json");
|
||||
File historyFile = new File(Utils.getConfigDir() + File.separator + "history.json");
|
||||
HISTORY.clear();
|
||||
if (historyFile.exists()) {
|
||||
try {
|
||||
logger.info("Loading history from history.json");
|
||||
HISTORY.fromFile("history.json");
|
||||
logger.info("Loading history from " + historyFile.getCanonicalPath());
|
||||
HISTORY.fromFile(historyFile.getCanonicalPath());
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to load history from file " + historyFile, e);
|
||||
System.out.println(
|
||||
|
@ -31,6 +31,9 @@ import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
@ -1001,12 +1004,12 @@ public final class MainWindow implements Runnable, RipStatusHandler {
|
||||
}
|
||||
|
||||
private void loadHistory() {
|
||||
File historyFile = new File("history.json");
|
||||
File historyFile = new File(Utils.getConfigDir() + File.separator + "history.json");
|
||||
HISTORY.clear();
|
||||
if (historyFile.exists()) {
|
||||
try {
|
||||
logger.info("Loading history from history.json");
|
||||
HISTORY.fromFile("history.json");
|
||||
logger.info("Loading history from " + historyFile.getCanonicalPath());
|
||||
HISTORY.fromFile(historyFile.getCanonicalPath());
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to load history from file " + historyFile, e);
|
||||
JOptionPane.showMessageDialog(null,
|
||||
@ -1044,11 +1047,17 @@ public final class MainWindow implements Runnable, RipStatusHandler {
|
||||
}
|
||||
|
||||
private void saveHistory() {
|
||||
Path historyFile = Paths.get(Utils.getConfigDir() + File.separator + "history.json");
|
||||
try {
|
||||
HISTORY.toFile("history.json");
|
||||
if (!Files.exists(historyFile)) {
|
||||
Files.createDirectories(historyFile.getParent());
|
||||
Files.createFile(historyFile);
|
||||
}
|
||||
|
||||
HISTORY.toFile(historyFile.toString());
|
||||
Utils.setConfigList("download.history", Collections.emptyList());
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to save history to file history.json", e);
|
||||
logger.error("Failed to save history to file " + historyFile, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,12 +36,13 @@ import com.rarchives.ripme.ripper.AbstractRipper;
|
||||
public class Utils {
|
||||
public static final String RIP_DIRECTORY = "rips";
|
||||
private static final String configFile = "rip.properties";
|
||||
private static final String OS = System.getProperty("os.name").toLowerCase();
|
||||
private static final Logger logger = Logger.getLogger(Utils.class);
|
||||
|
||||
private static PropertiesConfiguration config;
|
||||
static {
|
||||
try {
|
||||
String configPath = getConfigPath();
|
||||
String configPath = getConfigFilePath();
|
||||
File f = new File(configPath);
|
||||
if (!f.exists()) {
|
||||
// Use default bundled with .jar
|
||||
@ -132,18 +133,52 @@ public class Utils {
|
||||
|
||||
public static void saveConfig() {
|
||||
try {
|
||||
config.save(getConfigPath());
|
||||
logger.info("Saved configuration to " + getConfigPath());
|
||||
config.save(getConfigFilePath());
|
||||
logger.info("Saved configuration to " + getConfigFilePath());
|
||||
} catch (ConfigurationException e) {
|
||||
logger.error("Error while saving configuration: ", e);
|
||||
}
|
||||
}
|
||||
private static String getConfigPath() {
|
||||
try {
|
||||
return new File(".").getCanonicalPath() + File.separator + configFile;
|
||||
} catch (Exception e) {
|
||||
return "." + File.separator + configFile;
|
||||
|
||||
private static boolean isWindows() {
|
||||
return OS.contains("win");
|
||||
}
|
||||
|
||||
private static boolean isMacOS() {
|
||||
return OS.contains("mac");
|
||||
}
|
||||
|
||||
private static boolean isUnix() {
|
||||
return OS.contains("nix") || OS.contains("nux") || OS.contains("bsd");
|
||||
}
|
||||
|
||||
private static String getWindowsConfigDir() {
|
||||
return System.getenv("LOCALAPPDATA") + File.separator + "ripme";
|
||||
}
|
||||
|
||||
private static String getUnixConfigDir() {
|
||||
return System.getProperty("user.home") + File.separator + ".config" + File.separator + "ripme";
|
||||
}
|
||||
|
||||
private static String getMacOSConfigDir() {
|
||||
return System.getProperty("user.home")
|
||||
+ File.separator + "Library" + File.separator + "Application Support" + File.separator + "ripme";
|
||||
}
|
||||
|
||||
public static String getConfigDir() {
|
||||
if (isWindows()) return getWindowsConfigDir();
|
||||
if (isMacOS()) return getMacOSConfigDir();
|
||||
if (isUnix()) return getUnixConfigDir();
|
||||
|
||||
try {
|
||||
return new File(".").getCanonicalPath();
|
||||
} catch (Exception e) {
|
||||
return ".";
|
||||
}
|
||||
}
|
||||
|
||||
private static String getConfigFilePath() {
|
||||
return getConfigDir() + File.separator + configFile;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user