Merge remote-tracking branch 'cmaglie/fix-win-paths'

This commit is contained in:
Cristian Maglie 2016-11-03 12:10:24 +01:00
commit 21ff728c59
16 changed files with 78 additions and 255 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,53 +0,0 @@
package processing.app.windows;
import org.junit.Test;
import processing.app.helpers.FileUtils;
import java.io.File;
import static org.junit.Assert.assertEquals;
public class RegQueryParserTest {
@Test
public void testRegQueryParser() throws Exception {
String output = "! REG.EXE VERSION 3.0\n" +
"\n" +
"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\n" +
"\n" +
" Local 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);
}
@Test
public void testRegQueryParser2() throws Exception {
String output = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\n" +
" Local AppData REG_SZ C:\\Users\\username\\AppData\\Local";
String folderPath = new RegQueryParser(output).getValueOfKey();
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);
}
@Test
public void testRegQueryParserGerman() throws Exception {
String output = FileUtils.readFileToString(new File(RegQueryParserTest.class.getResource("german.reg.query.output.txt").getFile()), "Cp852");
String folderPath = new RegQueryParser(output).getValueOfKey();
assertEquals("C:\\Users\\René\\AppData\\Roaming", folderPath);
}
}

View File

@ -29,7 +29,7 @@
<classpathentry kind="lib" path="lib/jackson-databind-2.6.3.jar"/>
<classpathentry kind="lib" path="lib/jackson-module-mrbean-2.6.3.jar"/>
<classpathentry kind="lib" path="lib/java-semver-0.8.0.jar"/>
<classpathentry kind="lib" path="lib/jna-4.1.0.jar"/>
<classpathentry kind="lib" path="lib/jna-platform-4.1.0.jar"/>
<classpathentry kind="lib" path="lib/jna-4.2.2.jar"/>
<classpathentry kind="lib" path="lib/jna-platform-4.2.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

Binary file not shown.

Binary file not shown.

View File

@ -191,27 +191,28 @@ public class Compiler implements MessageConsumer {
return prefs;
}
private void addPathFlagIfPathExists(List<String> cmd, String flag, File folder) {
if (folder.exists()) {
cmd.add(flag);
cmd.add(folder.getAbsolutePath());
}
}
private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, TargetPackage aPackage, String vidpid, BuilderAction action, OutputStream outStream, OutputStream errStream) throws RunnerException {
List<String> cmd = new ArrayList<>();
cmd.add(BaseNoGui.getContentFile("arduino-builder").getAbsolutePath());
cmd.add(action.value);
cmd.add("-logger=machine");
Stream.of(BaseNoGui.getHardwarePath(), new File(BaseNoGui.getSettingsFolder(), "packages").getAbsolutePath(), BaseNoGui.getSketchbookHardwareFolder().getAbsolutePath())
.forEach(p -> {
if (Files.exists(Paths.get(p))) {
cmd.add("-hardware");
cmd.add(p);
}
});
File installedPackagesFolder = new File(BaseNoGui.getSettingsFolder(), "packages");
Stream.of(BaseNoGui.getContentFile("tools-builder").getAbsolutePath(), Paths.get(BaseNoGui.getHardwarePath(), "tools", "avr").toAbsolutePath().toString(), new File(BaseNoGui.getSettingsFolder(), "packages").getAbsolutePath())
.forEach(p -> {
if (Files.exists(Paths.get(p))) {
cmd.add("-tools");
cmd.add(p);
}
});
addPathFlagIfPathExists(cmd, "-hardware", BaseNoGui.getHardwareFolder());
addPathFlagIfPathExists(cmd, "-hardware", installedPackagesFolder);
addPathFlagIfPathExists(cmd, "-hardware", BaseNoGui.getSketchbookHardwareFolder());
addPathFlagIfPathExists(cmd, "-tools", BaseNoGui.getContentFile("tools-builder"));
addPathFlagIfPathExists(cmd, "-tools", Paths.get(BaseNoGui.getHardwarePath(), "tools", "avr").toFile());
addPathFlagIfPathExists(cmd, "-tools", installedPackagesFolder);
cmd.add("-built-in-libraries");
cmd.add(BaseNoGui.getContentFile("libraries").getAbsolutePath());

View File

@ -1,65 +0,0 @@
/*
* This file is part of Arduino.
*
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*/
package cc.arduino.os.windows;
import java.nio.file.Path;
public abstract class FolderFinder {
private final FolderFinder next;
protected final String folderName;
protected FolderFinder(FolderFinder next, String folderName) {
this.next = next;
this.folderName = folderName;
}
protected abstract Path findInternal() throws Exception;
public Path find() throws Exception {
try {
Path value = findInternal();
if (value != null) {
return value;
}
if (next != null) {
return next.find();
}
throw new IllegalStateException("Unable to find your " + folderName + " folder");
} catch (Exception e) {
if (next != null) {
return next.find();
}
throw e;
}
}
}

View File

@ -1,58 +0,0 @@
/*
* This file is part of Arduino.
*
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*/
package cc.arduino.os.windows;
import com.sun.jna.platform.win32.Advapi32Util;
import com.sun.jna.platform.win32.WinReg;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.regex.Matcher;
public class FolderFinderInWindowsRegistry extends FolderFinder {
private final String registryPath;
private final String registryKey;
public FolderFinderInWindowsRegistry(FolderFinder next, String folderName, String registryPath, String registryKey) {
super(next, folderName);
this.registryPath = registryPath;
this.registryKey = registryKey;
}
@Override
public Path findInternal() throws Exception {
String value = Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, registryPath, registryKey);
value = value.replaceAll("%[uU][sS][eE][rR][pP][rR][oO][fF][iI][lL][eE]%", Matcher.quoteReplacement(System.getenv("USERPROFILE")));
return Paths.get(value);
}
}

View File

@ -1,7 +1,7 @@
/*
* This file is part of Arduino.
*
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
* Copyright 2016 Arduino LLC (http://www.arduino.cc/)
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -29,26 +29,38 @@
package cc.arduino.os.windows;
import java.nio.file.Files;
import java.nio.file.Path;
import static com.sun.jna.platform.win32.KnownFolders.FOLDERID_Documents;
import static com.sun.jna.platform.win32.KnownFolders.FOLDERID_LocalAppData;
import static com.sun.jna.platform.win32.KnownFolders.FOLDERID_RoamingAppData;
import java.io.File;
import java.io.FileNotFoundException;
import java.nio.file.Paths;
public class FolderFinderInWindowsEnvVar extends FolderFinder {
import com.sun.jna.platform.win32.Shell32Util;
private final String envVar;
import processing.app.PreferencesData;
public FolderFinderInWindowsEnvVar(FolderFinder next, String folderName, String evnVar) {
super(next, folderName);
this.envVar = evnVar;
public class Win32KnownFolders {
public static File getLocalAppDataFolder() {
return new File(Shell32Util.getKnownFolderPath(FOLDERID_LocalAppData));
}
@Override
public Path findInternal() throws Exception {
String userprofile = System.getenv(envVar);
Path documents = Paths.get(userprofile, folderName);
if (Files.exists(documents)) {
return documents;
public static File getRoamingAppDataFolder() {
return new File(Shell32Util.getKnownFolderPath(FOLDERID_RoamingAppData));
}
public static File getDocumentsFolder() {
return new File(Shell32Util.getKnownFolderPath(FOLDERID_Documents));
}
public static File getLocalCacheFolder() throws FileNotFoundException {
if (!PreferencesData.getBoolean("runtime.is-windows-store-app")) {
throw new FileNotFoundException();
}
return null;
String localAppData = Shell32Util.getKnownFolderPath(FOLDERID_LocalAppData);
String appId = PreferencesData.get("runtime.windows-store-app.id");
return Paths.get(localAppData, "Packages", appId, "LocalCache").toFile();
}
}

View File

@ -62,6 +62,19 @@ public class BaseNoGui {
//noop
}
}
File windowsStoreConfig = new File(getContentFile("lib"), "windowsStore.txt");
if (windowsStoreConfig.exists()) {
try {
PreferencesMap conf = new PreferencesMap(windowsStoreConfig);
PreferencesData.setBoolean("runtime.is-windows-store-app", true);
PreferencesData.set("runtime.windows-store-app.id", conf.get("appid"));
versionNameLong += " (Windows Store " + conf.get("version") + ")";
} catch (IOException e1) {
e1.printStackTrace();
}
}
VERSION_NAME_LONG = versionNameLong;
}

View File

@ -22,8 +22,8 @@
package processing.app.windows;
import cc.arduino.os.windows.FolderFinderInWindowsEnvVar;
import cc.arduino.os.windows.FolderFinderInWindowsRegistry;
import cc.arduino.os.windows.Win32KnownFolders;
import processing.app.PreferencesData;
import processing.app.legacy.PApplet;
import processing.app.legacy.PConstants;
@ -51,28 +51,25 @@ public class Platform extends processing.app.Platform {
}
private void recoverSettingsFolderPath() throws Exception {
FolderFinderInWindowsRegistry findInUserShellFolders = new FolderFinderInWindowsRegistry(null, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", "Local AppData");
FolderFinderInWindowsRegistry findInShellFolders = new FolderFinderInWindowsRegistry(findInUserShellFolders, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Local AppData");
Path path = findInShellFolders.find();
this.settingsFolder = path.resolve("Arduino15").toFile();
if (PreferencesData.getBoolean("runtime.is-windows-store-app")) {
// LocalAppData is restricted for Windows Store Apps.
// We are forced to use a document folder to store tools.
Path path = Win32KnownFolders.getDocumentsFolder().toPath();
settingsFolder = path.resolve("ArduinoData").toFile();
} else {
Path path = Win32KnownFolders.getLocalAppDataFolder().toPath();
settingsFolder = path.resolve("Arduino15").toFile();
}
}
private Path recoverOldSettingsFolderPath() throws Exception {
FolderFinderInWindowsRegistry findInUserShellFolders = new FolderFinderInWindowsRegistry(null, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", "AppData");
FolderFinderInWindowsRegistry findInShellFolders = new FolderFinderInWindowsRegistry(findInUserShellFolders, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "AppData");
Path path = findInShellFolders.find();
Path path = Win32KnownFolders.getRoamingAppDataFolder().toPath();
return path.resolve("Arduino15");
}
private void recoverDefaultSketchbookFolder() throws Exception {
FolderFinderInWindowsEnvVar findInUserProfile = new FolderFinderInWindowsEnvVar(null, "Documents", "USERPROFILE");
FolderFinderInWindowsRegistry findInUserShellFolders = new FolderFinderInWindowsRegistry(findInUserProfile, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", "Personal");
FolderFinderInWindowsRegistry findInShellFolders = new FolderFinderInWindowsRegistry(findInUserShellFolders, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Personal");
Path path = findInShellFolders.find();
this.defaultSketchbookFolder = path.resolve("Arduino").toFile();
Path path = Win32KnownFolders.getDocumentsFolder().toPath();
defaultSketchbookFolder = path.resolve("Arduino").toFile();
}
/**
@ -213,6 +210,9 @@ public class Platform extends processing.app.Platform {
@Override
public void fixSettingsLocation() throws Exception {
if (PreferencesData.getBoolean("runtime.is-windows-store-app"))
return;
Path oldSettingsFolder = recoverOldSettingsFolderPath();
if (!Files.exists(oldSettingsFolder)) {
return;

View File

@ -1,27 +0,0 @@
package processing.app.windows;
import java.util.Arrays;
import java.util.List;
public class RegQueryParser {
private String valueOfKey;
public RegQueryParser(String regQueryOutput) {
parse(regQueryOutput);
}
private void parse(String regQueryOutput) {
List<String> rows = Arrays.asList(regQueryOutput.replace(" ", "\t").replace("\r", "\n").replace("\n\n", "\n").split("\n"));
String row = rows.stream().filter(input -> input.startsWith("\t")).findFirst().get();
String[] cols = row.split("\t");
assert cols.length == 4;
this.valueOfKey = cols[3];
}
public String getValueOfKey() {
return valueOfKey;
}
}

View File

@ -42,8 +42,8 @@
<cp>%EXEDIR%/lib/jackson-module-mrbean-2.6.3.jar</cp>
<cp>%EXEDIR%/lib/java-semver-0.8.0.jar</cp>
<cp>%EXEDIR%/lib/jmdns-3.4.1.jar</cp>
<cp>%EXEDIR%/lib/jna-4.1.0.jar</cp>
<cp>%EXEDIR%/lib/jna-platform-4.1.0.jar</cp>
<cp>%EXEDIR%/lib/jna-4.2.2.jar</cp>
<cp>%EXEDIR%/lib/jna-platform-4.2.2.jar</cp>
<cp>%EXEDIR%/lib/jsch-0.1.50.jar</cp>
<cp>%EXEDIR%/lib/jssc-2.8.0.jar</cp>
<cp>%EXEDIR%/lib/pde.jar</cp>

View File

@ -42,8 +42,8 @@
<cp>%EXEDIR%/lib/jackson-module-mrbean-2.6.3.jar</cp>
<cp>%EXEDIR%/lib/java-semver-0.8.0.jar</cp>
<cp>%EXEDIR%/lib/jmdns-3.4.1.jar</cp>
<cp>%EXEDIR%/lib/jna-4.1.0.jar</cp>
<cp>%EXEDIR%/lib/jna-platform-4.1.0.jar</cp>
<cp>%EXEDIR%/lib/jna-4.2.2.jar</cp>
<cp>%EXEDIR%/lib/jna-platform-4.2.2.jar</cp>
<cp>%EXEDIR%/lib/jsch-0.1.50.jar</cp>
<cp>%EXEDIR%/lib/jssc-2.8.0.jar</cp>
<cp>%EXEDIR%/lib/pde.jar</cp>