Skip to content

Commit 21ff728

Browse files
committed
Merge remote-tracking branch 'cmaglie/fix-win-paths'
2 parents de9bd89 + 3af99c0 commit 21ff728

16 files changed

+78
-255
lines changed

app/lib/jna-4.1.0.jar

-893 KB
Binary file not shown.

app/lib/jna-platform-4.1.0.jar

-1.4 MB
Binary file not shown.

app/test/processing/app/windows/RegQueryParserTest.java

-53
This file was deleted.

arduino-core/.classpath

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<classpathentry kind="lib" path="lib/jackson-databind-2.6.3.jar"/>
3030
<classpathentry kind="lib" path="lib/jackson-module-mrbean-2.6.3.jar"/>
3131
<classpathentry kind="lib" path="lib/java-semver-0.8.0.jar"/>
32-
<classpathentry kind="lib" path="lib/jna-4.1.0.jar"/>
33-
<classpathentry kind="lib" path="lib/jna-platform-4.1.0.jar"/>
32+
<classpathentry kind="lib" path="lib/jna-4.2.2.jar"/>
33+
<classpathentry kind="lib" path="lib/jna-platform-4.2.2.jar"/>
3434
<classpathentry kind="output" path="bin"/>
3535
</classpath>

arduino-core/lib/jna-4.1.0.jar

-893 KB
Binary file not shown.

arduino-core/lib/jna-4.2.2.jar

1.08 MB
Binary file not shown.

arduino-core/src/cc/arduino/Compiler.java

+15-14
Original file line numberDiff line numberDiff line change
@@ -191,27 +191,28 @@ private PreferencesMap loadPreferences(TargetBoard board, TargetPlatform platfor
191191
return prefs;
192192
}
193193

