Commits vergleichen
6 Commits
8098e2c339
...
5c2ffde227
Autor | SHA1 | Datum | |
---|---|---|---|
|
5c2ffde227 | ||
|
abafded876 | ||
|
634e931920 | ||
|
bb80ee110d | ||
|
8659bce671 | ||
|
bc1d50fb8e |
12
pom.xml
12
pom.xml
@ -118,12 +118,6 @@
|
|||||||
<artifactId>json</artifactId>
|
<artifactId>json</artifactId>
|
||||||
<version>20211205</version>
|
<version>20211205</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>1.18.22</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-cli</groupId>
|
<groupId>commons-cli</groupId>
|
||||||
<artifactId>commons-cli</artifactId>
|
<artifactId>commons-cli</artifactId>
|
||||||
@ -150,9 +144,9 @@
|
|||||||
<version>2.6</version>
|
<version>2.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.vatbub</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>mslinks</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<version>1.0.6.2</version>
|
<version>2.11.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
@ -2,7 +2,6 @@ package de.chaos.swlnmngr;
|
|||||||
|
|
||||||
import de.chaos.swlnmngr.config.CLIConfig;
|
import de.chaos.swlnmngr.config.CLIConfig;
|
||||||
import de.chaos.swlnmngr.route.Router;
|
import de.chaos.swlnmngr.route.Router;
|
||||||
import lombok.Getter;
|
|
||||||
import org.apache.logging.log4j.Level;
|
import org.apache.logging.log4j.Level;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@ -13,7 +12,6 @@ import java.util.Arrays;
|
|||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger(Main.class);
|
private static final Logger logger = LogManager.getLogger(Main.class);
|
||||||
@Getter
|
|
||||||
private static String[] allArgs;
|
private static String[] allArgs;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -36,4 +34,8 @@ public class Main {
|
|||||||
public static Logger getLogger() {
|
public static Logger getLogger() {
|
||||||
return logger;
|
return logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String[] getAllArgs() {
|
||||||
|
return allArgs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package de.chaos.swlnmngr
|
package de.chaos.swlnmngr
|
||||||
|
|
||||||
import de.chaos.swlnmngr.config.Config
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse
|
import org.apache.http.client.methods.CloseableHttpResponse
|
||||||
import org.apache.http.client.methods.HttpGet
|
import org.apache.http.client.methods.HttpGet
|
||||||
import org.apache.http.impl.client.CloseableHttpClient
|
import org.apache.http.impl.client.CloseableHttpClient
|
||||||
|
@ -4,6 +4,8 @@ import de.chaos.swlnmngr.Main;
|
|||||||
import org.apache.commons.cli.*;
|
import org.apache.commons.cli.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
public class CLIConfig {
|
public class CLIConfig {
|
||||||
|
|
||||||
@ -12,6 +14,7 @@ public class CLIConfig {
|
|||||||
public static final File CONFIG;
|
public static final File CONFIG;
|
||||||
public static final File INSTALL_DIR;
|
public static final File INSTALL_DIR;
|
||||||
public static final String[] ARGS;
|
public static final String[] ARGS;
|
||||||
|
public static final boolean INSTALL_DIR_IS_SET;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Options options = new Options();
|
Options options = new Options();
|
||||||
@ -43,8 +46,21 @@ public class CLIConfig {
|
|||||||
NO_UPDATE = cli.hasOption("u");
|
NO_UPDATE = cli.hasOption("u");
|
||||||
if(cli.hasOption("i")) {
|
if(cli.hasOption("i")) {
|
||||||
INSTALL_DIR = new File(cli.getOptionValue("i"));
|
INSTALL_DIR = new File(cli.getOptionValue("i"));
|
||||||
|
INSTALL_DIR_IS_SET = true;
|
||||||
} else {
|
} 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")) {
|
if(cli.hasOption("c")) {
|
||||||
CONFIG = new File(cli.getOptionValue("c"));
|
CONFIG = new File(cli.getOptionValue("c"));
|
||||||
|
@ -2,7 +2,6 @@ package de.chaos.swlnmngr.route.routes;
|
|||||||
|
|
||||||
import de.chaos.swlnmngr.Main;
|
import de.chaos.swlnmngr.Main;
|
||||||
import de.chaos.swlnmngr.config.CLIConfig;
|
import de.chaos.swlnmngr.config.CLIConfig;
|
||||||
import mslinks.ShellLink;
|
|
||||||
import org.apache.commons.lang.SystemUtils;
|
import org.apache.commons.lang.SystemUtils;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONTokener;
|
import org.json.JSONTokener;
|
||||||
@ -12,16 +11,13 @@ import java.io.IOException;
|
|||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.nio.file.attribute.FileAttribute;
|
|
||||||
import java.nio.file.attribute.PosixFilePermission;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class InstallRoute implements Route {
|
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
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@ -31,9 +27,12 @@ public class InstallRoute implements Route {
|
|||||||
@Override
|
@Override
|
||||||
public boolean route(String[] args) {
|
public boolean route(String[] args) {
|
||||||
File installDir = CLIConfig.INSTALL_DIR;
|
File installDir = CLIConfig.INSTALL_DIR;
|
||||||
|
if (!CLIConfig.INSTALL_DIR_IS_SET) {
|
||||||
|
installDir = new File(System.getProperty("user.home", ".swlnmngr"));
|
||||||
|
}
|
||||||
if(!installDir.exists()) {
|
if(!installDir.exists()) {
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(CLIConfig.INSTALL_DIR.toPath());
|
Files.createDirectories(installDir.toPath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Main.getLogger().error("Could not create Install Directory", e);
|
Main.getLogger().error("Could not create Install Directory", e);
|
||||||
return false;
|
return false;
|
||||||
@ -43,8 +42,8 @@ public class InstallRoute implements Route {
|
|||||||
for (String defaultFile : defaultFiles) {
|
for (String defaultFile : defaultFiles) {
|
||||||
String normalName = defaultFile.replace("default_", "");
|
String normalName = defaultFile.replace("default_", "");
|
||||||
try {
|
try {
|
||||||
Files.copy(Objects.requireNonNull(InstallRoute.class.getResourceAsStream("/" + defaultFile)), new File(CLIConfig.INSTALL_DIR, normalName).toPath(), StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(Objects.requireNonNull(InstallRoute.class.getResourceAsStream("/" + defaultFile)), new File(installDir, normalName).toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
new File(CLIConfig.INSTALL_DIR, normalName).setExecutable(true, true);
|
new File(installDir, normalName).setExecutable(true, true);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Main.getLogger().error("Could not create File", e);
|
Main.getLogger().error("Could not create File", e);
|
||||||
return false;
|
return false;
|
||||||
@ -53,18 +52,16 @@ public class InstallRoute implements Route {
|
|||||||
|
|
||||||
if(SystemUtils.IS_OS_UNIX) {
|
if(SystemUtils.IS_OS_UNIX) {
|
||||||
try {
|
try {
|
||||||
Files.deleteIfExists(new File(CLIConfig.INSTALL_DIR, "swlnmngr").toPath());
|
Files.deleteIfExists(new File(installDir, "swlnmngr").toPath());
|
||||||
Files.createSymbolicLink(new File(CLIConfig.INSTALL_DIR, "swlnmngr").toPath(), new File(CLIConfig.INSTALL_DIR, "swlnmngr.sh").toPath());
|
Files.createSymbolicLink(new File(installDir, "swlnmngr").toPath(), new File(installDir, "swlnmngr.sh").toPath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Main.getLogger().error("Could not create SymLink", e);
|
Main.getLogger().error("Could not create SymLink", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if(SystemUtils.IS_OS_WINDOWS) {
|
} else if(SystemUtils.IS_OS_WINDOWS) {
|
||||||
try {
|
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());
|
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);
|
||||||
link.getHeader().getLinkFlags().setRunAsUser();
|
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);
|
||||||
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) {
|
} catch (IOException e) {
|
||||||
Main.getLogger().error("Could not create Link", e);
|
Main.getLogger().error("Could not create Link", e);
|
||||||
return false;
|
return false;
|
||||||
@ -109,7 +106,7 @@ public class InstallRoute implements Route {
|
|||||||
try {
|
try {
|
||||||
File jar = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI());
|
File jar = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI());
|
||||||
Main.getLogger().debug(jar);
|
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) {
|
} catch (URISyntaxException e) {
|
||||||
Main.getLogger().error("Could parse Jar Location", e);
|
Main.getLogger().error("Could parse Jar Location", e);
|
||||||
return false;
|
return false;
|
||||||
|
@ -2,6 +2,7 @@ package de.chaos.swlnmngr.route.routes;
|
|||||||
|
|
||||||
import de.chaos.swlnmngr.Main;
|
import de.chaos.swlnmngr.Main;
|
||||||
import de.chaos.swlnmngr.config.Config;
|
import de.chaos.swlnmngr.config.Config;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -36,7 +37,13 @@ public class LinkRoute implements Route {
|
|||||||
}
|
}
|
||||||
File link = new File(projectDir, "lib");
|
File link = new File(projectDir, "lib");
|
||||||
try {
|
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(libsFile);
|
||||||
Main.getLogger().debug(link);
|
Main.getLogger().debug(link);
|
||||||
Path linkPath = Files.createSymbolicLink(link.toPath(), libsFile.toPath());
|
Path linkPath = Files.createSymbolicLink(link.toPath(), libsFile.toPath());
|
||||||
|
@ -1,5 +1,17 @@
|
|||||||
|
@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 args=--help
|
||||||
set /p args=Arguments:
|
set /p args=Arguments:
|
||||||
echo %args%
|
echo %args%
|
||||||
java -jar ${iDir}\SteamWarLinkManager.jar %args% %*
|
%JavaHome% -jar ${iDir}\SteamWarLinkManager.jar %args% %* -i %Home%
|
||||||
pause
|
pause
|
||||||
|
exit
|
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