From 058b3ea789876fbaaf86736d7178f57a60c6690b Mon Sep 17 00:00:00 2001 From: andreika-git Date: Wed, 21 Aug 2024 20:21:06 +0300 Subject: [PATCH] Implement https://github.com/rusefi/rusefi/issues/6838 --- .../rusefi/core/net/ConnectionAndMeta.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/java_console/shared_io/src/main/java/com/rusefi/core/net/ConnectionAndMeta.java b/java_console/shared_io/src/main/java/com/rusefi/core/net/ConnectionAndMeta.java index c601a566cb..bbd8d9bf0f 100644 --- a/java_console/shared_io/src/main/java/com/rusefi/core/net/ConnectionAndMeta.java +++ b/java_console/shared_io/src/main/java/com/rusefi/core/net/ConnectionAndMeta.java @@ -6,14 +6,17 @@ import javax.net.ssl.*; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; +import java.security.CodeSource; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.cert.X509Certificate; +import java.util.logging.Logger; import java.util.Objects; import java.util.Optional; import java.util.Properties; + public class ConnectionAndMeta { public static final String BASE_URL_RELEASE = "https://github.com/rusefi/rusefi/releases/latest/download/"; public static final String DEFAULT_WHITE_LABEL = "rusefi"; @@ -27,6 +30,9 @@ public class ConnectionAndMeta { private long completeFileSize; private long lastModified; + + private static Logger logger = Logger.getLogger(ConnectionAndMeta.class.getName()); + public ConnectionAndMeta(String zipFileName) { this.zipFileName = zipFileName; } @@ -37,12 +43,32 @@ public class ConnectionAndMeta { return result; } + public static String getWhiteLabelFromJarName() { + try { + CodeSource codeSource = ConnectionAndMeta.class.getProtectionDomain().getCodeSource(); + if (codeSource != null) { + URL jarUrl = codeSource.getLocation(); + String jarPath = jarUrl.getPath(); + String jarFileName = jarPath.substring(jarPath.lastIndexOf('/') + 1); + int startOfSuffix = jarFileName.lastIndexOf('_'); + if (startOfSuffix > 0) { + String whiteLabel = jarFileName.substring(0, startOfSuffix); + logger.info("WhiteLabel = " + whiteLabel); + return whiteLabel; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return DEFAULT_WHITE_LABEL; + } + public static String getWhiteLabel(Properties properties) { - return getStringProperty(properties, "white_label", DEFAULT_WHITE_LABEL); + return getStringProperty(properties, "white_label", getWhiteLabelFromJarName()); } public static String getRusEfiConsoleJarName() { - return getStringProperty(getProperties(), "console_jar", "rusefi_console.jar"); + return getStringProperty(getProperties(), "console_jar", getWhiteLabel(getProperties()) + "_console.jar"); } private static @NotNull String getStringProperty(Properties properties, String key, String defaultValue) {