Commits vergleichen
10 Commits
Autor | SHA1 | Datum | |
---|---|---|---|
|
d8227a18c3 | ||
|
634e931920 | ||
|
bb80ee110d | ||
|
8659bce671 | ||
|
bc1d50fb8e | ||
|
f41673e69a | ||
|
c6bbd58d18 | ||
|
88771145ed | ||
|
064a710c12 | ||
|
4ebd5ed133 |
4
README.md
Normale Datei
4
README.md
Normale Datei
@ -0,0 +1,4 @@
|
||||
# SteamWarLinkManager
|
||||
|
||||
## Installing
|
||||
``java -jar SteamWarLinkManager.java install``
|
17
pom.xml
17
pom.xml
@ -6,12 +6,12 @@
|
||||
|
||||
<groupId>de.chaos</groupId>
|
||||
<artifactId>swlnmngr</artifactId>
|
||||
<version>0.1.2</version>
|
||||
<version>0.2.0</version>
|
||||
<name>SteamWarLinkManager</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
@ -67,12 +67,6 @@
|
||||
<artifactId>json</artifactId>
|
||||
<version>20211205</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.22</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
<artifactId>commons-cli</artifactId>
|
||||
@ -98,5 +92,10 @@
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -2,7 +2,6 @@ package de.chaos.swlnmngr;
|
||||
|
||||
import de.chaos.swlnmngr.config.CLIConfig;
|
||||
import de.chaos.swlnmngr.route.Router;
|
||||
import lombok.Getter;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@ -12,9 +11,7 @@ import java.util.Arrays;
|
||||
|
||||
public class Main {
|
||||
|
||||
@Getter
|
||||
private static final Logger logger = LogManager.getLogger(Main.class);
|
||||
@Getter
|
||||
private static String[] allArgs;
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -23,7 +20,7 @@ public class Main {
|
||||
if(CLIConfig.IS_DEBUG) {
|
||||
Configurator.setRootLevel(Level.DEBUG);
|
||||
}
|
||||
if(!CLIConfig.NO_UPDATE) {
|
||||
if(CLIConfig.NO_UPDATE) {
|
||||
UpdateChecker.checkForUpdates();
|
||||
}
|
||||
logger.debug("Arguments: {}", Arrays.toString(allArgs));
|
||||
@ -33,4 +30,12 @@ public class Main {
|
||||
Router.printRoutes();
|
||||
}
|
||||
}
|
||||
|
||||
public static Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public static String[] getAllArgs() {
|
||||
return allArgs;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package de.chaos.swlnmngr;
|
||||
|
||||
import de.chaos.swlnmngr.config.Config;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
@ -13,9 +12,10 @@ import org.json.JSONTokener;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
@UtilityClass
|
||||
public class UpdateChecker {
|
||||
|
||||
private UpdateChecker() {}
|
||||
|
||||
private static final URI repoUrl = URI.create("https://steamwar.de/devlabs/api/v1/repos/Chaoscaot/SteamwarLinkManager/releases?draft=false&pre-release=" + Config.PRE_RELEASES + "&page=1&limit=1");
|
||||
|
||||
public static final String CURRENT_VERSION;
|
||||
|
@ -4,6 +4,8 @@ import de.chaos.swlnmngr.Main;
|
||||
import org.apache.commons.cli.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public class CLIConfig {
|
||||
|
||||
@ -12,6 +14,7 @@ public class CLIConfig {
|
||||
public static final File CONFIG;
|
||||
public static final File INSTALL_DIR;
|
||||
public static final String[] ARGS;
|
||||
public static final boolean INSTALL_DIR_IS_SET;
|
||||
|
||||
static {
|
||||
Options options = new Options();
|
||||
@ -19,7 +22,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();
|
||||
@ -43,8 +46,21 @@ public class CLIConfig {
|
||||
NO_UPDATE = cli.hasOption("u");
|
||||
if(cli.hasOption("i")) {
|
||||
INSTALL_DIR = new File(cli.getOptionValue("i"));
|
||||
INSTALL_DIR_IS_SET = true;
|
||||
} else {
|
||||
INSTALL_DIR = new File(System.getProperty("user.home"), ".swlnmngr/").toPath().normalize().toFile();
|
||||
try {
|
||||
INSTALL_DIR = new File(CLIConfig.class.getProtectionDomain()
|
||||
.getCodeSource()
|
||||
.getLocation()
|
||||
.toURI()
|
||||
.getPath())
|
||||
.getCanonicalFile()
|
||||
.getParentFile();
|
||||
INSTALL_DIR_IS_SET = false;
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
Main.getLogger().error(e.getMessage(), e);
|
||||
throw new SecurityException(e);
|
||||
}
|
||||
}
|
||||
if(cli.hasOption("c")) {
|
||||
CONFIG = new File(cli.getOptionValue("c"));
|
||||
|
@ -9,6 +9,7 @@ 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.StandardCopyOption;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
@ -16,7 +17,7 @@ import java.util.Objects;
|
||||
|
||||
public class InstallRoute implements Route {
|
||||
|
||||
private static final String[] defaultFiles = new String[] {"default_swlnmngr.bat", "default_swlnmngr.sh"};
|
||||
private static final String[] defaultFiles = new String[] {"default_swlnmngr.bat", "default_swlnmngr.sh", "default_swlnmngr_admin.bat"};
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
@ -26,9 +27,12 @@ public class InstallRoute implements Route {
|
||||
@Override
|
||||
public boolean route(String[] args) {
|
||||
File installDir = CLIConfig.INSTALL_DIR;
|
||||
if (!CLIConfig.INSTALL_DIR_IS_SET) {
|
||||
installDir = new File(System.getProperty("user.home", ".swlnmngr"));
|
||||
}
|
||||
if(!installDir.exists()) {
|
||||
try {
|
||||
Files.createDirectories(CLIConfig.INSTALL_DIR.toPath());
|
||||
Files.createDirectories(installDir.toPath());
|
||||
} catch (IOException e) {
|
||||
Main.getLogger().error("Could not create Install Directory", e);
|
||||
return false;
|
||||
@ -38,8 +42,8 @@ public class InstallRoute implements Route {
|
||||
for (String defaultFile : defaultFiles) {
|
||||
String normalName = defaultFile.replace("default_", "");
|
||||
try {
|
||||
Files.copy(Objects.requireNonNull(InstallRoute.class.getResourceAsStream("/" + defaultFile)), new File(CLIConfig.INSTALL_DIR, normalName).toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
new File(CLIConfig.INSTALL_DIR, normalName).setExecutable(true, true);
|
||||
Files.copy(Objects.requireNonNull(InstallRoute.class.getResourceAsStream("/" + defaultFile)), new File(installDir, normalName).toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
new File(installDir, normalName).setExecutable(true, true);
|
||||
} catch (IOException e) {
|
||||
Main.getLogger().error("Could not create File", e);
|
||||
return false;
|
||||
@ -48,18 +52,34 @@ public class InstallRoute implements Route {
|
||||
|
||||
if(SystemUtils.IS_OS_UNIX) {
|
||||
try {
|
||||
Files.deleteIfExists(new File(CLIConfig.INSTALL_DIR, "swlnmngr").toPath());
|
||||
Files.createSymbolicLink(new File(CLIConfig.INSTALL_DIR, "swlnmngr").toPath(), new File(CLIConfig.INSTALL_DIR, "swlnmngr.sh").toPath());
|
||||
Files.deleteIfExists(new File(installDir, "swlnmngr").toPath());
|
||||
Files.createSymbolicLink(new File(installDir, "swlnmngr").toPath(), new File(installDir, "swlnmngr.sh").toPath());
|
||||
} catch (IOException e) {
|
||||
Main.getLogger().error("Could not create SymLink", e);
|
||||
return false;
|
||||
}
|
||||
} else if(SystemUtils.IS_OS_WINDOWS) {
|
||||
try {
|
||||
Files.writeString(new File(installDir, "swlnmngr.bat").toPath(), Files.readString(new File(installDir, "swlnmngr.bat").toPath()).replace("${iDir}", installDir.getAbsolutePath()), StandardCharsets.UTF_8, StandardOpenOption.TRUNCATE_EXISTING);
|
||||
Files.writeString(new File(installDir, "swlnmngr_admin.bat").toPath(), Files.readString(new File(installDir, "swlnmngr_admin.bat").toPath()).replace("${iDir}", installDir.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;
|
||||
@ -86,7 +106,7 @@ public class InstallRoute implements Route {
|
||||
try {
|
||||
File jar = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI());
|
||||
Main.getLogger().debug(jar);
|
||||
Files.copy(jar.toPath(), new File(CLIConfig.INSTALL_DIR, "SteamWarLinkManager.jar").toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
Files.copy(jar.toPath(), new File(installDir, "SteamWarLinkManager.jar").toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
} catch (URISyntaxException e) {
|
||||
Main.getLogger().error("Could parse Jar Location", e);
|
||||
return false;
|
||||
|
@ -2,6 +2,7 @@ package de.chaos.swlnmngr.route.routes;
|
||||
|
||||
import de.chaos.swlnmngr.Main;
|
||||
import de.chaos.swlnmngr.config.Config;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -34,9 +35,15 @@ 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());
|
||||
if(link.exists()) {
|
||||
if(link.isDirectory()) {
|
||||
FileUtils.deleteDirectory(link);
|
||||
} else {
|
||||
FileUtils.delete(link);
|
||||
}
|
||||
}
|
||||
Main.getLogger().debug(libsFile);
|
||||
Main.getLogger().debug(link);
|
||||
Path linkPath = Files.createSymbolicLink(link.toPath(), libsFile.toPath());
|
||||
|
@ -1 +1,17 @@
|
||||
java -jar ./SteamWarLinkManager.jar %*
|
||||
@echo off
|
||||
:: Variables
|
||||
SET JavaHome=java
|
||||
SET Home=${iDir}
|
||||
|
||||
:: Code
|
||||
title Request Admin
|
||||
|
||||
Net session >nul 2>&1 || (PowerShell start -verb runas '%~0' & exit)
|
||||
|
||||
title SteamWarLinkManager
|
||||
set args=--help
|
||||
set /p args=Arguments:
|
||||
echo %args%
|
||||
%JavaHome% -jar ${iDir}\SteamWarLinkManager.jar %args% %* -i %Home%
|
||||
pause
|
||||
exit
|
@ -1,2 +1,3 @@
|
||||
#!/bin/bash
|
||||
java -jar ./SteamWarLinkManager.jar $@
|
||||
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
|
||||
java -jar $parent_path/SteamWarLinkManager.jar $@
|
5
src/main/resources/default_swlnmngr_admin.bat
Normale Datei
5
src/main/resources/default_swlnmngr_admin.bat
Normale Datei
@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
|
||||
title Admin
|
||||
runas /noprofile /savecred /user:Admin ${iDir}\swlnmngr.bat
|
||||
exit
|
In neuem Issue referenzieren
Einen Benutzer sperren