FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing/app/src/processing/app/Platform.java at master · orgicus/processing · GitHub
orgicus
processing
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
Platform.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
393 lines (307 loc) · 11.8 KB
Breadcrumbs
processing
/
app
/
src
/
processing
/
app
/
Platform.java
Copy path
File metadata and controls
393 lines (307 loc) · 11.8 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012-15 The Processing Foundation
Copyright (c) 2008-12 Ben Fry and Casey Reas
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package
processing
.
app
;
import
java
.
io
.
File
;
import
java
.
io
.
FilenameFilter
;
import
java
.
io
.
IOException
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
Map
;
import
com
.
sun
.
jna
.
platform
.
FileUtils
;
import
processing
.
app
.
platform
.
DefaultPlatform
;
import
processing
.
core
.
PApplet
;
import
processing
.
core
.
PConstants
;
public
class
Platform
{
static
DefaultPlatform
inst
;
static
Map
<
Integer
,
String
>
platformNames
=
new
HashMap
<
Integer
,
String
>();
static
{
platformNames
.
put
(
PConstants
.
WINDOWS
,
"windows"
);
//$NON-NLS-1$
platformNames
.
put
(
PConstants
.
MACOSX
,
"macosx"
);
//$NON-NLS-1$
platformNames
.
put
(
PConstants
.
LINUX
,
"linux"
);
//$NON-NLS-1$
}
static
Map
<
String
,
Integer
>
platformIndices
=
new
HashMap
<
String
,
Integer
>();
static
{
platformIndices
.
put
(
"windows"
,
PConstants
.
WINDOWS
);
//$NON-NLS-1$
platformIndices
.
put
(
"macosx"
,
PConstants
.
MACOSX
);
//$NON-NLS-1$
platformIndices
.
put
(
"linux"
,
PConstants
.
LINUX
);
//$NON-NLS-1$
}
/** How many bits this machine is */
static
int
nativeBits
;
static
{
nativeBits
=
32
;
// perhaps start with 32
String
bits
=
System
.
getProperty
(
"sun.arch.data.model"
);
//$NON-NLS-1$
if
(
bits
!=
null
) {
if
(
bits
.
equals
(
"64"
)) {
//$NON-NLS-1$
nativeBits
=
64
;
}
}
else
{
// if some other strange vm, maybe try this instead
if
(
System
.
getProperty
(
"java.vm.name"
).
contains
(
"64"
)) {
//$NON-NLS-1$ //$NON-NLS-2$
nativeBits
=
64
;
}
}
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static
public
void
init
() {
try
{
Class
<?>
platformClass
=
Class
.
forName
(
"processing.app.Platform"
);
//$NON-NLS-1$
if
(
Platform
.
isMacOS
()) {
platformClass
=
Class
.
forName
(
"processing.app.platform.MacPlatform"
);
//$NON-NLS-1$
}
else
if
(
Platform
.
isWindows
()) {
platformClass
=
Class
.
forName
(
"processing.app.platform.WindowsPlatform"
);
//$NON-NLS-1$
}
else
if
(
Platform
.
isLinux
()) {
platformClass
=
Class
.
forName
(
"processing.app.platform.LinuxPlatform"
);
//$NON-NLS-1$
}
inst
= (
DefaultPlatform
)
platformClass
.
newInstance
();
}
catch
(
Exception
e
) {
Messages
.
showError
(
"Problem Setting the Platform"
,
"An unknown error occurred while trying to load
\n
"
+
"platform-specific code for your machine."
,
e
);
}
}
static
public
void
initBase
(
Base
base
)
throws
Exception
{
inst
.
initBase
(
base
);
}
static
public
void
setLookAndFeel
()
throws
Exception
{
inst
.
setLookAndFeel
();
}
static
public
File
getSettingsFolder
()
throws
Exception
{
return
inst
.
getSettingsFolder
();
}
static
public
File
getDefaultSketchbookFolder
()
throws
Exception
{
return
inst
.
getDefaultSketchbookFolder
();
}
static
public
void
saveLanguage
(
String
languageCode
) {
inst
.
saveLanguage
(
languageCode
);
}
// static public void openURL(String url) throws Exception {
// inst.openURL(url);
// }
//
//
// public boolean openFolderAvailable() {
// return inst.openFolderAvailable();
// }
//
//
// public void openFolder(File file) throws Exception {
// inst.openFolder(file);
// }
/**
* Implements the cross-platform headache of opening URLs.
*
* For 2.0a8 and later, this requires the parameter to be an actual URL,
* meaning that you can't send it a file:// path without a prefix. It also
* just calls into Platform, which now uses java.awt.Desktop (where
* possible, meaning not on Linux) now that we're requiring Java 6.
* As it happens the URL must also be properly URL-encoded.
*/
static
public
void
openURL
(
String
url
) {
try
{
inst
.
openURL
(
url
);
}
catch
(
Exception
e
) {
Messages
.
showWarning
(
"Problem Opening URL"
,
"Could not open the URL
\n
"
+
url
,
e
);
}
}
/**
* Used to determine whether to disable the "Show Sketch Folder" option.
* @return true If a means of opening a folder is known to be available.
*/
static
public
boolean
openFolderAvailable
() {
return
inst
.
openFolderAvailable
();
}
/**
* Implements the other cross-platform headache of opening
* a folder in the machine's native file browser.
*/
static
public
void
openFolder
(
File
file
) {
try
{
inst
.
openFolder
(
file
);
}
catch
(
Exception
e
) {
Messages
.
showWarning
(
"Problem Opening Folder"
,
"Could not open the folder
\n
"
+
file
.
getAbsolutePath
(),
e
);
}
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
* Return whether sketches will run as 32- or 64-bits based
* on the JVM that's in use.
*/
static
public
int
getNativeBits
() {
return
nativeBits
;
}
/**
* Return the value of the os.arch property
*/
static
public
String
getNativeArch
() {
return
System
.
getProperty
(
"os.arch"
);
}
/*
* Return a string that identifies the variant of a platform
* e.g. "32" or "64" on Intel
*/
static
public
String
getVariant
() {
return
getVariant
(
PApplet
.
platform
,
getNativeArch
(),
getNativeBits
());
}
static
public
String
getVariant
(
int
platform
,
String
arch
,
int
bits
) {
if
(
platform
==
PConstants
.
LINUX
&&
bits
==
32
&&
"arm"
.
equals
(
Platform
.
getNativeArch
())) {
return
"armv6hf"
;
// assume armv6hf for now
}
return
Integer
.
toString
(
bits
);
// 32 or 64
}
static
public
String
getName
() {
return
PConstants
.
platformNames
[
PApplet
.
platform
];
}
/**
* Map a platform constant to its name.
* @param which PConstants.WINDOWS, PConstants.MACOSX, PConstants.LINUX
* @return one of "windows", "macosx", or "linux"
*/
static
public
String
getName
(
int
which
) {
return
platformNames
.
get
(
which
);
}
static
public
int
getIndex
(
String
what
) {
Integer
entry
=
platformIndices
.
get
(
what
);
return
(
entry
==
null
) ? -
1
:
entry
.
intValue
();
}
// These were changed to no longer rely on PApplet and PConstants because
// of conflicts that could happen with older versions of core.jar, where
// the MACOSX constant would instead read as the LINUX constant.
/**
* returns true if Processing is running on a Mac OS X machine.
*/
static
public
boolean
isMacOS
() {
//return PApplet.platform == PConstants.MACOSX;
return
System
.
getProperty
(
"os.name"
).
indexOf
(
"Mac"
) != -
1
;
//$NON-NLS-1$ //$NON-NLS-2$
}
/**
* returns true if running on windows.
*/
static
public
boolean
isWindows
() {
//return PApplet.platform == PConstants.WINDOWS;
return
System
.
getProperty
(
"os.name"
).
indexOf
(
"Windows"
) != -
1
;
//$NON-NLS-1$ //$NON-NLS-2$
}
/**
* true if running on linux.
*/
static
public
boolean
isLinux
() {
//return PApplet.platform == PConstants.LINUX;
return
System
.
getProperty
(
"os.name"
).
indexOf
(
"Linux"
) != -
1
;
//$NON-NLS-1$ //$NON-NLS-2$
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static
protected
File
processingRoot
;
/**
* Get reference to a file adjacent to the executable on Windows and Linux,
* or inside Contents/Resources/Java on Mac OS X. This will return the local
* JRE location, *whether or not it is the active JRE*.
*/
static
public
File
getContentFile
(
String
name
) {
if
(
processingRoot
==
null
) {
// Get the path to the .jar file that contains Base.class
String
path
=
Base
.
class
.
getProtectionDomain
().
getCodeSource
().
getLocation
().
getPath
();
// Path may have URL encoding, so remove it
String
decodedPath
=
PApplet
.
urlDecode
(
path
);
if
(
decodedPath
.
contains
(
"/app/bin"
)) {
// This means we're in Eclipse
if
(
Platform
.
isMacOS
()) {
processingRoot
=
new
File
(
path
,
"../../build/macosx/work/Processing.app/Contents/Java"
);
}
else
if
(
Platform
.
isWindows
()) {
processingRoot
=
new
File
(
path
,
"../../build/windows/work"
);
}
else
if
(
Platform
.
isLinux
()) {
processingRoot
=
new
File
(
path
,
"../../build/linux/work"
);
}
}
else
{
// The .jar file will be in the lib folder
File
jarFolder
=
new
File
(
decodedPath
).
getParentFile
();
if
(
jarFolder
.
getName
().
equals
(
"lib"
)) {
// The main Processing installation directory.
// This works for Windows, Linux, and Apple's Java 6 on OS X.
processingRoot
=
jarFolder
.
getParentFile
();
}
else
if
(
Platform
.
isMacOS
()) {
// This works for Java 8 on OS X. We don't have things inside a 'lib'
// folder on OS X. Adding it caused more problems than it was worth.
processingRoot
=
jarFolder
;
}
if
(
processingRoot
==
null
|| !
processingRoot
.
exists
()) {
// Try working directory instead (user.dir, different from user.home)
System
.
err
.
println
(
"Could not find lib folder via "
+
jarFolder
.
getAbsolutePath
() +
", switching to user.dir"
);
processingRoot
=
new
File
(
System
.
getProperty
(
"user.dir"
));
}
}
}
return
new
File
(
processingRoot
,
name
);
}
static
public
File
getJavaHome
() {
if
(
Platform
.
isMacOS
()) {
//return "Contents/PlugIns/jdk1.7.0_40.jdk/Contents/Home/jre/bin/java";
File
[]
plugins
=
getContentFile
(
"../PlugIns"
).
listFiles
(
new
FilenameFilter
() {
public
boolean
accept
(
File
dir
,
String
name
) {
return
dir
.
isDirectory
() &&
name
.
endsWith
(
".jdk"
) && !
name
.
startsWith
(
"."
);
}
});
return
new
File
(
plugins
[
0
],
"Contents/Home/jre"
);
}
// On all other platforms, it's the 'java' folder adjacent to Processing
return
getContentFile
(
"java"
);
}
/** Get the path to the embedded Java executable. */
static
public
String
getJavaPath
() {
String
javaPath
=
"bin/java"
+ (
Platform
.
isWindows
() ?
".exe"
:
""
);
File
javaFile
=
new
File
(
getJavaHome
(),
javaPath
);
try
{
return
javaFile
.
getCanonicalPath
();
}
catch
(
IOException
e
) {
return
javaFile
.
getAbsolutePath
();
}
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
* Attempts to move to the Trash on OS X, or the Recycle Bin on Windows.
* Also tries to find a suitable Trash location on Linux.
* If not possible, just deletes the file or folder instead.
* @param file the folder or file to be removed/deleted
* @return true if the folder was successfully removed
* @throws IOException
*/
static
public
boolean
deleteFile
(
File
file
)
throws
IOException
{
FileUtils
fu
=
FileUtils
.
getInstance
();
if
(
fu
.
hasTrash
()) {
fu
.
moveToTrash
(
new
File
[] {
file
});
return
true
;
}
else
if
(
file
.
isDirectory
()) {
Util
.
removeDir
(
file
);
return
true
;
}
else
{
return
file
.
delete
();
}
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
static
public
void
setenv
(
String
variable
,
String
value
) {
inst
.
setenv
(
variable
,
value
);
}
static
public
String
getenv
(
String
variable
) {
return
inst
.
getenv
(
variable
);
}
static
public
int
unsetenv
(
String
variable
) {
return
inst
.
unsetenv
(
variable
);
}
}
Back
|
FazBrowse Home
|
New Git URL