2019-06-02 05:03:08 +03:00
|
|
|
package pro.gravit.launchserver.binary;
|
2018-09-17 10:07:32 +03:00
|
|
|
|
2019-06-02 05:03:08 +03:00
|
|
|
import pro.gravit.launchserver.LaunchServer;
|
|
|
|
import pro.gravit.utils.helper.IOHelper;
|
|
|
|
import pro.gravit.utils.helper.SecurityHelper;
|
2018-09-17 10:07:32 +03:00
|
|
|
|
2019-10-19 19:46:04 +03:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
2019-10-27 19:51:48 +03:00
|
|
|
public abstract class LauncherBinary extends BinaryPipeline {
|
2018-12-06 05:29:34 +03:00
|
|
|
public final LaunchServer server;
|
2019-04-28 15:06:12 +03:00
|
|
|
public final Path syncBinaryFile;
|
2019-07-12 02:10:31 +03:00
|
|
|
private volatile byte[] digest;
|
2018-09-17 10:07:32 +03:00
|
|
|
|
2019-10-27 19:51:48 +03:00
|
|
|
protected LauncherBinary(LaunchServer server, Path binaryFile, String nameFormat) {
|
2021-04-13 14:23:39 +03:00
|
|
|
super(server.tmpDir.resolve("build"), nameFormat);
|
2018-09-17 10:07:32 +03:00
|
|
|
this.server = server;
|
|
|
|
syncBinaryFile = binaryFile;
|
|
|
|
}
|
2018-09-22 17:33:00 +03:00
|
|
|
|
2020-04-05 10:27:04 +03:00
|
|
|
public static Path resolve(LaunchServer server, String ext) {
|
|
|
|
return server.config.copyBinaries ? server.updatesDir.resolve(server.config.binaryName + ext) : server.dir.resolve(server.config.binaryName + ext);
|
2019-10-27 19:51:48 +03:00
|
|
|
}
|
2018-09-17 10:07:32 +03:00
|
|
|
|
2020-04-05 10:27:04 +03:00
|
|
|
public void build() throws IOException {
|
|
|
|
build(syncBinaryFile, server.config.launcher.deleteTempFiles);
|
|
|
|
}
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
public final boolean exists() {
|
2019-01-05 18:15:19 +03:00
|
|
|
return syncBinaryFile != null && IOHelper.isFile(syncBinaryFile);
|
2018-09-17 10:07:32 +03:00
|
|
|
}
|
|
|
|
|
2019-07-12 02:10:31 +03:00
|
|
|
public final byte[] getDigest() {
|
|
|
|
return digest;
|
2018-09-17 10:07:32 +03:00
|
|
|
}
|
2018-11-08 15:30:16 +03:00
|
|
|
|
2019-01-08 16:57:01 +03:00
|
|
|
public void init() {
|
|
|
|
}
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
public final boolean sync() throws IOException {
|
|
|
|
boolean exists = exists();
|
2019-07-12 02:10:31 +03:00
|
|
|
digest = exists ? SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA512, IOHelper.read(syncBinaryFile)) : null;
|
2019-06-11 12:14:08 +03:00
|
|
|
|
|
|
|
return exists;
|
2018-09-17 10:07:32 +03:00
|
|
|
}
|
|
|
|
}
|