Change folder logisim-defaults is located in

Changed the location that logisim-defaults is located in from the user's home directory, to the directory which the Logsim's .jar file is running from.
This commit is contained in:
Katie Page 2025-05-09 20:38:56 +01:00
parent d222402006
commit 3d4d12b70d
6 changed files with 18 additions and 4 deletions

View File

@ -1,14 +1,21 @@
# Automatically Importing Logisim Libraries
Logisim Evolution supports loading custom libraries at startup, contained in Logisim `.circ` files.
To do this, create a directory in your **home directory** named `logisim-defaults` and insert any Logisim libraries you
would like to load every time Logisim Evolution starts. **Every circuit must have a unique name, and must not be called
To do this, create a directory named `logisim-defaults` in either:
- The same directory as the `.jar` file which is executing Logisim ![Where the logisim-defaults folder goes, if executing from a JAR file.](img/logisim-defaults-jar.png)
- Inside `/build/classes/java/`, if running from Gradle. ![Where the logisim-defaults folder goes, if running from Gradle.](img/logisim-defaults-build.png)
Inside the `logisim-defaults`folder should be any `.circ` files which you would like to load automatically at startup.
**Every circuit must have a unique name, and must not be called
"main"**. This is to avoid conflicts caused by loading libraries with the same name.
![An example of a CIRC file in the logisim-defaults folder](img/logisim-defaults-folder.png)
Please note that any files added using the `logisim-defaults` folder are third-party,
and therefore will need referencing for any projects you use them in.
As of present, libraries are only automatically imported on *startup*. By creating a new file through the user interface,
only built-in libraries will be imported.
![Logisim-defaults](img/logisim-defaults.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

View File

@ -44,6 +44,8 @@ import java.awt.event.AWTEventListener;
import java.awt.event.ContainerEvent;
import java.io.File;
import java.io.FilenameFilter;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@ -760,6 +762,11 @@ public class Startup implements AWTEventListener {
System.exit(-1);
}
private static String getProgramDirectory() {
var pathOfMainClass = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath());
return URLDecoder.decode(pathOfMainClass.getParentFile().getAbsolutePath(), StandardCharsets.UTF_8);
}
private void doOpenFile(File file) {
if (initialized) {
ProjectActions.doOpen(null, null, file);
@ -888,7 +895,7 @@ public class Startup implements AWTEventListener {
// Load in any user-defined default circuit files
var defaultLibraries = templLoader.loadCustomStartupLibraries(
System.getProperty("user.home") + File.separator + "logisim-defaults");
getProgramDirectory() + File.separator + "logisim-defaults");
// load in template
loadTemplate(templLoader, templFile, templEmpty);