Commit 5ff60ab0 authored by Weihua Li's avatar Weihua Li

Internal issue:207, set up software problem in Wins 64 bit machine/limited account

Change-Id: I11147091a0a58cc95bcbb187a1f67116f7d5ed53
parent 3d3f8727
......@@ -361,45 +361,58 @@ public final class AIDirectory {
// to access the envars in Java.
// See http://en.wikipedia.org/wiki/Environment_variable#System_path_variables
private final String findWindowsCandidate() throws NoAIDirectoryException {
String candidate;
String candidate = null;
// "Appinventor Setup" is specified in the installed build file
final String registryQuery =
"reg.exe QUERY \"HKCU\\Software\\Appinventor Setup\" /v PATH";
try {
// The HKCU key might not exist and reg.exe will produce
// an error. Possible reasons are that the Appinventor Setup software
// was never installed, that there's there's a 32 vs. 64 bit incompatibility
// between the installer and the user machine, or because Windows
// is just generally painful. So we catch the
// error and try asking the user where the directory is.
// true as last argument means that we wait for the process output
String result = CodeBlocksProcessHelper.execOnWindows(registryQuery, true);
if (DEBUG) {
System.out.println("got QUERY result from Windows: " + result);
}
// Look for the part of the result after REG_SZ
// Warning: Windows 7 return two copies of the QUERY result, while Windows XP
// returns one copy, which is why we pick the last element in the match result rather
// than, e.g., the 2nd element
String [] matchResult = result.split("REG_SZ\\S?");
String directory = matchResult[matchResult.length - 1].trim();
if (DEBUG) {
System.out.println("got AI directory from Windows: " + directory);
// Need to look for all the 4 places since the differences in 32/64 bits
final String[] registryQuerys = new String[]{
"reg.exe QUERY \"HKLM\\Software\\Appinventor Setup\" /v PATH",
"reg.exe QUERY \"HKCU\\Software\\Appinventor Setup\" /v PATH",
"reg.exe QUERY \"HKLM\\Software\\Wow6432Node\\Appinventor Setup\" /v PATH",
"reg.exe QUERY \"HKCU\\Software\\Wow6432Node\\Appinventor Setup\" /v PATH",
};
for(int i =0; i<registryQuerys.length; i++){
candidate = lookForWindowsCandiate(registryQuerys[i]);
// At this point, candidate is the result of reading the registry. Now we need to test it.
// Just because we found the directory in the registry, it doesn't mean
// that the directory was there.
if (candidate != null && testCandidate(candidate)) {
return candidate;
}
}
// getCandidateFromUser will throw a NoAIDirectoryException if it loses
return getCandidateFromUser(candidate);
}
private final String lookForWindowsCandiate(String registryQuery) throws NoAIDirectoryException{
String candidate;
try {
// The HKCU key might not exist and reg.exe will produce
// an error. Possible reasons are that the Appinventor Setup software
// was never installed, that there's there's a 32 vs. 64 bit incompatibility
// between the installer and the user machine, or because Windows
// is just generally painful. So we catch the
// error and try asking the user where the directory is.
// true as last argument means that we wait for the process output
String result = CodeBlocksProcessHelper.execOnWindows(registryQuery, true);
if (DEBUG) {
System.out.println("got QUERY result from Windows: " + result);
}
// Look for the part of the result after REG_SZ
// Warning: Windows 7 return two copies of the QUERY result, while Windows XP
// returns one copy, which is why we pick the last element in the match result rather
// than, e.g., the 2nd element
String [] matchResult = result.split("REG_SZ\\S?");
String directory = matchResult[matchResult.length - 1].trim();
if (DEBUG) {
System.out.println("got AI directory from Windows: " + directory);
}
candidate = directory;
} catch (IOException e) {
System.out.println("Got error trying to read registry: " + e.getMessage());
candidate = null;
}
candidate = directory;
} catch (IOException e) {
System.out.println("Got error trying to read registry: " + e.getMessage());
candidate = null;
}
// At this point, candidate is the result of reading the registry. Now we need to test it.
// Just because we found the directory in the registry, it doesn't mean
// that the directory was there.
if (candidate != null && testCandidate(candidate)) {
return candidate;
} else {
// getCandidateFromUser will throw a NoAIDirectoryException if it loses
return getCandidateFromUser(candidate);
}
}
// Prints a message and requests the user to enter a location. The input
......@@ -576,4 +589,4 @@ public final class AIDirectory {
return CodeBlocksProcessHelper.exec(new String[] {command}, waitForOutput);
}
}
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment