diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 09d0db665..a6361d1d3 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1215,6 +1215,11 @@ public class Base { // } + static public Platform getPlatform() { + return platform; + } + + static public String getPlatformName() { String osname = System.getProperty("os.name"); @@ -1761,33 +1766,6 @@ public class Base { // ................................................................... - public interface CLibrary extends Library { - CLibrary INSTANCE = (CLibrary)Native.loadLibrary("c", CLibrary.class); - int setenv(String name, String value, int overwrite); - String getenv(String name); - int unsetenv(String name); - int putenv(String string); - } - - - static public void setenv(String variable, String value) { - CLibrary clib = CLibrary.INSTANCE; - clib.setenv(variable, value, 1); - } - - - static public String getenv(String variable) { - CLibrary clib = CLibrary.INSTANCE; - return clib.getenv(variable); - } - - - static public int unsetenv(String variable) { - CLibrary clib = CLibrary.INSTANCE; - return clib.unsetenv(variable); - } - - /** * Get the number of lines in a file by counting the number of newline * characters inside a String (and adding 1). diff --git a/app/src/processing/app/Platform.java b/app/src/processing/app/Platform.java index ef03f56ce..315954663 100644 --- a/app/src/processing/app/Platform.java +++ b/app/src/processing/app/Platform.java @@ -26,6 +26,9 @@ import java.io.File; import javax.swing.UIManager; +import com.sun.jna.Library; +import com.sun.jna.Native; + /** * Used by Base for platform-specific tweaking, for instance finding the @@ -128,6 +131,36 @@ public class Platform { // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + + public interface CLibrary extends Library { + CLibrary INSTANCE = (CLibrary)Native.loadLibrary("c", CLibrary.class); + int setenv(String name, String value, int overwrite); + String getenv(String name); + int unsetenv(String name); + int putenv(String string); + } + + + public void setenv(String variable, String value) { + CLibrary clib = CLibrary.INSTANCE; + clib.setenv(variable, value, 1); + } + + + public String getenv(String variable) { + CLibrary clib = CLibrary.INSTANCE; + return clib.getenv(variable); + } + + + public int unsetenv(String variable) { + CLibrary clib = CLibrary.INSTANCE; + return clib.unsetenv(variable); + } + + + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + protected void showLauncherWarning() { Base.showWarning("No launcher available", diff --git a/app/src/processing/app/tools/android/Android.java b/app/src/processing/app/tools/android/Android.java index fc54b60f7..155e8dde9 100644 --- a/app/src/processing/app/tools/android/Android.java +++ b/app/src/processing/app/tools/android/Android.java @@ -69,16 +69,17 @@ public class Android implements Tool { static protected void checkPath() { + Platform platform = Base.getPlatform(); // System.out.println("PATH is " + Base.getenv("PATH")); // System.out.println("PATH from System is " + System.getenv("PATH")); - if (Base.getenv("ANDROID_SDK") == null) { - Base.setenv("ANDROID_SDK", "/opt/android"); + if (platform.getenv("ANDROID_SDK") == null) { + platform.setenv("ANDROID_SDK", "/opt/android"); } - sdkPath = Base.getenv("ANDROID_SDK"); + sdkPath = platform.getenv("ANDROID_SDK"); // System.out.println("sdk path is " + sdkPath); // sdkPath = "/opt/android"; String toolsPath = sdkPath + File.separator + "tools"; - Base.setenv("PATH", Base.getenv("PATH") + File.pathSeparator + toolsPath); + platform.setenv("PATH", platform.getenv("PATH") + File.pathSeparator + toolsPath); // System.out.println("path after set is " + Base.getenv("PATH")); } diff --git a/app/src/processing/app/windows/Platform.java b/app/src/processing/app/windows/Platform.java index 278244447..04c12c259 100644 --- a/app/src/processing/app/windows/Platform.java +++ b/app/src/processing/app/windows/Platform.java @@ -25,8 +25,12 @@ package processing.app.windows; import java.io.File; import java.io.UnsupportedEncodingException; +import com.sun.jna.Library; +import com.sun.jna.Native; + import processing.app.Base; import processing.app.Preferences; +import processing.app.Platform.CLibrary; import processing.app.windows.Registry.REGISTRY_ROOT_KEY; import processing.core.PApplet; @@ -265,4 +269,36 @@ public class Platform extends processing.app.Platform { // not tested //Runtime.getRuntime().exec("start explorer \"" + folder + "\""); } + + + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + + + public interface WinLibC extends Library { + WinLibC INSTANCE = (WinLibC) Native.loadLibrary("msvcrt", WinLibC.class); + + public int _putenv(String name); +// int setenv(String name, String value, int overwrite); +// String getenv(String name); +// int unsetenv(String name); +// int putenv(String string); + } + + + public void setenv(String variable, String value) { + WinLibC clib = WinLibC.INSTANCE; + clib._putenv(variable + "=" + value); + } + + + public String getenv(String variable) { + return System.getenv(variable); + } + + + public int unsetenv(String variable) { + WinLibC clib = WinLibC.INSTANCE; + clib._putenv(variable + "="); + return 0; + } }