From c6bbd58d18e8b81a40537020529e96f93cfd4b6d Mon Sep 17 00:00:00 2001 From: Chaos Date: Tue, 11 Jan 2022 19:00:08 +0100 Subject: [PATCH] Fixing for version 0.1.3 --- pom.xml | 11 +++++--- .../de/chaos/swlnmngr/config/CLIConfig.java | 2 +- .../swlnmngr/route/routes/InstallRoute.java | 25 ++++++++++++++++++- .../swlnmngr/route/routes/LinkRoute.java | 2 +- src/main/resources/default_swlnmngr.bat | 6 ++++- 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index c424a42..d4b7c89 100644 --- a/pom.xml +++ b/pom.xml @@ -6,12 +6,12 @@ de.chaos swlnmngr - 0.1.2 + 0.1.3 SteamWarLinkManager - 17 - 17 + 11 + 11 @@ -98,5 +98,10 @@ commons-lang 2.6 + + com.github.vatbub + mslinks + 1.0.6.2 + \ No newline at end of file diff --git a/src/main/java/de/chaos/swlnmngr/config/CLIConfig.java b/src/main/java/de/chaos/swlnmngr/config/CLIConfig.java index 507b480..2d164b6 100644 --- a/src/main/java/de/chaos/swlnmngr/config/CLIConfig.java +++ b/src/main/java/de/chaos/swlnmngr/config/CLIConfig.java @@ -19,7 +19,7 @@ public class CLIConfig { options.addOption(new Option("d", "debug", false, "Set the Log Level to Debug")); options.addOption(new Option("c", "config", true, "Use another Config File")); options.addOption(new Option("i", "installdir", true, "Use other Install Dir")); - options.addOption(new Option("u", "no-update", false, "Disable the Auto-Update Checker")); + options.addOption(new Option("u", "update-checker", false, "Enable the Auto-Update Checker")); CommandLine cli = null; CommandLineParser parser = new DefaultParser(); diff --git a/src/main/java/de/chaos/swlnmngr/route/routes/InstallRoute.java b/src/main/java/de/chaos/swlnmngr/route/routes/InstallRoute.java index 613a80e..cf51554 100644 --- a/src/main/java/de/chaos/swlnmngr/route/routes/InstallRoute.java +++ b/src/main/java/de/chaos/swlnmngr/route/routes/InstallRoute.java @@ -2,6 +2,7 @@ package de.chaos.swlnmngr.route.routes; import de.chaos.swlnmngr.Main; import de.chaos.swlnmngr.config.CLIConfig; +import mslinks.ShellLink; import org.apache.commons.lang.SystemUtils; import org.json.JSONObject; import org.json.JSONTokener; @@ -9,9 +10,13 @@ import org.json.JSONTokener; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.nio.file.StandardOpenOption; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.PosixFilePermission; import java.util.Objects; public class InstallRoute implements Route { @@ -54,12 +59,30 @@ public class InstallRoute implements Route { Main.getLogger().error("Could not create SymLink", e); return false; } + } else if(SystemUtils.IS_OS_WINDOWS) { + try { + ShellLink link = ShellLink.createLink(new File(CLIConfig.INSTALL_DIR, "swlnmngr.bat").getAbsolutePath(), new File(CLIConfig.INSTALL_DIR, "swlnmngr.lnk").getAbsolutePath()).setWorkingDir(CLIConfig.INSTALL_DIR.getAbsolutePath()); + link.getHeader().getLinkFlags().setRunAsUser(); + link.saveTo(new File(CLIConfig.INSTALL_DIR, "swlnmngr.lnk").getAbsolutePath()); + Files.writeString(new File(CLIConfig.INSTALL_DIR, "swlnmngr.bat").toPath(), Files.readString(new File(CLIConfig.INSTALL_DIR, "swlnmngr.bat").toPath()).replace("${iDir}", CLIConfig.INSTALL_DIR.getAbsolutePath()), StandardCharsets.UTF_8, StandardOpenOption.TRUNCATE_EXISTING); + } catch (IOException e) { + Main.getLogger().error("Could not create Link", e); + return false; + } + } File configFile = new File(installDir, "config.json"); if(!configFile.exists()) { try { - Files.copy(Objects.requireNonNull(InstallRoute.class.getResourceAsStream("/default_config.json")), configFile.toPath()); + String configStr = new String(Objects.requireNonNull(InstallRoute.class.getResourceAsStream("/default_config.json")).readAllBytes()); + if(SystemUtils.IS_OS_WINDOWS) { + configStr = configStr.replace("~", System.getProperty("user.home")) + .replace("\\", "\\\\") + .replace("/", "\\\\") + .replace("https:\\\\\\\\steamwar.de\\\\lib.php", "https://steamwar.de/lib.php"); + } + Files.writeString(configFile.toPath(), configStr, StandardOpenOption.CREATE_NEW); } catch (IOException e) { Main.getLogger().error("Could not copy Config File", e); return false; diff --git a/src/main/java/de/chaos/swlnmngr/route/routes/LinkRoute.java b/src/main/java/de/chaos/swlnmngr/route/routes/LinkRoute.java index 3e26bca..3b2fd95 100644 --- a/src/main/java/de/chaos/swlnmngr/route/routes/LinkRoute.java +++ b/src/main/java/de/chaos/swlnmngr/route/routes/LinkRoute.java @@ -34,7 +34,7 @@ public class LinkRoute implements Route { Main.getLogger().error("No Project with name: {}", args[0]); return false; } - File link = new File(projectDir, "libs"); + File link = new File(projectDir, "lib"); try { Files.deleteIfExists(link.toPath()); Main.getLogger().debug(libsFile); diff --git a/src/main/resources/default_swlnmngr.bat b/src/main/resources/default_swlnmngr.bat index 8f3e2ed..eb0de03 100644 --- a/src/main/resources/default_swlnmngr.bat +++ b/src/main/resources/default_swlnmngr.bat @@ -1 +1,5 @@ -java -jar ./SteamWarLinkManager.jar %* \ No newline at end of file +set args=--help +set /p args=Arguments: +echo %args% +java -jar ${iDir}\SteamWarLinkManager.jar %args% %* +pause \ No newline at end of file