Skip to content

Commit 1de2823

Browse files
committed
some getenv/setenv muckety muck
1 parent e8e7500 commit 1de2823

File tree

4 files changed

+79
-31
lines changed

4 files changed

+79
-31
lines changed

app/src/processing/app/Base.java

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,11 @@ public void handlePrefs() {
12151215
// }
12161216

12171217

1218+
static public Platform getPlatform() {
1219+
return platform;
1220+
}
1221+
1222+
12181223
static public String getPlatformName() {
12191224
String osname = System.getProperty("os.name");
12201225

@@ -1761,33 +1766,6 @@ static public InputStream getLibStream(String filename) throws IOException {
17611766
// ...................................................................
17621767

17631768

1764-
public interface CLibrary extends Library {
1765-
CLibrary INSTANCE = (CLibrary)Native.loadLibrary("c", CLibrary.class);
1766-
int setenv(String name, String value, int overwrite);
1767-
String getenv(String name);
1768-
int unsetenv(String name);
1769-
int putenv(String string);
1770-
}
1771-
1772-
1773-
static public void setenv(String variable, String value) {
1774-
CLibrary clib = CLibrary.INSTANCE;
1775-
clib.setenv(variable, value, 1);
1776-
}
1777-
1778-
1779-
static public String getenv(String variable) {
1780-
CLibrary clib = CLibrary.INSTANCE;
1781-
return clib.getenv(variable);
1782-
}
1783-
1784-
1785-
static public int unsetenv(String variable) {
1786-
CLibrary clib = CLibrary.INSTANCE;
1787-
return clib.unsetenv(variable);
1788-
}
1789-
1790-
17911769
/**
17921770
* Get the number of lines in a file by counting the number of newline
17931771
* characters inside a String (and adding 1).

app/src/processing/app/Platform.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
import javax.swing.UIManager;
2828

29+
import com.sun.jna.Library;
30+
import com.sun.jna.Native;
31+
2932

3033
/**
3134
* Used by Base for platform-specific tweaking, for instance finding the
@@ -128,6 +131,36 @@ public void openFolder(File file) throws Exception {
128131

129132
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
130133

134+
135+
public interface CLibrary extends Library {
136+
CLibrary INSTANCE = (CLibrary)Native.loadLibrary("c", CLibrary.class);
137+
int setenv(String name, String value, int overwrite);
138+
String getenv(String name);
139+
int unsetenv(String name);
140+
int putenv(String string);
141+
}
142+
143+
144+
public void setenv(String variable, String value) {
145+
CLibrary clib = CLibrary.INSTANCE;
146+
clib.setenv(variable, value, 1);
147+
}
148+
149+
150+
public String getenv(String variable) {
151+
CLibrary clib = CLibrary.INSTANCE;
152+
return clib.getenv(variable);
153+
}
154+
155+
156+
public int unsetenv(String variable) {
157+
CLibrary clib = CLibrary.INSTANCE;
158+
return clib.unsetenv(variable);
159+
}
160+
161+
162+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
163+
131164

132165
protected void showLauncherWarning() {
133166
Base.showWarning("No launcher available",

app/src/processing/app/tools/android/Android.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,17 @@ public void run() {
6969

7070

7171
static protected void checkPath() {
72+
Platform platform = Base.getPlatform();
7273
// System.out.println("PATH is " + Base.getenv("PATH"));
7374
// System.out.println("PATH from System is " + System.getenv("PATH"));
74-
if (Base.getenv("ANDROID_SDK") == null) {
75-
Base.setenv("ANDROID_SDK", "/opt/android");
75+
if (platform.getenv("ANDROID_SDK") == null) {
76+
platform.setenv("ANDROID_SDK", "/opt/android");
7677
}
77-
sdkPath = Base.getenv("ANDROID_SDK");
78+
sdkPath = platform.getenv("ANDROID_SDK");
7879
// System.out.println("sdk path is " + sdkPath);
7980
// sdkPath = "/opt/android";
8081
String toolsPath = sdkPath + File.separator + "tools";
81-
Base.setenv("PATH", Base.getenv("PATH") + File.pathSeparator + toolsPath);
82+
platform.setenv("PATH", platform.getenv("PATH") + File.pathSeparator + toolsPath);
8283
// System.out.println("path after set is " + Base.getenv("PATH"));
8384
}
8485

app/src/processing/app/windows/Platform.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@
2525
import java.io.File;
2626
import java.io.UnsupportedEncodingException;
2727

28+
import com.sun.jna.Library;
29+
import com.sun.jna.Native;
30+
2831
import processing.app.Base;
2932
import processing.app.Preferences;
33+
import processing.app.Platform.CLibrary;
3034
import processing.app.windows.Registry.REGISTRY_ROOT_KEY;
3135
import processing.core.PApplet;
3236

@@ -265,4 +269,36 @@ public void openFolder(File file) throws Exception {
265269
// not tested
266270
//Runtime.getRuntime().exec("start explorer \"" + folder + "\"");
267271
}
272+
273+
274+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
275+
276+
277+
public interface WinLibC extends Library {
278+
WinLibC INSTANCE = (WinLibC) Native.loadLibrary("msvcrt", WinLibC.class);
279+
280+
public int _putenv(String name);
281+
// int setenv(String name, String value, int overwrite);
282+
// String getenv(String name);
283+
// int unsetenv(String name);
284+
// int putenv(String string);
285+
}
286+
287+
288+
public void setenv(String variable, String value) {
289+
WinLibC clib = WinLibC.INSTANCE;
290+
clib._putenv(variable + "=" + value);
291+
}
292+
293+
294+
public String getenv(String variable) {
295+
return System.getenv(variable);
296+
}
297+
298+
299+
public int unsetenv(String variable) {
300+
WinLibC clib = WinLibC.INSTANCE;
301+
clib._putenv(variable + "=");
302+
return 0;
303+
}
268304
}

0 commit comments

Comments
 (0)