mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +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:
parent
cb50ebc9c1
commit
3af99c0847
@ -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 static com.sun.jna.platform.win32.KnownFolders.FOLDERID_RoamingAppData;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
import com.sun.jna.platform.win32.Shell32Util;
|
import com.sun.jna.platform.win32.Shell32Util;
|
||||||
|
|
||||||
|
import processing.app.PreferencesData;
|
||||||
|
|
||||||
public class Win32KnownFolders {
|
public class Win32KnownFolders {
|
||||||
|
|
||||||
public static File getLocalAppDataFolder() {
|
public static File getLocalAppDataFolder() {
|
||||||
@ -51,4 +55,12 @@ public class Win32KnownFolders {
|
|||||||
return new File(Shell32Util.getKnownFolderPath(FOLDERID_Documents));
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,19 @@ public class BaseNoGui {
|
|||||||
//noop
|
//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;
|
VERSION_NAME_LONG = versionNameLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
package processing.app.windows;
|
package processing.app.windows;
|
||||||
|
|
||||||
import cc.arduino.os.windows.Win32KnownFolders;
|
import cc.arduino.os.windows.Win32KnownFolders;
|
||||||
|
import processing.app.PreferencesData;
|
||||||
import processing.app.legacy.PApplet;
|
import processing.app.legacy.PApplet;
|
||||||
import processing.app.legacy.PConstants;
|
import processing.app.legacy.PConstants;
|
||||||
|
|
||||||
@ -49,9 +50,16 @@ public class Platform extends processing.app.Platform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void recoverSettingsFolderPath() throws Exception {
|
private void recoverSettingsFolderPath() throws Exception {
|
||||||
|
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();
|
Path path = Win32KnownFolders.getLocalAppDataFolder().toPath();
|
||||||
settingsFolder = path.resolve("Arduino15").toFile();
|
settingsFolder = path.resolve("Arduino15").toFile();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Path recoverOldSettingsFolderPath() throws Exception {
|
private Path recoverOldSettingsFolderPath() throws Exception {
|
||||||
Path path = Win32KnownFolders.getRoamingAppDataFolder().toPath();
|
Path path = Win32KnownFolders.getRoamingAppDataFolder().toPath();
|
||||||
@ -192,6 +200,9 @@ public class Platform extends processing.app.Platform {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fixSettingsLocation() throws Exception {
|
public void fixSettingsLocation() throws Exception {
|
||||||
|
if (PreferencesData.getBoolean("runtime.is-windows-store-app"))
|
||||||
|
return;
|
||||||
|
|
||||||
Path oldSettingsFolder = recoverOldSettingsFolderPath();
|
Path oldSettingsFolder = recoverOldSettingsFolderPath();
|
||||||
if (!Files.exists(oldSettingsFolder)) {
|
if (!Files.exists(oldSettingsFolder)) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user