194+
private void addPathFlagIfPathExists(List<String> cmd, String flag, File folder) {
195+
if (folder.exists()) {
196+
cmd.add(flag);
197+
cmd.add(folder.getAbsolutePath());
198+
}
199+
}
200+
194201
private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, TargetPackage aPackage, String vidpid, BuilderAction action, OutputStream outStream, OutputStream errStream) throws RunnerException {
195202
List<String> cmd = new ArrayList<>();
196203
cmd.add(BaseNoGui.getContentFile("arduino-builder").getAbsolutePath());
197204
cmd.add(action.value);
198205
cmd.add("-logger=machine");
199206

200-
Stream.of(BaseNoGui.getHardwarePath(), new File(BaseNoGui.getSettingsFolder(), "packages").getAbsolutePath(), BaseNoGui.getSketchbookHardwareFolder().getAbsolutePath())
201-
.forEach(p -> {
202-
if (Files.exists(Paths.get(p))) {
203-
cmd.add("-hardware");
204-
cmd.add(p);
205-
}
206-
});
207+
File installedPackagesFolder = new File(BaseNoGui.getSettingsFolder(), "packages");
207208

208-
Stream.of(BaseNoGui.getContentFile("tools-builder").getAbsolutePath(), Paths.get(BaseNoGui.getHardwarePath(), "tools", "avr").toAbsolutePath().toString(), new File(BaseNoGui.getSettingsFolder(), "packages").getAbsolutePath())
209-
.forEach(p -> {
210-
if (Files.exists(Paths.get(p))) {
211-
cmd.add("-tools");
212-
cmd.add(p);
213-
}
214-
});
209+
addPathFlagIfPathExists(cmd, "-hardware", BaseNoGui.getHardwareFolder());
210+
addPathFlagIfPathExists(cmd, "-hardware", installedPackagesFolder);
211+
addPathFlagIfPathExists(cmd, "-hardware", BaseNoGui.getSketchbookHardwareFolder());
212+
213+
addPathFlagIfPathExists(cmd, "-tools", BaseNoGui.getContentFile("tools-builder"));
214+
addPathFlagIfPathExists(cmd, "-tools", Paths.get(BaseNoGui.getHardwarePath(), "tools", "avr").toFile());
215+
addPathFlagIfPathExists(cmd, "-tools", installedPackagesFolder);
215216

216217
cmd.add("-built-in-libraries");
217218
cmd.add(BaseNoGui.getContentFile("libraries").getAbsolutePath());

arduino-core/src/cc/arduino/os/windows/FolderFinder.java

-65
This file was deleted.

arduino-core/src/cc/arduino/os/windows/FolderFinderInWindowsRegistry.java

-58
This file was deleted.

arduino-core/src/cc/arduino/os/windows/FolderFinderInWindowsEnvVar.java renamed to arduino-core/src/cc/arduino/os/windows/Win32KnownFolders.java

+27-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* This file is part of Arduino.
33
*
4-
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
4+
* Copyright 2016 Arduino LLC (http://www.arduino.cc/)
55
*
66
* Arduino is free software; you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
@@ -29,26 +29,38 @@
2929

3030
package cc.arduino.os.windows;
3131

32-
import java.nio.file.Files;
33-
import java.nio.file.Path;
32+
import static com.sun.jna.platform.win32.KnownFolders.FOLDERID_Documents;
33+
import static com.sun.jna.platform.win32.KnownFolders.FOLDERID_LocalAppData;
34+
import static com.sun.jna.platform.win32.KnownFolders.FOLDERID_RoamingAppData;
35+
36+
import java.io.File;
37+
import java.io.FileNotFoundException;
3438
import java.nio.file.Paths;
3539

36-
public class FolderFinderInWindowsEnvVar extends FolderFinder {
40+
import com.sun.jna.platform.win32.Shell32Util;
41+
42+
import processing.app.PreferencesData;
43+
44+
public class Win32KnownFolders {
3745

38-
private final String envVar;
46+
public static File getLocalAppDataFolder() {
47+
return new File(Shell32Util.getKnownFolderPath(FOLDERID_LocalAppData));
48+
}
49+
50+
public static File getRoamingAppDataFolder() {
51+
return new File(Shell32Util.getKnownFolderPath(FOLDERID_RoamingAppData));
52+
}
3953

40-
public FolderFinderInWindowsEnvVar(FolderFinder next, String folderName, String evnVar) {
41-
super(next, folderName);
42-
this.envVar = evnVar;
54+
public static File getDocumentsFolder() {
55+
return new File(Shell32Util.getKnownFolderPath(FOLDERID_Documents));
4356
}
4457

45-
@Override
46-
public Path findInternal() throws Exception {
47-
String userprofile = System.getenv(envVar);
48-
Path documents = Paths.get(userprofile, folderName);
49-
if (Files.exists(documents)) {
50-
return documents;
58+
public static File getLocalCacheFolder() throws FileNotFoundException {
59+
if (!PreferencesData.getBoolean("runtime.is-windows-store-app")) {
60+
throw new FileNotFoundException();
5161
}
52-
return null;
62+
String localAppData = Shell32Util.getKnownFolderPath(FOLDERID_LocalAppData);
63+
String appId = PreferencesData.get("runtime.windows-store-app.id");
64+
return Paths.get(localAppData, "Packages", appId, "LocalCache").toFile();
5365
}
5466
}

arduino-core/src/processing/app/BaseNoGui.java

+13
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ public class BaseNoGui {
6262
//noop
6363
}
6464
}
65+
66+
File windowsStoreConfig = new File(getContentFile("lib"), "windowsStore.txt");
67+
if (windowsStoreConfig.exists()) {
68+
try {
69+
PreferencesMap conf = new PreferencesMap(windowsStoreConfig);
70+
PreferencesData.setBoolean("runtime.is-windows-store-app", true);
71+
PreferencesData.set("runtime.windows-store-app.id", conf.get("appid"));
72+
versionNameLong += " (Windows Store " + conf.get("version") + ")";
73+
} catch (IOException e1) {
74+
e1.printStackTrace();
75+
}
76+
}
77+
6578
VERSION_NAME_LONG = versionNameLong;
6679
}
6780

arduino-core/src/processing/app/windows/Platform.java

+17-17
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
package processing.app.windows;
2424

25-
import cc.arduino.os.windows.FolderFinderInWindowsEnvVar;
26-
import cc.arduino.os.windows.FolderFinderInWindowsRegistry;
25+
import cc.arduino.os.windows.Win32KnownFolders;
26+
import processing.app.PreferencesData;
2727
import processing.app.legacy.PApplet;
2828
import processing.app.legacy.PConstants;
2929

@@ -51,28 +51,25 @@ public void init() throws Exception {
5151
}
5252

5353
private void recoverSettingsFolderPath() throws Exception {
54-
FolderFinderInWindowsRegistry findInUserShellFolders = new FolderFinderInWindowsRegistry(null, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", "Local AppData");
55-
FolderFinderInWindowsRegistry findInShellFolders = new FolderFinderInWindowsRegistry(findInUserShellFolders, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Local AppData");
56-
57-
Path path = findInShellFolders.find();
58-
this.settingsFolder = path.resolve("Arduino15").toFile();
54+
if (PreferencesData.getBoolean("runtime.is-windows-store-app")) {
55+
// LocalAppData is restricted for Windows Store Apps.
56+
// We are forced to use a document folder to store tools.
57+
Path path = Win32KnownFolders.getDocumentsFolder().toPath();
58+
settingsFolder = path.resolve("ArduinoData").toFile();
59+
} else {
60+
Path path = Win32KnownFolders.getLocalAppDataFolder().toPath();
61+
settingsFolder = path.resolve("Arduino15").toFile();
62+
}
5963
}
6064

6165
private Path recoverOldSettingsFolderPath() throws Exception {
62-
FolderFinderInWindowsRegistry findInUserShellFolders = new FolderFinderInWindowsRegistry(null, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", "AppData");
63-
FolderFinderInWindowsRegistry findInShellFolders = new FolderFinderInWindowsRegistry(findInUserShellFolders, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "AppData");
64-
65-
Path path = findInShellFolders.find();
66+
Path path = Win32KnownFolders.getRoamingAppDataFolder().toPath();
6667
return path.resolve("Arduino15");
6768
}
6869

6970
private void recoverDefaultSketchbookFolder() throws Exception {
70-
FolderFinderInWindowsEnvVar findInUserProfile = new FolderFinderInWindowsEnvVar(null, "Documents", "USERPROFILE");
71-
FolderFinderInWindowsRegistry findInUserShellFolders = new FolderFinderInWindowsRegistry(findInUserProfile, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", "Personal");
72-
FolderFinderInWindowsRegistry findInShellFolders = new FolderFinderInWindowsRegistry(findInUserShellFolders, "Documents", "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Personal");
73-
74-
Path path = findInShellFolders.find();
75-
this.defaultSketchbookFolder = path.resolve("Arduino").toFile();
71+
Path path = Win32KnownFolders.getDocumentsFolder().toPath();
72+
defaultSketchbookFolder = path.resolve("Arduino").toFile();
7673
}
7774

7875
/**
@@ -213,6 +210,9 @@ public void chmod(File file, int mode) throws IOException, InterruptedException
213210

214211
@Override
215212
public void fixSettingsLocation() throws Exception {
213+
if (PreferencesData.getBoolean("runtime.is-windows-store-app"))
214+
return;
215+
216216
Path oldSettingsFolder = recoverOldSettingsFolderPath();
217217
if (!Files.exists(oldSettingsFolder)) {
218218
return;

0 commit comments

Comments
 (0)