-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevTerminalLauncherJar.java
More file actions
47 lines (41 loc) · 1.64 KB
/
Copy pathDevTerminalLauncherJar.java
File metadata and controls
47 lines (41 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import javax.swing.JOptionPane;
public final class DevTerminalLauncherJar {
private static final String EXE_RESOURCE = "/DevTerminalLauncher.exe";
private DevTerminalLauncherJar() {
}
public static void main(String[] args) {
try {
Path executable = extractExecutable();
Process process = new ProcessBuilder(executable.toString()).start();
process.waitFor();
deleteExtractedExecutable(executable);
} catch (Exception exception) {
showError(exception);
}
}
private static Path extractExecutable() throws IOException {
try (InputStream input = DevTerminalLauncherJar.class.getResourceAsStream(EXE_RESOURCE)) {
if (input == null) {
throw new IOException("Bundled executable was not found in the JAR.");
}
Path executable = Files.createTempFile("DevTerminalLauncher-", ".exe");
Files.copy(input, executable, StandardCopyOption.REPLACE_EXISTING);
return executable;
}
}
private static void deleteExtractedExecutable(Path executable) {
try {
Files.deleteIfExists(executable);
} catch (IOException ignored) {
// The temporary file can be cleaned up by the operating system later.
}
}
private static void showError(Exception exception) {
JOptionPane.showMessageDialog(null, exception.getMessage(), "Dev Terminal Launcher", JOptionPane.ERROR_MESSAGE);
}
}