2018-09-17 10:07:32 +03:00
|
|
|
package ru.gravit.launchserver.binary;
|
|
|
|
|
|
|
|
import net.sf.launch4j.Builder;
|
|
|
|
import net.sf.launch4j.Log;
|
2019-01-15 06:35:39 +03:00
|
|
|
import net.sf.launch4j.config.*;
|
2018-12-06 05:29:34 +03:00
|
|
|
import ru.gravit.launchserver.LaunchServer;
|
2019-05-03 17:06:22 +03:00
|
|
|
import ru.gravit.utils.Version;
|
2018-12-06 05:29:34 +03:00
|
|
|
import ru.gravit.utils.helper.IOHelper;
|
|
|
|
import ru.gravit.utils.helper.LogHelper;
|
2018-09-17 10:07:32 +03:00
|
|
|
|
2019-01-15 06:35:39 +03:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
public final class EXEL4JLauncherBinary extends LauncherBinary {
|
2018-09-22 17:33:00 +03:00
|
|
|
private final static class Launch4JLog extends Log {
|
|
|
|
private static final Launch4JLog INSTANCE = new Launch4JLog();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void append(String s) {
|
|
|
|
LogHelper.subInfo(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clear() {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// URL constants
|
|
|
|
private static final String DOWNLOAD_URL = "http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html"; // Oracle
|
2018-12-06 05:29:34 +03:00
|
|
|
// JRE 8
|
2018-09-22 17:33:00 +03:00
|
|
|
|
|
|
|
// File constants
|
|
|
|
private final Path faviconFile;
|
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-22 17:33:00 +03:00
|
|
|
public EXEL4JLauncherBinary(LaunchServer server) {
|
2019-04-28 15:06:12 +03:00
|
|
|
super(server, LauncherBinary.resolve(server, ".exe"));
|
2018-09-22 17:33:00 +03:00
|
|
|
faviconFile = server.dir.resolve("favicon.ico");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void build() throws IOException {
|
|
|
|
LogHelper.info("Building launcher EXE binary file (Using Launch4J)");
|
2019-01-05 18:15:19 +03:00
|
|
|
setConfig();
|
2018-09-22 17:33:00 +03:00
|
|
|
|
|
|
|
// Set favicon path
|
|
|
|
Config config = ConfigPersister.getInstance().getConfig();
|
|
|
|
if (IOHelper.isFile(faviconFile))
|
|
|
|
config.setIcon(faviconFile.toFile());
|
|
|
|
else {
|
|
|
|
config.setIcon(null);
|
|
|
|
LogHelper.warning("Missing favicon.ico file");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start building
|
|
|
|
Builder builder = new Builder(Launch4JLog.INSTANCE);
|
|
|
|
try {
|
|
|
|
builder.build();
|
|
|
|
} catch (Throwable e) {
|
|
|
|
throw new IOException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setConfig() {
|
|
|
|
Config config = new Config();
|
2018-12-27 10:09:13 +03:00
|
|
|
// Set file options
|
2018-09-22 17:33:00 +03:00
|
|
|
config.setChdir(".");
|
|
|
|
config.setErrTitle("JVM Error");
|
|
|
|
config.setDownloadUrl(DOWNLOAD_URL);
|
|
|
|
|
|
|
|
// Set boolean options
|
|
|
|
config.setPriorityIndex(0);
|
|
|
|
config.setHeaderType(Config.GUI_HEADER);
|
|
|
|
config.setStayAlive(false);
|
|
|
|
config.setRestartOnCrash(false);
|
|
|
|
|
|
|
|
// Prepare JRE
|
|
|
|
Jre jre = new Jre();
|
|
|
|
jre.setMinVersion("1.8.0");
|
2019-05-31 01:40:19 +03:00
|
|
|
if (server.config.launch4j.setMaxVersion)
|
2019-05-26 05:57:22 +03:00
|
|
|
jre.setMaxVersion(server.config.launch4j.maxVersion);
|
2018-09-22 17:33:00 +03:00
|
|
|
jre.setRuntimeBits(Jre.RUNTIME_BITS_64_AND_32);
|
|
|
|
jre.setJdkPreference(Jre.JDK_PREFERENCE_PREFER_JRE);
|
|
|
|
config.setJre(jre);
|
|
|
|
|
|
|
|
// Prepare version info (product)
|
|
|
|
VersionInfo info = new VersionInfo();
|
|
|
|
info.setProductName(server.config.launch4j.productName);
|
|
|
|
info.setProductVersion(formatVars(server.config.launch4j.productVer));
|
|
|
|
info.setFileDescription(server.config.launch4j.fileDesc);
|
|
|
|
info.setFileVersion(formatVars(server.config.launch4j.fileVer));
|
|
|
|
info.setCopyright(server.config.launch4j.copyright);
|
|
|
|
info.setTrademarks(server.config.launch4j.trademarks);
|
|
|
|
info.setInternalName(formatVars(server.config.launch4j.internalName));
|
|
|
|
// Prepare version info (file)
|
|
|
|
info.setTxtFileVersion(formatVars(server.config.launch4j.txtFileVersion));
|
|
|
|
info.setTxtProductVersion(formatVars(server.config.launch4j.txtProductVersion));
|
|
|
|
// Prepare version info (misc)
|
2019-01-05 18:15:19 +03:00
|
|
|
info.setOriginalFilename(syncBinaryFile.getFileName().toString());
|
2018-09-22 17:33:00 +03:00
|
|
|
info.setLanguage(LanguageID.RUSSIAN);
|
|
|
|
config.setVersionInfo(info);
|
|
|
|
|
|
|
|
// Set JAR wrapping options
|
|
|
|
config.setDontWrapJar(false);
|
|
|
|
config.setJar(server.launcherBinary.syncBinaryFile.toFile());
|
2019-01-05 18:15:19 +03:00
|
|
|
config.setOutfile(syncBinaryFile.toFile());
|
2018-09-22 17:33:00 +03:00
|
|
|
|
|
|
|
// Return prepared config
|
|
|
|
ConfigPersister.getInstance().setAntConfig(config, null);
|
|
|
|
}
|
|
|
|
|
2019-05-03 17:06:22 +03:00
|
|
|
private static String VERSION = Version.getVersion().getVersionString();
|
|
|
|
private static int BUILD = Version.getVersion().build;
|
2018-09-22 17:33:00 +03:00
|
|
|
|
|
|
|
public static String formatVars(String mask) {
|
|
|
|
return String.format(mask, VERSION, BUILD);
|
|
|
|
}
|
2018-09-17 10:07:32 +03:00
|
|
|
}
|