Moderate code cleanup

This commit is contained in:
Vhati 2017-12-04 13:36:04 -05:00
parent 598b67d4bb
commit 34a71e0aa5

View file

@ -3,6 +3,8 @@ package net.vhati.modmanager.core;
import java.awt.Component; import java.awt.Component;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
@ -34,40 +36,54 @@ public class FTLUtilities {
String gogPath = "GOG.com/Faster Than Light/resources"; String gogPath = "GOG.com/Faster Than Light/resources";
String humblePath = "FTL/resources"; String humblePath = "FTL/resources";
String programFiles86 = System.getenv( "ProgramFiles(x86)" );
String programFiles = System.getenv( "ProgramFiles" );
String home = System.getProperty( "user.home" );
String xdgDataHome = System.getenv( "XDG_DATA_HOME" ); String xdgDataHome = System.getenv( "XDG_DATA_HOME" );
if ( xdgDataHome == null ) if ( xdgDataHome == null && home != null )
xdgDataHome = System.getProperty("user.home") +"/.local/share"; xdgDataHome = home +"/.local/share";
String winePrefix = System.getProperty( "WINEPREFIX" ); String winePrefix = System.getProperty( "WINEPREFIX" );
if ( winePrefix == null ) if ( winePrefix == null && home != null )
winePrefix = System.getProperty("user.home") +"/.wine"; winePrefix = home +"/.wine";
File[] candidates = new File[] { List<File> candidates = new ArrayList<File>();
// Windows - Steam // Windows - Steam, GOG, Humble Bundle.
new File( new File(""+System.getenv("ProgramFiles(x86)")), steamPath ), if ( programFiles86 != null ) {
new File( new File(""+System.getenv("ProgramFiles")), steamPath ), candidates.add( new File( new File( programFiles86 ), steamPath ) );
// Windows - GOG candidates.add( new File( new File( programFiles86 ), gogPath ) );
new File( new File(""+System.getenv("ProgramFiles(x86)")), gogPath ), candidates.add( new File( new File( programFiles86 ), humblePath ) );
new File( new File(""+System.getenv("ProgramFiles")), gogPath ), }
// Windows - Humble Bundle if ( programFiles != null ) {
new File( new File(""+System.getenv("ProgramFiles(x86)")), humblePath ), candidates.add( new File( new File( programFiles ), steamPath ) );
new File( new File(""+System.getenv("ProgramFiles")), humblePath ), candidates.add( new File( new File( programFiles ), gogPath ) );
// Linux - Steam candidates.add( new File( new File( programFiles ), humblePath ) );
new File( xdgDataHome +"/Steam/SteamApps/common/FTL Faster Than Light/data/resources" ), }
new File( xdgDataHome +"/Steam/steamapps/common/FTL Faster Than Light/data/resources" ), // Linux - Steam.
new File( System.getProperty("user.home") +"/.steam/steam/SteamApps/common/FTL Faster Than Light/data/resources" ), if ( xdgDataHome != null ) {
new File( System.getProperty("user.home") +"/.steam/steam/steamapps/common/FTL Faster Than Light/data/resources" ), candidates.add( new File( xdgDataHome +"/Steam/steamapps/common/FTL Faster Than Light/data/resources" ) );
// OSX - Steam candidates.add( new File( xdgDataHome +"/Steam/SteamApps/common/FTL Faster Than Light/data/resources" ) );
new File( System.getProperty("user.home") +"/Library/Application Support/Steam/SteamApps/common/FTL Faster Than Light/FTL.app/Contents/Resources" ), }
new File( System.getProperty("user.home") +"/Library/Application Support/Steam/steamapps/common/FTL Faster Than Light/FTL.app/Contents/Resources" ), if ( home != null ) {
// OSX candidates.add( new File( home +"/.steam/steam/steamapps/common/FTL Faster Than Light/data/resources" ) );
new File( "/Applications/FTL.app/Contents/Resources" ), candidates.add( new File( home +"/.steam/steam/SteamApps/common/FTL Faster Than Light/data/resources" ) );
// Linux Wine }
new File( winePrefix +"/drive_c/Program Files (x86)/"+ gogPath ), // Linux - Wine.
new File( winePrefix +"/drive_c/Program Files/"+ gogPath ), if ( winePrefix != null ) {
new File( winePrefix +"/drive_c/Program Files (x86)/"+ humblePath ), candidates.add( new File( winePrefix +"/drive_c/Program Files (x86)/"+ gogPath ) );
new File( winePrefix +"/drive_c/Program Files/"+ humblePath ) candidates.add( new File( winePrefix +"/drive_c/Program Files (x86)/"+ humblePath ) );
}; candidates.add( new File( winePrefix +"/drive_c/Program Files/"+ gogPath ) );
candidates.add( new File( winePrefix +"/drive_c/Program Files/"+ humblePath ) );
}
// OSX - Steam.
if ( home != null ) {
candidates.add( new File( home +"/Library/Application Support/Steam/steamapps/common/FTL Faster Than Light/FTL.app/Contents/Resources" ) );
candidates.add( new File( home +"/Library/Application Support/Steam/SteamApps/common/FTL Faster Than Light/FTL.app/Contents/Resources" ) );
}
// OSX - Standalone.
candidates.add( new File( "/Applications/FTL.app/Contents/Resources" ) );
File result = null; File result = null;
@ -123,10 +139,11 @@ public class FTLUtilities {
} }
else if ( f.getName().endsWith( ".app" ) && f.isDirectory() ) { else if ( f.getName().endsWith( ".app" ) && f.isDirectory() ) {
File contentsPath = new File( f, "Contents" ); File contentsPath = new File( f, "Contents" );
if( contentsPath.exists() && contentsPath.isDirectory() && new File(contentsPath, "Resources").exists() ) if ( contentsPath.exists() && contentsPath.isDirectory() && new File( contentsPath, "Resources" ).exists() ) {
result = new File( contentsPath, "Resources" ); result = new File( contentsPath, "Resources" );
} }
} }
}
if ( result != null && isDatsDirValid( result ) ) { if ( result != null && isDatsDirValid( result ) ) {
return result; return result;
@ -186,13 +203,29 @@ public class FTLUtilities {
* The args to launch FTL are: ["-applaunch", STEAM_APPID_FTL] * The args to launch FTL are: ["-applaunch", STEAM_APPID_FTL]
*/ */
public static File findSteamExe() { public static File findSteamExe() {
File result = null; String programFiles86 = System.getenv( "ProgramFiles(x86)" );
String programFiles = System.getenv( "ProgramFiles" );
if ( System.getProperty("os.name").startsWith("Windows") ) { String osName = System.getProperty( "os.name" );
File[] candidates = new File[] {
new File( new File(""+System.getenv("ProgramFiles(x86)")), "Steam/Steam.exe" ), List<File> candidates = new ArrayList<File>();
new File( new File(""+System.getenv("ProgramFiles")), "Steam/Steam.exe" )
}; if ( osName.startsWith( "Windows" ) ) {
if ( programFiles86 != null ) {
candidates.add( new File( new File( programFiles86 ), "Steam/Steam.exe" ) );
}
if ( programFiles != null ) {
candidates.add( new File( new File( programFiles ), "Steam/Steam.exe" ) );
}
}
else if ( osName.equals( "Linux" ) ) {
candidates.add( new File( "/usr/bin/steam" ) );
}
else if ( osName.contains( "OS X" ) ) {
candidates.add( new File( "/Applications/Steam.app" ) );
}
File result = null;
for ( File candidate : candidates ) { for ( File candidate : candidates ) {
if ( candidate.exists() ) { if ( candidate.exists() ) {
@ -200,17 +233,6 @@ public class FTLUtilities {
break; break;
} }
} }
}
else if ( System.getProperty("os.name").equals("Linux") ) {
File candidate = new File( "/usr/bin/steam" );
if ( candidate.exists() ) result = candidate;
}
else if ( System.getProperty("os.name").contains("OS X") ) {
File candidate = new File( "/Applications/Steam.app" );
if ( candidate.exists() ) result = candidate;
}
return result; return result;
} }
@ -261,21 +283,29 @@ public class FTLUtilities {
* Returns the directory for user profiles and saved games, or null. * Returns the directory for user profiles and saved games, or null.
*/ */
public static File findUserDataDir() { public static File findUserDataDir() {
String home = System.getProperty( "user.home" );
String xdgDataHome = System.getenv( "XDG_DATA_HOME" ); String xdgDataHome = System.getenv( "XDG_DATA_HOME" );
if ( xdgDataHome == null ) if ( xdgDataHome == null && home != null )
xdgDataHome = System.getProperty("user.home") +"/.local/share"; xdgDataHome = home +"/.local/share";
File[] candidates = new File[] { List<File> candidates = new ArrayList<File>();
// Windows XP
new File( System.getProperty("user.home") +"/My Documents/My Games/FasterThanLight" ), // Windows.
// Windows Vista/7 if ( home != null ) {
new File( System.getProperty("user.home") +"/Documents/My Games/FasterThanLight" ), // Windows XP.
// Linux candidates.add( new File( home +"/My Documents/My Games/FasterThanLight" ) );
new File( xdgDataHome +"/FasterThanLight" ), // Windows Vista/7/etc.
// OSX candidates.add( new File( home +"/Documents/My Games/FasterThanLight" ) );
new File( System.getProperty("user.home") +"/Library/Application Support/FasterThanLight" ) }
}; // Linux.
if ( xdgDataHome != null ) {
candidates.add( new File( xdgDataHome +"/FasterThanLight" ) );
}
// OSX.
if ( home != null ) {
candidates.add( new File( home +"/Library/Application Support/FasterThanLight" ) );
}
File result = null; File result = null;