Search in sources :

Example 1 with LogisimVersion

use of com.cburch.logisim.LogisimVersion in project logisim-evolution by reds-heig.

the class XmlReader method considerRepairs.

private void considerRepairs(Document doc, Element root) {
    LogisimVersion version = LogisimVersion.parse(root.getAttribute("source"));
    if (version.compareTo(LogisimVersion.get(2, 3, 0)) < 0) {
        // with the Edit tool instead.
        for (Element toolbar : XmlIterator.forChildElements(root, "toolbar")) {
            Element wiring = null;
            Element select = null;
            Element edit = null;
            for (Element elt : XmlIterator.forChildElements(toolbar, "tool")) {
                String eltName = elt.getAttribute("name");
                if (eltName != null && !eltName.equals("")) {
                    if (eltName.equals("Select Tool"))
                        select = elt;
                    if (eltName.equals("Wiring Tool"))
                        wiring = elt;
                    if (eltName.equals("Edit Tool"))
                        edit = elt;
                }
            }
            if (select != null && wiring != null && edit == null) {
                select.setAttribute("name", "Edit Tool");
                toolbar.removeChild(wiring);
            }
        }
    }
    if (version.compareTo(LogisimVersion.get(2, 6, 3)) < 0) {
        for (Element circElt : XmlIterator.forChildElements(root, "circuit")) {
            for (Element attrElt : XmlIterator.forChildElements(circElt, "a")) {
                String name = attrElt.getAttribute("name");
                if (name != null && name.startsWith("label")) {
                    attrElt.setAttribute("name", "c" + name);
                }
            }
        }
        repairForWiringLibrary(doc, root);
        repairForLegacyLibrary(doc, root);
    }
}
Also used : Element(org.w3c.dom.Element) LogisimVersion(com.cburch.logisim.LogisimVersion)

Example 2 with LogisimVersion

use of com.cburch.logisim.LogisimVersion in project logisim-evolution by reds-heig.

the class Startup method autoUpdate.

/**
 * Auto-update Logisim-evolution if a new version is available
 *
 * Original idea taken from Jupar:
 * http://masterex.github.io/archive/2011/12/25/jupar.html by Periklis
 * Master_ex Ntanasis <pntanasis@gmail.com>
 *
 * @return true if the code has been updated, and therefore the execution
 *         has to be stopped, false otherwise
 */
