From 431078a218d66632ec7633a42a0a45c795bbf9de Mon Sep 17 00:00:00 2001 From: hneemann Date: Fri, 27 Nov 2020 08:01:13 +0100 Subject: [PATCH] zip export also adds the preload ram content to the zip file. --- .../java/de/neemann/digital/FileLocator.java | 32 +++++++++++++++++-- .../neemann/digital/gui/ExportZipAction.java | 12 +++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/neemann/digital/FileLocator.java b/src/main/java/de/neemann/digital/FileLocator.java index 0a4218b4b..97b7b44c3 100644 --- a/src/main/java/de/neemann/digital/FileLocator.java +++ b/src/main/java/de/neemann/digital/FileLocator.java @@ -7,6 +7,7 @@ package de.neemann.digital; import de.neemann.digital.draw.library.ElementLibrary; import de.neemann.digital.gui.FileHistory; +import de.neemann.digital.gui.Main; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,11 +21,23 @@ public class FileLocator { private static final int MAX_FILE_COUNTER = 5000; private final String filename; + private File file; private FileHistory history; private ElementLibrary library; private File baseFile; private int fileCounter; + + /** + * Creates a new instance + * + * @param file the file to serach for + */ + public FileLocator(File file) { + this(file == null ? null : file.getName()); + this.file = file; + } + /** * Creates a new instance * @@ -70,14 +83,29 @@ public class FileLocator { return this; } + /** + * Configures the file locator with the given main + * + * @param main the main class + * @return this for chained calls + */ + public FileLocator setupWithMain(Main main) { + setBaseFile(main.getBaseFileName()); + setLibrary(main.getLibrary()); + return this; + } + /** * Tries to locate the given file. * * @return the file or null if not found */ public File locate() { + if (file != null && file.exists()) + return file; + if (filename == null) - return null; + return file; if (baseFile != null) { File f = new File(baseFile.getParentFile(), filename); @@ -110,7 +138,7 @@ public class FileLocator { } LOGGER.debug(filename + " not found"); - return null; + return file; } private File search(File path) { diff --git a/src/main/java/de/neemann/digital/gui/ExportZipAction.java b/src/main/java/de/neemann/digital/gui/ExportZipAction.java index fa7194684..870df410a 100644 --- a/src/main/java/de/neemann/digital/gui/ExportZipAction.java +++ b/src/main/java/de/neemann/digital/gui/ExportZipAction.java @@ -5,7 +5,10 @@ */ package de.neemann.digital.gui; +import de.neemann.digital.FileLocator; +import de.neemann.digital.core.element.ElementAttributes; import de.neemann.digital.core.element.ElementTypeDescription; +import de.neemann.digital.core.element.Keys; import de.neemann.digital.draw.elements.Circuit; import de.neemann.digital.draw.elements.VisualElement; import de.neemann.digital.draw.library.ElementLibrary; @@ -52,6 +55,15 @@ public class ExportZipAction extends ToolTipAction { File origin = circuit.getOrigin(); elementSet = new HashSet<>(); addFile(zip, origin, circuit); + + ElementAttributes settings = circuit.getAttributes(); + if (settings.get(Keys.PRELOAD_PROGRAM)) { + File prog = new FileLocator(settings.get(Keys.PROGRAM_TO_PRELOAD)) + .setupWithMain(main) + .locate(); + addToZip(zip, prog); + } + addToZip(zip, "MANIFEST.TXT", "Main-Circuit: " + origin.getName() + "\n"); } catch (ElementNotFoundException e1) { throw new IOException(Lang.get("err_errorExportingZip"), e1);