mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
clean up ForgeProfileProperties and move profile dir creation to FModel
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
|||||||
/*.iml
|
/*.iml
|
||||||
/*.tmp
|
/*.tmp
|
||||||
/.metadata
|
/.metadata
|
||||||
|
/forge.profile.properties
|
||||||
res/PerSetTrackingResults
|
res/PerSetTrackingResults
|
||||||
res/oracleScript.log
|
res/oracleScript.log
|
||||||
res/reprintSetInfo.log
|
res/reprintSetInfo.log
|
||||||
|
|||||||
@@ -45,17 +45,8 @@ import forge.properties.NewConstants;
|
|||||||
import forge.util.CopyFiles;
|
import forge.util.CopyFiles;
|
||||||
import forge.util.FileFinder;
|
import forge.util.FileFinder;
|
||||||
|
|
||||||
/**
|
@SuppressWarnings("serial")
|
||||||
* <p>
|
|
||||||
* GUI_ImportPicture class.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Forge
|
|
||||||
* @version $Id$
|
|
||||||
*/
|
|
||||||
public class GuiImportPicture extends JDialog {
|
public class GuiImportPicture extends JDialog {
|
||||||
/** Constant <code>serialVersionUID=-4191539152208389089L</code>. */
|
|
||||||
private static final long serialVersionUID = -4191539152208389089L;
|
|
||||||
private JPanel jContentPane = null;
|
private JPanel jContentPane = null;
|
||||||
private JLabel jLabel = null;
|
private JLabel jLabel = null;
|
||||||
private JLabel jLabel1 = null;
|
private JLabel jLabel1 = null;
|
||||||
@@ -65,12 +56,10 @@ public class GuiImportPicture extends JDialog {
|
|||||||
private JCheckBox jCheckBox = null;
|
private JCheckBox jCheckBox = null;
|
||||||
private JButton jButtonStart = null;
|
private JButton jButtonStart = null;
|
||||||
|
|
||||||
/** The frame. */
|
|
||||||
private final GuiImportPicture frame;
|
private final GuiImportPicture frame;
|
||||||
private JLabel jLabelHDDFree = null;
|
private JLabel jLabelHDDFree = null;
|
||||||
private JLabel jLabelNeedSpace = null;
|
private JLabel jLabelNeedSpace = null;
|
||||||
|
|
||||||
/** The j label total files. */
|
|
||||||
private JLabel jLabelTotalFiles = null;
|
private JLabel jLabelTotalFiles = null;
|
||||||
private List<File> listFiles;
|
private List<File> listFiles;
|
||||||
private ArrayList<File> fileCopyList;
|
private ArrayList<File> fileCopyList;
|
||||||
@@ -79,23 +68,12 @@ public class GuiImportPicture extends JDialog {
|
|||||||
private String oldText;
|
private String oldText;
|
||||||
private JProgressBar jProgressBar = null;
|
private JProgressBar jProgressBar = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* Constructor for GUI_ImportPicture.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @param owner
|
|
||||||
* a {@link javax.swing.JFrame} object.
|
|
||||||
*/
|
|
||||||
public GuiImportPicture(final JFrame owner) {
|
public GuiImportPicture(final JFrame owner) {
|
||||||
super(owner);
|
super(owner);
|
||||||
this.frame = this;
|
this.frame = this;
|
||||||
this.initialize();
|
this.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes this.
|
|
||||||
*/
|
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
final Dimension screen = this.getToolkit().getScreenSize();
|
final Dimension screen = this.getToolkit().getScreenSize();
|
||||||
final Rectangle bounds = this.getBounds();
|
final Rectangle bounds = this.getBounds();
|
||||||
@@ -112,11 +90,6 @@ public class GuiImportPicture extends JDialog {
|
|||||||
this.setContentPane(this.getJContentPane());
|
this.setContentPane(this.getJContentPane());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes jContentPane.
|
|
||||||
*
|
|
||||||
* @return javax.swing.JPanel
|
|
||||||
*/
|
|
||||||
private JPanel getJContentPane() {
|
private JPanel getJContentPane() {
|
||||||
if (this.jContentPane == null) {
|
if (this.jContentPane == null) {
|
||||||
this.jLabelTotalFiles = new JLabel();
|
this.jLabelTotalFiles = new JLabel();
|
||||||
@@ -163,11 +136,6 @@ public class GuiImportPicture extends JDialog {
|
|||||||
return this.jContentPane;
|
return this.jContentPane;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes jButtonSource.
|
|
||||||
*
|
|
||||||
* @return javax.swing.JButton
|
|
||||||
*/
|
|
||||||
private JButton getJButtonSource() {
|
private JButton getJButtonSource() {
|
||||||
if (this.jButtonSource == null) {
|
if (this.jButtonSource == null) {
|
||||||
this.jButtonSource = new JButton();
|
this.jButtonSource = new JButton();
|
||||||
@@ -254,11 +222,6 @@ public class GuiImportPicture extends JDialog {
|
|||||||
return this.jButtonSource;
|
return this.jButtonSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes jPanel.
|
|
||||||
*
|
|
||||||
* @return javax.swing.JPanel
|
|
||||||
*/
|
|
||||||
private JPanel getJPanel() {
|
private JPanel getJPanel() {
|
||||||
if (this.jPanel == null) {
|
if (this.jPanel == null) {
|
||||||
final GridBagConstraints gridBagConstraints = new GridBagConstraints();
|
final GridBagConstraints gridBagConstraints = new GridBagConstraints();
|
||||||
@@ -275,11 +238,6 @@ public class GuiImportPicture extends JDialog {
|
|||||||
return this.jPanel;
|
return this.jPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes jCheckBox.
|
|
||||||
*
|
|
||||||
* @return javax.swing.JCheckBox
|
|
||||||
*/
|
|
||||||
private JCheckBox getJCheckBox() {
|
private JCheckBox getJCheckBox() {
|
||||||
if (this.jCheckBox == null) {
|
if (this.jCheckBox == null) {
|
||||||
this.jCheckBox = new JCheckBox();
|
this.jCheckBox = new JCheckBox();
|
||||||
@@ -347,11 +305,6 @@ public class GuiImportPicture extends JDialog {
|
|||||||
return this.jCheckBox;
|
return this.jCheckBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes jButtonStart.
|
|
||||||
*
|
|
||||||
* @return javax.swing.JButton
|
|
||||||
*/
|
|
||||||
private JButton getJButtonStart() {
|
private JButton getJButtonStart() {
|
||||||
if (this.jButtonStart == null) {
|
if (this.jButtonStart == null) {
|
||||||
this.jButtonStart = new JButton();
|
this.jButtonStart = new JButton();
|
||||||
@@ -404,11 +357,6 @@ public class GuiImportPicture extends JDialog {
|
|||||||
return this.jButtonStart;
|
return this.jButtonStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes jProgressBar.
|
|
||||||
*
|
|
||||||
* @return javax.swing.JProgressBar
|
|
||||||
*/
|
|
||||||
private JProgressBar getJProgressBar() {
|
private JProgressBar getJProgressBar() {
|
||||||
if (this.jProgressBar == null) {
|
if (this.jProgressBar == null) {
|
||||||
this.jProgressBar = new JProgressBar();
|
this.jProgressBar = new JProgressBar();
|
||||||
@@ -418,4 +366,4 @@ public class GuiImportPicture extends JDialog {
|
|||||||
}
|
}
|
||||||
return this.jProgressBar;
|
return this.jProgressBar;
|
||||||
}
|
}
|
||||||
} // @jve:decl-index=0:visual-constraint="10,10"
|
}
|
||||||
|
|||||||
@@ -103,6 +103,18 @@ public enum FModel {
|
|||||||
// Fire up log file and exception handling
|
// Fire up log file and exception handling
|
||||||
ExceptionHandler.registerErrorHandling();
|
ExceptionHandler.registerErrorHandling();
|
||||||
|
|
||||||
|
// create profile dirs if they don't already exist
|
||||||
|
for (String dname : NewConstants.PROFILE_DIRS) {
|
||||||
|
File path = new File(dname);
|
||||||
|
if (path.isDirectory()) {
|
||||||
|
// already exists
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!path.mkdirs()) {
|
||||||
|
throw new RuntimeException("cannot create profile directory: " + dname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final File logFile = new File(NewConstants.LOG_FILE);
|
final File logFile = new File(NewConstants.LOG_FILE);
|
||||||
final boolean deleteSucceeded = logFile.delete();
|
final boolean deleteSucceeded = logFile.delete();
|
||||||
|
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ public class ForgeProfileProperties {
|
|||||||
public final String cacheDir;
|
public final String cacheDir;
|
||||||
public final String cardPicsDir;
|
public final String cardPicsDir;
|
||||||
|
|
||||||
private final String _USER_DIR_KEY = "userDir";
|
private static final String _USER_DIR_KEY = "userDir";
|
||||||
private final String _CACHE_DIR_KEY = "cacheDir";
|
private static final String _CACHE_DIR_KEY = "cacheDir";
|
||||||
private final String _CARD_PICS_DIR_KEY = "cardPicsDir";
|
private static final String _CARD_PICS_DIR_KEY = "cardPicsDir";
|
||||||
|
|
||||||
public ForgeProfileProperties(String filename) {
|
public ForgeProfileProperties(String filename) {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
@@ -47,31 +47,29 @@ public class ForgeProfileProperties {
|
|||||||
props.load(new FileInputStream(propFile));
|
props.load(new FileInputStream(propFile));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// ignore
|
System.err.println("error while reading from profile properties file: " + filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<String, String> defaults = _getDefaultDirs();
|
Pair<String, String> defaults = _getDefaultDirs();
|
||||||
|
userDir = _getDir(props, _USER_DIR_KEY, defaults.getLeft());
|
||||||
|
cacheDir = _getDir(props, _CACHE_DIR_KEY, defaults.getRight());
|
||||||
|
cardPicsDir = _getDir(props, _CARD_PICS_DIR_KEY, cacheDir + "pics/cards/");
|
||||||
|
}
|
||||||
|
|
||||||
String propUserDir = props.getProperty(_USER_DIR_KEY, defaults.getLeft());
|
private static String _getDir(Properties props, String propertyKey, String defaultVal) {
|
||||||
String propCacheDir = props.getProperty(_CACHE_DIR_KEY, defaults.getRight());
|
String retDir = props.getProperty(propertyKey, defaultVal).trim();
|
||||||
|
if (retDir.isEmpty()) {
|
||||||
// use defaults if the dirs are "defined" as empty strings in the properties file
|
// use default if dir is "defined" as an empty or whitespace string in the properties file
|
||||||
propUserDir = StringUtils.isEmpty(propUserDir) ? defaults.getLeft() : propUserDir.trim();
|
return defaultVal;
|
||||||
propCacheDir = StringUtils.isEmpty(propCacheDir) ? defaults.getRight() : propCacheDir.trim();
|
}
|
||||||
|
if (retDir.endsWith("/") || retDir.endsWith(File.pathSeparator)) {
|
||||||
propUserDir += propUserDir.endsWith("/") || propUserDir.endsWith(File.pathSeparator) ? "" : "/";
|
return retDir;
|
||||||
propCacheDir += propCacheDir.endsWith("/") || propCacheDir.endsWith(File.pathSeparator) ? "" : "/";
|
}
|
||||||
|
return retDir + "/";
|
||||||
String propCardPicsDir = props.getProperty(_CARD_PICS_DIR_KEY, propCacheDir + "pics/cards/");
|
|
||||||
propCardPicsDir += propCardPicsDir.endsWith("/") || propCardPicsDir.endsWith(File.pathSeparator) ? "" : "/";
|
|
||||||
|
|
||||||
userDir = propUserDir;
|
|
||||||
cacheDir = propCacheDir;
|
|
||||||
cardPicsDir = propCardPicsDir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns a pair <userDir, cacheDir>
|
// returns a pair <userDir, cacheDir>
|
||||||
private Pair<String, String> _getDefaultDirs() {
|
private static Pair<String, String> _getDefaultDirs() {
|
||||||
String osName = System.getProperty("os.name");
|
String osName = System.getProperty("os.name");
|
||||||
String homeDir = System.getProperty("user.home");
|
String homeDir = System.getProperty("user.home");
|
||||||
|
|
||||||
@@ -83,7 +81,8 @@ public class ForgeProfileProperties {
|
|||||||
|
|
||||||
if (StringUtils.containsIgnoreCase("windows", osName)) {
|
if (StringUtils.containsIgnoreCase("windows", osName)) {
|
||||||
// the split between appdata and localappdata on windows is relatively recent. If
|
// the split between appdata and localappdata on windows is relatively recent. If
|
||||||
// localappdata is not defined, use appdata for both.
|
// localappdata is not defined, use appdata for both. and if appdata is not defined,
|
||||||
|
// fall back to a linux-style dot dir in the home directory
|
||||||
String appRoot = System.getenv().get("APPDATA");
|
String appRoot = System.getenv().get("APPDATA");
|
||||||
if (StringUtils.isEmpty(appRoot)) {
|
if (StringUtils.isEmpty(appRoot)) {
|
||||||
appRoot = fallbackDataDir;
|
appRoot = fallbackDataDir;
|
||||||
@@ -93,6 +92,8 @@ public class ForgeProfileProperties {
|
|||||||
cacheRoot = appRoot;
|
cacheRoot = appRoot;
|
||||||
}
|
}
|
||||||
// just use '/' everywhere instead of file.separator. it always works
|
// just use '/' everywhere instead of file.separator. it always works
|
||||||
|
// the cache dir is Forge/Cache instead of just Forge since appRoot and cacheRoot might be the
|
||||||
|
// same directory on windows and we need to distinguish them.
|
||||||
return Pair.of(String.format("%s/Forge", appRoot),
|
return Pair.of(String.format("%s/Forge", appRoot),
|
||||||
String.format("%s/Forge/Cache", cacheRoot));
|
String.format("%s/Forge/Cache", cacheRoot));
|
||||||
} else if (StringUtils.containsIgnoreCase("mac os x", osName)) {
|
} else if (StringUtils.containsIgnoreCase("mac os x", osName)) {
|
||||||
|
|||||||
@@ -17,12 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
package forge.view;
|
package forge.view;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.control.FControl;
|
import forge.control.FControl;
|
||||||
import forge.model.FModel;
|
import forge.model.FModel;
|
||||||
import forge.properties.NewConstants;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main class for Forge's swing application view.
|
* Main class for Forge's swing application view.
|
||||||
@@ -35,18 +32,6 @@ public final class Main {
|
|||||||
// HACK - temporary solution to "Comparison method violates it's general contract!" crash
|
// HACK - temporary solution to "Comparison method violates it's general contract!" crash
|
||||||
System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
|
System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
|
||||||
|
|
||||||
// create profile dirs if they don't already exist
|
|
||||||
for (String dname : NewConstants.PROFILE_DIRS) {
|
|
||||||
File path = new File(dname);
|
|
||||||
if (path.isDirectory()) {
|
|
||||||
// already exists
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!path.mkdirs()) {
|
|
||||||
throw new RuntimeException("cannot create profile directory: " + dname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start splash screen first, then data models, then controller.
|
// Start splash screen first, then data models, then controller.
|
||||||
Singletons.setView(FView.SINGLETON_INSTANCE);
|
Singletons.setView(FView.SINGLETON_INSTANCE);
|
||||||
Singletons.setModel(FModel.SINGLETON_INSTANCE);
|
Singletons.setModel(FModel.SINGLETON_INSTANCE);
|
||||||
|
|||||||
Reference in New Issue
Block a user