-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
103 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
Launcher/src/main/java/pro/gravit/launcher/utils/LauncherUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package pro.gravit.launcher.utils; | ||
|
||
import pro.gravit.launcher.Launcher; | ||
import pro.gravit.launcher.LauncherEngine; | ||
import pro.gravit.launcher.events.request.LauncherRequestEvent; | ||
import pro.gravit.launcher.request.update.LauncherRequest; | ||
import pro.gravit.utils.helper.IOHelper; | ||
import pro.gravit.utils.helper.LogHelper; | ||
import pro.gravit.utils.helper.SecurityHelper; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardOpenOption; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class LauncherUpdater { | ||
public static void nothing() { | ||
|
||
} | ||
private static Path getLauncherPath() { | ||
Path pathToCore = IOHelper.getCodeSource(IOHelper.class); | ||
Path pathToApi = IOHelper.getCodeSource(LauncherRequest.class); | ||
Path pathToSelf = IOHelper.getCodeSource(LauncherUpdater.class); | ||
if(pathToCore.equals(pathToApi) && pathToCore.equals(pathToSelf)) { | ||
return pathToCore; | ||
} else { | ||
throw new SecurityException("Found split-jar launcher"); | ||
} | ||
} | ||
|
||
public static Path prepareUpdate(URL url) throws Exception { | ||
Path pathToLauncher = getLauncherPath(); | ||
Path tempFile = Files.createTempFile("launcher-update-", ".jar"); | ||
URLConnection connection = url.openConnection(); | ||
try (InputStream in = connection.getInputStream()) { | ||
IOHelper.transfer(in, tempFile); | ||
} | ||
if (Arrays.equals(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.MD5, tempFile), | ||
SecurityHelper.digest(SecurityHelper.DigestAlgorithm.MD5, pathToLauncher))) | ||
throw new IOException("Invalid update (launcher needs update, but link has old launcher), check LaunchServer config..."); | ||
return tempFile; | ||
} | ||
|
||
public static void restart() { | ||
List<String> args = new ArrayList<>(8); | ||
args.add(IOHelper.resolveJavaBin(null).toString()); | ||
args.add("-jar"); | ||
args.add(IOHelper.getCodeSource(LauncherUpdater.class).toString()); | ||
ProcessBuilder builder = new ProcessBuilder(args.toArray(new String[0])); | ||
builder.inheritIO(); | ||
try { | ||
builder.start(); | ||
} catch (IOException e) { | ||
LogHelper.error(e); | ||
} | ||
LauncherEngine.forceExit(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
И всё что содержит 0?