mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
More cleanup of ForgeProfileProperties
This commit is contained in:
@@ -56,6 +56,8 @@ public class FilesPage extends TabPage {
|
|||||||
return new GuiDownloadPrices();
|
return new GuiDownloadPrices();
|
||||||
}
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
|
//storage options
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package forge.properties;
|
|||||||
|
|
||||||
import forge.GuiBase;
|
import forge.GuiBase;
|
||||||
import forge.util.FileSection;
|
import forge.util.FileSection;
|
||||||
|
import forge.util.FileUtil;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
@@ -26,7 +27,6 @@ import org.apache.commons.lang3.tuple.Pair;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@@ -42,20 +42,11 @@ public class ForgeProfileProperties {
|
|||||||
public final Map<String, String> cardPicsSubDir;
|
public final Map<String, String> cardPicsSubDir;
|
||||||
public final int serverPort;
|
public final int serverPort;
|
||||||
|
|
||||||
private static final String _USER_DIR_KEY = "userDir";
|
private static final String USER_DIR_KEY = "userDir";
|
||||||
private static final String _CACHE_DIR_KEY = "cacheDir";
|
private static final String CACHE_DIR_KEY = "cacheDir";
|
||||||
private static final String _CARD_PICS_DIR_KEY = "cardPicsDir";
|
private static final String CARD_PICS_DIR_KEY = "cardPicsDir";
|
||||||
private static final String _CARD_PICS_SUB_DIRS_KEY = "cardPicsSubDirs";
|
private static final String CARD_PICS_SUB_DIRS_KEY = "cardPicsSubDirs";
|
||||||
|
private static final String SERVER_PORT = "serverPort";
|
||||||
private static final String _SERVER_PORT = "serverPort";
|
|
||||||
|
|
||||||
public ForgeProfileProperties(String userDir0, String cacheDir0) {
|
|
||||||
userDir = userDir0;
|
|
||||||
cacheDir = cacheDir0;
|
|
||||||
cardPicsDir = cacheDir + "pics/cards/";
|
|
||||||
cardPicsSubDir = new HashMap<String, String>();
|
|
||||||
serverPort = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ForgeProfileProperties() {
|
public ForgeProfileProperties() {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
@@ -70,36 +61,31 @@ public class ForgeProfileProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Pair<String, String> defaults = _getDefaultDirs();
|
Pair<String, String> defaults = _getDefaultDirs();
|
||||||
userDir = _getDir(props, _USER_DIR_KEY, defaults.getLeft());
|
userDir = getDir(props, USER_DIR_KEY, defaults.getLeft());
|
||||||
cacheDir = _getDir(props, _CACHE_DIR_KEY, defaults.getRight());
|
cacheDir = getDir(props, CACHE_DIR_KEY, defaults.getRight());
|
||||||
cardPicsDir = _getDir(props, _CARD_PICS_DIR_KEY, cacheDir + "pics/cards/");
|
cardPicsDir = getDir(props, CARD_PICS_DIR_KEY, cacheDir + "pics/cards/");
|
||||||
cardPicsSubDir = _getMap(props, _CARD_PICS_SUB_DIRS_KEY);
|
cardPicsSubDir = getMap(props, CARD_PICS_SUB_DIRS_KEY);
|
||||||
serverPort = _getInt(props, _SERVER_PORT, 0);
|
serverPort = getInt(props, SERVER_PORT, 0);
|
||||||
|
|
||||||
//ensure directories exist
|
//ensure directories exist
|
||||||
File dir = new File(userDir);
|
FileUtil.ensureDirectoryExists(userDir);
|
||||||
if (!dir.exists()) {
|
FileUtil.ensureDirectoryExists(cacheDir);
|
||||||
dir.mkdirs();
|
FileUtil.ensureDirectoryExists(cardPicsDir);
|
||||||
}
|
|
||||||
dir = new File(cacheDir);
|
|
||||||
if (!dir.exists()) {
|
|
||||||
dir.mkdirs();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String,String> _getMap(Properties props, String propertyKey) {
|
private Map<String, String> getMap(Properties props, String propertyKey) {
|
||||||
String strMap = props.getProperty(propertyKey, "").trim();
|
String strMap = props.getProperty(propertyKey, "").trim();
|
||||||
return FileSection.parseToMap(strMap, "->", "|");
|
return FileSection.parseToMap(strMap, "->", "|");
|
||||||
}
|
}
|
||||||
|
|
||||||
private int _getInt(Properties props, String propertyKey, int defaultValue) {
|
private int getInt(Properties props, String propertyKey, int defaultValue) {
|
||||||
String strValue = props.getProperty(propertyKey, "").trim();
|
String strValue = props.getProperty(propertyKey, "").trim();
|
||||||
if ( StringUtils.isNotBlank(strValue) && StringUtils.isNumeric(strValue) )
|
if ( StringUtils.isNotBlank(strValue) && StringUtils.isNumeric(strValue) )
|
||||||
return Integer.parseInt(strValue);
|
return Integer.parseInt(strValue);
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String _getDir(Properties props, String propertyKey, String defaultVal) {
|
private static String getDir(Properties props, String propertyKey, String defaultVal) {
|
||||||
String retDir = props.getProperty(propertyKey, defaultVal).trim();
|
String retDir = props.getProperty(propertyKey, defaultVal).trim();
|
||||||
if (retDir.isEmpty()) {
|
if (retDir.isEmpty()) {
|
||||||
// use default if dir is "defined" as an empty string in the properties file
|
// use default if dir is "defined" as an empty string in the properties file
|
||||||
|
|||||||
Reference in New Issue
Block a user