From 3af99c08477bc97c78c8d5ddf0d66c0b5ff87bac Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 13 Sep 2016 16:38:26 +0300 Subject: [PATCH] Use Documents/ArduinoData when running as a Windows UWP LocalAppData is restricted for Windows Apps, so we are forced to use a document folder. --- .../cc/arduino/os/windows/Win32KnownFolders.java | 12 ++++++++++++ arduino-core/src/processing/app/BaseNoGui.java | 13 +++++++++++++ .../src/processing/app/windows/Platform.java | 15 +++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/arduino-core/src/cc/arduino/os/windows/Win32KnownFolders.java b/arduino-core/src/cc/arduino/os/windows/Win32KnownFolders.java index ee4846e49..e8f66cbf9 100644 --- a/arduino-core/src/cc/arduino/os/windows/Win32KnownFolders.java +++ b/arduino-core/src/cc/arduino/os/windows/Win32KnownFolders.java @@ -34,9 +34,13 @@ 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; import com.sun.jna.platform.win32.Shell32Util; +import processing.app.PreferencesData; + public class Win32KnownFolders { public static File getLocalAppDataFolder() { @@ -51,4 +55,12 @@ public class Win32KnownFolders { return new File(Shell32Util.getKnownFolderPath(FOLDERID_Documents)); } + public static File getLocalCacheFolder() throws FileNotFoundException { + if (!PreferencesData.getBoolean("runtime.is-windows-store-app")) { + throw new FileNotFoundException(); + } + String localAppData = Shell32Util.getKnownFolderPath(FOLDERID_LocalAppData); + String appId = PreferencesData.get("runtime.windows-store-app.id"); + return Paths.get(localAppData, "Packages", appId, "LocalCache").toFile(); + } } diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index 8642f025a..0c9c5acef 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -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; } diff --git a/arduino-core/src/processing/app/windows/Platform.java b/arduino-core/src/processing/app/windows/Platform.java index 5796c20cf..9646addb2 100644 --- a/arduino-core/src/processing/app/windows/Platform.java +++ b/arduino-core/src/processing/app/windows/Platform.java @@ -23,6 +23,7 @@ package processing.app.windows; import cc.arduino.os.windows.Win32KnownFolders; +import processing.app.PreferencesData; import processing.app.legacy.PApplet; import processing.app.legacy.PConstants; @@ -49,8 +50,15 @@ public class Platform extends processing.app.Platform { } private void recoverSettingsFolderPath() throws Exception { - Path path = Win32KnownFolders.getLocalAppDataFolder().toPath(); - 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 { @@ -192,6 +200,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;