Skip to content

Commit

Permalink
Resolve SceneBuilder config path based on the platform #42
Browse files Browse the repository at this point in the history
  • Loading branch information
mkpaz committed May 30, 2023
1 parent d3bb571 commit 7fceac1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private Pane createStartScreen() {
var previewBox = new HBox(20, previewImg, new VBox(20, previewLbl, downloadLnk));
previewBox.setAlignment(Pos.TOP_LEFT);

var browseLbl = new Label("Select SceneBuilder installation directory:");
var browseLbl = new Label("Select the SceneBuilder installation directory:");
browseLbl.getStyleClass().addAll(TEXT_CAPTION, TEXT_MUTED);

var browseBtn = new Button("Browse", new FontIcon(Material2OutlinedAL.FOLDER));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.nio.charset.StandardCharsets.UTF_8;

import atlantafx.base.util.PlatformUtils;
import atlantafx.sampler.theme.SamplerTheme;
import atlantafx.sampler.theme.SceneBuilderTheme;
import java.io.BufferedOutputStream;
Expand All @@ -23,9 +24,11 @@

final class SceneBuilderInstaller {

private static final String CONFIG_FILE_NAME = "SceneBuilder.cfg";
private static final String THEME_PACK_FILE_NAME = "atlantafx-scene-builder.zip";

private final Path sceneBuilderDir;
private Path configDir;

public SceneBuilderInstaller(Path dir) {
this.sceneBuilderDir = Objects.requireNonNull(dir);
Expand Down Expand Up @@ -217,11 +220,41 @@ public static void deleteFile(Path path) {
}

private Path getConfigDir() {
return sceneBuilderDir.resolve("lib/app");
if (configDir != null) {
return configDir;
}

// app image structure is documented here
// https://docs.oracle.com/en/java/javase/20/jpackage/packaging-overview.html
Path dir = sceneBuilderDir;
if (PlatformUtils.isWindows()) {
dir = sceneBuilderDir.resolve("app");
} else if (PlatformUtils.isMac()) {
dir = sceneBuilderDir.resolve("Contents/app");
} else if (PlatformUtils.isUnix()) {
dir = sceneBuilderDir.resolve("lib/app");
}

// last chance, if app image has an unknown structure
if (!Files.exists(dir.resolve(CONFIG_FILE_NAME))) {
try (var stream = Files.walk(sceneBuilderDir)) {
dir = stream
.filter(f -> Objects.equals(f.getFileName().toString(), CONFIG_FILE_NAME))
.findAny()
.map(Path::getParent)
.orElse(null);
} catch (IOException e) {
e.printStackTrace();
}
}

this.configDir = dir;

return Objects.requireNonNullElse(dir, sceneBuilderDir);
}

private Path getConfigFile() {
return getConfigDir().resolve("SceneBuilder.cfg");
return getConfigDir().resolve(CONFIG_FILE_NAME);
}

private Path getBackupConfigFile() {
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 7fceac1

Please sign in to comment.