Added FTLUtilities.findUserDataDir()

This commit is contained in:
Vhati 2013-09-23 07:13:25 -04:00
parent d635ce0158
commit b980f4cdf6
3 changed files with 36 additions and 2 deletions

View file

@ -121,4 +121,4 @@ public class EmptyAwareSAXHandlerFactory implements SAXHandlerFactory {
}
}
}
}
}

View file

@ -29,7 +29,7 @@ public class FTLUtilities {
String humblePath = "FTL/resources";
String xdgDataHome = System.getenv("XDG_DATA_HOME");
if (xdgDataHome == null)
if ( xdgDataHome == null )
xdgDataHome = System.getProperty("user.home") +"/.local/share";
File[] candidates = new File[] {
@ -174,4 +174,37 @@ public class FTLUtilities {
}
return result;
}
/**
* Returns the directory for user profiles and saved games, or null.
*/
public static File findUserDataDir() {
String xdgDataHome = System.getenv("XDG_DATA_HOME");
if ( xdgDataHome == null )
xdgDataHome = System.getProperty("user.home") +"/.local/share";
File[] candidates = new File[] {
// Windows XP
new File( System.getProperty("user.home") +"/My Documents/My Games/FasterThanLight" ),
// Windows Vista/7
new File( System.getProperty("user.home") +"/Documents/My Games/FasterThanLight" ),
// Linux
new File( xdgDataHome +"/FasterThanLight" ),
// OSX
new File( System.getProperty("user.home") +"/Library/Application Support/FasterThanLight" )
};
File result = null;
for ( File candidate : candidates ) {
if ( candidate.isDirectory() && candidate.exists() ) {
result = candidate;
break;
}
}
return result;
}
}

View file

@ -27,6 +27,7 @@ import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import net.vhati.modmanager.core.EmptyAwareSAXHandlerFactory;
import net.vhati.modmanager.core.Report;
import net.vhati.modmanager.core.Report.ReportMessage;
import net.vhati.modmanager.core.SloppyXMLParser;