Fix version reading - fallback to JAR manifest, fix server version URL

This commit is contained in:
SashegDev
2026-05-08 14:51:53 +00:00
parent d8f189558a
commit 659265c2f0
@@ -9,6 +9,9 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
public class Bootstrap {
private static final String JAR_NAME = "zernmclauncher.jar";
@@ -79,14 +82,31 @@ public class Bootstrap {
if (!v.isBlank()) return v;
} catch (Exception ignored) {}
}
// Fallback: читаем из манифеста JAR
Path jar = getLauncherJar();
if (Files.exists(jar)) {
try (JarFile jarFile = new JarFile(jar.toFile())) {
Manifest manifest = jarFile.getManifest();
if (manifest != null) {
String v = manifest.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION);
if (v != null && !v.isBlank()) return v;
}
} catch (Exception e) {
log("Ошибка чтения манифеста: " + e.getMessage());
}
}
return "0.0.0";
}
private static String getServerVersion() {
try {
URL url = new URL(BASE_URL.replace("download?type=jar", "version"));
URL url = new URL(BASE_URL + "/launcher/version");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
if (conn.getResponseCode() == 200) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
String line = br.readLine();
@@ -95,7 +115,9 @@ public class Bootstrap {
}
}
}
} catch (Exception ignored) {}
} catch (Exception e) {
log("Ошибка получения версии: " + e.getMessage());
}
return "unknown";
}