Избавление от formatVars

This commit is contained in:
Gravit 2018-09-22 21:01:38 +07:00
parent f8853ff353
commit d14564f54e
4 changed files with 17 additions and 18 deletions

View file

@ -30,6 +30,7 @@
import java.util.zip.CRC32; import java.util.zip.CRC32;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherVersion;
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
@ -195,9 +196,9 @@ private ExeConf(BlockConfigEntry block) {
trademarks = block.hasEntry("trademarks") ? block.getEntryValue("trademarks", StringConfigEntry.class) trademarks = block.hasEntry("trademarks") ? block.getEntryValue("trademarks", StringConfigEntry.class)
: "This product is licensed under MIT License"; : "This product is licensed under MIT License";
txtFileVersion = block.hasEntry("txtFileVersion") ? block.getEntryValue("txtFileVersion", StringConfigEntry.class) 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) 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<Path> { private final class ProfilesFileVisitor extends SimpleFileVisitor<Path> {

View file

@ -4,6 +4,7 @@
import java.nio.file.Path; import java.nio.file.Path;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherVersion;
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
@ -91,15 +92,15 @@ private void setConfig() {
// Prepare version info (product) // Prepare version info (product)
VersionInfo info = new VersionInfo(); VersionInfo info = new VersionInfo();
info.setProductName(server.config.launch4j.productName); 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.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.setCopyright(server.config.launch4j.copyright);
info.setTrademarks(server.config.launch4j.trademarks); 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) // Prepare version info (file)
info.setTxtFileVersion(CommonHelper.formatVars(server.config.launch4j.txtFileVersion)); info.setTxtFileVersion(formatVars(server.config.launch4j.txtFileVersion));
info.setTxtProductVersion(CommonHelper.formatVars(server.config.launch4j.txtProductVersion)); info.setTxtProductVersion(formatVars(server.config.launch4j.txtProductVersion));
// Prepare version info (misc) // Prepare version info (misc)
info.setOriginalFilename(binaryFile.getFileName().toString()); info.setOriginalFilename(binaryFile.getFileName().toString());
info.setLanguage(LanguageID.RUSSIAN); info.setLanguage(LanguageID.RUSSIAN);
@ -113,4 +114,10 @@ private void setConfig() {
// Return prepared config // Return prepared config
ConfigPersister.getInstance().setAntConfig(config, null); 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);
}
} }

View file

@ -63,8 +63,8 @@ launch4J: {
copyright: "© sashok724 LLC"; copyright: "© sashok724 LLC";
trademarks: "This product is licensed under MIT License"; trademarks: "This product is licensed under MIT License";
# version and build number # version and build number
txtFileVersion: "%VERSION%, build %BUILDNUMBER%"; txtFileVersion: "%s, build %d";
txtProductVersion: "%VERSION%, build %BUILDNUMBER%"; txtProductVersion: "%s, build %d";
}; };
# Compress files when updating using Inflate algorithm # Compress files when updating using Inflate algorithm

View file

@ -12,20 +12,11 @@
import ru.gravit.launcher.LauncherVersion; import ru.gravit.launcher.LauncherVersion;
public final class CommonHelper { public final class CommonHelper {
@LauncherAPI
public static final String VERSIONREPLACE = "VERSION";
@LauncherAPI
public static final String BUILDREPLACE = "BUILDNUMBER";
@LauncherAPI @LauncherAPI
public static final ScriptEngineManager scriptManager = new ScriptEngineManager(); public static final ScriptEngineManager scriptManager = new ScriptEngineManager();
@LauncherAPI @LauncherAPI
public static final ScriptEngineFactory nashornFactory = getEngineFactories(scriptManager); 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) { private static ScriptEngineFactory getEngineFactories(ScriptEngineManager manager) {
// Метод похож на костыль но таковым не является, ибо единоразовое получение фактории быстрее, чем её переполучение на ходу. // Метод похож на костыль но таковым не является, ибо единоразовое получение фактории быстрее, чем её переполучение на ходу.
for (ScriptEngineFactory fact : manager.getEngineFactories()) for (ScriptEngineFactory fact : manager.getEngineFactories())