Hopefully a more robust way to get the user data dir on Windows, especially on Windows Vista 64-bit, which jdatapath.dll isn't built for.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@311 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-03-17 03:51:58 +00:00
parent e1d064f25c
commit b26160dc2b

View File

@ -53,14 +53,38 @@ public class ProjectManager {
String os = Configurations.get("os.name").toLowerCase();
if (os.contains("windows")) {
// NOTE(SM): finding the "local data app" in windows from java is actually a PITA
// see http://stackoverflow.com/questions/1198911/how-to-get-local-application-data-folder-in-java
// so we're using a library that uses JNI to ask directly the win32 APIs,
// it's not elegant but it's the safest bet
DataPath localDataPath = JDataPathSystem.getLocalSystem().getLocalDataPath("Gridworks");
File data = new File(localDataPath.getPath());
data.mkdirs();
return data;
try {
// NOTE(SM): finding the "local data app" in windows from java is actually a PITA
// see http://stackoverflow.com/questions/1198911/how-to-get-local-application-data-folder-in-java
// so we're using a library that uses JNI to ask directly the win32 APIs,
// it's not elegant but it's the safest bet
DataPath localDataPath = JDataPathSystem.getLocalSystem().getLocalDataPath("Gridworks");
File data = new File(localDataPath.getPath());
data.mkdirs();
return data;
} catch (Error e) {
Gridworks.log("Failed to use jdatapath to detect user data path. Resorting to environment variables.");
String appData = System.getenv("APPDATA");
File parentDir = null;
if (appData != null && appData.length() > 0) {
parentDir = new File(appData);
} else {
String userProfile = System.getenv("USERPROFILE");
if (userProfile != null && userProfile.length() > 0) {
parentDir = new File(userProfile);
}
}
if (parentDir == null) {
parentDir = new File(".");
}
File data = new File(parentDir, "Gridworks");
data.mkdirs();
return data;
}
} else if (os.contains("mac os x")) {
// on macosx, use "~/Library/Application Support"
String home = System.getProperty("user.home");