Moderate code cleanup
This commit is contained in:
parent
598b67d4bb
commit
34a71e0aa5
1 changed files with 104 additions and 74 deletions
|
@ -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 xdgDataHome = System.getenv("XDG_DATA_HOME");
|
String programFiles86 = System.getenv( "ProgramFiles(x86)" );
|
||||||
if ( xdgDataHome == null )
|
String programFiles = System.getenv( "ProgramFiles" );
|
||||||
xdgDataHome = System.getProperty("user.home") +"/.local/share";
|
|
||||||
|
|
||||||
String winePrefix = System.getProperty("WINEPREFIX");
|
String home = System.getProperty( "user.home" );
|
||||||
if ( winePrefix == null )
|
|
||||||
winePrefix = System.getProperty("user.home") +"/.wine";
|
|
||||||
|
|
||||||
File[] candidates = new File[] {
|
String xdgDataHome = System.getenv( "XDG_DATA_HOME" );
|
||||||
// Windows - Steam
|
if ( xdgDataHome == null && home != null )
|
||||||
new File( new File(""+System.getenv("ProgramFiles(x86)")), steamPath ),
|
xdgDataHome = home +"/.local/share";
|
||||||
new File( new File(""+System.getenv("ProgramFiles")), steamPath ),
|
|
||||||
// Windows - GOG
|
String winePrefix = System.getProperty( "WINEPREFIX" );
|
||||||
new File( new File(""+System.getenv("ProgramFiles(x86)")), gogPath ),
|
if ( winePrefix == null && home != null )
|
||||||
new File( new File(""+System.getenv("ProgramFiles")), gogPath ),
|
winePrefix = home +"/.wine";
|
||||||
// Windows - Humble Bundle
|
|
||||||
new File( new File(""+System.getenv("ProgramFiles(x86)")), humblePath ),
|
List<File> candidates = new ArrayList<File>();
|
||||||
new File( new File(""+System.getenv("ProgramFiles")), humblePath ),
|
// Windows - Steam, GOG, Humble Bundle.
|
||||||
// Linux - Steam
|
if ( programFiles86 != null ) {
|
||||||
new File( xdgDataHome +"/Steam/SteamApps/common/FTL Faster Than Light/data/resources" ),
|
candidates.add( new File( new File( programFiles86 ), steamPath ) );
|
||||||
new File( xdgDataHome +"/Steam/steamapps/common/FTL Faster Than Light/data/resources" ),
|
candidates.add( new File( new File( programFiles86 ), gogPath ) );
|
||||||
new File( System.getProperty("user.home") +"/.steam/steam/SteamApps/common/FTL Faster Than Light/data/resources" ),
|
candidates.add( new File( new File( programFiles86 ), humblePath ) );
|
||||||
new File( System.getProperty("user.home") +"/.steam/steam/steamapps/common/FTL Faster Than Light/data/resources" ),
|
}
|
||||||
// OSX - Steam
|
if ( programFiles != null ) {
|
||||||
new File( System.getProperty("user.home") +"/Library/Application Support/Steam/SteamApps/common/FTL Faster Than Light/FTL.app/Contents/Resources" ),
|
candidates.add( new File( new File( programFiles ), steamPath ) );
|
||||||
new File( System.getProperty("user.home") +"/Library/Application Support/Steam/steamapps/common/FTL Faster Than Light/FTL.app/Contents/Resources" ),
|
candidates.add( new File( new File( programFiles ), gogPath ) );
|
||||||
// OSX
|
candidates.add( new File( new File( programFiles ), humblePath ) );
|
||||||
new File( "/Applications/FTL.app/Contents/Resources" ),
|
}
|
||||||
// Linux Wine
|
// Linux - Steam.
|
||||||
new File( winePrefix +"/drive_c/Program Files (x86)/"+ gogPath ),
|
if ( xdgDataHome != null ) {
|
||||||
new File( winePrefix +"/drive_c/Program Files/"+ gogPath ),
|
candidates.add( new File( xdgDataHome +"/Steam/steamapps/common/FTL Faster Than Light/data/resources" ) );
|
||||||
new File( winePrefix +"/drive_c/Program Files (x86)/"+ humblePath ),
|
candidates.add( new File( xdgDataHome +"/Steam/SteamApps/common/FTL Faster Than Light/data/resources" ) );
|
||||||
new File( winePrefix +"/drive_c/Program Files/"+ humblePath )
|
}
|
||||||
};
|
if ( home != null ) {
|
||||||
|
candidates.add( new File( home +"/.steam/steam/steamapps/common/FTL Faster Than Light/data/resources" ) );
|
||||||
|
candidates.add( new File( home +"/.steam/steam/SteamApps/common/FTL Faster Than Light/data/resources" ) );
|
||||||
|
}
|
||||||
|
// Linux - Wine.
|
||||||
|
if ( winePrefix != null ) {
|
||||||
|
candidates.add( new File( winePrefix +"/drive_c/Program Files (x86)/"+ gogPath ) );
|
||||||
|
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;
|
||||||
|
|
||||||
|
@ -110,21 +126,22 @@ public class FTLUtilities {
|
||||||
return "FTL Data File - (FTL dir)/resources/data.dat";
|
return "FTL Data File - (FTL dir)/resources/data.dat";
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File f) {
|
public boolean accept( File f ) {
|
||||||
return f.isDirectory() || f.getName().equals("data.dat") || f.getName().equals("FTL.app");
|
return f.isDirectory() || f.getName().equals( "data.dat" ) || f.getName().equals( "FTL.app" );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fc.setMultiSelectionEnabled(false);
|
fc.setMultiSelectionEnabled(false);
|
||||||
|
|
||||||
if ( fc.showOpenDialog( parentComponent ) == JFileChooser.APPROVE_OPTION ) {
|
if ( fc.showOpenDialog( parentComponent ) == JFileChooser.APPROVE_OPTION ) {
|
||||||
File f = fc.getSelectedFile();
|
File f = fc.getSelectedFile();
|
||||||
if ( f.getName().equals("data.dat") ) {
|
if ( f.getName().equals( "data.dat" ) ) {
|
||||||
result = f.getParentFile();
|
result = f.getParentFile();
|
||||||
}
|
}
|
||||||
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" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,21 +163,21 @@ public class FTLUtilities {
|
||||||
public static File findGameExe( File datsDir ) {
|
public static File findGameExe( File datsDir ) {
|
||||||
File result = null;
|
File result = null;
|
||||||
|
|
||||||
if ( System.getProperty("os.name").startsWith("Windows") ) {
|
if ( System.getProperty( "os.name" ).startsWith( "Windows" ) ) {
|
||||||
File ftlDir = datsDir.getParentFile();
|
File ftlDir = datsDir.getParentFile();
|
||||||
if ( ftlDir != null ) {
|
if ( ftlDir != null ) {
|
||||||
File exeFile = new File( ftlDir, "FTLGame.exe" );
|
File exeFile = new File( ftlDir, "FTLGame.exe" );
|
||||||
if ( exeFile.exists() ) result = exeFile;
|
if ( exeFile.exists() ) result = exeFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( System.getProperty("os.name").equals("Linux") ) {
|
else if ( System.getProperty( "os.name" ).equals( "Linux" ) ) {
|
||||||
File ftlDir = datsDir.getParentFile();
|
File ftlDir = datsDir.getParentFile();
|
||||||
if ( ftlDir != null ) {
|
if ( ftlDir != null ) {
|
||||||
File exeFile = new File( ftlDir, "FTL" );
|
File exeFile = new File( ftlDir, "FTL" );
|
||||||
if ( exeFile.exists() ) result = exeFile;
|
if ( exeFile.exists() ) result = exeFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( System.getProperty("os.name").contains("OS X") ) {
|
else if ( System.getProperty( "os.name" ).contains( "OS X" ) ) {
|
||||||
// FTL.app/Contents/Resources/
|
// FTL.app/Contents/Resources/
|
||||||
File contentsDir = datsDir.getParentFile();
|
File contentsDir = datsDir.getParentFile();
|
||||||
if ( contentsDir != null ) {
|
if ( contentsDir != null ) {
|
||||||
|
@ -186,30 +203,35 @@ 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" ),
|
|
||||||
new File( new File(""+System.getenv("ProgramFiles")), "Steam/Steam.exe" )
|
|
||||||
};
|
|
||||||
|
|
||||||
for ( File candidate : candidates ) {
|
List<File> candidates = new ArrayList<File>();
|
||||||
if ( candidate.exists() ) {
|
|
||||||
result = candidate;
|
if ( osName.startsWith( "Windows" ) ) {
|
||||||
break;
|
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 ( System.getProperty("os.name").equals("Linux") ) {
|
else if ( osName.equals( "Linux" ) ) {
|
||||||
File candidate = new File( "/usr/bin/steam" );
|
candidates.add( new File( "/usr/bin/steam" ) );
|
||||||
|
}
|
||||||
if ( candidate.exists() ) result = candidate;
|
else if ( osName.contains( "OS X" ) ) {
|
||||||
|
candidates.add( new File( "/Applications/Steam.app" ) );
|
||||||
}
|
}
|
||||||
else if ( System.getProperty("os.name").contains("OS X") ) {
|
|
||||||
File candidate = new File( "/Applications/Steam.app" );
|
|
||||||
|
|
||||||
if ( candidate.exists() ) result = candidate;
|
File result = null;
|
||||||
|
|
||||||
|
for ( File candidate : candidates ) {
|
||||||
|
if ( candidate.exists() ) {
|
||||||
|
result = candidate;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -233,7 +255,7 @@ public class FTLUtilities {
|
||||||
|
|
||||||
Process result = null;
|
Process result = null;
|
||||||
ProcessBuilder pb = null;
|
ProcessBuilder pb = null;
|
||||||
if ( System.getProperty("os.name").contains("OS X") ) {
|
if ( System.getProperty( "os.name" ).contains( "OS X" ) ) {
|
||||||
String[] args = new String[3 + exeArgs.length];
|
String[] args = new String[3 + exeArgs.length];
|
||||||
args[0] = "open";
|
args[0] = "open";
|
||||||
args[1] = "-a";
|
args[1] = "-a";
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue