1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-29 10:24:12 +01:00

Windows: reg query uses different separators on xp, fooling parser. Fixed

This commit is contained in:
Federico Fissore 2015-06-04 11:44:56 +02:00
parent 3c982759c2
commit e9d66015a4
2 changed files with 16 additions and 3 deletions

View File

@ -26,4 +26,17 @@ public class RegQueryParserTest {
String folderPath = new RegQueryParser(output).getValueOfKey(); String folderPath = new RegQueryParser(output).getValueOfKey();
assertEquals("C:\\Users\\username\\AppData\\Local", folderPath); assertEquals("C:\\Users\\username\\AppData\\Local", folderPath);
} }
@Test
public void testRegQueryParserXP() throws Exception {
String output = "! REG.EXE VERSION 3.0\n" +
"\n" +
"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\n" +
"\n" +
"\tLocal AppData REG_SZ C:\\Documents and Settings\\username\\My Documents";
String folderPath = new RegQueryParser(output).getValueOfKey();
assertEquals("C:\\Documents and Settings\\username\\My Documents", folderPath);
}
} }

View File

@ -15,16 +15,16 @@ public class RegQueryParser {
} }
private void parse(String regQueryOutput) { private void parse(String regQueryOutput) {
List<String> rows = Arrays.asList(regQueryOutput.replace("\r", "\n").replace("\n\n", "\n").split("\n")); List<String> rows = Arrays.asList(regQueryOutput.replace(" ", "\t").replace("\r", "\n").replace("\n\n", "\n").split("\n"));
String row = Iterables.find(rows, new Predicate<String>() { String row = Iterables.find(rows, new Predicate<String>() {
@Override @Override
public boolean apply(String input) { public boolean apply(String input) {
return input.startsWith(" "); return input.startsWith("\t");
} }
}); });
String[] cols = row.split(" "); String[] cols = row.split("\t");
assert cols.length == 4; assert cols.length == 4;
this.valueOfKey = cols[3]; this.valueOfKey = cols[3];
} }