Fixed issue 5: Localized Windows cause save problems for Gridworks. jdatapath library returns a path in which each unicode character (in the user ID) has been replaced by ?. So we need to grab the actual user ID from environment variables such as APPDATA or USERPROFILE.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@707 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-05-11 04:16:26 +00:00
parent 3d59ba713e
commit 114be582e8

View File

@ -82,7 +82,7 @@ public class ProjectManager {
// it's not elegant but it's the safest bet.
DataPath localDataPath = JDataPathSystem.getLocalSystem().getLocalDataPath("Gridworks");
File data = new File(localDataPath.getPath());
File data = new File(fixWindowsUnicodePath(localDataPath.getPath()));
data.mkdirs();
return data;
} catch (Error e) {
@ -139,6 +139,31 @@ public class ProjectManager {
}
}
/**
* For Windows file paths that contain user IDs with non ASCII characters,
* those characters might get replaced with ?. We need to use the environment
* APPDATA value to substitute back the original user ID.
*/
static protected String fixWindowsUnicodePath(String path) {
int q = path.indexOf('?');
if (q < 0) {
return path;
}
int pathSep = path.indexOf(File.separatorChar, q);
String goodPath = System.getenv("APPDATA");
if (goodPath == null || goodPath.length() == 0) {
goodPath = System.getenv("USERPROFILE");
if (!goodPath.endsWith(File.separator)) {
goodPath = goodPath + File.separator;
}
}
int goodPathSep = goodPath.indexOf(File.separatorChar, q);
return path.substring(0, q) + goodPath.substring(q, goodPathSep) + path.substring(pathSep);
}
private ProjectManager(File dir) {
_workspaceDir = dir;
_workspaceDir.mkdirs();