mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
update AVR src
* java code not tested * Merge remote-tracking branch 'remotes/arduino/master' into esp8266 Conflicts: README.md app/src/processing/app/AbstractMonitor.java arduino-core/src/processing/app/Serial.java libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino libraries/WiFi/library.properties
This commit is contained in:
@ -8,6 +8,7 @@ import cc.arduino.files.DeleteFilesOnShutdown;
|
||||
import cc.arduino.packages.DiscoveryManager;
|
||||
import cc.arduino.packages.Uploader;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.apache.commons.logging.impl.LogFactoryImpl;
|
||||
import org.apache.commons.logging.impl.NoOpLog;
|
||||
import processing.app.debug.Compiler;
|
||||
@ -30,9 +31,9 @@ import static processing.app.I18n._;
|
||||
public class BaseNoGui {
|
||||
|
||||
/** Version string to be used for build */
|
||||
public static final int REVISION = 10605;
|
||||
public static final int REVISION = 10606;
|
||||
/** Extended version string displayed on GUI */
|
||||
public static final String VERSION_NAME = "1.6.5";
|
||||
public static final String VERSION_NAME = "1.6.6";
|
||||
public static final String VERSION_NAME_LONG;
|
||||
|
||||
static {
|
||||
@ -315,14 +316,15 @@ public class BaseNoGui {
|
||||
static public File getSketchbookLibrariesFolder() {
|
||||
File libdir = new File(getSketchbookFolder(), "libraries");
|
||||
if (!libdir.exists()) {
|
||||
FileWriter freadme = null;
|
||||
try {
|
||||
libdir.mkdirs();
|
||||
File readme = new File(libdir, "readme.txt");
|
||||
FileWriter freadme = new FileWriter(readme);
|
||||
freadme = new FileWriter(new File(libdir, "readme.txt"));
|
||||
freadme.write(_("For information on installing libraries, see: " +
|
||||
"http://arduino.cc/en/Guide/Libraries\n"));
|
||||
freadme.close();
|
||||
"http://www.arduino.cc/en/Guide/Libraries\n"));
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
IOUtils.closeQuietly(freadme);
|
||||
}
|
||||
}
|
||||
return libdir;
|
||||
@ -417,7 +419,7 @@ public class BaseNoGui {
|
||||
* within the header files at the top-level).
|
||||
*/
|
||||
static public String[] headerListFromIncludePath(File path) throws IOException {
|
||||
String[] list = path.list(new OnlyFilesWithExtension(".h"));
|
||||
String[] list = path.list(new OnlyFilesWithExtension(".h", ".hh", ".hpp"));
|
||||
if (list == null) {
|
||||
throw new IOException();
|
||||
}
|
||||
@ -425,8 +427,9 @@ public class BaseNoGui {
|
||||
}
|
||||
|
||||
static public void init(String[] args) throws Exception {
|
||||
getPlatform().init();
|
||||
|
||||
CommandlineParser parser = new CommandlineParser(args);
|
||||
parser.parseArgumentsPhase1();
|
||||
|
||||
String sketchbookPath = getSketchbookPath();
|
||||
|
||||
// If no path is set, get the default sketchbook folder for this platform
|
||||
@ -436,13 +439,13 @@ public class BaseNoGui {
|
||||
else
|
||||
showError(_("No sketchbook"), _("Sketchbook path not defined"), null);
|
||||
}
|
||||
|
||||
|
||||
BaseNoGui.initPackages();
|
||||
|
||||
// Setup board-dependent variables.
|
||||
onBoardOrPortChange();
|
||||
|
||||
CommandlineParser parser = CommandlineParser.newCommandlineParser(args);
|
||||
|
||||
parser.parseArgumentsPhase2();
|
||||
|
||||
for (String path: parser.getFilenames()) {
|
||||
// Correctly resolve relative paths
|
||||
@ -570,6 +573,12 @@ public class BaseNoGui {
|
||||
System.exit(0);
|
||||
}
|
||||
else if (parser.isGetPrefMode()) {
|
||||
dumpPrefs(parser);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void dumpPrefs(CommandlineParser parser) {
|
||||
if (parser.getGetPref() != null) {
|
||||
String value = PreferencesData.get(parser.getGetPref(), null);
|
||||
if (value != null) {
|
||||
System.out.println(value);
|
||||
@ -577,6 +586,13 @@ public class BaseNoGui {
|
||||
} else {
|
||||
System.exit(4);
|
||||
}
|
||||
} else {
|
||||
System.out.println("#PREFDUMP#");
|
||||
PreferencesMap prefs = PreferencesData.getMap();
|
||||
for (Map.Entry<String, String> entry : prefs.entrySet()) {
|
||||
System.out.println(entry.getKey() + "=" + entry.getValue());
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -586,7 +602,7 @@ public class BaseNoGui {
|
||||
}
|
||||
|
||||
static public void initPackages() throws Exception {
|
||||
indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
|
||||
indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder(), BaseNoGui.getPlatform());
|
||||
File indexFile = indexer.getIndexFile("package_index.json");
|
||||
File defaultPackageJsonFile = new File(getContentFile("dist"), "package_index.json");
|
||||
if (!indexFile.isFile() || (defaultPackageJsonFile.isFile() && defaultPackageJsonFile.lastModified() > indexFile.lastModified())) {
|
||||
@ -597,11 +613,8 @@ public class BaseNoGui {
|
||||
try {
|
||||
out = new FileOutputStream(indexFile);
|
||||
out.write("{ \"packages\" : [ ] }".getBytes());
|
||||
out.close();
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
}
|
||||
|
||||
@ -624,13 +637,13 @@ public class BaseNoGui {
|
||||
}
|
||||
indexer.syncWithFilesystem(getHardwareFolder());
|
||||
|
||||
packages = new HashMap<String, TargetPackage>();
|
||||
packages = new LinkedHashMap<String, TargetPackage>();
|
||||
loadHardware(getHardwareFolder());
|
||||
loadHardware(getSketchbookHardwareFolder());
|
||||
loadContributedHardware(indexer);
|
||||
loadHardware(getSketchbookHardwareFolder());
|
||||
createToolPreferences(indexer);
|
||||
|
||||
librariesIndexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder());
|
||||
librariesIndexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder(), indexer);
|
||||
File librariesIndexFile = librariesIndexer.getIndexFile();
|
||||
if (!librariesIndexFile.isFile()) {
|
||||
File defaultLibraryJsonFile = new File(getContentFile("dist"), "library_index.json");
|
||||
@ -645,9 +658,7 @@ public class BaseNoGui {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -734,20 +745,47 @@ public class BaseNoGui {
|
||||
}
|
||||
|
||||
static public void main(String args[]) throws Exception {
|
||||
if (args.length == 0)
|
||||
if (args.length == 0) {
|
||||
showError(_("No parameters"), _("No command line parameters found"), null);
|
||||
}
|
||||
System.setProperty("java.net.useSystemProxies", "true");
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(DeleteFilesOnShutdown.INSTANCE));
|
||||
|
||||
initPlatform();
|
||||
|
||||
|
||||
getPlatform().init();
|
||||
|
||||
initPortableFolder();
|
||||
|
||||
initParameters(args);
|
||||
|
||||
|
||||
checkInstallationFolder();
|
||||
|
||||
init(args);
|
||||
}
|
||||
|
||||
public static void checkInstallationFolder() {
|
||||
if (isIDEInstalledIntoSettingsFolder()) {
|
||||
showError(_("Incorrect IDE installation folder"), _("Your copy of the IDE is installed in a subfolder of your settings folder.\nPlease move the IDE to another folder."), 10);
|
||||
}
|
||||
if (isIDEInstalledIntoSketchbookFolder()) {
|
||||
showError(_("Incorrect IDE installation folder"), _("Your copy of the IDE is installed in a subfolder of your sketchbook.\nPlease move the IDE to another folder."), 10);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isIDEInstalledIntoSketchbookFolder() {
|
||||
return PreferencesData.has("sketchbook.path") && FileUtils.isSubDirectory(new File(PreferencesData.get("sketchbook.path")), new File(PreferencesData.get("runtime.ide.path")));
|
||||
}
|
||||
|
||||
public static boolean isIDEInstalledIntoSettingsFolder() {
|
||||
try {
|
||||
return FileUtils.isSubDirectory(BaseNoGui.getPlatform().getSettingsFolder(), new File(PreferencesData.get("runtime.ide.path")));
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static public void onBoardOrPortChange() {
|
||||
examplesFolder = getContentFile("examples");
|
||||
toolsFolder = getContentFile("tools");
|
||||
@ -788,7 +826,7 @@ public class BaseNoGui {
|
||||
populateImportToLibraryTable();
|
||||
}
|
||||
|
||||
static protected void loadContributedHardware(ContributionsIndexer indexer) throws TargetPlatformException {
|
||||
static protected void loadContributedHardware(ContributionsIndexer indexer) {
|
||||
for (TargetPackage pack : indexer.createTargetPackages()) {
|
||||
packages.put(pack.getId(), pack);
|
||||
}
|
||||
@ -800,7 +838,7 @@ public class BaseNoGui {
|
||||
PreferencesData.removeAllKeysWithPrefix(prefix);
|
||||
|
||||
for (ContributedTool tool : indexer.getInstalledTools()) {
|
||||
File installedFolder = tool.getDownloadableContribution().getInstalledFolder();
|
||||
File installedFolder = tool.getDownloadableContribution(getPlatform()).getInstalledFolder();
|
||||
if (installedFolder != null) {
|
||||
PreferencesData.set(prefix + tool.getName() + ".path", installedFolder.getAbsolutePath());
|
||||
PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", installedFolder.getAbsolutePath());
|
||||
@ -956,14 +994,18 @@ public class BaseNoGui {
|
||||
if (!dir.exists()) return;
|
||||
|
||||
String files[] = dir.list();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].equals(".") || files[i].equals("..")) continue;
|
||||
File dead = new File(dir, files[i]);
|
||||
if (files == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String file : files) {
|
||||
if (file.equals(".") || file.equals("..")) continue;
|
||||
File dead = new File(dir, file);
|
||||
if (!dead.isDirectory()) {
|
||||
if (!PreferencesData.getBoolean("compiler.save_build_files")) {
|
||||
if (!dead.delete()) {
|
||||
// temporarily disabled
|
||||
System.err.println(I18n.format(_("Could not delete {0}"), dead));
|
||||
System.err.println(I18n.format(_("Could not delete {0}"), dead));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -1068,10 +1110,11 @@ public class BaseNoGui {
|
||||
|
||||
public static void selectSerialPort(String port) {
|
||||
PreferencesData.set("serial.port", port);
|
||||
if (port.startsWith("/dev/"))
|
||||
PreferencesData.set("serial.port.file", port.substring(5));
|
||||
else
|
||||
PreferencesData.set("serial.port.file", port);
|
||||
String portFile = port;
|
||||
if (port.startsWith("/dev/")) {
|
||||
portFile = portFile.substring(5);
|
||||
}
|
||||
PreferencesData.set("serial.port.file", portFile);
|
||||
}
|
||||
|
||||
public static void setBuildFolder(File newBuildFolder) {
|
||||
|
@ -29,8 +29,12 @@ import processing.app.debug.TargetPlatform;
|
||||
import processing.app.legacy.PConstants;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@ -38,42 +42,42 @@ import static processing.app.I18n._;
|
||||
/**
|
||||
* Used by Base for platform-specific tweaking, for instance finding the
|
||||
* sketchbook location using the Windows registry, or OS X event handling.
|
||||
*
|
||||
* The methods in this implementation are used by default, and can be
|
||||
* overridden by a subclass, if loaded by Base.main().
|
||||
*
|
||||
* <p/>
|
||||
* The methods in this implementation are used by default, and can be
|
||||
* overridden by a subclass, if loaded by Base.main().
|
||||
* <p/>
|
||||
* These methods throw vanilla-flavored Exceptions, so that error handling
|
||||
* occurs inside Base.
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* know if name is proper Java package syntax.)
|
||||
*/
|
||||
public class Platform {
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set the default L & F. While I enjoy the bounty of the sixteen possible
|
||||
* exception types that this UIManager method might throw, I feel that in
|
||||
* exception types that this UIManager method might throw, I feel that in
|
||||
* 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
|
||||
* all into a single catch-all "Exception". Because in the end, all I really
|
||||
* all into a single catch-all "Exception". Because in the end, all I really
|
||||
* care about is whether things worked or not. And even then, I don't care.
|
||||
*
|
||||
*
|
||||
* @throws Exception Just like I said.
|
||||
*/
|
||||
public void setLookAndFeel() throws Exception {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void init() throws IOException {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public File getSettingsFolder() throws Exception {
|
||||
// otherwise make a .processing directory int the user's home dir
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
@ -95,37 +99,46 @@ public class Platform {
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return null if not overridden, which will cause a prompt to show instead.
|
||||
* @return null if not overridden, which will cause a prompt to show instead.
|
||||
* @throws Exception
|
||||
*/
|
||||
public File getDefaultSketchbookFolder() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void openURL(String url) throws Exception {
|
||||
String launcher = PreferencesData.get("launcher");
|
||||
if (launcher != null) {
|
||||
Runtime.getRuntime().exec(new String[] { launcher, url });
|
||||
Runtime.getRuntime().exec(new String[]{launcher, url});
|
||||
} else {
|
||||
showLauncherWarning();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean openFolderAvailable() {
|
||||
return PreferencesData.get("launcher") != null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void openFolder(File file) throws Exception {
|
||||
String launcher = PreferencesData.get("launcher");
|
||||
if (launcher != null) {
|
||||
String folder = file.getAbsolutePath();
|
||||
Runtime.getRuntime().exec(new String[] { launcher, folder });
|
||||
Runtime.getRuntime().exec(new String[]{launcher, folder});
|
||||
} else {
|
||||
showLauncherWarning();
|
||||
}
|
||||
@ -184,14 +197,14 @@ public class Platform {
|
||||
return PConstants.platformNames[PConstants.OTHER];
|
||||
}
|
||||
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
protected void showLauncherWarning() {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
public List<BoardPort> filterPorts(List<BoardPort> ports, boolean aBoolean) {
|
||||
|
@ -1,23 +1,23 @@
|
||||
package processing.app;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.helpers.PreferencesHelper;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.legacy.PApplet;
|
||||
import processing.app.legacy.PConstants;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
|
||||
public class PreferencesData {
|
||||
|
||||
@ -50,14 +50,14 @@ public class PreferencesData {
|
||||
prefs.load(new File(BaseNoGui.getContentFile("lib"), PREFS_FILE));
|
||||
} catch (IOException e) {
|
||||
BaseNoGui.showError(null, _("Could not read default settings.\n" +
|
||||
"You'll need to reinstall Arduino."), e);
|
||||
"You'll need to reinstall Arduino."), e);
|
||||
}
|
||||
|
||||
// set some runtime constants (not saved on preferences file)
|
||||
File hardwareFolder = BaseNoGui.getHardwareFolder();
|
||||
prefs.put("runtime.ide.path", hardwareFolder.getParentFile().getAbsolutePath());
|
||||
prefs.put("runtime.ide.version", "" + BaseNoGui.REVISION);
|
||||
|
||||
|
||||
// clone the hash table
|
||||
defaults = new PreferencesMap(prefs);
|
||||
|
||||
@ -67,10 +67,10 @@ public class PreferencesData {
|
||||
prefs.load(preferencesFile);
|
||||
} catch (IOException ex) {
|
||||
BaseNoGui.showError(_("Error reading preferences"),
|
||||
I18n.format(_("Error reading the preferences file. "
|
||||
+ "Please delete (or move)\n"
|
||||
+ "{0} and restart Arduino."),
|
||||
preferencesFile.getAbsolutePath()), ex);
|
||||
I18n.format(_("Error reading the preferences file. "
|
||||
+ "Please delete (or move)\n"
|
||||
+ "{0} and restart Arduino."),
|
||||
preferencesFile.getAbsolutePath()), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,9 +124,7 @@ public class PreferencesData {
|
||||
|
||||
writer.flush();
|
||||
} finally {
|
||||
if (writer != null) {
|
||||
writer.close();
|
||||
}
|
||||
IOUtils.closeQuietly(writer);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -198,8 +196,7 @@ public class PreferencesData {
|
||||
}
|
||||
|
||||
// get a copy of the Preferences
|
||||
static public PreferencesMap getMap()
|
||||
{
|
||||
static public PreferencesMap getMap() {
|
||||
return new PreferencesMap(prefs);
|
||||
}
|
||||
|
||||
@ -212,8 +209,7 @@ public class PreferencesData {
|
||||
|
||||
// Decide wether changed preferences will be saved. When value is
|
||||
// false, Preferences.save becomes a no-op.
|
||||
static public void setDoSave(boolean value)
|
||||
{
|
||||
static public void setDoSave(boolean value) {
|
||||
doSave = value;
|
||||
}
|
||||
|
||||
@ -226,4 +222,13 @@ public class PreferencesData {
|
||||
}
|
||||
return font;
|
||||
}
|
||||
|
||||
public static Collection<String> getCollection(String key) {
|
||||
return Arrays.asList(get(key, "").split(","));
|
||||
}
|
||||
|
||||
public static void setCollection(String key, Collection<String> values) {
|
||||
String value = Joiner.on(',').join(values);
|
||||
set(key, value);
|
||||
}
|
||||
}
|
||||
|
@ -22,16 +22,16 @@
|
||||
|
||||
package processing.app;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
import jssc.SerialPort;
|
||||
import jssc.SerialPortEvent;
|
||||
import jssc.SerialPortEventListener;
|
||||
import jssc.SerialPortException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import jssc.SerialPort;
|
||||
import jssc.SerialPortEvent;
|
||||
import jssc.SerialPortEventListener;
|
||||
import jssc.SerialPortException;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
|
||||
public class Serial implements SerialPortEventListener {
|
||||
@ -45,19 +45,14 @@ public class Serial implements SerialPortEventListener {
|
||||
// for the classloading problem.. because if code ran again,
|
||||
// the static class would have an object that could be closed
|
||||
|
||||
SerialPort port;
|
||||
|
||||
int rate;
|
||||
int parity;
|
||||
int databits;
|
||||
int stopbits;
|
||||
private SerialPort port;
|
||||
|
||||
public Serial() throws SerialException {
|
||||
this(PreferencesData.get("serial.port"),
|
||||
PreferencesData.getInteger("serial.debug_rate"),
|
||||
PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue(),
|
||||
Float.parseFloat(PreferencesData.get("serial.stopbits"))),
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableRTS") == null,
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableDTR") == null);
|
||||
}
|
||||
@ -66,7 +61,7 @@ public class Serial implements SerialPortEventListener {
|
||||
this(PreferencesData.get("serial.port"), irate,
|
||||
PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue(),
|
||||
Float.parseFloat(PreferencesData.get("serial.stopbits"))),
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableRTS") == null,
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableDTR") == null);
|
||||
}
|
||||
@ -74,7 +69,7 @@ public class Serial implements SerialPortEventListener {
|
||||
public Serial(String iname, int irate) throws SerialException {
|
||||
this(iname, irate, PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue(),
|
||||
Float.parseFloat(PreferencesData.get("serial.stopbits"))),
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableRTS") == null,
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableDTR") == null);
|
||||
}
|
||||
@ -83,7 +78,7 @@ public class Serial implements SerialPortEventListener {
|
||||
this(iname, PreferencesData.getInteger("serial.debug_rate"),
|
||||
PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue(),
|
||||
Float.parseFloat(PreferencesData.get("serial.stopbits"))),
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableRTS") == null,
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableDTR") == null);
|
||||
}
|
||||
@ -109,29 +104,28 @@ public class Serial implements SerialPortEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
public Serial(String iname, int irate, char iparity, int idatabits, float istopbits, boolean setRTS, boolean setDTR) throws SerialException {
|
||||
private Serial(String iname, int irate, char iparity, int idatabits, float istopbits, boolean setRTS, boolean setDTR) throws SerialException {
|
||||
//if (port != null) port.close();
|
||||
//this.parent = parent;
|
||||
//parent.attach(this);
|
||||
|
||||
this.rate = irate;
|
||||
|
||||
parity = SerialPort.PARITY_NONE;
|
||||
int parity = SerialPort.PARITY_NONE;
|
||||
if (iparity == 'E') parity = SerialPort.PARITY_EVEN;
|
||||
if (iparity == 'O') parity = SerialPort.PARITY_ODD;
|
||||
|
||||
this.databits = idatabits;
|
||||
|
||||
stopbits = SerialPort.STOPBITS_1;
|
||||
int stopbits = SerialPort.STOPBITS_1;
|
||||
if (istopbits == 1.5f) stopbits = SerialPort.STOPBITS_1_5;
|
||||
if (istopbits == 2) stopbits = SerialPort.STOPBITS_2;
|
||||
|
||||
try {
|
||||
port = new SerialPort(iname);
|
||||
port.openPort();
|
||||
port.setParams(rate, databits, stopbits, parity, setRTS, setDTR);
|
||||
port.setParams(irate, idatabits, stopbits, parity, setRTS, setDTR);
|
||||
port.addEventListener(this);
|
||||
} catch (Exception e) {
|
||||
} catch (SerialPortException e) {
|
||||
if (e.getPortName().startsWith("/dev") && SerialPortException.TYPE_PERMISSION_DENIED.equals(e.getExceptionType())) {
|
||||
throw new SerialException(I18n.format(_("Error opening serial port ''{0}''. Try consulting the documentation at http://playground.arduino.cc/Linux/All#Permission"), iname));
|
||||
}
|
||||
throw new SerialException(I18n.format(_("Error opening serial port ''{0}''."), iname), e);
|
||||
}
|
||||
|
||||
@ -176,9 +170,6 @@ public class Serial implements SerialPortEventListener {
|
||||
/**
|
||||
* This method is intented to be extended to receive messages
|
||||
* coming from serial port.
|
||||
*
|
||||
* @param chars
|
||||
* @param length
|
||||
*/
|
||||
protected void message(char[] chars, int length) {
|
||||
// Empty
|
||||
@ -197,7 +188,7 @@ public class Serial implements SerialPortEventListener {
|
||||
}
|
||||
|
||||
|
||||
public void write(byte bytes[]) {
|
||||
private void write(byte bytes[]) {
|
||||
try {
|
||||
port.writeBytes(bytes);
|
||||
} catch (SerialPortException e) {
|
||||
@ -213,7 +204,7 @@ public class Serial implements SerialPortEventListener {
|
||||
* (most often the case for networking and serial i/o) and
|
||||
* will only use the bottom 8 bits of each char in the string.
|
||||
* (Meaning that internally it uses String.getBytes)
|
||||
* <p/>
|
||||
* <p>
|
||||
* If you want to move Unicode data, you can first convert the
|
||||
* String to a byte stream in the representation of your choice
|
||||
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
|
||||
@ -247,92 +238,8 @@ public class Serial implements SerialPortEventListener {
|
||||
* General error reporting, all corraled here just in case
|
||||
* I think of something slightly more intelligent to do.
|
||||
*/
|
||||
static public void errorMessage(String where, Throwable e) {
|
||||
private static void errorMessage(String where, Throwable e) {
|
||||
System.err.println(I18n.format(_("Error inside Serial.{0}()"), where));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
class SerialMenuListener implements ItemListener {
|
||||
//public SerialMenuListener() { }
|
||||
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
int count = serialMenu.getItemCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
((CheckboxMenuItem)serialMenu.getItem(i)).setState(false);
|
||||
}
|
||||
CheckboxMenuItem item = (CheckboxMenuItem)e.getSource();
|
||||
item.setState(true);
|
||||
String name = item.getLabel();
|
||||
//System.out.println(item.getLabel());
|
||||
PdeBase.properties.put("serial.port", name);
|
||||
//System.out.println("set to " + get("serial.port"));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
protected Vector buildPortList() {
|
||||
// get list of names for serial ports
|
||||
// have the default port checked (if present)
|
||||
Vector list = new Vector();
|
||||
|
||||
//SerialMenuListener listener = new SerialMenuListener();
|
||||
boolean problem = false;
|
||||
|
||||
// if this is failing, it may be because
|
||||
// lib/javax.comm.properties is missing.
|
||||
// java is weird about how it searches for java.comm.properties
|
||||
// so it tends to be very fragile. i.e. quotes in the CLASSPATH
|
||||
// environment variable will hose things.
|
||||
try {
|
||||
//System.out.println("building port list");
|
||||
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
||||
while (portList.hasMoreElements()) {
|
||||
CommPortIdentifier portId =
|
||||
(CommPortIdentifier) portList.nextElement();
|
||||
//System.out.println(portId);
|
||||
|
||||
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
|
||||
//if (portId.getName().equals(port)) {
|
||||
String name = portId.getName();
|
||||
//CheckboxMenuItem mi =
|
||||
//new CheckboxMenuItem(name, name.equals(defaultName));
|
||||
|
||||
//mi.addItemListener(listener);
|
||||
//serialMenu.add(mi);
|
||||
list.addElement(name);
|
||||
}
|
||||
}
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
e.printStackTrace();
|
||||
problem = true;
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("exception building serial menu");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//if (serialMenu.getItemCount() == 0) {
|
||||
//System.out.println("dimming serial menu");
|
||||
//serialMenu.setEnabled(false);
|
||||
//}
|
||||
|
||||
// only warn them if this is the first time
|
||||
if (problem && PdeBase.firstTime) {
|
||||
JOptionPane.showMessageDialog(this, //frame,
|
||||
"Serial port support not installed.\n" +
|
||||
"Check the readme for instructions\n" +
|
||||
"if you need to use the serial port. ",
|
||||
"Serial Port Warning",
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
@ -22,31 +22,37 @@
|
||||
|
||||
package processing.app;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
import processing.app.helpers.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
/**
|
||||
* Represents a single tab of a sketch.
|
||||
* Represents a single tab of a sketch.
|
||||
*/
|
||||
public class SketchCode {
|
||||
|
||||
/** Pretty name (no extension), not the full file name */
|
||||
private String prettyName;
|
||||
|
||||
/** File object for where this code is located */
|
||||
/**
|
||||
* File object for where this code is located
|
||||
*/
|
||||
private File file;
|
||||
|
||||
/** Text of the program text for this tab */
|
||||
/**
|
||||
* Text of the program text for this tab
|
||||
*/
|
||||
private String program;
|
||||
|
||||
private boolean modified;
|
||||
|
||||
/** where this code starts relative to the concat'd code */
|
||||
private int preprocOffset;
|
||||
/**
|
||||
* where this code starts relative to the concat'd code
|
||||
*/
|
||||
private int preprocOffset;
|
||||
|
||||
private Object metadata;
|
||||
|
||||
@ -62,8 +68,6 @@ public class SketchCode {
|
||||
this.file = file;
|
||||
this.metadata = metadata;
|
||||
|
||||
makePrettyName();
|
||||
|
||||
try {
|
||||
load();
|
||||
} catch (IOException e) {
|
||||
@ -73,28 +77,21 @@ public class SketchCode {
|
||||
}
|
||||
|
||||
|
||||
protected void makePrettyName() {
|
||||
prettyName = file.getName();
|
||||
int dot = prettyName.lastIndexOf('.');
|
||||
prettyName = prettyName.substring(0, dot);
|
||||
}
|
||||
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected boolean fileExists() {
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected boolean fileReadOnly() {
|
||||
return !file.canWrite();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected boolean deleteFile(File tempBuildFolder) {
|
||||
if (!file.delete()) {
|
||||
return false;
|
||||
@ -106,38 +103,42 @@ public class SketchCode {
|
||||
}
|
||||
});
|
||||
for (File compiledFile : compiledFiles) {
|
||||
compiledFile.delete();
|
||||
if (!compiledFile.delete()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected boolean renameTo(File what) {
|
||||
boolean success = file.renameTo(what);
|
||||
if (success) {
|
||||
file = what;
|
||||
makePrettyName();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
protected void copyTo(File dest) throws IOException {
|
||||
BaseNoGui.saveFile(program, dest);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getFileName() {
|
||||
return file.getName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String getPrettyName() {
|
||||
return prettyName;
|
||||
String prettyName = getFileName();
|
||||
int dot = prettyName.lastIndexOf('.');
|
||||
return prettyName.substring(0, dot);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getFileNameWithExtensionIfNotIno() {
|
||||
if (getFileName().endsWith(".ino")) {
|
||||
return getPrettyName();
|
||||
}
|
||||
return getFileName();
|
||||
}
|
||||
|
||||
public boolean isExtension(String... extensions) {
|
||||
return isExtension(Arrays.asList(extensions));
|
||||
}
|
||||
@ -145,23 +146,23 @@ public class SketchCode {
|
||||
public boolean isExtension(List<String> extensions) {
|
||||
return FileUtils.hasExtension(file, extensions);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String getProgram() {
|
||||
return program;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setProgram(String replacement) {
|
||||
program = replacement;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public int getLineCount() {
|
||||
return BaseNoGui.countLines(program);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setModified(boolean modified) {
|
||||
this.modified = modified;
|
||||
}
|
||||
@ -177,25 +178,21 @@ public class SketchCode {
|
||||
}
|
||||
|
||||
|
||||
public int getPreprocOffset() {
|
||||
return preprocOffset;
|
||||
}
|
||||
|
||||
|
||||
public void addPreprocOffset(int extra) {
|
||||
preprocOffset += extra;
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
/**
|
||||
* Load this piece of code from a file.
|
||||
*/
|
||||
public void load() throws IOException {
|
||||
private void load() throws IOException {
|
||||
program = BaseNoGui.loadFile(file);
|
||||
|
||||
if (program == null) {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
if (program.indexOf('\uFFFD') != -1) {
|
||||
System.err.println(
|
||||
I18n.format(
|
||||
@ -209,7 +206,7 @@ public class SketchCode {
|
||||
);
|
||||
System.err.println();
|
||||
}
|
||||
|
||||
|
||||
setModified(false);
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,19 @@
|
||||
package processing.app;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class SketchData {
|
||||
|
||||
public static final List<String> SKETCH_EXTENSIONS = Arrays.asList("ino", "pde");
|
||||
public static final List<String> OTHER_ALLOWED_EXTENSIONS = Arrays.asList("c", "cpp", "h", "s");
|
||||
public static final List<String> EXTENSIONS = new LinkedList<String>(FluentIterable.from(SKETCH_EXTENSIONS).append(OTHER_ALLOWED_EXTENSIONS).toList());
|
||||
|
||||
/** main pde file for this sketch. */
|
||||
private File primaryFile;
|
||||
|
||||
@ -95,6 +97,9 @@ public class SketchData {
|
||||
|
||||
// get list of files in the sketch folder
|
||||
String list[] = folder.list();
|
||||
if (list == null) {
|
||||
throw new IOException("Unable to list files from " + folder);
|
||||
}
|
||||
|
||||
// reset these because load() may be called after an
|
||||
// external editor event. (fix for 0099)
|
||||
@ -102,8 +107,6 @@ public class SketchData {
|
||||
clearCodeDocs();
|
||||
// data.setCodeDocs(codeDocs);
|
||||
|
||||
List<String> extensions = getExtensions();
|
||||
|
||||
for (String filename : list) {
|
||||
// Ignoring the dot prefix files is especially important to avoid files
|
||||
// with the ._ prefix on Mac OS X. (You'll see this with Mac files on
|
||||
@ -116,7 +119,7 @@ public class SketchData {
|
||||
// figure out the name without any extension
|
||||
String base = filename;
|
||||
// now strip off the .pde and .java extensions
|
||||
for (String extension : extensions) {
|
||||
for (String extension : EXTENSIONS) {
|
||||
if (base.toLowerCase().endsWith("." + extension)) {
|
||||
base = base.substring(0, base.length() - (extension.length() + 1));
|
||||
|
||||
@ -170,13 +173,6 @@ public class SketchData {
|
||||
return "ino";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String[] array of proper extensions.
|
||||
*/
|
||||
public List<String> getExtensions() {
|
||||
return Arrays.asList("ino", "pde", "c", "cpp", "h");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a file object for the primary .pde of this sketch.
|
||||
*/
|
||||
|
@ -34,14 +34,16 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import cc.arduino.MyStreamPumper;
|
||||
import cc.arduino.packages.BoardPort;
|
||||
import cc.arduino.packages.Uploader;
|
||||
import cc.arduino.packages.UploaderFactory;
|
||||
|
||||
import org.apache.commons.exec.CommandLine;
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
import org.apache.commons.exec.ExecuteStreamHandler;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.apache.commons.exec.*;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.PreferencesData;
|
||||
@ -100,12 +102,14 @@ public class Compiler implements MessageConsumer {
|
||||
compiler.cleanup(prefsChanged, tempBuildFolder);
|
||||
|
||||
if (prefsChanged) {
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
PrintWriter out = new PrintWriter(buildPrefsFile);
|
||||
out = new PrintWriter(buildPrefsFile);
|
||||
out.print(newBuildPrefs);
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
System.err.println(_("Could not write build preferences file"));
|
||||
} finally {
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,15 +135,12 @@ public class Compiler implements MessageConsumer {
|
||||
TargetPlatform target = BaseNoGui.getTargetPlatform();
|
||||
String board = PreferencesData.get("board");
|
||||
|
||||
if (noUploadPort)
|
||||
{
|
||||
return new UploaderFactory().newUploader(target.getBoards().get(board), null, noUploadPort);
|
||||
}
|
||||
else
|
||||
{
|
||||
BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
|
||||
return new UploaderFactory().newUploader(target.getBoards().get(board), boardPort, noUploadPort);
|
||||
BoardPort boardPort = null;
|
||||
if (!noUploadPort) {
|
||||
boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
|
||||
}
|
||||
|
||||
return new UploaderFactory().newUploader(target.getBoards().get(board), boardPort, noUploadPort);
|
||||
}
|
||||
|
||||
static public boolean upload(SketchData data, Uploader uploader, String buildPath, String suggestedClassName, boolean usingProgrammer, boolean noUploadPort, List<String> warningsAccumulator) throws Exception {
|
||||
@ -151,7 +152,7 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
if (uploader.requiresAuthorization() && !PreferencesData.has(uploader.getAuthorizationKey())) {
|
||||
BaseNoGui.showError(_("Authorization required"),
|
||||
_("No athorization data found"), null);
|
||||
_("No authorization data found"), null);
|
||||
}
|
||||
|
||||
boolean useNewWarningsAccumulator = false;
|
||||
@ -277,11 +278,13 @@ public class Compiler implements MessageConsumer {
|
||||
// used. Keep everything else, which might be reusable
|
||||
if (tempBuildFolder.exists()) {
|
||||
String files[] = tempBuildFolder.list();
|
||||
for (String file : files) {
|
||||
if (file.endsWith(".c") || file.endsWith(".cpp") || file.endsWith(".s")) {
|
||||
File deleteMe = new File(tempBuildFolder, file);
|
||||
if (!deleteMe.delete()) {
|
||||
System.err.println("Could not delete " + deleteMe);
|
||||
if (files != null) {
|
||||
for (String file : files) {
|
||||
if (file.endsWith(".c") || file.endsWith(".cpp") || file.endsWith(".s")) {
|
||||
File deleteMe = new File(tempBuildFolder, file);
|
||||
if (!deleteMe.delete()) {
|
||||
System.err.println("Could not delete " + deleteMe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -399,26 +402,44 @@ public class Compiler implements MessageConsumer {
|
||||
System.err.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
runActions("hooks.sketch.prebuild", prefs);
|
||||
|
||||
// 1. compile the sketch (already in the buildPath)
|
||||
progressListener.progress(20);
|
||||
compileSketch(includeFolders);
|
||||
sketchIsCompiled = true;
|
||||
|
||||
runActions("hooks.sketch.postbuild", prefs);
|
||||
|
||||
runActions("hooks.libraries.prebuild", prefs);
|
||||
|
||||
// 2. compile the libraries, outputting .o files to: <buildPath>/<library>/
|
||||
// Doesn't really use configPreferences
|
||||
progressListener.progress(30);
|
||||
compileLibraries(includeFolders);
|
||||
|
||||
runActions("hooks.libraries.postbuild", prefs);
|
||||
|
||||
runActions("hooks.core.prebuild", prefs);
|
||||
|
||||
// 3. compile the core, outputting .o files to <buildPath> and then
|
||||
// collecting them into the core.a library file.
|
||||
progressListener.progress(40);
|
||||
compileCore();
|
||||
|
||||
runActions("hooks.core.postbuild", prefs);
|
||||
|
||||
runActions("hooks.linking.prelink", prefs);
|
||||
|
||||
// 4. link it all together into the .elf file
|
||||
progressListener.progress(50);
|
||||
compileLink();
|
||||
|
||||
runActions("hooks.linking.postlink", prefs);
|
||||
|
||||
runActions("hooks.objcopy.preobjcopy", prefs);
|
||||
|
||||
// 5. run objcopy to generate output files
|
||||
progressListener.progress(60);
|
||||
List<String> objcopyPatterns = new ArrayList<String>();
|
||||
@ -431,10 +452,16 @@ public class Compiler implements MessageConsumer {
|
||||
runRecipe(recipe);
|
||||
}
|
||||
|
||||
runActions("hooks.objcopy.postobjcopy", prefs);
|
||||
|
||||
// 7. save the hex file
|
||||
if (saveHex) {
|
||||
runActions("hooks.savehex.presavehex", prefs);
|
||||
|
||||
progressListener.progress(80);
|
||||
saveHex();
|
||||
|
||||
runActions("hooks.savehex.postsavehex", prefs);
|
||||
}
|
||||
|
||||
progressListener.progress(90);
|
||||
@ -557,6 +584,17 @@ public class Compiler implements MessageConsumer {
|
||||
p.put("build.variant.path", "");
|
||||
}
|
||||
|
||||
// Build Time
|
||||
Date d = new Date();
|
||||
GregorianCalendar cal = new GregorianCalendar();
|
||||
long current = d.getTime()/1000;
|
||||
long timezone = cal.get(cal.ZONE_OFFSET)/1000;
|
||||
long daylight = cal.get(cal.DST_OFFSET)/1000;
|
||||
p.put("extra.time.utc", Long.toString(current));
|
||||
p.put("extra.time.local", Long.toString(current + timezone + daylight));
|
||||
p.put("extra.time.zone", Long.toString(timezone));
|
||||
p.put("extra.time.dst", Long.toString(daylight));
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
@ -617,6 +655,7 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
private boolean isAlreadyCompiled(File src, File obj, File dep, Map<String, String> prefs) {
|
||||
boolean ret=true;
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
//System.out.println("\n isAlreadyCompiled: begin checks: " + obj.getPath());
|
||||
if (!obj.exists()) return false; // object file (.o) does not exist
|
||||
@ -625,7 +664,7 @@ public class Compiler implements MessageConsumer {
|
||||
long obj_modified = obj.lastModified();
|
||||
if (src_modified >= obj_modified) return false; // source modified since object compiled
|
||||
if (src_modified >= dep.lastModified()) return false; // src modified since dep compiled
|
||||
BufferedReader reader = new BufferedReader(new FileReader(dep.getPath()));
|
||||
reader = new BufferedReader(new FileReader(dep.getPath()));
|
||||
String line;
|
||||
boolean need_obj_parse = true;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
@ -669,9 +708,10 @@ public class Compiler implements MessageConsumer {
|
||||
//System.out.println(" isAlreadyCompiled: prerequisite ok");
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
return false; // any error reading dep file = recompile it
|
||||
} finally {
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
if (ret && verbose) {
|
||||
System.out.println(I18n.format(_("Using previously compiled file: {0}"), obj.getPath()));
|
||||
@ -703,37 +743,13 @@ public class Compiler implements MessageConsumer {
|
||||
}
|
||||
|
||||
DefaultExecutor executor = new DefaultExecutor();
|
||||
executor.setStreamHandler(new ExecuteStreamHandler() {
|
||||
@Override
|
||||
public void setProcessInputStream(OutputStream os) throws IOException {
|
||||
|
||||
}
|
||||
executor.setStreamHandler(new PumpStreamHandler() {
|
||||
|
||||
@Override
|
||||
public void setProcessErrorStream(InputStream is) throws IOException {
|
||||
forwardToMessage(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProcessOutputStream(InputStream is) throws IOException {
|
||||
forwardToMessage(is);
|
||||
}
|
||||
|
||||
private void forwardToMessage(InputStream is) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
message(line + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
protected Thread createPump(InputStream is, OutputStream os, boolean closeWhenExhausted) {
|
||||
final Thread result = new Thread(new MyStreamPumper(is, Compiler.this));
|
||||
result.setDaemon(true);
|
||||
return result;
|
||||
|
||||
}
|
||||
});
|
||||
@ -1149,6 +1165,7 @@ public class Compiler implements MessageConsumer {
|
||||
void runRecipe(String recipe) throws RunnerException, PreferencesMapException {
|
||||
PreferencesMap dict = new PreferencesMap(prefs);
|
||||
dict.put("ide_version", "" + BaseNoGui.REVISION);
|
||||
dict.put("sketch_path", sketch.getFolder().getAbsolutePath());
|
||||
|
||||
String[] cmdArray;
|
||||
String cmd = prefs.getOrExcept(recipe);
|
||||
@ -1226,7 +1243,7 @@ public class Compiler implements MessageConsumer {
|
||||
StringBuffer bigCode = new StringBuffer();
|
||||
int bigCount = 0;
|
||||
for (SketchCode sc : sketch.getCodes()) {
|
||||
if (sc.isExtension("ino") || sc.isExtension("pde")) {
|
||||
if (sc.isExtension(SketchData.SKETCH_EXTENSIONS)) {
|
||||
sc.setPreprocOffset(bigCount);
|
||||
// These #line directives help the compiler report errors with
|
||||
// correct the filename and line number (issue 281 & 907)
|
||||
@ -1272,13 +1289,7 @@ public class Compiler implements MessageConsumer {
|
||||
ex.printStackTrace();
|
||||
throw new RunnerException(ex.toString());
|
||||
} finally {
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
//noop
|
||||
}
|
||||
}
|
||||
IOUtils.closeQuietly(outputStream);
|
||||
}
|
||||
|
||||
// grab the imports from the code just preproc'd
|
||||
@ -1303,7 +1314,7 @@ public class Compiler implements MessageConsumer {
|
||||
// 3. then loop over the code[] and save each .java file
|
||||
|
||||
for (SketchCode sc : sketch.getCodes()) {
|
||||
if (sc.isExtension("c") || sc.isExtension("cpp") || sc.isExtension("h")) {
|
||||
if (sc.isExtension(SketchData.OTHER_ALLOWED_EXTENSIONS)) {
|
||||
// no pre-processing services necessary for java files
|
||||
// just write the the contents of 'program' to a .java file
|
||||
// into the build directory. uses byte stream and reader/writer
|
||||
|
@ -58,7 +58,7 @@ public class LegacyTargetBoard implements TargetBoard {
|
||||
String board = containerPlatform.getId() + "_" + id;
|
||||
board = board.toUpperCase();
|
||||
prefs.put("build.board", board);
|
||||
System.out
|
||||
System.err
|
||||
.println(format(_("Board {0}:{1}:{2} doesn''t define a ''build.board'' preference. Auto-set to: {3}"),
|
||||
containerPlatform.getContainerPackage().getId(),
|
||||
containerPlatform.getId(), id, board));
|
||||
|
@ -51,7 +51,7 @@ public class LegacyTargetPackage implements TargetPackage {
|
||||
TargetPlatform platform = new LegacyTargetPlatform(arch, subFolder, this);
|
||||
platforms.put(arch, platform);
|
||||
} catch (TargetPlatformException e) {
|
||||
System.out.println(e.getMessage());
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,7 @@ import processing.app.debug.TargetPlatform;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@ -32,6 +29,8 @@ public class CommandlineParser {
|
||||
}
|
||||
}
|
||||
|
||||
private final String[] args;
|
||||
private final Map<String, ACTION> actions;
|
||||
private ACTION action = ACTION.GUI;
|
||||
private boolean doVerboseBuild = false;
|
||||
private boolean doVerboseUpload = false;
|
||||
@ -44,39 +43,32 @@ public class CommandlineParser {
|
||||
private String libraryToInstall;
|
||||
private List<String> filenames = new LinkedList<String>();
|
||||
|
||||
public static CommandlineParser newCommandlineParser(String[] args) {
|
||||
return new CommandlineParser(args);
|
||||
}
|
||||
public CommandlineParser(String[] args) {
|
||||
this.args = args;
|
||||
|
||||
private CommandlineParser(String[] args) {
|
||||
parseArguments(args);
|
||||
checkAction();
|
||||
}
|
||||
|
||||
private void parseArguments(String[] args) {
|
||||
// Map of possible actions and corresponding options
|
||||
final Map<String, ACTION> actions = new HashMap<String, ACTION>();
|
||||
actions = new HashMap<String, ACTION>();
|
||||
actions.put("--verify", ACTION.VERIFY);
|
||||
actions.put("--upload", ACTION.UPLOAD);
|
||||
actions.put("--get-pref", ACTION.GET_PREF);
|
||||
actions.put("--install-boards", ACTION.INSTALL_BOARD);
|
||||
actions.put("--install-library", ACTION.INSTALL_LIBRARY);
|
||||
}
|
||||
|
||||
// Check if any files were passed in on the command line
|
||||
public void parseArgumentsPhase1() {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
ACTION a = actions.get(args[i]);
|
||||
if (a != null) {
|
||||
if (action != ACTION.GUI && action != ACTION.NOOP) {
|
||||
String[] valid = actions.keySet().toArray(new String[0]);
|
||||
Set<String> strings = actions.keySet();
|
||||
String[] valid = strings.toArray(new String[strings.size()]);
|
||||
String mess = I18n.format(_("Can only pass one of: {0}"), PApplet.join(valid, ", "));
|
||||
BaseNoGui.showError(null, mess, 3);
|
||||
}
|
||||
if (a == ACTION.GET_PREF) {
|
||||
i++;
|
||||
if (i >= args.length) {
|
||||
BaseNoGui.showError(null, I18n.format(_("Argument required for {0}"), a.value), 3);
|
||||
if (i < args.length) {
|
||||
getPref = args[i];
|
||||
}
|
||||
getPref = args[i];
|
||||
}
|
||||
if (a == ACTION.INSTALL_BOARD) {
|
||||
i++;
|
||||
@ -140,7 +132,6 @@ public class CommandlineParser {
|
||||
i++;
|
||||
if (i >= args.length)
|
||||
BaseNoGui.showError(null, _("Argument required for --board"), 3);
|
||||
processBoardArgument(args[i]);
|
||||
if (action == ACTION.GUI)
|
||||
action = ACTION.NOOP;
|
||||
continue;
|
||||
@ -201,6 +192,23 @@ public class CommandlineParser {
|
||||
|
||||
filenames.add(args[i]);
|
||||
}
|
||||
|
||||
checkAction();
|
||||
}
|
||||
|
||||
public void parseArgumentsPhase2() {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (args[i].equals("--board")) {
|
||||
i++;
|
||||
if (i >= args.length) {
|
||||
BaseNoGui.showError(null, _("Argument required for --board"), 3);
|
||||
}
|
||||
processBoardArgument(args[i]);
|
||||
if (action == ACTION.GUI) {
|
||||
action = ACTION.NOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAction() {
|
||||
|
@ -1,5 +1,7 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -49,12 +51,8 @@ public class FileUtils {
|
||||
fos.write(buf, 0, readBytes);
|
||||
}
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
IOUtils.closeQuietly(fis);
|
||||
IOUtils.closeQuietly(fos);
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,7 +169,15 @@ public class FileUtils {
|
||||
}
|
||||
|
||||
public static boolean isSCCSOrHiddenFile(File file) {
|
||||
return file.isHidden() || file.getName().charAt(0) == '.' || (file.isDirectory() && SOURCE_CONTROL_FOLDERS.contains(file.getName()));
|
||||
return isSCCSFolder(file) || isHiddenFile(file);
|
||||
}
|
||||
|
||||
public static boolean isHiddenFile(File file) {
|
||||
return file.isHidden() || file.getName().charAt(0) == '.';
|
||||
}
|
||||
|
||||
public static boolean isSCCSFolder(File file) {
|
||||
return file.isDirectory() && SOURCE_CONTROL_FOLDERS.contains(file.getName());
|
||||
}
|
||||
|
||||
public static String readFileToString(File file) throws IOException {
|
||||
@ -185,13 +191,7 @@ public class FileUtils {
|
||||
}
|
||||
return sb.toString();
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
package processing.app.helpers;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
import java.io.*;
|
||||
@ -72,9 +73,7 @@ public class PreferencesMap extends LinkedHashMap<String, String> {
|
||||
fileInputStream = new FileInputStream(file);
|
||||
load(fileInputStream);
|
||||
} finally {
|
||||
if (fileInputStream != null) {
|
||||
fileInputStream.close();
|
||||
}
|
||||
IOUtils.closeQuietly(fileInputStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package processing.app.legacy;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
@ -272,13 +274,7 @@ public class PApplet {
|
||||
if (is != null) return loadStrings(is);
|
||||
return null;
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
}
|
||||
|
||||
@ -312,14 +308,7 @@ public class PApplet {
|
||||
e.printStackTrace();
|
||||
//throw new RuntimeException("Error inside loadStrings()");
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -335,27 +324,25 @@ public class PApplet {
|
||||
outputStream = createOutput(file);
|
||||
saveStrings(outputStream, strings);
|
||||
} finally {
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
//noop
|
||||
}
|
||||
}
|
||||
IOUtils.closeQuietly(outputStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public void saveStrings(OutputStream output, String strings[]) {
|
||||
PrintWriter writer = createWriter(output);
|
||||
if (writer == null) {
|
||||
return;
|
||||
PrintWriter writer = null;
|
||||
try {
|
||||
writer = createWriter(output);
|
||||
if (writer == null) {
|
||||
return;
|
||||
}
|
||||
for (String string : strings) {
|
||||
writer.println(string);
|
||||
}
|
||||
writer.flush();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(writer);
|
||||
}
|
||||
for (String string : strings) {
|
||||
writer.println(string);
|
||||
}
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,11 +23,12 @@
|
||||
package processing.app.linux;
|
||||
|
||||
import org.apache.commons.exec.CommandLine;
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
import org.apache.commons.exec.Executor;
|
||||
import org.apache.commons.exec.PumpStreamHandler;
|
||||
import processing.app.PreferencesData;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.legacy.PConstants;
|
||||
import processing.app.tools.CollectStdOutExecutor;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@ -124,7 +125,8 @@ public class Platform extends processing.app.Platform {
|
||||
public Map<String, Object> resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
|
||||
assert packages != null;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Executor executor = new CollectStdOutExecutor(baos);
|
||||
Executor executor = new DefaultExecutor();
|
||||
executor.setStreamHandler(new PumpStreamHandler(baos, null));
|
||||
|
||||
try {
|
||||
CommandLine toDevicePath = CommandLine.parse("udevadm info -q path -n " + serial);
|
||||
|
@ -25,19 +25,23 @@ package processing.app.macosx;
|
||||
import cc.arduino.packages.BoardPort;
|
||||
import com.apple.eio.FileManager;
|
||||
import org.apache.commons.exec.CommandLine;
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
import org.apache.commons.exec.Executor;
|
||||
import org.apache.commons.exec.PumpStreamHandler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.legacy.PApplet;
|
||||
import processing.app.legacy.PConstants;
|
||||
import processing.app.tools.CollectStdOutExecutor;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
@ -57,6 +61,8 @@ public class Platform extends processing.app.Platform {
|
||||
}
|
||||
|
||||
public void init() throws IOException {
|
||||
super.init();
|
||||
|
||||
System.setProperty("apple.laf.useScreenMenuBar", "true");
|
||||
|
||||
discoverRealOsArch();
|
||||
@ -65,7 +71,8 @@ public class Platform extends processing.app.Platform {
|
||||
private void discoverRealOsArch() throws IOException {
|
||||
CommandLine uname = CommandLine.parse("uname -m");
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
CollectStdOutExecutor executor = new CollectStdOutExecutor(baos);
|
||||
Executor executor = new DefaultExecutor();
|
||||
executor.setStreamHandler(new PumpStreamHandler(baos, null));
|
||||
executor.execute(uname);
|
||||
osArch = StringUtils.trim(new String(baos.toByteArray()));
|
||||
}
|
||||
@ -94,45 +101,13 @@ public class Platform extends processing.app.Platform {
|
||||
|
||||
|
||||
public void openURL(String url) throws Exception {
|
||||
if (PApplet.javaVersion < 1.6f) {
|
||||
if (url.startsWith("http")) {
|
||||
// formerly com.apple.eio.FileManager.openURL(url);
|
||||
// but due to deprecation, instead loading dynamically
|
||||
try {
|
||||
Class<?> eieio = Class.forName("com.apple.eio.FileManager");
|
||||
Method openMethod =
|
||||
eieio.getMethod("openURL", new Class[] { String.class });
|
||||
openMethod.invoke(null, new Object[] { url });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
// Assume this is a file instead, and just open it.
|
||||
// Extension of http://dev.processing.org/bugs/show_bug.cgi?id=1010
|
||||
PApplet.open(url);
|
||||
}
|
||||
Desktop desktop = Desktop.getDesktop();
|
||||
if (url.startsWith("http") || url.startsWith("file:")) {
|
||||
desktop.browse(new URI(url));
|
||||
} else {
|
||||
try {
|
||||
Class<?> desktopClass = Class.forName("java.awt.Desktop");
|
||||
Method getMethod = desktopClass.getMethod("getDesktop");
|
||||
Object desktop = getMethod.invoke(null, new Object[] { });
|
||||
|
||||
// for Java 1.6, replacing with java.awt.Desktop.browse()
|
||||
// and java.awt.Desktop.open()
|
||||
if (url.startsWith("http")) { // browse to a location
|
||||
Method browseMethod =
|
||||
desktopClass.getMethod("browse", new Class[] { URI.class });
|
||||
browseMethod.invoke(desktop, new Object[] { new URI(url) });
|
||||
} else { // open a file
|
||||
Method openMethod =
|
||||
desktopClass.getMethod("open", new Class[] { File.class });
|
||||
openMethod.invoke(desktop, new Object[] { new File(url) });
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
desktop.open(new File(url));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean openFolderAvailable() {
|
||||
@ -152,13 +127,13 @@ public class Platform extends processing.app.Platform {
|
||||
// Some of these are supposedly constants in com.apple.eio.FileManager,
|
||||
// however they don't seem to link properly from Eclipse.
|
||||
|
||||
static final int kDocumentsFolderType =
|
||||
private static final int kDocumentsFolderType =
|
||||
('d' << 24) | ('o' << 16) | ('c' << 8) | 's';
|
||||
//static final int kPreferencesFolderType =
|
||||
// ('p' << 24) | ('r' << 16) | ('e' << 8) | 'f';
|
||||
static final int kDomainLibraryFolderType =
|
||||
private static final int kDomainLibraryFolderType =
|
||||
('d' << 24) | ('l' << 16) | ('i' << 8) | 'b';
|
||||
static final short kUserDomain = -32763;
|
||||
private static final short kUserDomain = -32763;
|
||||
|
||||
|
||||
// apple java extensions documentation
|
||||
@ -175,12 +150,12 @@ public class Platform extends processing.app.Platform {
|
||||
// /Versions/Current/Frameworks/CarbonCore.framework/Headers/
|
||||
|
||||
|
||||
protected String getLibraryFolder() throws FileNotFoundException {
|
||||
private String getLibraryFolder() throws FileNotFoundException {
|
||||
return FileManager.findFolder(kUserDomain, kDomainLibraryFolderType);
|
||||
}
|
||||
|
||||
|
||||
protected String getDocumentsFolder() throws FileNotFoundException {
|
||||
private String getDocumentsFolder() throws FileNotFoundException {
|
||||
return FileManager.findFolder(kUserDomain, kDocumentsFolderType);
|
||||
}
|
||||
|
||||
@ -193,7 +168,7 @@ public class Platform extends processing.app.Platform {
|
||||
public Map<String, Object> resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
|
||||
assert packages != null;
|
||||
if (devicesListOutput == null) {
|
||||
return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput);
|
||||
return super.resolveDeviceAttachedTo(serial, packages, null);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -212,7 +187,8 @@ public class Platform extends processing.app.Platform {
|
||||
@Override
|
||||
public String preListAllCandidateDevices() {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Executor executor = new CollectStdOutExecutor(baos);
|
||||
Executor executor = new DefaultExecutor();
|
||||
executor.setStreamHandler(new PumpStreamHandler(baos, null));
|
||||
|
||||
try {
|
||||
CommandLine toDevicePath = CommandLine.parse("/usr/sbin/system_profiler SPUSBDataType");
|
||||
|
@ -55,7 +55,7 @@ public class SystemProfilerParser {
|
||||
|
||||
if ((matcher = serialNumberRegex.matcher(line)).matches()) {
|
||||
device.put(SERIAL_NUMBER, matcher.group(1));
|
||||
if ((serial.startsWith(DEV_TTY_USBSERIAL) || serial.startsWith(DEV_CU_USBSERIAL))) {
|
||||
if (serial.startsWith(DEV_TTY_USBSERIAL) || serial.startsWith(DEV_CU_USBSERIAL)) {
|
||||
String devicePath = devicePrefix + matcher.group(1);
|
||||
device.put(DEVICE_PATH, devicePath);
|
||||
}
|
||||
@ -65,17 +65,24 @@ public class SystemProfilerParser {
|
||||
device.put(DEVICE_PATH, devicePath);
|
||||
} else if ((matcher = pidRegex.matcher(line)).matches()) {
|
||||
String pid = matcher.group(1);
|
||||
if (pid.indexOf(" ") > 0)
|
||||
if (pid.indexOf(" ") > 0) {
|
||||
pid = pid.substring(0, pid.indexOf(" ")); // Remove any text after the hex number
|
||||
}
|
||||
device.put(PID, pid);
|
||||
} else if ((matcher = vidRegex.matcher(line)).matches()) {
|
||||
String vid = matcher.group(1);
|
||||
if (vid.indexOf(" ") > 0)
|
||||
if (vid.indexOf(" ") > 0) {
|
||||
vid = vid.substring(0, vid.indexOf(" ")); // Remove any text after the hex number
|
||||
}
|
||||
device.put(VID, vid);
|
||||
} else if (line.equals("")) {
|
||||
if (device.containsKey(DEVICE_PATH) && device.get(DEVICE_PATH).equals(serial)) {
|
||||
return (device.get(VID) + "_" + device.get(PID)).toUpperCase();
|
||||
if (device.containsKey(DEVICE_PATH)) {
|
||||
String computedDevicePath = device.get(DEVICE_PATH);
|
||||
String computedDevicePathMinusChar = computedDevicePath.substring(0, computedDevicePath.length() - 1);
|
||||
String serialMinusChar = serial.substring(0, serial.length() - 1);
|
||||
if (computedDevicePath.equals(serial) || computedDevicePathMinusChar.equals(serialMinusChar)) {
|
||||
return (device.get(VID) + "_" + device.get(PID)).toUpperCase();
|
||||
}
|
||||
}
|
||||
device = new HashMap<String, String>();
|
||||
}
|
||||
|
@ -32,8 +32,6 @@ import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibraryReference;
|
||||
|
||||
public class LegacyUserLibrary extends UserLibrary {
|
||||
|
||||
private String name;
|
||||
@ -45,6 +43,8 @@ public class LegacyUserLibrary extends UserLibrary {
|
||||
res.setInstalled(true);
|
||||
res.layout = LibraryLayout.FLAT;
|
||||
res.name = libFolder.getName();
|
||||
res.setTypes(Arrays.asList("Contributed"));
|
||||
res.setCategory("Uncategorized");
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -58,66 +58,6 @@ public class LegacyUserLibrary extends UserLibrary {
|
||||
return Arrays.asList("*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParagraph() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSentence() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWebsite() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return "Uncategorized";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLicense() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMaintainer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChecksum() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContributedLibraryReference> getRequires() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LegacyLibrary:" + name + "\n";
|
||||
|
@ -56,13 +56,13 @@ public class UserLibrary extends ContributedLibrary {
|
||||
private List<String> declaredTypes;
|
||||
|
||||
private static final List<String> MANDATORY_PROPERTIES = Arrays
|
||||
.asList(new String[]{"name", "version", "author", "maintainer",
|
||||
"sentence", "paragraph", "url"});
|
||||
.asList("name", "version", "author", "maintainer",
|
||||
"sentence", "paragraph", "url");
|
||||
|
||||
private static final List<String> CATEGORIES = Arrays.asList(new String[]{
|
||||
"Display", "Communication", "Signal Input/Output", "Sensors",
|
||||
"Device Control", "Timing", "Data Storage", "Data Processing", "Other",
|
||||
"Uncategorized"});
|
||||
private static final List<String> CATEGORIES = Arrays.asList(
|
||||
"Display", "Communication", "Signal Input/Output", "Sensors",
|
||||
"Device Control", "Timing", "Data Storage", "Data Processing", "Other",
|
||||
"Uncategorized");
|
||||
|
||||
public static UserLibrary create(File libFolder) throws IOException {
|
||||
// Parse metadata
|
||||
@ -83,8 +83,7 @@ public class UserLibrary extends ContributedLibrary {
|
||||
// "arch" folder no longer supported
|
||||
File archFolder = new File(libFolder, "arch");
|
||||
if (archFolder.isDirectory())
|
||||
throw new IOException("'arch' folder is no longer supported! See "
|
||||
+ "http://goo.gl/gfFJzU for more information");
|
||||
throw new IOException("'arch' folder is no longer supported! See http://goo.gl/gfFJzU for more information");
|
||||
|
||||
// Check mandatory properties
|
||||
for (String p : MANDATORY_PROPERTIES)
|
||||
@ -101,8 +100,7 @@ public class UserLibrary extends ContributedLibrary {
|
||||
|
||||
File utilFolder = new File(libFolder, "utility");
|
||||
if (utilFolder.exists() && utilFolder.isDirectory()) {
|
||||
throw new IOException(
|
||||
"Library can't use both 'src' and 'utility' folders.");
|
||||
throw new IOException("Library can't use both 'src' and 'utility' folders.");
|
||||
}
|
||||
} else {
|
||||
// Layout with source code on library's root and "utility" folders
|
||||
@ -110,11 +108,14 @@ public class UserLibrary extends ContributedLibrary {
|
||||
}
|
||||
|
||||
// Warn if root folder contains development leftovers
|
||||
for (File file : libFolder.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
if (FileUtils.isSCCSOrHiddenFile(file)) {
|
||||
File[] files = libFolder.listFiles();
|
||||
if (files == null) {
|
||||
throw new IOException("Unable to list files of library in " + libFolder);
|
||||
}
|
||||
for (File file : files) {
|
||||
if (file.isDirectory() && FileUtils.isSCCSOrHiddenFile(file)) {
|
||||
if (!FileUtils.isSCCSFolder(file) && FileUtils.isHiddenFile(file)) {
|
||||
System.out.println("WARNING: Spurious " + file.getName() + " folder in '" + properties.get("name") + "' library");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -131,8 +132,7 @@ public class UserLibrary extends ContributedLibrary {
|
||||
if (category == null)
|
||||
category = "Uncategorized";
|
||||
if (!CATEGORIES.contains(category)) {
|
||||
System.out.println("WARNING: Category '" + category + "' in library " +
|
||||
properties.get("name") + " is not valid. Setting to 'Uncategorized'");
|
||||
System.out.println("WARNING: Category '" + category + "' in library " + properties.get("name") + " is not valid. Setting to 'Uncategorized'");
|
||||
category = "Uncategorized";
|
||||
}
|
||||
|
||||
|
@ -1,44 +0,0 @@
|
||||
package processing.app.tools;
|
||||
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
import org.apache.commons.exec.ExecuteStreamHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Handy process executor, collecting stdout into a given OutputStream
|
||||
*/
|
||||
public class CollectStdOutExecutor extends DefaultExecutor {
|
||||
|
||||
public CollectStdOutExecutor(final OutputStream stdout) {
|
||||
this.setStreamHandler(new ExecuteStreamHandler() {
|
||||
@Override
|
||||
public void setProcessInputStream(OutputStream outputStream) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProcessErrorStream(InputStream inputStream) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProcessOutputStream(InputStream inputStream) throws IOException {
|
||||
byte[] buf = new byte[4096];
|
||||
int bytes = -1;
|
||||
while ((bytes = inputStream.read(buf)) != -1) {
|
||||
stdout.write(buf, 0, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package processing.app.tools;
|
||||
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
import org.apache.commons.exec.ExecuteStreamHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Handy process executor, collecting stdout and stderr into given OutputStreams
|
||||
*/
|
||||
public class CollectStdOutStdErrExecutor extends DefaultExecutor {
|
||||
|
||||
public CollectStdOutStdErrExecutor(final OutputStream stdout, final OutputStream stderr) {
|
||||
this.setStreamHandler(new ExecuteStreamHandler() {
|
||||
@Override
|
||||
public void setProcessInputStream(OutputStream outputStream) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProcessErrorStream(InputStream inputStream) throws IOException {
|
||||
byte[] buf = new byte[4096];
|
||||
int bytes = -1;
|
||||
while ((bytes = inputStream.read(buf)) != -1) {
|
||||
stderr.write(buf, 0, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProcessOutputStream(InputStream inputStream) throws IOException {
|
||||
byte[] buf = new byte[4096];
|
||||
int bytes = -1;
|
||||
while ((bytes = inputStream.read(buf)) != -1) {
|
||||
stdout.write(buf, 0, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -1,335 +0,0 @@
|
||||
package processing.app.windows;
|
||||
|
||||
/*
|
||||
* Advapi32.java
|
||||
*
|
||||
* Created on 6. August 2007, 11:24
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
import com.sun.jna.*;
|
||||
import com.sun.jna.ptr.*;
|
||||
import com.sun.jna.win32.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface Advapi32 extends StdCallLibrary {
|
||||
Advapi32 INSTANCE = (Advapi32) Native.loadLibrary("Advapi32", Advapi32.class, Options.UNICODE_OPTIONS);
|
||||
|
||||
/*
|
||||
BOOL WINAPI LookupAccountName(
|
||||
LPCTSTR lpSystemName,
|
||||
LPCTSTR lpAccountName,
|
||||
PSID Sid,
|
||||
LPDWORD cbSid,
|
||||
LPTSTR ReferencedDomainName,
|
||||
LPDWORD cchReferencedDomainName,
|
||||
PSID_NAME_USE peUse
|
||||
);*/
|
||||
public boolean LookupAccountName(String lpSystemName, String lpAccountName,
|
||||
byte[] Sid, IntByReference cbSid, char[] ReferencedDomainName,
|
||||
IntByReference cchReferencedDomainName, PointerByReference peUse);
|
||||
|
||||
/*
|
||||
BOOL WINAPI LookupAccountSid(
|
||||
LPCTSTR lpSystemName,
|
||||
PSID lpSid,
|
||||
LPTSTR lpName,
|
||||
LPDWORD cchName,
|
||||
LPTSTR lpReferencedDomainName,
|
||||
LPDWORD cchReferencedDomainName,
|
||||
PSID_NAME_USE peUse
|
||||
);*/
|
||||
public boolean LookupAccountSid(String lpSystemName, byte[] Sid,
|
||||
char[] lpName, IntByReference cchName, char[] ReferencedDomainName,
|
||||
IntByReference cchReferencedDomainName, PointerByReference peUse);
|
||||
|
||||
/*
|
||||
BOOL ConvertSidToStringSid(
|
||||
PSID Sid,
|
||||
LPTSTR* StringSid
|
||||
);*/
|
||||
public boolean ConvertSidToStringSid(byte[] Sid, PointerByReference StringSid);
|
||||
|
||||
/*
|
||||
BOOL WINAPI ConvertStringSidToSid(
|
||||
LPCTSTR StringSid,
|
||||
PSID* Sid
|
||||
);*/
|
||||
public boolean ConvertStringSidToSid(String StringSid, PointerByReference Sid);
|
||||
|
||||
/*
|
||||
SC_HANDLE WINAPI OpenSCManager(
|
||||
LPCTSTR lpMachineName,
|
||||
LPCTSTR lpDatabaseName,
|
||||
DWORD dwDesiredAccess
|
||||
);*/
|
||||
public Pointer OpenSCManager(String lpMachineName, WString lpDatabaseName, int dwDesiredAccess);
|
||||
|
||||
/*
|
||||
BOOL WINAPI CloseServiceHandle(
|
||||
SC_HANDLE hSCObject
|
||||
);*/
|
||||
public boolean CloseServiceHandle(Pointer hSCObject);
|
||||
|
||||
/*
|
||||
SC_HANDLE WINAPI OpenService(
|
||||
SC_HANDLE hSCManager,
|
||||
LPCTSTR lpServiceName,
|
||||
DWORD dwDesiredAccess
|
||||
);*/
|
||||
public Pointer OpenService(Pointer hSCManager, String lpServiceName, int dwDesiredAccess);
|
||||
|
||||
/*
|
||||
BOOL WINAPI StartService(
|
||||
SC_HANDLE hService,
|
||||
DWORD dwNumServiceArgs,
|
||||
LPCTSTR* lpServiceArgVectors
|
||||
);*/
|
||||
public boolean StartService(Pointer hService, int dwNumServiceArgs, char[] lpServiceArgVectors);
|
||||
|
||||
/*
|
||||
BOOL WINAPI ControlService(
|
||||
SC_HANDLE hService,
|
||||
DWORD dwControl,
|
||||
LPSERVICE_STATUS lpServiceStatus
|
||||
);*/
|
||||
public boolean ControlService(Pointer hService, int dwControl, SERVICE_STATUS lpServiceStatus);
|
||||
|
||||
/*
|
||||
BOOL WINAPI StartServiceCtrlDispatcher(
|
||||
const SERVICE_TABLE_ENTRY* lpServiceTable
|
||||
);*/
|
||||
public boolean StartServiceCtrlDispatcher(Structure[] lpServiceTable);
|
||||
|
||||
/*
|
||||
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandler(
|
||||
LPCTSTR lpServiceName,
|
||||
LPHANDLER_FUNCTION lpHandlerProc
|
||||
);*/
|
||||
public Pointer RegisterServiceCtrlHandler(String lpServiceName, Handler lpHandlerProc);
|
||||
|
||||
/*
|
||||
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerEx(
|
||||
LPCTSTR lpServiceName,
|
||||
LPHANDLER_FUNCTION_EX lpHandlerProc,
|
||||
LPVOID lpContext
|
||||
);*/
|
||||
public Pointer RegisterServiceCtrlHandlerEx(String lpServiceName, HandlerEx lpHandlerProc, Pointer lpContext);
|
||||
|
||||
/*
|
||||
BOOL WINAPI SetServiceStatus(
|
||||
SERVICE_STATUS_HANDLE hServiceStatus,
|
||||
LPSERVICE_STATUS lpServiceStatus
|
||||
);*/
|
||||
public boolean SetServiceStatus(Pointer hServiceStatus, SERVICE_STATUS lpServiceStatus);
|
||||
|
||||
/*
|
||||
SC_HANDLE WINAPI CreateService(
|
||||
SC_HANDLE hSCManager,
|
||||
LPCTSTR lpServiceName,
|
||||
LPCTSTR lpDisplayName,
|
||||
DWORD dwDesiredAccess,
|
||||
DWORD dwServiceType,
|
||||
DWORD dwStartType,
|
||||
DWORD dwErrorControl,
|
||||
LPCTSTR lpBinaryPathName,
|
||||
LPCTSTR lpLoadOrderGroup,
|
||||
LPDWORD lpdwTagId,
|
||||
LPCTSTR lpDependencies,
|
||||
LPCTSTR lpServiceStartName,
|
||||
LPCTSTR lpPassword
|
||||
);*/
|
||||
public Pointer CreateService(Pointer hSCManager, String lpServiceName, String lpDisplayName,
|
||||
int dwDesiredAccess, int dwServiceType, int dwStartType, int dwErrorControl,
|
||||
String lpBinaryPathName, String lpLoadOrderGroup, IntByReference lpdwTagId,
|
||||
String lpDependencies, String lpServiceStartName, String lpPassword);
|
||||
|
||||
/*
|
||||
BOOL WINAPI DeleteService(
|
||||
SC_HANDLE hService
|
||||
);*/
|
||||
public boolean DeleteService(Pointer hService);
|
||||
|
||||
/*
|
||||
BOOL WINAPI ChangeServiceConfig2(
|
||||
SC_HANDLE hService,
|
||||
DWORD dwInfoLevel,
|
||||
LPVOID lpInfo
|
||||
);*/
|
||||
public boolean ChangeServiceConfig2(Pointer hService, int dwInfoLevel, ChangeServiceConfig2Info lpInfo);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegOpenKeyEx(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpSubKey,
|
||||
DWORD ulOptions,
|
||||
REGSAM samDesired,
|
||||
PHKEY phkResult
|
||||
);*/
|
||||
public int RegOpenKeyEx(int hKey, String lpSubKey, int ulOptions, int samDesired, IntByReference phkResult);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegQueryValueEx(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpValueName,
|
||||
LPDWORD lpReserved,
|
||||
LPDWORD lpType,
|
||||
LPBYTE lpData,
|
||||
LPDWORD lpcbData
|
||||
);*/
|
||||
public int RegQueryValueEx(int hKey, String lpValueName, IntByReference lpReserved, IntByReference lpType, byte[] lpData, IntByReference lpcbData);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegCloseKey(
|
||||
HKEY hKey
|
||||
);*/
|
||||
public int RegCloseKey(int hKey);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegDeleteValue(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpValueName
|
||||
);*/
|
||||
public int RegDeleteValue(int hKey, String lpValueName);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegSetValueEx(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpValueName,
|
||||
DWORD Reserved,
|
||||
DWORD dwType,
|
||||
const BYTE* lpData,
|
||||
DWORD cbData
|
||||
);*/
|
||||
public int RegSetValueEx(int hKey, String lpValueName, int Reserved, int dwType, byte[] lpData, int cbData);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegCreateKeyEx(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpSubKey,
|
||||
DWORD Reserved,
|
||||
LPTSTR lpClass,
|
||||
DWORD dwOptions,
|
||||
REGSAM samDesired,
|
||||
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||
PHKEY phkResult,
|
||||
LPDWORD lpdwDisposition
|
||||
);*/
|
||||
public int RegCreateKeyEx(int hKey, String lpSubKey, int Reserved, String lpClass, int dwOptions,
|
||||
int samDesired, WINBASE.SECURITY_ATTRIBUTES lpSecurityAttributes, IntByReference phkResult,
|
||||
IntByReference lpdwDisposition);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegDeleteKey(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpSubKey
|
||||
);*/
|
||||
public int RegDeleteKey(int hKey, String name);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegEnumKeyEx(
|
||||
HKEY hKey,
|
||||
DWORD dwIndex,
|
||||
LPTSTR lpName,
|
||||
LPDWORD lpcName,
|
||||
LPDWORD lpReserved,
|
||||
LPTSTR lpClass,
|
||||
LPDWORD lpcClass,
|
||||
PFILETIME lpftLastWriteTime
|
||||
);*/
|
||||
public int RegEnumKeyEx(int hKey, int dwIndex, char[] lpName, IntByReference lpcName, IntByReference reserved,
|
||||
char[] lpClass, IntByReference lpcClass, WINBASE.FILETIME lpftLastWriteTime);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegEnumValue(
|
||||
HKEY hKey,
|
||||
DWORD dwIndex,
|
||||
LPTSTR lpValueName,
|
||||
LPDWORD lpcchValueName,
|
||||
LPDWORD lpReserved,
|
||||
LPDWORD lpType,
|
||||
LPBYTE lpData,
|
||||
LPDWORD lpcbData
|
||||
);*/
|
||||
public int RegEnumValue(int hKey, int dwIndex, char[] lpValueName, IntByReference lpcchValueName, IntByReference reserved,
|
||||
IntByReference lpType, byte[] lpData, IntByReference lpcbData);
|
||||
|
||||
interface SERVICE_MAIN_FUNCTION extends StdCallCallback {
|
||||
/*
|
||||
VOID WINAPI ServiceMain(
|
||||
DWORD dwArgc,
|
||||
LPTSTR* lpszArgv
|
||||
);*/
|
||||
public void callback(int dwArgc, Pointer lpszArgv);
|
||||
}
|
||||
|
||||
interface Handler extends StdCallCallback {
|
||||
/*
|
||||
VOID WINAPI Handler(
|
||||
DWORD fdwControl
|
||||
);*/
|
||||
public void callback(int fdwControl);
|
||||
}
|
||||
|
||||
interface HandlerEx extends StdCallCallback {
|
||||
/*
|
||||
DWORD WINAPI HandlerEx(
|
||||
DWORD dwControl,
|
||||
DWORD dwEventType,
|
||||
LPVOID lpEventData,
|
||||
LPVOID lpContext
|
||||
);*/
|
||||
public void callback(int dwControl, int dwEventType, Pointer lpEventData, Pointer lpContext);
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _SERVICE_STATUS {
|
||||
DWORD dwServiceType;
|
||||
DWORD dwCurrentState;
|
||||
DWORD dwControlsAccepted;
|
||||
DWORD dwWin32ExitCode;
|
||||
DWORD dwServiceSpecificExitCode;
|
||||
DWORD dwCheckPoint;
|
||||
DWORD dwWaitHint;
|
||||
} SERVICE_STATUS,
|
||||
*LPSERVICE_STATUS;*/
|
||||
public static class SERVICE_STATUS extends Structure {
|
||||
public int dwServiceType;
|
||||
public int dwCurrentState;
|
||||
public int dwControlsAccepted;
|
||||
public int dwWin32ExitCode;
|
||||
public int dwServiceSpecificExitCode;
|
||||
public int dwCheckPoint;
|
||||
public int dwWaitHint;
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _SERVICE_TABLE_ENTRY {
|
||||
LPTSTR lpServiceName;
|
||||
LPSERVICE_MAIN_FUNCTION lpServiceProc;
|
||||
} SERVICE_TABLE_ENTRY,
|
||||
*LPSERVICE_TABLE_ENTRY;*/
|
||||
public static class SERVICE_TABLE_ENTRY extends Structure {
|
||||
public String lpServiceName;
|
||||
public SERVICE_MAIN_FUNCTION lpServiceProc;
|
||||
}
|
||||
|
||||
public static class ChangeServiceConfig2Info extends Structure {
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _SERVICE_DESCRIPTION {
|
||||
LPTSTR lpDescription;
|
||||
} SERVICE_DESCRIPTION,
|
||||
*LPSERVICE_DESCRIPTION;*/
|
||||
public static class SERVICE_DESCRIPTION extends ChangeServiceConfig2Info {
|
||||
public String lpDescription;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Options.java
|
||||
*
|
||||
* Created on 8. August 2007, 17:07
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package processing.app.windows;
|
||||
|
||||
import static com.sun.jna.Library.*;
|
||||
import com.sun.jna.win32.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface Options {
|
||||
@SuppressWarnings("serial")
|
||||
Map<String, Object> UNICODE_OPTIONS = new HashMap<String, Object>() {
|
||||
{
|
||||
put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
|
||||
put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
|
||||
}
|
||||
};
|
||||
}
|
@ -23,127 +23,54 @@
|
||||
package processing.app.windows;
|
||||
|
||||
import org.apache.commons.exec.CommandLine;
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
import org.apache.commons.exec.Executor;
|
||||
import processing.app.PreferencesData;
|
||||
import org.apache.commons.exec.PumpStreamHandler;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.legacy.PApplet;
|
||||
import processing.app.legacy.PConstants;
|
||||
import processing.app.tools.CollectStdOutExecutor;
|
||||
import processing.app.windows.Registry.REGISTRY_ROOT_KEY;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
// http://developer.apple.com/documentation/QuickTime/Conceptual/QT7Win_Update_Guide/Chapter03/chapter_3_section_1.html
|
||||
// HKEY_LOCAL_MACHINE\SOFTWARE\Apple Computer, Inc.\QuickTime\QTSysDir
|
||||
|
||||
// HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\CurrentVersion -> 1.6 (String)
|
||||
// HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\CurrentVersion\1.6\JavaHome -> c:\jdk-1.6.0_05
|
||||
|
||||
public class Platform extends processing.app.Platform {
|
||||
|
||||
static final String openCommand =
|
||||
System.getProperty("user.dir").replace('/', '\\') +
|
||||
"\\arduino.exe \"%1\"";
|
||||
static final String DOC = "Arduino.Document";
|
||||
private File settingsFolder;
|
||||
private File defaultSketchbookFolder;
|
||||
|
||||
public void init() throws IOException {
|
||||
super.init();
|
||||
|
||||
checkAssociations();
|
||||
checkQuickTime();
|
||||
checkPath();
|
||||
recoverSettingsFolderPath();
|
||||
recoverDefaultSketchbookFolder();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make sure that .pde files are associated with processing.exe.
|
||||
*/
|
||||
protected void checkAssociations() {
|
||||
try {
|
||||
String knownCommand =
|
||||
Registry.getStringValue(REGISTRY_ROOT_KEY.CLASSES_ROOT,
|
||||
DOC + "\\shell\\open\\command", "");
|
||||
if (knownCommand == null) {
|
||||
if (PreferencesData.getBoolean("platform.auto_file_type_associations")) {
|
||||
setAssociations();
|
||||
}
|
||||
|
||||
} else if (!knownCommand.equals(openCommand)) {
|
||||
// If the value is set differently, just change the registry setting.
|
||||
if (PreferencesData.getBoolean("platform.auto_file_type_associations")) {
|
||||
setAssociations();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
private void recoverSettingsFolderPath() throws IOException {
|
||||
String path = getFolderPathFromRegistry("AppData");
|
||||
this.settingsFolder = new File(path, "Arduino15");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Associate .pde files with this version of Processing.
|
||||
*/
|
||||
protected void setAssociations() throws UnsupportedEncodingException {
|
||||
if (Registry.createKey(REGISTRY_ROOT_KEY.CLASSES_ROOT,
|
||||
"", ".ino") &&
|
||||
Registry.setStringValue(REGISTRY_ROOT_KEY.CLASSES_ROOT,
|
||||
".ino", "", DOC) &&
|
||||
|
||||
Registry.createKey(REGISTRY_ROOT_KEY.CLASSES_ROOT, "", DOC) &&
|
||||
Registry.setStringValue(REGISTRY_ROOT_KEY.CLASSES_ROOT, DOC, "",
|
||||
"Arduino Source Code") &&
|
||||
|
||||
Registry.createKey(REGISTRY_ROOT_KEY.CLASSES_ROOT,
|
||||
DOC, "shell") &&
|
||||
Registry.createKey(REGISTRY_ROOT_KEY.CLASSES_ROOT,
|
||||
DOC + "\\shell", "open") &&
|
||||
Registry.createKey(REGISTRY_ROOT_KEY.CLASSES_ROOT,
|
||||
DOC + "\\shell\\open", "command") &&
|
||||
Registry.setStringValue(REGISTRY_ROOT_KEY.CLASSES_ROOT,
|
||||
DOC + "\\shell\\open\\command", "",
|
||||
openCommand)) {
|
||||
// everything ok
|
||||
// hooray!
|
||||
|
||||
} else {
|
||||
PreferencesData.setBoolean("platform.auto_file_type_associations", false);
|
||||
}
|
||||
private void recoverDefaultSketchbookFolder() throws IOException {
|
||||
String path = getFolderPathFromRegistry("Personal");
|
||||
this.defaultSketchbookFolder = new File(path, "Arduino");
|
||||
}
|
||||
|
||||
private String getFolderPathFromRegistry(String folderType) throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Executor executor = new DefaultExecutor();
|
||||
executor.setStreamHandler(new PumpStreamHandler(baos, null));
|
||||
|
||||
/**
|
||||
* Find QuickTime for Java installation.
|
||||
*/
|
||||
protected void checkQuickTime() {
|
||||
try {
|
||||
String qtsystemPath =
|
||||
Registry.getStringValue(REGISTRY_ROOT_KEY.LOCAL_MACHINE,
|
||||
"Software\\Apple Computer, Inc.\\QuickTime",
|
||||
"QTSysDir");
|
||||
// Could show a warning message here if QT not installed, but that
|
||||
// would annoy people who don't want anything to do with QuickTime.
|
||||
if (qtsystemPath != null) {
|
||||
File qtjavaZip = new File(qtsystemPath, "QTJava.zip");
|
||||
if (qtjavaZip.exists()) {
|
||||
String qtjavaZipPath = qtjavaZip.getAbsolutePath();
|
||||
String cp = System.getProperty("java.class.path");
|
||||
System.setProperty("java.class.path",
|
||||
cp + File.pathSeparator + qtjavaZipPath);
|
||||
}
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
CommandLine toDevicePath = CommandLine.parse("reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\" /v \"" + folderType + "\"");
|
||||
executor.execute(toDevicePath);
|
||||
return new RegQueryParser(new String(baos.toByteArray())).getValueOfKey();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Remove extra quotes, slashes, and garbage from the Windows PATH.
|
||||
*/
|
||||
@ -178,54 +105,15 @@ public class Platform extends processing.app.Platform {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// looking for Documents and Settings/blah/Application Data/Processing
|
||||
public File getSettingsFolder() throws Exception {
|
||||
// HKEY_CURRENT_USER\Software\Microsoft
|
||||
// \Windows\CurrentVersion\Explorer\Shell Folders
|
||||
// Value Name: AppData
|
||||
// Value Type: REG_SZ
|
||||
// Value Data: path
|
||||
|
||||
String keyPath =
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion" +
|
||||
"\\Explorer\\Shell Folders";
|
||||
String appDataPath =
|
||||
Registry.getStringValue(REGISTRY_ROOT_KEY.CURRENT_USER, keyPath, "AppData");
|
||||
|
||||
File dataFolder = new File(appDataPath, "Arduino15");
|
||||
return dataFolder;
|
||||
public File getSettingsFolder() {
|
||||
return settingsFolder;
|
||||
}
|
||||
|
||||
|
||||
// looking for Documents and Settings/blah/My Documents/Processing
|
||||
// (though using a reg key since it's different on other platforms)
|
||||
public File getDefaultSketchbookFolder() throws Exception {
|
||||
|
||||
// http://support.microsoft.com/?kbid=221837&sd=RMVP
|
||||
// http://support.microsoft.com/kb/242557/en-us
|
||||
|
||||
// The path to the My Documents folder is stored in the following
|
||||
// registry key, where path is the complete path to your storage location
|
||||
|
||||
// HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
|
||||
// Value Name: Personal
|
||||
// Value Type: REG_SZ
|
||||
// Value Data: path
|
||||
|
||||
// in some instances, this may be overridden by a policy, in which case check:
|
||||
// HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
|
||||
|
||||
String keyPath =
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion" +
|
||||
"\\Explorer\\Shell Folders";
|
||||
String personalPath =
|
||||
Registry.getStringValue(REGISTRY_ROOT_KEY.CURRENT_USER, keyPath, "Personal");
|
||||
|
||||
return new File(personalPath, "Arduino");
|
||||
return defaultSketchbookFolder;
|
||||
}
|
||||
|
||||
|
||||
public void openURL(String url) throws Exception {
|
||||
// this is not guaranteed to work, because who knows if the
|
||||
// path will always be c:\progra~1 et al. also if the user has
|
||||
@ -242,7 +130,7 @@ public class Platform extends processing.app.Platform {
|
||||
// "Access is denied" in both cygwin and the "dos" prompt.
|
||||
//Runtime.getRuntime().exec("cmd /c " + currentDir + "\\reference\\" +
|
||||
// referenceFile + ".html");
|
||||
if (url.startsWith("http")) {
|
||||
if (url.startsWith("http") || url.startsWith("file:")) {
|
||||
// open dos prompt, give it 'start' command, which will
|
||||
// open the url properly. start by itself won't work since
|
||||
// it appears to need cmd
|
||||
@ -307,7 +195,8 @@ public class Platform extends processing.app.Platform {
|
||||
@Override
|
||||
public String preListAllCandidateDevices() {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Executor executor = new CollectStdOutExecutor(baos);
|
||||
Executor executor = new DefaultExecutor();
|
||||
executor.setStreamHandler(new PumpStreamHandler(baos, null));
|
||||
|
||||
try {
|
||||
String listComPorts = new File(System.getProperty("user.dir"), "hardware/tools/listComPorts.exe").getCanonicalPath();
|
||||
|
35
arduino-core/src/processing/app/windows/RegQueryParser.java
Normal file
35
arduino-core/src/processing/app/windows/RegQueryParser.java
Normal file
@ -0,0 +1,35 @@
|
||||
package processing.app.windows;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class RegQueryParser {
|
||||
|
||||
private String valueOfKey;
|
||||
|
||||
public RegQueryParser(String regQueryOutput) {
|
||||
parse(regQueryOutput);
|
||||
}
|
||||
|
||||
private void parse(String regQueryOutput) {
|
||||
List<String> rows = Arrays.asList(regQueryOutput.replace(" ", "\t").replace("\r", "\n").replace("\n\n", "\n").split("\n"));
|
||||
|
||||
String row = Iterables.find(rows, new Predicate<String>() {
|
||||
@Override
|
||||
public boolean apply(String input) {
|
||||
return input.startsWith("\t");
|
||||
}
|
||||
});
|
||||
|
||||
String[] cols = row.split("\t");
|
||||
assert cols.length == 4;
|
||||
this.valueOfKey = cols[3];
|
||||
}
|
||||
|
||||
public String getValueOfKey() {
|
||||
return valueOfKey;
|
||||
}
|
||||
}
|
@ -1,456 +0,0 @@
|
||||
package processing.app.windows;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
|
||||
/**
|
||||
* Methods for accessing the Windows Registry. Only String and DWORD values supported at the moment.
|
||||
*/
|
||||
public class Registry {
|
||||
public static enum REGISTRY_ROOT_KEY{CLASSES_ROOT, CURRENT_USER, LOCAL_MACHINE, USERS};
|
||||
private final static HashMap<REGISTRY_ROOT_KEY, Integer> rootKeyMap = new HashMap<REGISTRY_ROOT_KEY, Integer>();
|
||||
|
||||
static {
|
||||
rootKeyMap.put(REGISTRY_ROOT_KEY.CLASSES_ROOT, WINREG.HKEY_CLASSES_ROOT);
|
||||
rootKeyMap.put(REGISTRY_ROOT_KEY.CURRENT_USER, WINREG.HKEY_CURRENT_USER);
|
||||
rootKeyMap.put(REGISTRY_ROOT_KEY.LOCAL_MACHINE, WINREG.HKEY_LOCAL_MACHINE);
|
||||
rootKeyMap.put(REGISTRY_ROOT_KEY.USERS, WINREG.HKEY_USERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing.
|
||||
*
|
||||
* @param args arguments
|
||||
* @throws java.lang.Exception on error
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets one of the root keys.
|
||||
*
|
||||
* @param key key type
|
||||
* @return root key
|
||||
*/
|
||||
private static int getRegistryRootKey(REGISTRY_ROOT_KEY key) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference pHandle;
|
||||
int handle = 0;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
pHandle = new IntByReference();
|
||||
|
||||
if(advapi32.RegOpenKeyEx(rootKeyMap.get(key), null, 0, 0, pHandle) == WINERROR.ERROR_SUCCESS) {
|
||||
handle = pHandle.getValue();
|
||||
}
|
||||
return(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a key.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param subKeyName name of the key
|
||||
* @param access access mode
|
||||
* @return handle to the key or 0
|
||||
*/
|
||||
private static int openKey(REGISTRY_ROOT_KEY rootKey, String subKeyName, int access) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference pHandle;
|
||||
int rootKeyHandle;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
rootKeyHandle = getRegistryRootKey(rootKey);
|
||||
pHandle = new IntByReference();
|
||||
|
||||
if(advapi32.RegOpenKeyEx(rootKeyHandle, subKeyName, 0, access, pHandle) == WINERROR.ERROR_SUCCESS) {
|
||||
return(pHandle.getValue());
|
||||
|
||||
} else {
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Windows buffer to a Java String.
|
||||
*
|
||||
* @param buf buffer
|
||||
* @throws java.io.UnsupportedEncodingException on error
|
||||
* @return String
|
||||
*/
|
||||
private static String convertBufferToString(byte[] buf) throws UnsupportedEncodingException {
|
||||
return(new String(buf, 0, buf.length - 2, "UTF-16LE"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Windows buffer to an int.
|
||||
*
|
||||
* @param buf buffer
|
||||
* @return int
|
||||
*/
|
||||
private static int convertBufferToInt(byte[] buf) {
|
||||
return(((int)(buf[0] & 0xff)) + (((int)(buf[1] & 0xff)) << 8) + (((int)(buf[2] & 0xff)) << 16) + (((int)(buf[3] & 0xff)) << 24));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a String value.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
* @throws java.io.UnsupportedEncodingException on error
|
||||
* @return String or null
|
||||
*/
|
||||
public static String getStringValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) throws UnsupportedEncodingException {
|
||||
Advapi32 advapi32;
|
||||
IntByReference pType, lpcbData;
|
||||
byte[] lpData = new byte[1];
|
||||
int handle = 0;
|
||||
String ret = null;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
pType = new IntByReference();
|
||||
lpcbData = new IntByReference();
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_MORE_DATA) {
|
||||
lpData = new byte[lpcbData.getValue()];
|
||||
|
||||
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = convertBufferToString(lpData);
|
||||
}
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an int value.
|
||||
*
|
||||
*
|
||||
* @return int or 0
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
*/
|
||||
public static int getIntValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference pType, lpcbData;
|
||||
byte[] lpData = new byte[1];
|
||||
int handle = 0;
|
||||
int ret = 0;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
pType = new IntByReference();
|
||||
lpcbData = new IntByReference();
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_MORE_DATA) {
|
||||
lpData = new byte[lpcbData.getValue()];
|
||||
|
||||
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = convertBufferToInt(lpData);
|
||||
}
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a value.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
* @return true on success
|
||||
*/
|
||||
public static boolean deleteValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) {
|
||||
Advapi32 advapi32;
|
||||
int handle;
|
||||
boolean ret = true;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ | WINNT.KEY_WRITE);
|
||||
|
||||
if(handle != 0) {
|
||||
if(advapi32.RegDeleteValue(handle, name) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = true;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a String value.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
* @param value value
|
||||
* @throws java.io.UnsupportedEncodingException on error
|
||||
* @return true on success
|
||||
*/
|
||||
public static boolean setStringValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name, String value) throws UnsupportedEncodingException {
|
||||
Advapi32 advapi32;
|
||||
int handle;
|
||||
byte[] data;
|
||||
boolean ret = false;
|
||||
|
||||
// appears to be Java 1.6 syntax, removing [fry]
|
||||
//data = Arrays.copyOf(value.getBytes("UTF-16LE"), value.length() * 2 + 2);
|
||||
data = new byte[value.length() * 2 + 2];
|
||||
byte[] src = value.getBytes("UTF-16LE");
|
||||
System.arraycopy(src, 0, data, 0, src.length);
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ | WINNT.KEY_WRITE);
|
||||
|
||||
if(handle != 0) {
|
||||
if(advapi32.RegSetValueEx(handle, name, 0, WINNT.REG_SZ, data, data.length) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = true;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an int value.
|
||||
*
|
||||
*
|
||||
* @return true on success
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
* @param value value
|
||||
*/
|
||||
public static boolean setIntValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name, int value) {
|
||||
Advapi32 advapi32;
|
||||
int handle;
|
||||
byte[] data;
|
||||
boolean ret = false;
|
||||
|
||||
data = new byte[4];
|
||||
data[0] = (byte)(value & 0xff);
|
||||
data[1] = (byte)((value >> 8) & 0xff);
|
||||
data[2] = (byte)((value >> 16) & 0xff);
|
||||
data[3] = (byte)((value >> 24) & 0xff);
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ | WINNT.KEY_WRITE);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegSetValueEx(handle, name, 0, WINNT.REG_DWORD, data, data.length) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = true;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for existence of a value.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
* @return true if exists
|
||||
*/
|
||||
public static boolean valueExists(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference pType, lpcbData;
|
||||
byte[] lpData = new byte[1];
|
||||
int handle = 0;
|
||||
boolean ret = false;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
pType = new IntByReference();
|
||||
lpcbData = new IntByReference();
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) != WINERROR.ERROR_FILE_NOT_FOUND) {
|
||||
ret = true;
|
||||
|
||||
} else {
|
||||
ret = false;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new key.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param parent name of parent key
|
||||
* @param name key name
|
||||
* @return true on success
|
||||
*/
|
||||
public static boolean createKey(REGISTRY_ROOT_KEY rootKey, String parent, String name) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference hkResult, dwDisposition;
|
||||
int handle = 0;
|
||||
boolean ret = false;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
hkResult = new IntByReference();
|
||||
dwDisposition = new IntByReference();
|
||||
handle = openKey(rootKey, parent, WINNT.KEY_READ);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegCreateKeyEx(handle, name, 0, null, WINNT.REG_OPTION_NON_VOLATILE, WINNT.KEY_READ, null,
|
||||
hkResult, dwDisposition) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = true;
|
||||
advapi32.RegCloseKey(hkResult.getValue());
|
||||
|
||||
} else {
|
||||
ret = false;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a key.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param parent name of parent key
|
||||
* @param name key name
|
||||
* @return true on success
|
||||
*/
|
||||
public static boolean deleteKey(REGISTRY_ROOT_KEY rootKey, String parent, String name) {
|
||||
Advapi32 advapi32;
|
||||
int handle = 0;
|
||||
boolean ret = false;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = openKey(rootKey, parent, WINNT.KEY_READ);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegDeleteKey(handle, name) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = true;
|
||||
|
||||
} else {
|
||||
ret = false;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all sub keys of a key.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param parent key name
|
||||
* @return array with all sub key names
|
||||
*/
|
||||
public static String[] getSubKeys(REGISTRY_ROOT_KEY rootKey, String parent) {
|
||||
Advapi32 advapi32;
|
||||
int handle = 0, dwIndex;
|
||||
char[] lpName;
|
||||
IntByReference lpcName;
|
||||
WINBASE.FILETIME lpftLastWriteTime;
|
||||
TreeSet<String> subKeys = new TreeSet<String>();
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = openKey(rootKey, parent, WINNT.KEY_READ);
|
||||
lpName = new char[256];
|
||||
lpcName = new IntByReference(256);
|
||||
lpftLastWriteTime = new WINBASE.FILETIME();
|
||||
|
||||
if(handle != 0) {
|
||||
dwIndex = 0;
|
||||
|
||||
while(advapi32.RegEnumKeyEx(handle, dwIndex, lpName, lpcName, null,
|
||||
null, null, lpftLastWriteTime) == WINERROR.ERROR_SUCCESS) {
|
||||
subKeys.add(new String(lpName, 0, lpcName.getValue()));
|
||||
lpcName.setValue(256);
|
||||
dwIndex++;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
|
||||
return(subKeys.toArray(new String[]{}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all values under a key.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param key jey name
|
||||
* @throws java.io.UnsupportedEncodingException on error
|
||||
* @return TreeMap with name and value pairs
|
||||
*/
|
||||
public static TreeMap<String, Object> getValues(REGISTRY_ROOT_KEY rootKey, String key) throws UnsupportedEncodingException {
|
||||
Advapi32 advapi32;
|
||||
int handle = 0, dwIndex, result = 0;
|
||||
char[] lpValueName;
|
||||
byte[] lpData;
|
||||
IntByReference lpcchValueName, lpType, lpcbData;
|
||||
String name;
|
||||
TreeMap<String, Object> values = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = openKey(rootKey, key, WINNT.KEY_READ);
|
||||
lpValueName = new char[16384];
|
||||
lpcchValueName = new IntByReference(16384);
|
||||
lpType = new IntByReference();
|
||||
lpData = new byte[1];
|
||||
lpcbData = new IntByReference();
|
||||
|
||||
if(handle != 0) {
|
||||
dwIndex = 0;
|
||||
|
||||
do {
|
||||
lpcbData.setValue(0);
|
||||
result = advapi32.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null,
|
||||
lpType, lpData, lpcbData);
|
||||
|
||||
if(result == WINERROR.ERROR_MORE_DATA) {
|
||||
lpData = new byte[lpcbData.getValue()];
|
||||
lpcchValueName = new IntByReference(16384);
|
||||
result = advapi32.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null,
|
||||
lpType, lpData, lpcbData);
|
||||
|
||||
if(result == WINERROR.ERROR_SUCCESS) {
|
||||
name = new String(lpValueName, 0, lpcchValueName.getValue());
|
||||
|
||||
switch(lpType.getValue()) {
|
||||
case WINNT.REG_SZ:
|
||||
values.put(name, convertBufferToString(lpData));
|
||||
break;
|
||||
case WINNT.REG_DWORD:
|
||||
values.put(name, convertBufferToInt(lpData));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
dwIndex++;
|
||||
} while(result == WINERROR.ERROR_SUCCESS);
|
||||
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(values);
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* WINBASE.java
|
||||
*
|
||||
* Created on 5. September 2007, 11:24
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package processing.app.windows;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface WINBASE {
|
||||
/*
|
||||
typedef struct _SECURITY_ATTRIBUTES {
|
||||
DWORD nLength;
|
||||
LPVOID lpSecurityDescriptor;
|
||||
BOOL bInheritHandle;
|
||||
} SECURITY_ATTRIBUTES,
|
||||
*PSECURITY_ATTRIBUTES,
|
||||
*LPSECURITY_ATTRIBUTES;*/
|
||||
public static class SECURITY_ATTRIBUTES extends Structure {
|
||||
public int nLength;
|
||||
public Pointer lpSecurityDescriptor;
|
||||
public boolean bInheritHandle;
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _FILETIME {
|
||||
DWORD dwLowDateTime;
|
||||
DWORD dwHighDateTime;
|
||||
} FILETIME, *PFILETIME, *LPFILETIME;*/
|
||||
public static class FILETIME extends Structure {
|
||||
public int dwLowDateTime;
|
||||
public int dwHighDateTime;
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* WINERROR.java
|
||||
*
|
||||
* Created on 7. August 2007, 08:09
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package processing.app.windows;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface WINERROR {
|
||||
public final static int ERROR_SUCCESS = 0;
|
||||
public final static int NO_ERROR = 0;
|
||||
public final static int ERROR_FILE_NOT_FOUND = 2;
|
||||
public final static int ERROR_MORE_DATA = 234;
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* WINNT.java
|
||||
*
|
||||
* Created on 8. August 2007, 13:41
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package processing.app.windows;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface WINNT {
|
||||
public final static int DELETE = 0x00010000;
|
||||
public final static int READ_CONTROL = 0x00020000;
|
||||
public final static int WRITE_DAC = 0x00040000;
|
||||
public final static int WRITE_OWNER = 0x00080000;
|
||||
public final static int SYNCHRONIZE = 0x00100000;
|
||||
|
||||
public final static int STANDARD_RIGHTS_REQUIRED = 0x000F0000;
|
||||
|
||||
public final static int STANDARD_RIGHTS_READ = READ_CONTROL;
|
||||
public final static int STANDARD_RIGHTS_WRITE = READ_CONTROL;
|
||||
public final static int STANDARD_RIGHTS_EXECUTE = READ_CONTROL;
|
||||
|
||||
public final static int STANDARD_RIGHTS_ALL = 0x001F0000;
|
||||
|
||||
public final static int SPECIFIC_RIGHTS_ALL = 0x0000FFFF;
|
||||
|
||||
public final static int GENERIC_EXECUTE = 0x20000000;
|
||||
|
||||
public final static int SERVICE_WIN32_OWN_PROCESS = 0x00000010;
|
||||
|
||||
public final static int KEY_QUERY_VALUE = 0x0001;
|
||||
public final static int KEY_SET_VALUE = 0x0002;
|
||||
public final static int KEY_CREATE_SUB_KEY = 0x0004;
|
||||
public final static int KEY_ENUMERATE_SUB_KEYS = 0x0008;
|
||||
public final static int KEY_NOTIFY = 0x0010;
|
||||
public final static int KEY_CREATE_LINK = 0x0020;
|
||||
|
||||
public final static int KEY_READ = ((STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY) & (~SYNCHRONIZE));
|
||||
public final static int KEY_WRITE = ((STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY) & (~SYNCHRONIZE));
|
||||
|
||||
public final static int REG_NONE = 0; // No value type
|
||||
public final static int REG_SZ = 1; // Unicode nul terminated string
|
||||
public final static int REG_EXPAND_SZ = 2; // Unicode nul terminated string
|
||||
// (with environment variable references)
|
||||
public final static int REG_BINARY = 3; // Free form binary
|
||||
public final static int REG_DWORD = 4; // 32-bit number
|
||||
public final static int REG_DWORD_LITTLE_ENDIAN = 4; // 32-bit number (same as REG_DWORD)
|
||||
public final static int REG_DWORD_BIG_ENDIAN = 5; // 32-bit number
|
||||
public final static int REG_LINK = 6; // Symbolic Link (unicode)
|
||||
public final static int REG_MULTI_SZ = 7; // Multiple Unicode strings
|
||||
public final static int REG_RESOURCE_LIST = 8; // Resource list in the resource map
|
||||
public final static int REG_FULL_RESOURCE_DESCRIPTOR = 9; // Resource list in the hardware description
|
||||
public final static int REG_RESOURCE_REQUIREMENTS_LIST = 10;
|
||||
|
||||
public final static int REG_OPTION_RESERVED = 0x00000000; // Parameter is reserved
|
||||
public final static int REG_OPTION_NON_VOLATILE = 0x00000000; // Key is preserved
|
||||
// when system is rebooted
|
||||
public final static int REG_OPTION_VOLATILE = 0x00000001; // Key is not preserved
|
||||
// when system is rebooted
|
||||
public final static int REG_OPTION_CREATE_LINK = 0x00000002; // Created key is a
|
||||
// symbolic link
|
||||
public final static int REG_OPTION_BACKUP_RESTORE = 0x00000004; // open for backup or restore
|
||||
// special access rules
|
||||
// privilege required
|
||||
public final static int REG_OPTION_OPEN_LINK = 0x00000008; // Open symbolic link
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
/*
|
||||
* WINREG.java
|
||||
*
|
||||
* Created on 17. August 2007, 14:32
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package processing.app.windows;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface WINREG {
|
||||
public final static int HKEY_CLASSES_ROOT = 0x80000000;
|
||||
public final static int HKEY_CURRENT_USER = 0x80000001;
|
||||
public final static int HKEY_LOCAL_MACHINE = 0x80000002;
|
||||
public final static int HKEY_USERS = 0x80000003;
|
||||
}
|
Reference in New Issue
Block a user