zip export also adds the preload ram content to the zip file.

This commit is contained in:
hneemann 2020-11-27 08:01:13 +01:00
parent 34f305d3e3
commit 431078a218
2 changed files with 42 additions and 2 deletions

View File

@ -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) {

View File

@ -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);