diff --git a/src/main/java/net/vhati/modmanager/core/SlipstreamConfig.java b/src/main/java/net/vhati/modmanager/core/SlipstreamConfig.java index 976dfdf..72d0008 100644 --- a/src/main/java/net/vhati/modmanager/core/SlipstreamConfig.java +++ b/src/main/java/net/vhati/modmanager/core/SlipstreamConfig.java @@ -5,11 +5,25 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import java.util.Properties; public class SlipstreamConfig { + public static final String ALLOW_ZIP = "allow_zip"; + public static final String FTL_DATS_PATH = "ftl_dats_path"; + public static final String RUN_STEAM_FTL = "run_steam_ftl"; + public static final String NEVER_RUN_FTL = "never_run_ftl"; + public static final String UPDATE_CATALOG = "update_catalog"; + public static final String UPDATE_APP = "update_app"; + public static final String USE_DEFAULT_UI = "use_default_ui"; + public static final String REMEMBER_GEOMETRY = "remember_geometry"; + public static final String MANAGER_GEOMETRY = "manager_geometry"; + private Properties config; private File configFile; @@ -60,21 +74,40 @@ public class SlipstreamConfig { OutputStream out = null; try { out = new FileOutputStream( configFile ); - String configComments = ""; - configComments += "\n"; - configComments += " allow_zip - Sets whether to treat .zip files as .ftl files. Default: false.\n"; - configComments += " ftl_dats_path - The path to FTL's resources folder. If invalid, you'll be prompted.\n"; - configComments += " run_steam_ftl - If true, SMM will use Steam to launch FTL, if possible. Default: false.\n"; - configComments += " never_run_ftl - If true, there will be no offer to run FTL after patching. Default: false.\n"; - configComments += " update_catalog - If a number greater than 0, check for new mod descriptions every N days.\n"; - configComments += " update_app - If a number greater than 0, check for newer app versions every N days.\n"; - configComments += " use_default_ui - If true, no attempt will be made to resemble a native GUI. Default: false.\n"; - configComments += " remember_geometry - If true, window geometry will be saved on exit and restored on startup.\n"; - configComments += "\n"; - configComments += " manager_geometry - Last saved position/size/etc of the main window.\n"; + + Map userFieldsMap = new LinkedHashMap(); + Map appFieldsMap = new LinkedHashMap(); + + userFieldsMap.put( ALLOW_ZIP, "Sets whether to treat .zip files as .ftl files. Default: false." ); + userFieldsMap.put( FTL_DATS_PATH, "The path to FTL's resources folder. If invalid, you'll be prompted." ); + userFieldsMap.put( RUN_STEAM_FTL, "If true, SMM will use Steam to launch FTL, if possible. Default: false." ); + userFieldsMap.put( NEVER_RUN_FTL, "If true, there will be no offer to run FTL after patching. Default: false." ); + userFieldsMap.put( UPDATE_CATALOG, "If a number greater than 0, check for new mod descriptions every N days." ); + userFieldsMap.put( UPDATE_APP, "If a number greater than 0, check for newer app versions every N days." ); + userFieldsMap.put( USE_DEFAULT_UI, "If true, no attempt will be made to resemble a native GUI. Default: false." ); + userFieldsMap.put( REMEMBER_GEOMETRY, "If true, window geometry will be saved on exit and restored on startup." ); + + appFieldsMap.put( MANAGER_GEOMETRY, "Last saved position/size/etc of the main window." ); + + List allFieldsList = new ArrayList( userFieldsMap.size() + appFieldsMap.size() ); + allFieldsList.addAll( userFieldsMap.keySet() ); + allFieldsList.addAll( userFieldsMap.keySet() ); + int fieldWidth = 0; + for ( String fieldName : allFieldsList ) { + fieldWidth = Math.max( fieldName.length(), fieldWidth ); + } + + StringBuilder commentsBuf = new StringBuilder( "\n" ); + for ( Map.Entry entry : userFieldsMap.entrySet() ) { + commentsBuf.append( String.format( " %-"+ fieldWidth +"s - %s\n", entry.getKey(), entry.getValue() ) ); + } + commentsBuf.append( "\n" ); + for ( Map.Entry entry : appFieldsMap.entrySet() ) { + commentsBuf.append( String.format( " %-"+ fieldWidth +"s - %s\n", entry.getKey(), entry.getValue() ) ); + } OutputStreamWriter writer = new OutputStreamWriter( out, "UTF-8" ); - config.store( writer, configComments ); + config.store( writer, commentsBuf.toString() ); writer.flush(); } finally {