2009-05-31 15:53:33 +00:00
|
|
|
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
Part of the Processing project - http://processing.org
|
|
|
|
|
|
|
|
Copyright (c) 2008 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;
|
|
|
|
|
2015-02-11 11:11:58 +01:00
|
|
|
import cc.arduino.packages.BoardPort;
|
2013-04-18 17:33:33 +02:00
|
|
|
import processing.app.debug.TargetBoard;
|
2013-01-28 16:33:18 +01:00
|
|
|
import processing.app.debug.TargetPackage;
|
|
|
|
import processing.app.debug.TargetPlatform;
|
2014-08-19 11:53:44 +02:00
|
|
|
import processing.app.legacy.PConstants;
|
2010-04-21 01:58:57 +00:00
|
|
|
|
2015-03-17 15:48:25 +01:00
|
|
|
import javax.swing.*;
|
2015-06-08 14:39:11 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2015-03-17 15:48:25 +01:00
|
|
|
|
|
|
|
import static processing.app.I18n._;
|
|
|
|
|
2009-05-31 15:53:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used by Base for platform-specific tweaking, for instance finding the
|
|
|
|
* sketchbook location using the Windows registry, or OS X event handling.
|
2015-06-08 14:39:11 +02:00
|
|
|
* <p/>
|
|
|
|
* The methods in this implementation are used by default, and can be
|
|
|
|
* overridden by a subclass, if loaded by Base.main().
|
|
|
|
* <p/>
|
2009-05-31 15:53:33 +00:00
|
|
|
* These methods throw vanilla-flavored Exceptions, so that error handling
|
2015-06-08 14:39:11 +02:00
|
|
|
* occurs inside Base.
|
|
|
|
* <p/>
|
|
|
|
* There is currently no mechanism for adding new platforms, as the setup is
|
|
|
|
* not automated. We could use getProperty("os.arch") perhaps, but that's
|
|
|
|
* debatable (could be upper/lowercase, have spaces, etc.. basically we don't
|
2009-05-31 15:53:33 +00:00
|
|
|
* know if name is proper Java package syntax.)
|
|
|
|
*/
|
|
|
|
public class Platform {
|
2015-06-08 14:39:11 +02:00
|
|
|
|
|
|
|
|
2009-05-31 15:53:33 +00:00
|
|
|
/**
|
|
|
|
* Set the default L & F. While I enjoy the bounty of the sixteen possible
|
2015-06-08 14:39:11 +02:00
|
|
|
* exception types that this UIManager method might throw, I feel that in
|
2009-05-31 15:53:33 +00:00
|
|
|
* just this one particular case, I'm being spoiled by those engineers
|
|
|
|
* at Sun, those Masters of the Abstractionverse. It leaves me feeling sad
|
|
|
|
* and overweight. So instead, I'll pretend that I'm not offered eleven dozen
|
|
|
|
* ways to report to the user exactly what went wrong, and I'll bundle them
|
2015-06-08 14:39:11 +02:00
|
|
|
* all into a single catch-all "Exception". Because in the end, all I really
|
2009-05-31 15:53:33 +00:00
|
|
|
* care about is whether things worked or not. And even then, I don't care.
|
2015-06-08 14:39:11 +02:00
|
|
|
*
|
2009-05-31 15:53:33 +00:00
|
|
|
* @throws Exception Just like I said.
|
|
|
|
*/
|
|
|
|
public void setLookAndFeel() throws Exception {
|
|
|
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
|
|
}
|
2015-06-08 14:39:11 +02:00
|
|
|
|
|
|
|
|
2015-03-24 10:15:06 +01:00
|
|
|
public void init() throws IOException {
|
2009-05-31 15:53:33 +00:00
|
|
|
}
|
2015-06-08 14:39:11 +02:00
|
|
|
|
|
|
|
|
2009-05-31 15:53:33 +00:00
|
|
|
public File getSettingsFolder() throws Exception {
|
|
|
|
// otherwise make a .processing directory int the user's home dir
|
|
|
|
File home = new File(System.getProperty("user.home"));
|
2012-12-12 10:23:04 +01:00
|
|
|
File dataFolder = new File(home, ".arduino15");
|
2009-05-31 15:53:33 +00:00
|
|
|
return dataFolder;
|
|
|
|
|
|
|
|
/*
|
|
|
|
try {
|
|
|
|
Class clazz = Class.forName("processing.app.macosx.ThinkDifferent");
|
|
|
|
Method m = clazz.getMethod("getLibraryFolder", new Class[] { });
|
|
|
|
String libraryPath = (String) m.invoke(null, new Object[] { });
|
|
|
|
//String libraryPath = BaseMacOS.getLibraryFolder();
|
|
|
|
File libraryFolder = new File(libraryPath);
|
|
|
|
dataFolder = new File(libraryFolder, "Processing");
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
showError("Problem getting data folder",
|
|
|
|
"Error getting the Processing data folder.", e);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
2015-06-08 14:39:11 +02:00
|
|
|
|
2009-05-31 15:53:33 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-08 14:39:11 +02:00
|
|
|
* @return null if not overridden, which will cause a prompt to show instead.
|
2009-05-31 15:53:33 +00:00
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public File getDefaultSketchbookFolder() throws Exception {
|
|
|
|
return null;
|
|
|
|
}
|
2015-06-08 14:39:11 +02:00
|
|
|
|
|
|
|
public void openURL(File folder, String url) throws Exception {
|
|
|
|
if (!url.startsWith("file://./")) {
|
|
|
|
openURL(url);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
url = url.replaceAll("file://./", folder.getCanonicalFile().toURI().toASCIIString());
|
|
|
|
openURL(url);
|
|
|
|
}
|
|
|
|
|
2009-05-31 15:53:33 +00:00
|
|
|
public void openURL(String url) throws Exception {
|
2014-08-22 12:47:43 +02:00
|
|
|
String launcher = PreferencesData.get("launcher");
|
2009-05-31 15:53:33 +00:00
|
|
|
if (launcher != null) {
|
2015-06-08 14:39:11 +02:00
|
|
|
Runtime.getRuntime().exec(new String[]{launcher, url});
|
2009-05-31 15:53:33 +00:00
|
|
|
} else {
|
|
|
|
showLauncherWarning();
|
2015-06-08 14:39:11 +02:00
|
|
|
}
|
2009-05-31 15:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean openFolderAvailable() {
|
2014-08-22 12:47:43 +02:00
|
|
|
return PreferencesData.get("launcher") != null;
|
2009-05-31 15:53:33 +00:00
|
|
|
}
|
2015-06-08 14:39:11 +02:00
|
|
|
|
|
|
|
|
2009-05-31 15:53:33 +00:00
|
|
|
public void openFolder(File file) throws Exception {
|
2014-08-22 12:47:43 +02:00
|
|
|
String launcher = PreferencesData.get("launcher");
|
2009-05-31 15:53:33 +00:00
|
|
|
if (launcher != null) {
|
|
|
|
String folder = file.getAbsolutePath();
|
2015-06-08 14:39:11 +02:00
|
|
|
Runtime.getRuntime().exec(new String[]{launcher, folder});
|
2009-05-31 15:53:33 +00:00
|
|
|
} else {
|
|
|
|
showLauncherWarning();
|
|
|
|
}
|
|
|
|
}
|
2013-01-28 16:33:18 +01:00
|
|
|
|
2015-03-06 12:46:21 +01:00
|
|
|
public Map<String, Object> resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
|
2013-02-04 15:35:16 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String preListAllCandidateDevices() {
|
2013-01-28 16:33:18 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-03-06 12:46:21 +01:00
|
|
|
protected Map<String, Object> resolveDeviceByVendorIdProductId(Map<String, TargetPackage> packages, String readVIDPID) {
|
2013-01-28 16:33:18 +01:00
|
|
|
for (TargetPackage targetPackage : packages.values()) {
|
|
|
|
for (TargetPlatform targetPlatform : targetPackage.getPlatforms().values()) {
|
2013-04-18 17:33:33 +02:00
|
|
|
for (TargetBoard board : targetPlatform.getBoards().values()) {
|
2015-03-06 12:46:21 +01:00
|
|
|
List<String> vids = new LinkedList<String>(board.getPreferences().subTree("vid", 1).values());
|
2013-01-30 13:05:10 +01:00
|
|
|
if (!vids.isEmpty()) {
|
2015-03-06 12:46:21 +01:00
|
|
|
List<String> pids = new LinkedList<String>(board.getPreferences().subTree("pid", 1).values());
|
|
|
|
for (int i = 0; i < vids.size(); i++) {
|
2013-01-30 13:05:10 +01:00
|
|
|
String vidPid = vids.get(i) + "_" + pids.get(i);
|
2013-01-28 18:21:41 +01:00
|
|
|
if (vidPid.toUpperCase().equals(readVIDPID)) {
|
2015-03-06 12:46:21 +01:00
|
|
|
Map<String, Object> boardData = new HashMap<String, Object>();
|
|
|
|
boardData.put("board", board);
|
|
|
|
boardData.put("vid", vids.get(i));
|
|
|
|
boardData.put("pid", pids.get(i));
|
|
|
|
return boardData;
|
2013-01-28 16:33:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-06-04 17:26:31 +02:00
|
|
|
public String resolveDeviceByBoardID(Map<String, TargetPackage> packages, String boardId) {
|
2015-04-13 13:29:05 +02:00
|
|
|
assert packages != null;
|
|
|
|
assert boardId != null;
|
2013-06-04 17:26:31 +02:00
|
|
|
for (TargetPackage targetPackage : packages.values()) {
|
|
|
|
for (TargetPlatform targetPlatform : targetPackage.getPlatforms().values()) {
|
|
|
|
for (TargetBoard board : targetPlatform.getBoards().values()) {
|
|
|
|
if (boardId.equals(board.getId())) {
|
|
|
|
return board.getName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-01-28 16:33:18 +01:00
|
|
|
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
|
|
|
|
2012-12-13 15:18:22 +01:00
|
|
|
public String getName() {
|
|
|
|
return PConstants.platformNames[PConstants.OTHER];
|
|
|
|
}
|
|
|
|
|
2015-06-08 14:39:11 +02:00
|
|
|
|
2010-04-21 01:58:57 +00:00
|
|
|
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
|
|
|
|
|
|
|
|
2009-05-31 15:53:33 +00:00
|
|
|
protected void showLauncherWarning() {
|
2015-06-08 14:39:11 +02:00
|
|
|
BaseNoGui.showWarning(_("No launcher available"),
|
|
|
|
_("Unspecified platform, no launcher available.\nTo enable opening URLs or folders, add a \n\"launcher=/path/to/app\" line to preferences.txt"),
|
|
|
|
null);
|
2009-05-31 15:53:33 +00:00
|
|
|
}
|
2015-02-11 11:11:58 +01:00
|
|
|
|
|
|
|
public List<BoardPort> filterPorts(List<BoardPort> ports, boolean aBoolean) {
|
|
|
|
return new LinkedList<BoardPort>(ports);
|
|
|
|
}
|
2015-03-17 15:48:25 +01:00
|
|
|
|
|
|
|
public void fixPrefsFilePermissions(File prefsFile) throws IOException, InterruptedException {
|
|
|
|
Process process = Runtime.getRuntime().exec(new String[]{"chmod", "600", prefsFile.getAbsolutePath()}, null, null);
|
|
|
|
process.waitFor();
|
|
|
|
}
|
2015-03-19 12:24:19 +01:00
|
|
|
|
|
|
|
public List<File> postInstallScripts(File folder) {
|
|
|
|
List<File> scripts = new LinkedList<File>();
|
|
|
|
scripts.add(new File(folder, "install_script.sh"));
|
|
|
|
scripts.add(new File(folder, "post_install.sh"));
|
|
|
|
return scripts;
|
|
|
|
}
|
2015-03-24 10:15:06 +01:00
|
|
|
|
|
|
|
public String getOsName() {
|
|
|
|
return System.getProperty("os.name");
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getOsArch() {
|
|
|
|
return System.getProperty("os.arch");
|
|
|
|
}
|
2015-03-30 09:30:03 +02:00
|
|
|
|
2015-03-30 17:12:38 +02:00
|
|
|
public void symlink(String something, File somewhere) throws IOException, InterruptedException {
|
|
|
|
Process process = Runtime.getRuntime().exec(new String[]{"ln", "-s", something, somewhere.getAbsolutePath()}, null, somewhere.getParentFile());
|
2015-03-30 09:30:03 +02:00
|
|
|
process.waitFor();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void link(File something, File somewhere) throws IOException, InterruptedException {
|
|
|
|
Process process = Runtime.getRuntime().exec(new String[]{"ln", something.getAbsolutePath(), somewhere.getAbsolutePath()}, null, null);
|
|
|
|
process.waitFor();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void chmod(File file, int mode) throws IOException, InterruptedException {
|
|
|
|
Process process = Runtime.getRuntime().exec(new String[]{"chmod", Integer.toOctalString(mode), file.getAbsolutePath()}, null, null);
|
|
|
|
process.waitFor();
|
|
|
|
}
|
2011-10-05 03:03:19 +09:00
|
|
|
}
|