From ba011d78eefd261c21cc263c341ef4a1cdf26373 Mon Sep 17 00:00:00 2001 From: Vhati Date: Mon, 11 Dec 2017 02:04:22 -0500 Subject: [PATCH] Made the commandline interface aware of STEAM_EXE_PATH --- .../vhati/modmanager/cli/SlipstreamCLI.java | 67 +++++++++++++------ .../vhati/modmanager/core/ModPatchThread.java | 2 +- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/vhati/modmanager/cli/SlipstreamCLI.java b/src/main/java/net/vhati/modmanager/cli/SlipstreamCLI.java index b286497..bc4341c 100644 --- a/src/main/java/net/vhati/modmanager/cli/SlipstreamCLI.java +++ b/src/main/java/net/vhati/modmanager/cli/SlipstreamCLI.java @@ -166,12 +166,12 @@ public class SlipstreamCLI { } File configFile = new File( "modman.cfg" ); - Properties config = getConfig( configFile ); + SlipstreamConfig appConfig = getConfig( configFile ); if ( cmdline.hasOption( "list-mods" ) ) { // Exits. log.info( "Listing mods..." ); - boolean allowZip = config.getProperty( SlipstreamConfig.ALLOW_ZIP, "false" ).equals( "true" ); + boolean allowZip = appConfig.getProperty( SlipstreamConfig.ALLOW_ZIP, "false" ).equals( "true" ); File[] modFiles = modsDir.listFiles( new ModAndDirFileFilter( allowZip, true ) ); List dirList = new ArrayList(); List fileList = new ArrayList(); @@ -193,7 +193,7 @@ public class SlipstreamCLI { if ( cmdline.hasOption( "extract-dats" ) || cmdline.hasOption( "patch" ) || cmdline.hasOption( "runftl" ) ) { - datsDir = getDatsDir( config ); + datsDir = getDatsDir( appConfig ); } if ( cmdline.hasOption( "extract-dats" ) ) { // Exits (0/1). @@ -306,19 +306,34 @@ public class SlipstreamCLI { File exeFile = null; String[] exeArgs = null; - if ( config.getProperty( SlipstreamConfig.RUN_STEAM_FTL, "false" ).equals( "true" ) ) { - exeFile = FTLUtilities.findSteamExe(); - exeArgs = new String[] {"-applaunch", FTLUtilities.STEAM_APPID_FTL}; + // Try to run via Steam. + if ( "true".equals( appConfig.getProperty( SlipstreamConfig.RUN_STEAM_FTL, "false" ) ) ) { + + String steamPath = appConfig.getProperty( SlipstreamConfig.STEAM_EXE_PATH ); + if ( steamPath.length() > 0 ) { + exeFile = new File( steamPath ); + + if ( exeFile.exists() ) { + exeArgs = new String[] {"-applaunch", FTLUtilities.STEAM_APPID_FTL}; + } + else { + log.warn( String.format( "%s does not exist: %s", SlipstreamConfig.STEAM_EXE_PATH, exeFile.getAbsolutePath() ) ); + exeFile = null; + } + } if ( exeFile == null ) { - log.warn( "Steam executable could not be found; FTL will be launched directly" ); + log.warn( "Steam executable could not be found, so FTL will be launched directly" ); } + } + // Try to run directly. if ( exeFile == null ) { exeFile = FTLUtilities.findGameExe( datsDir ); - exeArgs = new String[0]; - if ( exeFile == null ) { + if ( exeFile != null ) { + exeArgs = new String[0]; + } else { log.warn( "FTL executable could not be found" ); } } @@ -326,7 +341,8 @@ public class SlipstreamCLI { if ( exeFile != null ) { try { FTLUtilities.launchExe( exeFile, exeArgs ); - } catch ( Exception e ) { + } + catch ( Exception e ) { log.error( "Error launching FTL", e ); System.exit( 1 ); } @@ -349,14 +365,19 @@ public class SlipstreamCLI { * If an error occurs, it'll be logged, * and default settings will be returned. */ - private static Properties getConfig( File configFile ) { + private static SlipstreamConfig getConfig( File configFile ) { - Properties config = new Properties(); - 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" ); + Properties props = new Properties(); + props.setProperty( SlipstreamConfig.ALLOW_ZIP, "false" ); + props.setProperty( SlipstreamConfig.FTL_DATS_PATH, "" ); + props.setProperty( SlipstreamConfig.STEAM_EXE_PATH, "" ); + props.setProperty( SlipstreamConfig.RUN_STEAM_FTL, "false" ); + props.setProperty( SlipstreamConfig.NEVER_RUN_FTL, "false" ); + props.setProperty( SlipstreamConfig.USE_DEFAULT_UI, "false" ); + props.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. // Read the config file. InputStream in = null; @@ -364,7 +385,7 @@ public class SlipstreamCLI { if ( configFile.exists() ) { log.trace( "Loading properties from config file" ); in = new FileInputStream( configFile ); - config.load( new InputStreamReader( in, "UTF-8" ) ); + props.load( new InputStreamReader( in, "UTF-8" ) ); } } catch ( IOException e ) { @@ -375,7 +396,8 @@ public class SlipstreamCLI { catch ( IOException e ) {} } - return config; + SlipstreamConfig appConfig = new SlipstreamConfig( props, configFile ); + return appConfig; } @@ -383,18 +405,19 @@ public class SlipstreamCLI { * Checks the validity of the config's dats path and returns it. * Or exits if the path is invalid. */ - private static File getDatsDir( Properties config ) { + private static File getDatsDir( SlipstreamConfig appConfig ) { File datsDir = null; - String datsPath = config.getProperty( SlipstreamConfig.FTL_DATS_PATH, "" ); + String datsPath = appConfig.getProperty( SlipstreamConfig.FTL_DATS_PATH, "" ); if ( datsPath.length() > 0 ) { log.info( "Using FTL dats path from config: "+ datsPath ); datsDir = new File( datsPath ); if ( FTLUtilities.isDatsDirValid( datsDir ) == false ) { - log.error( "The config's ftl_dats_path does not exist" ); + log.error( "The config's "+ SlipstreamConfig.FTL_DATS_PATH +" does not exist, or it is invalid" ); datsDir = null; } - } else { + } + else { log.error( "No FTL dats path previously set" ); } if ( datsDir == null ) { diff --git a/src/main/java/net/vhati/modmanager/core/ModPatchThread.java b/src/main/java/net/vhati/modmanager/core/ModPatchThread.java index 1778c64..b51b67b 100644 --- a/src/main/java/net/vhati/modmanager/core/ModPatchThread.java +++ b/src/main/java/net/vhati/modmanager/core/ModPatchThread.java @@ -276,7 +276,7 @@ public class ModPatchThread extends Thread { else { InputStream mainStream = null; try { - mainStream = pack.getInputStream(innerPath); + mainStream = pack.getInputStream( innerPath ); InputStream mergedStream = ModUtilities.patchXMLFile( mainStream, zis, "windows-1252", globalPanic, pack.getName()+":"+innerPath, modFile.getName()+":"+parentPath+fileName ); mainStream.close(); pack.remove( innerPath );