1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-03-13 10:29:35 +01:00

Use Documents/ArduinoData when running as a Windows UWP

LocalAppData is restricted for Windows Apps, so we are forced to use
a document folder.
This commit is contained in:
Cristian Maglie 2016-09-13 16:38:26 +03:00
parent cb50ebc9c1
commit 3af99c0847
3 changed files with 38 additions and 2 deletions

View File

@ -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();
}
}

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

@ -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;