diff --git a/core/src/main/java/leikr/GameRuntime.java b/core/src/main/java/leikr/GameRuntime.java index 6f1da9fe..22837952 100644 --- a/core/src/main/java/leikr/GameRuntime.java +++ b/core/src/main/java/leikr/GameRuntime.java @@ -48,7 +48,7 @@ import org.mini2Dx.core.graphics.Pixmap; import org.mini2Dx.core.graphics.viewport.FitViewport; -public class GameRuntime extends ScreenBasedGame { +public final class GameRuntime extends ScreenBasedGame { public final String GAME_IDENTIFIER = "torbuntu.leikr"; public String fileDroppedTitle; @@ -58,11 +58,11 @@ public class GameRuntime extends ScreenBasedGame { private boolean directLaunch; private String gameName; - private final String programsPath; - private final String basePath; - private final String dataPath; - private final String deployPath; - private final String packagePath; + private String programsPath; + private String basePath; + private String dataPath; + private String deployPath; + private String packagePath; private final FitViewport viewport; private AssetManager assetManager; @@ -88,7 +88,7 @@ public class GameRuntime extends ScreenBasedGame { private CustomCursor cursor; - private final CustomSystemProperties customSystemProperties; + private CustomSystemProperties customSystemProperties; /** * Creates CustomSystemProperties for detecting launch title. @@ -96,22 +96,10 @@ public class GameRuntime extends ScreenBasedGame { * @param args */ public GameRuntime(String[] args) { - String userHome = System.getProperty("user.home"); - String leikrHome = System.getenv("LEIKR_HOME"); - if (leikrHome != null) { - basePath = leikrHome + "/Leikr/"; - programsPath = leikrHome + "/Leikr/Programs/"; - dataPath = leikrHome + "/Leikr/Data/"; - deployPath = leikrHome + "/Leikr/Deploy/"; - packagePath = leikrHome + "/Leikr/Packages/"; - Logger.getLogger(GameRuntime.class.getName()).log(Level.INFO, "Using custom Leikr home at: {0}", basePath); + if (System.getenv("LEIKR_HOME") != null) { + customPathVariables(); } else { - basePath = userHome + "/Leikr/"; - programsPath = userHome + "/Leikr/Programs/"; - dataPath = userHome + "/Leikr/Data/"; - deployPath = userHome + "/Leikr/Deploy/"; - packagePath = userHome + "/Leikr/Packages/"; - Logger.getLogger(GameRuntime.class.getName()).log(Level.INFO, "Using default Leikr home at: {0}", basePath); + defaultPathVariables(); } System.out.println(programsPath + "\n" + dataPath); @@ -130,7 +118,44 @@ public GameRuntime(String[] args) { } } - void checkFileSystem() throws IOException { + public void setLeikrHome(String leikrHome) { + try { + basePath = leikrHome + "/Leikr/"; + programsPath = leikrHome + "/Leikr/Programs/"; + dataPath = leikrHome + "/Leikr/Data/"; + deployPath = leikrHome + "/Leikr/Deploy/"; + packagePath = leikrHome + "/Leikr/Packages/"; + + customSystemProperties = new CustomSystemProperties(); + checkFileSystem(); + Logger.getLogger(GameRuntime.class.getName()).log(Level.INFO, "Using custom Leikr home at: {0}", basePath); + + } catch (IOException ex) { + Logger.getLogger(GameRuntime.class.getName()).log(Level.WARNING, "Unable to use custom Leikr home: {0}", basePath); + } + } + + private void customPathVariables() { + String leikrHome = System.getenv("LEIKR_HOME"); + basePath = leikrHome + "/Leikr/"; + programsPath = leikrHome + "/Leikr/Programs/"; + dataPath = leikrHome + "/Leikr/Data/"; + deployPath = leikrHome + "/Leikr/Deploy/"; + packagePath = leikrHome + "/Leikr/Packages/"; + Logger.getLogger(GameRuntime.class.getName()).log(Level.INFO, "Using custom Leikr home at: {0}", basePath); + } + + private void defaultPathVariables() { + String userHome = System.getProperty("user.home"); + basePath = userHome + "/Leikr/"; + programsPath = userHome + "/Leikr/Programs/"; + dataPath = userHome + "/Leikr/Data/"; + deployPath = userHome + "/Leikr/Deploy/"; + packagePath = userHome + "/Leikr/Packages/"; + Logger.getLogger(GameRuntime.class.getName()).log(Level.INFO, "Using default Leikr home at: {0}", basePath); + } + + private void checkFileSystem() throws IOException { if (!Mdx.files.external(basePath).exists()) { Mdx.files.external(basePath).mkdirs(); Mdx.files.external(programsPath).mkdirs(); diff --git a/core/src/main/java/leikr/commands/HomeCommand.java b/core/src/main/java/leikr/commands/HomeCommand.java new file mode 100644 index 00000000..3760ae78 --- /dev/null +++ b/core/src/main/java/leikr/commands/HomeCommand.java @@ -0,0 +1,58 @@ +/* + * Copyright 2020 tor. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package leikr.commands; + +import java.security.Policy; +import java.util.logging.Level; +import java.util.logging.Logger; +import leikr.GameRuntime; + +/** + * + * @author tor + */ +public class HomeCommand implements Command { + + private final GameRuntime runtime; + + public HomeCommand(GameRuntime runtime){ + this.runtime = runtime; + } + + @Override + public String execute(String[] args) { + try { + System.setProperty("leikr.home", args[1]); + Policy.getPolicy().refresh(); + runtime.setLeikrHome(System.getProperty("leikr.home")); + } catch (Exception ex) { + Logger.getLogger(HomeCommand.class.getName()).log(Level.SEVERE, null, ex); + return "[E] Unable to set LEIKR_HOME: "; + } + return "[I] Set LEIKR_HOME to [" + args[1] + "]"; + } + + @Override + public String help() { + return "home [path] \nSets the LEIKR_HOME property telling the host where Leikr's home directory should be."; + } + + @Override + public String getName() { + return "home"; + } + +} diff --git a/core/src/main/java/leikr/managers/TerminalManager.java b/core/src/main/java/leikr/managers/TerminalManager.java index 29f34798..95b917c6 100644 --- a/core/src/main/java/leikr/managers/TerminalManager.java +++ b/core/src/main/java/leikr/managers/TerminalManager.java @@ -35,6 +35,7 @@ import leikr.commands.InstallCommand; import leikr.commands.NewProgramCommand; import leikr.commands.DeployCommand; +import leikr.commands.HomeCommand; import leikr.commands.PrintCommand; import leikr.commands.PrintDirectoryCommand; import leikr.commands.PrintWorkspaceCommand; @@ -120,7 +121,8 @@ public TerminalManager(GameRuntime runtime, EngineLoader engineLoader) { commandList.put("compile", new CompileCommand(runtime, engineLoader)); commandList.put("get", new GetCommand(runtime)); commandList.put("set", new SetCommand(runtime)); - + commandList.put("home", new HomeCommand(runtime)); + this.runtime = runtime; } diff --git a/core/src/main/java/leikr/screens/LoadScreen.java b/core/src/main/java/leikr/screens/LoadScreen.java index c75f3c70..b4c1035b 100644 --- a/core/src/main/java/leikr/screens/LoadScreen.java +++ b/core/src/main/java/leikr/screens/LoadScreen.java @@ -132,7 +132,13 @@ public void render(GameContainer gc, Graphics g) { viewport.apply(g); if (!engineGetter.isDone()) { // logo and loading - g.drawTexture(assetManager.get(runtime.getDataPath()+"Images/leikr-logo.png", Texture.class), 80, 64, 48, 16); + if (assetManager.isLoaded(runtime.getDataPath() + "Images/leikr-logo.png")) { + g.drawTexture(assetManager.get(runtime.getDataPath() + "Images/leikr-logo.png", Texture.class), 80, 64, 48, 16); + } else { + assetManager.load(runtime.getDataPath() + "Images/leikr-logo.png", Texture.class); + assetManager.finishLoading(); + } + g.setColor(Colors.WHITE()); g.drawString("Loading", 96, 73); diff --git a/desktop/src/leikr/desktop/DesktopLauncher.java b/desktop/src/leikr/desktop/DesktopLauncher.java index 72b41512..2b6101db 100644 --- a/desktop/src/leikr/desktop/DesktopLauncher.java +++ b/desktop/src/leikr/desktop/DesktopLauncher.java @@ -35,7 +35,9 @@ public static void main(String[] args) { if (Arrays.asList(args).contains("insecure")) { Logger.getLogger(Security.class.getName()).log(Level.WARNING, "Leikr is running without security policy."); } else if (System.getSecurityManager() == null) { - System.setProperty("leikr.home", System.getenv("LEIKR_HOME")); + if (System.getenv("LEKR_HOME") != null) { + System.setProperty("leikr.home", System.getenv("LEIKR_HOME")); + } Logger.getLogger(Security.class.getName()).log(Level.INFO, "Setting Leikr security policy."); System.setProperty("java.security.policy", new File("Sys/mysecurity.policy").getAbsolutePath());