public boolean autoUpdate() {
    if (!Main.UPDATE || !networkConnectionAvailable()) {
        // available
        return (false);
    }
    // Get the remote XML file containing the current version
    URL xmlURL;
    try {
        xmlURL = new URL(Main.UPDATE_URL);
    } catch (MalformedURLException e) {
        logger.error("The URL of the XML file for the auto-updater is malformed.\nPlease report this error to the software maintainer\n-- AUTO-UPDATE ABORTED --");
        return (false);
    }
    URLConnection conn;
    try {
        conn = xmlURL.openConnection();
    } catch (IOException e) {
        logger.error("Although an Internet connection should be available, the system couldn't connect to the URL requested by the auto-updater\nIf the error persist, please contact the software maintainer\n-- AUTO-UPDATE ABORTED --");
        return (false);
    }
    InputStream in;
    try {
        in = conn.getInputStream();
    } catch (IOException e) {
        logger.error("Although an Internet connection should be available, the system couldn't retrieve the data requested by the auto-updater.\nIf the error persist, please contact the software maintainer\n-- AUTO-UPDATE ABORTED --");
        return (false);
    }
    ArgonXML logisimData = new ArgonXML(in, "logisim-evolution");
    // Get the appropriate remote version number
    LogisimVersion remoteVersion = LogisimVersion.parse(Main.VERSION.hasTracker() ? logisimData.child("tracked_version").content() : logisimData.child("untracked_version").content());
    // If the remote version is newer, perform the update
    if (remoteVersion.compareTo(Main.VERSION) > 0) {
        int answer = JOptionPane.showConfirmDialog(null, "A new Logisim-evolution version (" + remoteVersion + ") is available!\nWould you like to update?", "Update", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
        if (answer == 1) {
            // annoyed by the message that he finally updates!
            return (false);
        }
        // Obtain the base directory of the jar archive
        CodeSource codeSource = Startup.class.getProtectionDomain().getCodeSource();
        File jarFile = null;
        try {
            jarFile = new File(codeSource.getLocation().toURI().getPath());
        } catch (URISyntaxException e) {
            logger.error("Error in the syntax of the URI for the path of the executed Logisim-evolution JAR file!");
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "An error occurred while updating to the new Logisim-evolution version.\nPlease check the console for log information.", "Update failed", JOptionPane.ERROR_MESSAGE);
            return (false);
        }
        // Get the appropriate remote filename to download
        String remoteJar = Main.VERSION.hasTracker() ? logisimData.child("tracked_file").content() : logisimData.child("untracked_file").content();
        boolean updateOk = downloadInstallUpdatedVersion(remoteJar, jarFile.getAbsolutePath());
        if (updateOk) {
            JOptionPane.showMessageDialog(null, "The new Logisim-evolution version (" + remoteVersion + ") has been correctly installed.\nPlease restart Logisim-evolution for the changes to take effect.", "Update succeeded", JOptionPane.INFORMATION_MESSAGE);
            return (true);
        } else {
            JOptionPane.showMessageDialog(null, "An error occurred while updating to the new Logisim-evolution version.\nPlease check the console for log information.", "Update failed", JOptionPane.ERROR_MESSAGE);
            return (false);
        }
    }
    return (false);
}
Also used : MalformedURLException(java.net.MalformedURLException) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ArgonXML(com.cburch.logisim.util.ArgonXML) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) CodeSource(java.security.CodeSource) LogisimVersion(com.cburch.logisim.LogisimVersion) URL(java.net.URL) URLConnection(java.net.URLConnection) Print(com.cburch.logisim.gui.main.Print) File(java.io.File)

Example 3 with LogisimVersion

use of com.cburch.logisim.LogisimVersion in project logisim-evolution by reds-heig.

the class XmlWriter method addAttributeSetContent.

void addAttributeSetContent(Element elt, AttributeSet attrs, AttributeDefaultProvider source) {
    if (attrs == null)
        return;
    LogisimVersion ver = Main.VERSION;
    if (source != null && source.isAllDefaultValues(attrs, ver))
        return;
    for (Attribute<?> attrBase : attrs.getAttributes()) {
        @SuppressWarnings("unchecked") Attribute<Object> attr = (Attribute<Object>) attrBase;
        Object val = attrs.getValue(attr);
        if (attrs.isToSave(attr) && val != null) {
            Object dflt = source == null ? null : source.getDefaultAttributeValue(attr, ver);
            if (dflt == null || !dflt.equals(val)) {
                Element a = doc.createElement("a");
                a.setAttribute("name", attr.getName());
                String value = attr.toStandardString(val);
                if (attr.getName().equals("filePath") && outFilepath != null) {
                    Path outFP = Paths.get(outFilepath);
                    Path attrValP = Paths.get(value);
                    value = (outFP.relativize(attrValP)).toString();
                    a.setAttribute("val", value);
                } else {
                    if (value.indexOf("\n") >= 0) {
                        a.appendChild(doc.createTextNode(value));
                    } else {
                        a.setAttribute("val", attr.toStandardString(val));
                    }
                }
                elt.appendChild(a);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) Attribute(com.cburch.logisim.data.Attribute) Element(org.w3c.dom.Element) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) LogisimVersion(com.cburch.logisim.LogisimVersion)

Aggregations

LogisimVersion (com.cburch.logisim.LogisimVersion)3 Element (org.w3c.dom.Element)2 AbstractCanvasObject (com.cburch.draw.model.AbstractCanvasObject)1 Attribute (com.cburch.logisim.data.Attribute)1 Print (com.cburch.logisim.gui.main.Print)1 ArgonXML (com.cburch.logisim.util.ArgonXML)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 Path (java.nio.file.Path)1 CodeSource (java.security.CodeSource)1