Skip to content

Commit 3af99c0

Browse files
committed
Use Documents/ArduinoData when running as a Windows UWP
LocalAppData is restricted for Windows Apps, so we are forced to use a document folder.
1 parent cb50ebc commit 3af99c0

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

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

+12
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@
3434
import static com.sun.jna.platform.win32.KnownFolders.FOLDERID_RoamingAppData;
3535

3636
import java.io.File;
37+
import java.io.FileNotFoundException;
38+
import java.nio.file.Paths;
3739

3840
import com.sun.jna.platform.win32.Shell32Util;
3941

42+
import processing.app.PreferencesData;
43+
4044
public class Win32KnownFolders {
4145

4246
public static File getLocalAppDataFolder() {
@@ -51,4 +55,12 @@ public static File getDocumentsFolder() {
5155
return new File(Shell32Util.getKnownFolderPath(FOLDERID_Documents));
5256
}
5357

58+
public static File getLocalCacheFolder() throws FileNotFoundException {
59+
if (!PreferencesData.getBoolean("runtime.is-windows-store-app")) {
60+
throw new FileNotFoundException();
61+
}
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();
65+
}
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

+13-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package processing.app.windows;
2424

2525
import cc.arduino.os.windows.Win32KnownFolders;
26+
import processing.app.PreferencesData;
2627
import processing.app.legacy.PApplet;
2728
import processing.app.legacy.PConstants;
2829

@@ -49,8 +50,15 @@ public void init() throws Exception {
4950
}
5051

5152
private void recoverSettingsFolderPath() throws Exception {
52-
Path path = Win32KnownFolders.getLocalAppDataFolder().toPath();
53-
settingsFolder = path.resolve("Arduino15").toFile();
53+
if (PreferencesData.getBoolean("runtime.is-windows-store-app")) {
54+
// LocalAppData is restricted for Windows Store Apps.
55+
// We are forced to use a document folder to store tools.
56+
Path path = Win32KnownFolders.getDocumentsFolder().toPath();
57+
settingsFolder = path.resolve("ArduinoData").toFile();
58+
} else {
59+
Path path = Win32KnownFolders.getLocalAppDataFolder().toPath();
60+
settingsFolder = path.resolve("Arduino15").toFile();
61+
}
5462
}
5563

5664
private Path recoverOldSettingsFolderPath() throws Exception {
@@ -192,6 +200,9 @@ public void chmod(File file, int mode) throws IOException, InterruptedException
192200

193201
@Override
194202
public void fixSettingsLocation() throws Exception {
203+
if (PreferencesData.getBoolean("runtime.is-windows-store-app"))
204+
return;
205+
195206
Path oldSettingsFolder = recoverOldSettingsFolderPath();
196207
if (!Files.exists(oldSettingsFolder)) {
197208
return;

0 commit comments

Comments
 (0)