From d14564f54e6b14a9e7c643fc8863b11e2f1e3f24 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 22 Sep 2018 21:01:38 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=82=20formatVars?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launchserver/LaunchServer.java | 5 +++-- .../binary/EXEL4JLauncherBinary.java | 17 ++++++++++++----- .../ru/gravit/launchserver/defaults/config.cfg | 4 ++-- .../ru/gravit/utils/helper/CommonHelper.java | 9 --------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 712cea14..9e163d16 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -30,6 +30,7 @@ import java.util.zip.CRC32; import ru.gravit.launcher.LauncherAPI; +import ru.gravit.launcher.LauncherVersion; import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; @@ -195,9 +196,9 @@ private ExeConf(BlockConfigEntry block) { trademarks = block.hasEntry("trademarks") ? block.getEntryValue("trademarks", StringConfigEntry.class) : "This product is licensed under MIT License"; txtFileVersion = block.hasEntry("txtFileVersion") ? block.getEntryValue("txtFileVersion", StringConfigEntry.class) - : CommonHelper.formatVars("$VERSION$, build $BUILDNUMBER$"); + : String.format("%s, build %d", LauncherVersion.getVersion().getVersionString(),LauncherVersion.getVersion().build); txtProductVersion = block.hasEntry("txtProductVersion") ? block.getEntryValue("txtProductVersion", StringConfigEntry.class) - : CommonHelper.formatVars("$VERSION$, build $BUILDNUMBER$"); + : String.format("%s, build %d", LauncherVersion.getVersion().getVersionString(),LauncherVersion.getVersion().build); } } private final class ProfilesFileVisitor extends SimpleFileVisitor { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java index ca95a8df..b9fc4498 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/EXEL4JLauncherBinary.java @@ -4,6 +4,7 @@ import java.nio.file.Path; import ru.gravit.launcher.LauncherAPI; +import ru.gravit.launcher.LauncherVersion; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; @@ -91,15 +92,15 @@ private void setConfig() { // Prepare version info (product) VersionInfo info = new VersionInfo(); info.setProductName(server.config.launch4j.productName); - info.setProductVersion(CommonHelper.formatVars(server.config.launch4j.productVer)); + info.setProductVersion(formatVars(server.config.launch4j.productVer)); info.setFileDescription(server.config.launch4j.fileDesc); - info.setFileVersion(CommonHelper.formatVars(server.config.launch4j.fileVer)); + info.setFileVersion(formatVars(server.config.launch4j.fileVer)); info.setCopyright(server.config.launch4j.copyright); info.setTrademarks(server.config.launch4j.trademarks); - info.setInternalName(CommonHelper.formatVars(server.config.launch4j.internalName)); + info.setInternalName(formatVars(server.config.launch4j.internalName)); // Prepare version info (file) - info.setTxtFileVersion(CommonHelper.formatVars(server.config.launch4j.txtFileVersion)); - info.setTxtProductVersion(CommonHelper.formatVars(server.config.launch4j.txtProductVersion)); + info.setTxtFileVersion(formatVars(server.config.launch4j.txtFileVersion)); + info.setTxtProductVersion(formatVars(server.config.launch4j.txtProductVersion)); // Prepare version info (misc) info.setOriginalFilename(binaryFile.getFileName().toString()); info.setLanguage(LanguageID.RUSSIAN); @@ -113,4 +114,10 @@ private void setConfig() { // Return prepared config ConfigPersister.getInstance().setAntConfig(config, null); } + private static String VERSION = LauncherVersion.getVersion().getVersionString(); + private static int BUILD = LauncherVersion.getVersion().build; + public static String formatVars(String mask) + { + return String.format(mask, VERSION, BUILD); + } } diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg index fd830096..788f827c 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg @@ -63,8 +63,8 @@ launch4J: { copyright: "© sashok724 LLC"; trademarks: "This product is licensed under MIT License"; # version and build number - txtFileVersion: "%VERSION%, build %BUILDNUMBER%"; - txtProductVersion: "%VERSION%, build %BUILDNUMBER%"; + txtFileVersion: "%s, build %d"; + txtProductVersion: "%s, build %d"; }; # Compress files when updating using Inflate algorithm diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/CommonHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/CommonHelper.java index b6e2f888..c924fd71 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/CommonHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/CommonHelper.java @@ -12,20 +12,11 @@ import ru.gravit.launcher.LauncherVersion; public final class CommonHelper { - @LauncherAPI - public static final String VERSIONREPLACE = "VERSION"; - @LauncherAPI - public static final String BUILDREPLACE = "BUILDNUMBER"; @LauncherAPI public static final ScriptEngineManager scriptManager = new ScriptEngineManager(); @LauncherAPI public static final ScriptEngineFactory nashornFactory = getEngineFactories(scriptManager); - @LauncherAPI - public static String formatVars(String in) { - return replace(in, VERSIONREPLACE , LauncherVersion.getVersion().getVersionString(), BUILDREPLACE, Integer.toString(LauncherVersion.BUILD)); - } - private static ScriptEngineFactory getEngineFactories(ScriptEngineManager manager) { // Метод похож на костыль но таковым не является, ибо единоразовое получение фактории быстрее, чем её переполучение на ходу. for (ScriptEngineFactory fact : manager.getEngineFactories())