1
0

Add saveAdmin Script

Dieser Commit ist enthalten in:
Chaos 2022-01-11 20:56:07 +01:00
Ursprung f41673e69a
Commit bc1d50fb8e
4 geänderte Dateien mit 21 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -98,10 +98,5 @@
<artifactId>commons-lang</artifactId> <artifactId>commons-lang</artifactId>
<version>2.6</version> <version>2.6</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.vatbub</groupId>
<artifactId>mslinks</artifactId>
<version>1.0.6.2</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

Datei anzeigen

@ -2,26 +2,23 @@ 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;
import java.io.File; import java.io.File;
import java.io.FileWriter;
import java.io.IOException; 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() {
@ -61,10 +58,8 @@ public class InstallRoute implements Route {
} }
} 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());
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); 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);
Files.writeString(new File(CLIConfig.INSTALL_DIR, "swlnmngr_admin.bat").toPath(), Files.readString(new File(CLIConfig.INSTALL_DIR, "swlnmngr_admin.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;

Datei anzeigen

@ -1,5 +1,16 @@
@echo off
:: Variables
SET JavaHome=java
:: 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% %*
pause pause
exit

Datei anzeigen

@ -0,0 +1,5 @@
@echo off
title Admin
runas /noprofile /savecred /user:Admin ${iDir}\swlnmngr.bat
exit