diff options
author | cflip <cflip@cflip.net> | 2023-08-24 19:31:05 -0600 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2023-08-24 19:31:05 -0600 |
commit | 1a1e124db2bd5e6d71ecb5fcaba4c26e576d70ea (patch) | |
tree | 635a211dfefdf8a36ec9ae2e41e957b625e8961d /src/net/minecraft/GameVersion.java | |
parent | 7b45cf43de3ff5e95b43107a338856901ccb7383 (diff) |
Get versions and jar URL from BetaCraft's version_list.txt
Diffstat (limited to 'src/net/minecraft/GameVersion.java')
-rw-r--r-- | src/net/minecraft/GameVersion.java | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/net/minecraft/GameVersion.java b/src/net/minecraft/GameVersion.java new file mode 100644 index 0000000..7698b5d --- /dev/null +++ b/src/net/minecraft/GameVersion.java @@ -0,0 +1,79 @@ +package net.minecraft; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Files; +import java.time.Instant; +import java.util.Scanner; + +public class GameVersion { + public String name; + public String desc; + public Instant compiledOn; + public Instant releasedOn; + + public URL gameJarUrl; + public String proxyArgs; + + private boolean infoDownloaded = false; + + public GameVersion(String name, String desc, long compileTimestamp, long releaseTimestamp) { + this.name = name; + this.desc = desc; + this.compiledOn = Instant.ofEpochMilli(compileTimestamp); + this.releasedOn = Instant.ofEpochMilli(releaseTimestamp); + } + + public void downloadInfo() throws IOException { + URL infoUrl = new URL("http://files.betacraft.uk/launcher/assets/jsons/" + name + ".info"); + Scanner scanner = new Scanner(infoUrl.openStream(), "UTF-8"); + while (scanner.hasNextLine()) { + String[] keyValueList = scanner.nextLine().split(":", 2); + + if (keyValueList.length < 2) + continue; + + String key = keyValueList[0]; + String value = keyValueList[1]; + + switch (key) { + case "url": + gameJarUrl = new URL(value); + break; + case "proxy-args": + proxyArgs = value; + break; + } + } + infoDownloaded = true; + } + + public boolean hasFullInfo() { + return infoDownloaded; + } + + public boolean isPreleaseOrDemo() { + boolean isDemo = name.contains("demo"); + boolean isPrerelease = name.contains("pre") || name.contains("test") || name.contains("w"); + boolean isClassic = name.startsWith("c"); + return isDemo || isPrerelease || isClassic; + } + + public boolean isSameVersion(File versionFile) throws IOException { + DataInputStream dis = new DataInputStream(Files.newInputStream(versionFile.toPath())); + String version = dis.readUTF(); + dis.close(); + + long versionTimestamp = Long.parseLong(version); + return releasedOn.getEpochSecond() == versionTimestamp; + } + + public void writeVersionFile(File file) throws IOException { + DataOutputStream dos = new DataOutputStream(Files.newOutputStream(file.toPath())); + dos.writeUTF(String.valueOf(releasedOn.getEpochSecond())); + dos.close(); + } +} |