From 114be582e804d796119598ada772a81fee0b9f4e Mon Sep 17 00:00:00 2001 From: David Huynh Date: Tue, 11 May 2010 04:16:26 +0000 Subject: [PATCH] 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 --- .../com/metaweb/gridworks/ProjectManager.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/metaweb/gridworks/ProjectManager.java b/src/main/java/com/metaweb/gridworks/ProjectManager.java index a714c1514..50e1e5308 100644 --- a/src/main/java/com/metaweb/gridworks/ProjectManager.java +++ b/src/main/java/com/metaweb/gridworks/ProjectManager.java @@ -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();