Changed config keys to static constants

This commit is contained in:
Vhati 2017-12-08 15:04:23 -05:00
parent 7949e1ac3d
commit c4637d83d7
4 changed files with 72 additions and 67 deletions

View file

@ -67,12 +67,12 @@ public class FTLModManager {
boolean writeConfig = false;
Properties config = new Properties();
config.setProperty( "allow_zip", "false" );
config.setProperty( "ftl_dats_path", "" );
config.setProperty( "run_steam_ftl", "false" );
config.setProperty( "never_run_ftl", "false" );
config.setProperty( "use_default_ui", "false" );
config.setProperty( "remember_geometry", "true" );
config.setProperty( SlipstreamConfig.ALLOW_ZIP, "false" );
config.setProperty( SlipstreamConfig.FTL_DATS_PATH, "" );
config.setProperty( SlipstreamConfig.RUN_STEAM_FTL, "false" );
config.setProperty( SlipstreamConfig.NEVER_RUN_FTL, "false" );
config.setProperty( SlipstreamConfig.USE_DEFAULT_UI, "false" );
config.setProperty( SlipstreamConfig.REMEMBER_GEOMETRY, "true" );
// "update_catalog" doesn't have a default.
// "update_app" doesn't have a default.
// "manager_geometry" doesn't have a default.
@ -98,7 +98,7 @@ public class FTLModManager {
}
// Look-and-Feel.
String useDefaultUI = config.getProperty( "use_default_ui", "false" );
String useDefaultUI = config.getProperty( SlipstreamConfig.USE_DEFAULT_UI, "false" );
if ( !useDefaultUI.equals("true") ) {
try {
@ -107,15 +107,16 @@ public class FTLModManager {
}
catch ( Exception e ) {
log.error( "Error setting system Look and Feel.", e );
log.info( "Setting 'useDefaultUI=true' in the config file will prevent this error." );
log.info( "Setting '"+ SlipstreamConfig.USE_DEFAULT_UI +"=true' in the config file will prevent this error." );
}
} else {
}
else {
log.debug( "Using default Look and Feel." );
}
// FTL Resources Path.
File datsDir = null;
String datsPath = config.getProperty( "ftl_dats_path", "" );
String datsPath = config.getProperty( SlipstreamConfig.FTL_DATS_PATH, "" );
if ( datsPath.length() > 0 ) {
log.info( "Using FTL dats path from config: "+ datsPath );
@ -142,7 +143,7 @@ public class FTLModManager {
}
if ( datsDir != null ) {
config.setProperty( "ftl_dats_path", datsDir.getAbsolutePath() );
config.setProperty( SlipstreamConfig.FTL_DATS_PATH, datsDir.getAbsolutePath() );
writeConfig = true;
log.info( "FTL dats located at: "+ datsDir.getAbsolutePath() );
}
@ -159,8 +160,8 @@ public class FTLModManager {
// Prompt if update_catalog is invalid or hasn't been set.
boolean askAboutUpdates = false;
String catalogUpdateInterval = config.getProperty( "update_catalog" );
String appUpdateInterval = config.getProperty( "update_app" );
String catalogUpdateInterval = config.getProperty( SlipstreamConfig.UPDATE_CATALOG );
String appUpdateInterval = config.getProperty( SlipstreamConfig.UPDATE_APP );
if ( catalogUpdateInterval == null || !catalogUpdateInterval.matches( "^\\d+$" ) )
askAboutUpdates = true;
@ -176,11 +177,12 @@ public class FTLModManager {
int response = JOptionPane.showConfirmDialog( null, message, "Updates", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE );
if ( response == JOptionPane.YES_OPTION ) {
config.setProperty( "update_catalog", "7" );
config.setProperty( "update_app", "4" );
} else {
config.setProperty( "update_catalog", "0" );
config.setProperty( "update_app", "0" );
config.setProperty( SlipstreamConfig.UPDATE_CATALOG, "7" );
config.setProperty( SlipstreamConfig.UPDATE_APP, "4" );
}
else {
config.setProperty( SlipstreamConfig.UPDATE_CATALOG, "0" );
config.setProperty( SlipstreamConfig.UPDATE_APP, "0" );
}
}

View file

@ -29,6 +29,7 @@ import net.vhati.modmanager.core.ModUtilities;
import net.vhati.modmanager.core.Report;
import net.vhati.modmanager.core.Report.ReportFormatter;
import net.vhati.modmanager.core.Report.ReportMessage;
import net.vhati.modmanager.core.SlipstreamConfig;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.OptionBuilder;
@ -170,7 +171,7 @@ public class SlipstreamCLI {
if ( cmdline.hasOption( "list-mods" ) ) { // Exits.
log.info( "Listing mods..." );
boolean allowZip = config.getProperty( "allow_zip", "false" ).equals( "true" );
boolean allowZip = config.getProperty( SlipstreamConfig.ALLOW_ZIP, "false" ).equals( "true" );
File[] modFiles = modsDir.listFiles( new ModAndDirFileFilter( allowZip, true ) );
List<String> dirList = new ArrayList<String>();
List<String> fileList = new ArrayList<String>();
@ -305,7 +306,7 @@ public class SlipstreamCLI {
File exeFile = null;
String[] exeArgs = null;
if ( config.getProperty( "run_steam_ftl", "false" ).equals( "true" ) ) {
if ( config.getProperty( SlipstreamConfig.RUN_STEAM_FTL, "false" ).equals( "true" ) ) {
exeFile = FTLUtilities.findSteamExe();
exeArgs = new String[] {"-applaunch", FTLUtilities.STEAM_APPID_FTL};
@ -351,10 +352,10 @@ public class SlipstreamCLI {
private static Properties getConfig( File configFile ) {
Properties config = new Properties();
config.setProperty( "allow_zip", "false" );
config.setProperty( "ftl_dats_path", "" );
config.setProperty( "never_run_ftl", "false" );
config.setProperty( "use_default_ui", "false" );
config.setProperty( SlipstreamConfig.ALLOW_ZIP, "false" );
config.setProperty( SlipstreamConfig.FTL_DATS_PATH, "" );
config.setProperty( SlipstreamConfig.NEVER_RUN_FTL, "false" );
config.setProperty( SlipstreamConfig.USE_DEFAULT_UI, "false" );
// "update_catalog" doesn't have a default.
// Read the config file.
@ -384,7 +385,7 @@ public class SlipstreamCLI {
*/
private static File getDatsDir( Properties config ) {
File datsDir = null;
String datsPath = config.getProperty( "ftl_dats_path", "" );
String datsPath = config.getProperty( SlipstreamConfig.FTL_DATS_PATH, "" );
if ( datsPath.length() > 0 ) {
log.info( "Using FTL dats path from config: "+ datsPath );

View file

@ -175,7 +175,7 @@ public class ManagerFrame extends JFrame implements ActionListener, ModsScanObse
patchBtn = new JButton( "Patch" );
patchBtn.setMargin( actionInsets );
patchBtn.addMouseListener( new StatusbarMouseListener( this, "Incorporate all selected mods into the game." ) );
patchBtn.addMouseListener( new StatusbarMouseListener( this, "Incorporate all selected mods into the game. Or revert to vanilla, if none are." ) );
patchBtn.addActionListener( this );
modActionsPanel.add( patchBtn );
@ -264,12 +264,12 @@ public class ManagerFrame extends JFrame implements ActionListener, ModsScanObse
SlipstreamConfig appConfig = ManagerFrame.this.appConfig;
if ( appConfig.getProperty( "remember_geometry" ).equals( "true" ) ) {
if ( appConfig.getProperty( SlipstreamConfig.REMEMBER_GEOMETRY ).equals( "true" ) ) {
if ( ManagerFrame.this.getExtendedState() == JFrame.NORMAL ) {
Rectangle managerBounds = ManagerFrame.this.getBounds();
int dividerLoc = splitPane.getDividerLocation();
String geometry = String.format( "x,%d;y,%d;w,%d;h,%d;divider,%d", managerBounds.x, managerBounds.y, managerBounds.width, managerBounds.height, dividerLoc );
appConfig.setProperty( "manager_geometry", geometry );
appConfig.setProperty( SlipstreamConfig.MANAGER_GEOMETRY, geometry );
}
}
@ -347,14 +347,14 @@ public class ManagerFrame extends JFrame implements ActionListener, ModsScanObse
this.setMinimumSize( new Dimension( 300, modActionsPanel.getPreferredSize().height+90 ) );
this.setLocationRelativeTo( null );
if ( appConfig.getProperty( "remember_geometry" ).equals( "true" ) )
if ( appConfig.getProperty( SlipstreamConfig.REMEMBER_GEOMETRY ).equals( "true" ) )
setGeometryFromConfig();
showAboutInfo();
}
private void setGeometryFromConfig() {
String geometry = appConfig.getProperty( "manager_geometry" );
String geometry = appConfig.getProperty( SlipstreamConfig.MANAGER_GEOMETRY );
if ( geometry != null ) {
int[] xywh = new int[4];
int dividerLoc = -1;
@ -490,7 +490,7 @@ public class ManagerFrame extends JFrame implements ActionListener, ModsScanObse
modFileHashes.clear();
modsTablePanel.clear();
boolean allowZip = appConfig.getProperty( "allow_zip", "false" ).equals( "true" );
boolean allowZip = appConfig.getProperty( SlipstreamConfig.ALLOW_ZIP, "false" ).equals( "true" );
File[] modFiles = modsDir.listFiles( new ModFileFilter( allowZip ) );
List<ModFileInfo> unsortedMods = new ArrayList<ModFileInfo>();
@ -663,16 +663,16 @@ public class ManagerFrame extends JFrame implements ActionListener, ModsScanObse
modFiles.add( modFileInfo.getFile() );
}
File datsDir = new File( appConfig.getProperty( "ftl_dats_path" ) );
File datsDir = new File( appConfig.getProperty( SlipstreamConfig.FTL_DATS_PATH ) );
ModPatchDialog patchDlg = new ModPatchDialog( this, true );
String neverRunFtl = appConfig.getProperty( "never_run_ftl", "false" );
String neverRunFtl = appConfig.getProperty( SlipstreamConfig.NEVER_RUN_FTL, "false" );
if ( !neverRunFtl.equals( "true" ) ) {
File exeFile = null;
String[] exeArgs = null;
if ( appConfig.getProperty( "run_steam_ftl", "false" ).equals( "true" ) ) {
if ( appConfig.getProperty( SlipstreamConfig.RUN_STEAM_FTL, "false" ).equals( "true" ) ) {
exeFile = FTLUtilities.findSteamExe();
exeArgs = new String[] {"-applaunch", FTLUtilities.STEAM_APPID_FTL};
@ -680,6 +680,7 @@ public class ManagerFrame extends JFrame implements ActionListener, ModsScanObse
log.warn( "Steam executable could not be found; FTL will be launched directly" );
}
}
// Try to run directly.
if ( exeFile == null ) {
exeFile = FTLUtilities.findGameExe( datsDir );
exeArgs = new String[0];
@ -772,7 +773,7 @@ public class ManagerFrame extends JFrame implements ActionListener, ModsScanObse
File extractDir = extractChooser.getSelectedFile();
File datsDir = new File( appConfig.getProperty( "ftl_dats_path" ) );
File datsDir = new File( appConfig.getProperty( SlipstreamConfig.FTL_DATS_PATH ) );
DatExtractDialog extractDlg = new DatExtractDialog( this, extractDir, datsDir );
extractDlg.getWorkerThread().setDefaultUncaughtExceptionHandler( this );
@ -781,7 +782,7 @@ public class ManagerFrame extends JFrame implements ActionListener, ModsScanObse
}
else if ( source == sandboxMenuItem ) {
setStatusText( "" );
File datsDir = new File( appConfig.getProperty( "ftl_dats_path" ) );
File datsDir = new File( appConfig.getProperty( SlipstreamConfig.FTL_DATS_PATH ) );
ModXMLSandbox sandboxFrame = new ModXMLSandbox( datsDir );
sandboxFrame.addWindowListener( nerfListener );

View file

@ -27,14 +27,15 @@ import net.vhati.modmanager.ui.FieldEditorPanel.ContentType;
public class SlipstreamConfigDialog extends JFrame implements ActionListener {
protected static final String ALLOW_ZIP = "allow_zip";
protected static final String RUN_STEAM_FTL = "run_steam_ftl";
protected static final String NEVER_RUN_FTL = "never_run_ftl";
protected static final String USE_DEFAULT_UI = "use_default_ui";
protected static final String REMEMBER_GEOMETRY = "remember_geometry";
protected static final String UPDATE_CATALOG = "update_catalog";
protected static final String UPDATE_APP = "update_app";
protected static final String FTL_DATS_PATH = "ftl_dats_path";
protected static final String ALLOW_ZIP = SlipstreamConfig.ALLOW_ZIP;
protected static final String RUN_STEAM_FTL = SlipstreamConfig.RUN_STEAM_FTL;
protected static final String NEVER_RUN_FTL = SlipstreamConfig.NEVER_RUN_FTL;
protected static final String USE_DEFAULT_UI = SlipstreamConfig.USE_DEFAULT_UI;
protected static final String REMEMBER_GEOMETRY = SlipstreamConfig.REMEMBER_GEOMETRY;
protected static final String UPDATE_CATALOG = SlipstreamConfig.UPDATE_CATALOG;
protected static final String UPDATE_APP = SlipstreamConfig.UPDATE_APP;
protected static final String FTL_DATS_PATH = SlipstreamConfig.FTL_DATS_PATH;
protected SlipstreamConfig appConfig;
@ -80,25 +81,25 @@ public class SlipstreamConfigDialog extends JFrame implements ActionListener {
editorPanel.addBlankRow();
editorPanel.addFillRow();
editorPanel.getBoolean( ALLOW_ZIP ).setSelected( appConfig.getProperty( ALLOW_ZIP, "false" ).equals( "true" ) );
editorPanel.getBoolean( RUN_STEAM_FTL ).setSelected( appConfig.getProperty( RUN_STEAM_FTL, "false" ).equals( "true" ) );
editorPanel.getBoolean( NEVER_RUN_FTL ).setSelected( appConfig.getProperty( NEVER_RUN_FTL, "false" ).equals( "true" ) );
editorPanel.getBoolean( USE_DEFAULT_UI ).setSelected( appConfig.getProperty( USE_DEFAULT_UI, "false" ).equals( "true" ) );
editorPanel.getBoolean( REMEMBER_GEOMETRY ).setSelected( appConfig.getProperty( REMEMBER_GEOMETRY, "true" ).equals( "true" ) );
editorPanel.getInt( UPDATE_CATALOG ).setText( Integer.toString(appConfig.getPropertyAsInt( UPDATE_CATALOG, 0 )) );
editorPanel.getInt( UPDATE_APP ).setText( Integer.toString(appConfig.getPropertyAsInt( UPDATE_APP, 0 )) );
editorPanel.getBoolean( ALLOW_ZIP ).setSelected( appConfig.getProperty( SlipstreamConfig.ALLOW_ZIP, "false" ).equals( "true" ) );
editorPanel.getBoolean( RUN_STEAM_FTL ).setSelected( appConfig.getProperty( SlipstreamConfig.RUN_STEAM_FTL, "false" ).equals( "true" ) );
editorPanel.getBoolean( NEVER_RUN_FTL ).setSelected( appConfig.getProperty( SlipstreamConfig.NEVER_RUN_FTL, "false" ).equals( "true" ) );
editorPanel.getBoolean( USE_DEFAULT_UI ).setSelected( appConfig.getProperty( SlipstreamConfig.USE_DEFAULT_UI, "false" ).equals( "true" ) );
editorPanel.getBoolean( REMEMBER_GEOMETRY ).setSelected( appConfig.getProperty( SlipstreamConfig.REMEMBER_GEOMETRY, "true" ).equals( "true" ) );
editorPanel.getInt( UPDATE_CATALOG ).setText( Integer.toString( appConfig.getPropertyAsInt( SlipstreamConfig.UPDATE_CATALOG, 0 ) ) );
editorPanel.getInt( UPDATE_APP ).setText( Integer.toString( appConfig.getPropertyAsInt( SlipstreamConfig.UPDATE_APP, 0 ) ) );
JTextField ftlDatsPathField = editorPanel.getChooser( FTL_DATS_PATH ).getTextField();
ftlDatsPathField.setText( appConfig.getProperty( FTL_DATS_PATH, "" ) );
ftlDatsPathField.setPreferredSize( new Dimension(150, ftlDatsPathField.getPreferredSize().height) );
editorPanel.getChooser( FTL_DATS_PATH ).getButton().addActionListener(this);
ftlDatsPathField.setText( appConfig.getProperty( SlipstreamConfig.FTL_DATS_PATH, "" ) );
ftlDatsPathField.setPreferredSize( new Dimension( 150, ftlDatsPathField.getPreferredSize().height ) );
editorPanel.getChooser( FTL_DATS_PATH ).getButton().addActionListener( this );
JPanel ctrlPanel = new JPanel();
ctrlPanel.setLayout( new BoxLayout( ctrlPanel, BoxLayout.X_AXIS ) );
ctrlPanel.setBorder( BorderFactory.createEmptyBorder( 10, 0, 10, 0 ) );
ctrlPanel.add( Box.createHorizontalGlue() );
applyBtn = new JButton( "Apply" );
applyBtn.addActionListener(this);
applyBtn.addActionListener( this );
ctrlPanel.add( applyBtn );
ctrlPanel.add( Box.createHorizontalGlue() );
@ -106,20 +107,20 @@ public class SlipstreamConfigDialog extends JFrame implements ActionListener {
editorScroll.setVerticalScrollBarPolicy( ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS );
editorScroll.getVerticalScrollBar().setUnitIncrement( 10 );
int vbarWidth = editorScroll.getVerticalScrollBar().getPreferredSize().width;
editorScroll.setPreferredSize( new Dimension(editorPanel.getPreferredSize().width+vbarWidth+5, 400) );
editorScroll.setPreferredSize( new Dimension( editorPanel.getPreferredSize().width+vbarWidth+5, 400 ) );
JPanel contentPane = new JPanel( new BorderLayout() );
contentPane.add( editorScroll, BorderLayout.CENTER );
contentPane.add( ctrlPanel, BorderLayout.SOUTH );
this.setContentPane( contentPane );
this.pack();
this.setMinimumSize( new Dimension(250, 250) );
this.setMinimumSize( new Dimension( 250, 250 ) );
editorScroll.addAncestorListener(new AncestorListener() {
@Override
public void ancestorAdded( AncestorEvent e ) {
editorScroll.getViewport().setViewPosition( new Point(0, 0) );
editorScroll.getViewport().setViewPosition( new Point( 0, 0 ) );
}
@Override
public void ancestorMoved( AncestorEvent e ) {
@ -137,17 +138,17 @@ public class SlipstreamConfigDialog extends JFrame implements ActionListener {
if ( source == applyBtn ) {
String tmp;
appConfig.setProperty( ALLOW_ZIP, editorPanel.getBoolean( ALLOW_ZIP ).isSelected() ? "true" : "false" );
appConfig.setProperty( RUN_STEAM_FTL, editorPanel.getBoolean( RUN_STEAM_FTL ).isSelected() ? "true" : "false" );
appConfig.setProperty( NEVER_RUN_FTL, editorPanel.getBoolean( NEVER_RUN_FTL ).isSelected() ? "true" : "false" );
appConfig.setProperty( USE_DEFAULT_UI, editorPanel.getBoolean( USE_DEFAULT_UI ).isSelected() ? "true" : "false" );
appConfig.setProperty( REMEMBER_GEOMETRY, editorPanel.getBoolean( REMEMBER_GEOMETRY ).isSelected() ? "true" : "false" );
appConfig.setProperty( SlipstreamConfig.ALLOW_ZIP, editorPanel.getBoolean( ALLOW_ZIP ).isSelected() ? "true" : "false" );
appConfig.setProperty( SlipstreamConfig.RUN_STEAM_FTL, editorPanel.getBoolean( RUN_STEAM_FTL ).isSelected() ? "true" : "false" );
appConfig.setProperty( SlipstreamConfig.NEVER_RUN_FTL, editorPanel.getBoolean( NEVER_RUN_FTL ).isSelected() ? "true" : "false" );
appConfig.setProperty( SlipstreamConfig.USE_DEFAULT_UI, editorPanel.getBoolean( USE_DEFAULT_UI ).isSelected() ? "true" : "false" );
appConfig.setProperty( SlipstreamConfig.REMEMBER_GEOMETRY, editorPanel.getBoolean( REMEMBER_GEOMETRY ).isSelected() ? "true" : "false" );
tmp = editorPanel.getInt( UPDATE_CATALOG ).getText();
try {
int n = Integer.parseInt( tmp );
n = Math.max( 0, n );
appConfig.setProperty( UPDATE_CATALOG, Integer.toString( n ) );
appConfig.setProperty( SlipstreamConfig.UPDATE_CATALOG, Integer.toString( n ) );
}
catch ( NumberFormatException f ) {}
@ -155,13 +156,13 @@ public class SlipstreamConfigDialog extends JFrame implements ActionListener {
try {
int n = Integer.parseInt( tmp );
n = Math.max( 0, n );
appConfig.setProperty( UPDATE_APP, Integer.toString( n ) );
appConfig.setProperty( SlipstreamConfig.UPDATE_APP, Integer.toString( n ) );
}
catch ( NumberFormatException f ) {}
tmp = editorPanel.getChooser( FTL_DATS_PATH ).getTextField().getText();
if ( tmp.length() > 0 && FTLUtilities.isDatsDirValid( new File(tmp) ) ) {
appConfig.setProperty( FTL_DATS_PATH, tmp );
if ( tmp.length() > 0 && FTLUtilities.isDatsDirValid( new File( tmp ) ) ) {
appConfig.setProperty( SlipstreamConfig.FTL_DATS_PATH, tmp );
}
this.setVisible( false );